void readTiled1 (const char fileName[], Array2D<GZ> &pixels, int &width, int &height) { TiledInputFile in (fileName); Box2i dw = in.header().dataWindow(); width = dw.max.x - dw.min.x + 1; height = dw.max.y - dw.min.y + 1; int dx = dw.min.x; int dy = dw.min.y; pixels.resizeErase (height, width); FrameBuffer frameBuffer; frameBuffer.insert ("G", // name Slice (HALF, // type (char *) &pixels[-dy][-dx].g, // base sizeof (pixels[0][0]) * 1, // xStride sizeof (pixels[0][0]) * width)); // yStride frameBuffer.insert ("Z", // name Slice (FLOAT, // type (char *) &pixels[-dy][-dx].z, // base sizeof (pixels[0][0]) * 1, // xStride sizeof (pixels[0][0]) * width)); // yStride in.setFrameBuffer (frameBuffer); in.readTiles (0, in.numXTiles() - 1, 0, in.numYTiles() - 1); }
TiledRgbaInputFile::FromYa::FromYa (TiledInputFile &inputFile) : _inputFile (inputFile) { const TileDescription &td = inputFile.header().tileDescription(); _tileXSize = td.xSize; _tileYSize = td.ySize; _yw = ywFromHeader (_inputFile.header()); _buf.resizeErase (_tileYSize, _tileXSize); _fbBase = 0; _fbXStride = 0; _fbYStride = 0; }
void TiledOutputFile::copyPixels (TiledInputFile &in) { Lock lock (*_streamData); // // Check if this file's and and the InputFile's // headers are compatible. // const Header &hdr = _data->header; const Header &inHdr = in.header(); if (!hdr.hasTileDescription() || !inHdr.hasTileDescription()) THROW (IEX_NAMESPACE::ArgExc, "Cannot perform a quick pixel copy from image " "file \"" << in.fileName() << "\" to image " "file \"" << fileName() << "\". The " "output file is tiled, but the input file is not. " "Try using OutputFile::copyPixels() instead."); if (!(hdr.tileDescription() == inHdr.tileDescription())) THROW (IEX_NAMESPACE::ArgExc, "Quick pixel copy from image " "file \"" << in.fileName() << "\" to image " "file \"" << fileName() << "\" failed. " "The files have different tile descriptions."); if (!(hdr.dataWindow() == inHdr.dataWindow())) THROW (IEX_NAMESPACE::ArgExc, "Cannot copy pixels from image " "file \"" << in.fileName() << "\" to image " "file \"" << fileName() << "\". The " "files have different data windows."); if (!(hdr.lineOrder() == inHdr.lineOrder())) THROW (IEX_NAMESPACE::ArgExc, "Quick pixel copy from image " "file \"" << in.fileName() << "\" to image " "file \"" << fileName() << "\" failed. " "The files have different line orders."); if (!(hdr.compression() == inHdr.compression())) THROW (IEX_NAMESPACE::ArgExc, "Quick pixel copy from image " "file \"" << in.fileName() << "\" to image " "file \"" << fileName() << "\" failed. " "The files use different compression methods."); if (!(hdr.channels() == inHdr.channels())) THROW (IEX_NAMESPACE::ArgExc, "Quick pixel copy from image " "file \"" << in.fileName() << "\" to image " "file \"" << fileName() << "\" " "failed. The files have different channel " "lists."); // // Verify that no pixel data have been written to this file yet. // if (!_data->tileOffsets.isEmpty()) THROW (IEX_NAMESPACE::LogicExc, "Quick pixel copy from image " "file \"" << in.fileName() << "\" to image " "file \"" << _streamData->os->fileName() << "\" " "failed. \"" << fileName() << "\" " "already contains pixel data."); // // Calculate the total number of tiles in the file // int numAllTiles = 0; switch (levelMode ()) { case ONE_LEVEL: case MIPMAP_LEVELS: for (int i_l = 0; i_l < numLevels (); ++i_l) numAllTiles += numXTiles (i_l) * numYTiles (i_l); break; case RIPMAP_LEVELS: for (int i_ly = 0; i_ly < numYLevels (); ++i_ly) for (int i_lx = 0; i_lx < numXLevels (); ++i_lx) numAllTiles += numXTiles (i_lx) * numYTiles (i_ly); break; default: throw IEX_NAMESPACE::ArgExc ("Unknown LevelMode format."); } bool random_y = _data->lineOrder==RANDOM_Y; std::vector<int> dx_table(random_y ? numAllTiles : 1); std::vector<int> dy_table(random_y ? numAllTiles : 1); std::vector<int> lx_table(random_y ? numAllTiles : 1); std::vector<int> ly_table(random_y ? numAllTiles : 1); if(random_y) { in.tileOrder(&dx_table[0],&dy_table[0],&lx_table[0],&ly_table[0]); _data->nextTileToWrite.dx=dx_table[0]; _data->nextTileToWrite.dy=dy_table[0]; _data->nextTileToWrite.lx=lx_table[0]; _data->nextTileToWrite.ly=ly_table[0]; } for (int i = 0; i < numAllTiles; ++i) { const char *pixelData; int pixelDataSize; int dx = _data->nextTileToWrite.dx; int dy = _data->nextTileToWrite.dy; int lx = _data->nextTileToWrite.lx; int ly = _data->nextTileToWrite.ly; in.rawTileData (dx, dy, lx, ly, pixelData, pixelDataSize); writeTileData (_streamData, _data, dx, dy, lx, ly, pixelData, pixelDataSize); if(random_y) { if(i<numAllTiles-1) { _data->nextTileToWrite.dx=dx_table[i+1]; _data->nextTileToWrite.dy=dy_table[i+1]; _data->nextTileToWrite.lx=lx_table[i+1]; _data->nextTileToWrite.ly=ly_table[i+1]; } }else{ _data->nextTileToWrite=_data->nextTileCoord(_data->nextTileToWrite); } } }