ReadTile() 공개 메소드

Reads and decodes a tile of data from an open TIFF file/stream.

The tile to read and decode is selected by the (x, y, z, plane) coordinates (i.e. ReadTile returns the data for the tile containing the specified coordinates. The data placed in buffer are returned decompressed and, typically, in the native byte- and bit-ordering, but are otherwise packed (see further below). The buffer must be large enough to hold an entire tile of data. Applications should call the TileSize to find out the size (in bytes) of a tile buffer. The x and y parameters are always used by ReadTile. The z parameter is used if the image is deeper than 1 slice (a value of TiffTag.IMAGEDEPTH > 1). In other cases the value of z is ignored. The plane parameter is used only if data are organized in separate planes (TiffTag.PLANARCONFIG = PlanarConfig.SEPARATE). In other cases the value of plane is ignored.

The library attempts to hide bit- and byte-ordering differences between the image and the native machine by converting data to the native machine order. Bit reversal is done if the value of TiffTag.FILLORDER tag is opposite to the native machine bit order. 16- and 32-bit samples are automatically byte-swapped if the file was written with a byte order opposite to the native machine byte order.

public ReadTile ( byte buffer, int offset, int x, int y, int z, short plane ) : int
buffer byte The buffer to place read and decoded image data to.
offset int The zero-based byte offset in at which /// to begin storing read and decoded bytes.
x int The x-coordinate of the pixel within a tile to be read and decoded.
y int The y-coordinate of the pixel within a tile to be read and decoded.
z int The z-coordinate of the pixel within a tile to be read and decoded.
plane short The zero-based index of the sample plane.
리턴 int
예제 #1
0
        bool readSeparateTilesIntoBuffer(Tiff inImage, byte[] buf, int imagelength, int imagewidth, short spp)
        {
            byte[] tilebuf = new byte[inImage.TileSize()];

            FieldValue[] result = inImage.GetField(TiffTag.TILEWIDTH);
            int tw = result[0].ToInt();

            result = inImage.GetField(TiffTag.TILELENGTH);
            int tl = result[0].ToInt();

            result = inImage.GetField(TiffTag.BITSPERSAMPLE);
            short bps = result[0].ToShort();

            Debug.Assert(bps % 8 == 0);

            short bytes_per_sample = (short)(bps / 8);

            int imagew = inImage.RasterScanlineSize();
            int tilew = inImage.TileRowSize();
            int iskew = imagew - tilew * spp;

            int bufp = 0;

            for (int row = 0; row < imagelength; row += tl)
            {
                int nrow = (row + tl > imagelength) ? imagelength - row : tl;
                int colb = 0;

                for (int col = 0; col < imagewidth; col += tw)
                {
                    for (short s = 0; s < spp; s++)
                    {
                        if (inImage.ReadTile(tilebuf, 0, col, row, 0, s) < 0 && !m_ignore)
                        {
                            Tiff.Error(inImage.FileName(), "Error, can't read tile at {0} {1}, sample {2}", col, row, s);
                            return false;
                        }

                        /*
                         * Tile is clipped horizontally.  Calculate
                         * visible portion and skewing factors.
                         */
                        if (colb + tilew * spp > imagew)
                        {
                            int width = imagew - colb;
                            int oskew = tilew * spp - width;
                            cpSeparateBufToContigBuf(buf, bufp + colb + s * bytes_per_sample, tilebuf, nrow, width / (spp * bytes_per_sample), oskew + iskew, oskew / spp, spp, bytes_per_sample);
                        }
                        else
                            cpSeparateBufToContigBuf(buf, bufp + colb + s * bytes_per_sample, tilebuf, nrow, tw, iskew, 0, spp, bytes_per_sample);
                    }

                    colb += tilew * spp;
                }

                bufp += imagew * nrow;
            }

            return true;
        }
예제 #2
0
        bool readContigTilesIntoBuffer(Tiff inImage, byte[] buf, int imagelength, int imagewidth, short spp)
        {
            byte[] tilebuf = new byte[inImage.TileSize()];

            FieldValue[] result = inImage.GetField(TiffTag.TILEWIDTH);
            int tw = result[0].ToInt();

            result = inImage.GetField(TiffTag.TILELENGTH);
            int tl = result[0].ToInt();

            int imagew = inImage.ScanlineSize();
            int tilew = inImage.TileRowSize();
            int iskew = imagew - tilew;

            int bufp = 0;

            for (int row = 0; row < imagelength; row += tl)
            {
                int nrow = (row + tl > imagelength) ? imagelength - row : tl;
                int colb = 0;

                for (int col = 0; col < imagewidth; col += tw)
                {
                    if (inImage.ReadTile(tilebuf, 0, col, row, 0, 0) < 0 && !m_ignore)
                    {
                        Tiff.Error(inImage.FileName(), "Error, can't read tile at {0} {1}", col, row);
                        return false;
                    }

                    if (colb + tilew > imagew)
                    {
                        int width = imagew - colb;
                        int oskew = tilew - width;
                        cpStripToTile(buf, bufp + colb, tilebuf, 0, nrow, width, oskew + iskew, oskew);
                    }
                    else
                        cpStripToTile(buf, bufp + colb, tilebuf, 0, nrow, tilew, iskew, 0);

                    colb += tilew;
                }

                bufp += imagew * nrow;
            }

            return true;
        }