Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

21
LINES

< > BotCompany Repo | #1030563 // grabbableIntPixels_ComponentSampleModel - try to rip int[] pixels from a BufferedImage without copying [dev.]

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (2874L) is out of date.

static GrabbableIntPixels grabbableIntPixels_ComponentSampleModel(BufferedImage img) {
  if (img == null) null;
  
  Raster raster = img.getRaster();
  ComponentSampleModel sampleModel = cast raster.getSampleModel();
  DataBufferByte dataBuffer = cast raster.getDataBuffer();
  assertEquals(1, dataBuffer.getNumBanks());
  assertEquals(DataBuffer.TYPE_INT, dataBuffer.getDataType());

  // Let's at this point assume the raster data is what we
  // think it is... (TODO: test on unusual platforms)
  
  int w = img.getWidth(), h = img.getHeight();
  int scanlineStride = sampleModel.getScanlineStride();
  int[] pixels = dataBuffer.getData();
  int offset = dataBuffer.getOffset();
  int translateX = raster.getSampleModelTranslateX();
  int translateY = raster.getSampleModelTranslateY();
  offset += -translateX-translateY*scanlineStride;
  ret GrabbableIntPixels(pixels, w, h, offset, scanlineStride);
}

Author comment

Began life as a copy of #1030544

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1030563
Snippet name: grabbableIntPixels_ComponentSampleModel - try to rip int[] pixels from a BufferedImage without copying [dev.]
Eternal ID of this version: #1030563/3
Text MD5: 4e3c9c642748c31c177d093b86fd3e0e
Author: stefan
Category: javax / imaging
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-01-07 19:11:53
Source code size: 926 bytes / 21 lines
Pitched / IR pitched: No / No
Views / Downloads: 161 / 240
Version history: 2 change(s)
Referenced in: [show references]