📄 imagecomponentretained.java
字号:
int minTileX = ri.getMinTileX(); // min tile x index int minTileY = ri.getMinTileY(); // min tile y index tilew = ri.getTileWidth(); // tile width in pixels tileh = ri.getTileHeight(); // tile height in pixels // determine the first tile of the image float mt; mt = (float)(srcX - xoff) / (float)tilew; if (mt < 0) { minTileX = (int)(mt - 1); } else { minTileX = (int)mt; } mt = (float)(srcY - yoff) / (float)tileh; if (mt < 0) { minTileY = (int)(mt - 1); } else { minTileY = (int)mt; } // determine the pixel offset of the upper-left corner of the // first tile int startXTile = minTileX * tilew + xoff; int startYTile = minTileY * tileh + yoff; // image dimension in the first tile int curw = (startXTile + tilew - srcX); int curh = (startYTile + tileh - srcY); // check if the to-be-copied region is less than the tile image // if so, update the to-be-copied dimension of this tile if (curw > copyWidth) { curw = copyWidth; } if (curh > copyHeight) { curh = copyHeight; } // save the to-be-copied width of the left most tile int startw = curw; // temporary variable for dimension of the to-be-copied region int tmpw = copyWidth; int tmph = copyHeight; // offset of the first pixel of the tile to be copied; offset is // relative to the upper left corner of the title int x = srcX - startXTile; int y = srcY - startYTile; // determine the number of tiles in each direction that the // image spans numXTiles = (copyWidth + x) / tilew; numYTiles = (copyHeight + y) / tileh; if (((float)(copyWidth + x ) % (float)tilew) > 0) { numXTiles += 1; } if (((float)(copyHeight + y ) % (float)tileh) > 0) { numYTiles += 1; } assert (data != null); int dataWidth = data.dataWidth; int dataHeight = data.dataHeight; int lineBytes = dataWidth * unitsPerPixel; // nbytes per line in if (yUp) { // destination buffer offset tileStart = (depthIndex * dataWidth * dataHeight + dstY * dataWidth + dstX) * unitsPerPixel; sign = 1; dstLineBytes = lineBytes; } else { // destination buffer offset tileStart = (depthIndex * dataWidth * dataHeight + (dataHeight - dstY - 1) * dataWidth + dstX) * unitsPerPixel; sign = -1; dstLineBytes = -lineBytes; } /* System.err.println("tileStart= " + tileStart + " dstLineBytes= " + dstLineBytes); System.err.println("startw= " + startw); */ // allocate memory for a pixel ras = ri.getTile(minTileX,minTileY); pixel = getDataElementBuffer(ras); byte[] dstBuffer = imageData.getAsByteArray(); switch(numberOfComponents) { case 4: { // System.err.println("Case 1: byReference = "+byReference); for (n = minTileY; n < minTileY+numYTiles; n++) { dstBegin = tileStart; // destination buffer offset tmpw = copyWidth; // reset the width to be copied curw = startw; // reset the width to be copied of // the left most tile x = srcX - startXTile; // reset the starting x offset of // the left most tile for (m = minTileX; m < minTileX+numXTiles; m++) { // retrieve the raster for the next tile ras = ri.getTile(m,n); j = dstBegin; offset = 0; //System.err.println("curh = "+curh+" curw = "+curw); //System.err.println("x = "+x+" y = "+y); for (h = y; h < (y + curh); h++) { // System.err.println("j = "+j); for (w = x; w < (x + curw); w++) { ras.getDataElements(w, h, pixel); dstBuffer[j++] = (byte)cm.getRed(pixel); dstBuffer[j++] = (byte)cm.getGreen(pixel); dstBuffer[j++] = (byte)cm.getBlue(pixel); dstBuffer[j++] = (byte)cm.getAlpha(pixel); } offset += dstLineBytes; j = dstBegin + offset; } // advance the destination buffer offset dstBegin += curw * unitsPerPixel; // move to the next tile in x direction x = 0; // determine the width of copy region of the next tile tmpw -= curw; if (tmpw < tilew) { curw = tmpw; } else { curw = tilew; } } // we are done copying an array of tiles in the x direction // advance the tileStart offset tileStart += dataWidth * unitsPerPixel * curh * sign; // move to the next set of tiles in y direction y = 0; // determine the height of copy region for the next set // of tiles tmph -= curh; if (tmph < tileh) { curh = tmph; } else { curh = tileh; } } } break; case 3: { for (n = minTileY; n < minTileY+numYTiles; n++) { dstBegin = tileStart; // destination buffer offset tmpw = copyWidth; // reset the width to be copied curw = startw; // reset the width to be copied of // the left most tile x = srcX - startXTile; // reset the starting x offset of // the left most tile for (m = minTileX; m < minTileX+numXTiles; m++) { // retrieve the raster for the next tile ras = ri.getTile(m,n); j = dstBegin; offset = 0; //System.err.println("curh = "+curh+" curw = "+curw); //System.err.println("x = "+x+" y = "+y); for (h = y; h < (y + curh); h++) { // System.err.println("j = "+j); for (w = x; w < (x + curw); w++) { ras.getDataElements(w, h, pixel); dstBuffer[j++] = (byte)cm.getRed(pixel); dstBuffer[j++] = (byte)cm.getGreen(pixel); dstBuffer[j++] = (byte)cm.getBlue(pixel); } offset += dstLineBytes; j = dstBegin + offset; } // advance the destination buffer offset dstBegin += curw * unitsPerPixel; // move to the next tile in x direction x = 0; // determine the width of copy region of the next tile tmpw -= curw; if (tmpw < tilew) { curw = tmpw; } else { curw = tilew; } } // we are done copying an array of tiles in the x direction // advance the tileStart offset tileStart += dataWidth * unitsPerPixel * curh * sign; // move to the next set of tiles in y direction y = 0; // determine the height of copy region for the next set // of tiles tmph -= curh; if (tmph < tileh) { curh = tmph; } else { curh = tileh; } } } break; case 2: { for (n = minTileY; n < minTileY+numYTiles; n++) { dstBegin = tileStart; // destination buffer offset tmpw = copyWidth; // reset the width to be copied curw = startw; // reset the width to be copied of // the left most tile x = srcX - startXTile; // reset the starting x offset of // the left most tile for (m = minTileX; m < minTileX+numXTiles; m++) { // retrieve the raster for the next tile ras = ri.getTile(m,n); j = dstBegin; offset = 0; //System.err.println("curh = "+curh+" curw = "+curw); //System.err.println("x = "+x+" y = "+y); for (h = y; h < (y + curh); h++) { // System.err.println("j = "+j); for (w = x; w < (x + curw); w++) { ras.getDataElements(w, h, pixel); dstBuffer[j++] = (byte)cm.getRed(pixel); dstBuffer[j++] = (byte)cm.getAlpha(pixel); } offset += dstLineBytes; j = dstBegin + offset; } // advance the destination buffer offset dstBegin += curw * unitsPerPixel; // move to the next tile in x direction x = 0; // determine the width of copy region of the next tile tmpw -= curw; if (tmpw < tilew) { curw = tmpw; } else { curw = tilew; } } // we are done copying an array of tiles in the x direction // advance the tileStart offset tileStart += dataWidth * unitsPerPixel * curh * sign; // move to the next set of tiles in y direction y = 0; // determine the height of copy region for the next set // of tiles tmph -= curh; if (tmph < tileh) { curh = tmph; } else { curh = tileh; } } } break; case 1: { for (n = minTileY; n < minTileY+numYTiles; n++) { dstBegin = tileStart; // destination buffer offset tmpw = copyWidth; // reset the width to be copied curw = startw; // reset the width to be copied of // the left most tile x = srcX - startXTile; // reset the starting x offset of // the left most tile for (m = minTileX; m < minTileX+numXTiles; m++) { // retrieve the raster for the next tile ras = ri.getTile(m,n); j = dstBegin; offset = 0; //System.err.println("curh = "+curh+" curw = "+curw); //System.err.println("x = "+x+" y = "+y); for (h = y; h < (y + curh); h++) { // System.err.println("j = "+j); for (w = x; w < (x + curw); w++) { ras.getDataElements(w, h, pixel); dstBuffer[j++] = (byte)cm.getRed(pixel); } offset += dstLineBytes; j = dstBegin + offset; } // advance the destination buffer offset
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -