WriteTile() public method

Encodes and writes a tile of data to an open TIFF file/stream.

The tile to place encoded data is selected by the (x, y, z, plane) coordinates (i.e. WriteTile writes data to the tile containing the specified coordinates. WriteTile (potentially) encodes the data buffer and writes it to open file/stream. The buffer must contain 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 WriteTile. 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.

A correct value for the TiffTag.IMAGELENGTH tag must be setup before writing; WriteTile does not support automatically growing the image on each write (as O:BitMiracle.LibTiff.Classic.Tiff.WriteScanline does).

public WriteTile ( byte buffer, int offset, int x, int y, int z, short plane ) : int
buffer byte The buffer with image data to be encoded and written.
offset int The zero-based byte offset in at which /// to begin reading bytes to be encoded and written.
x int The x-coordinate of the pixel within a tile to be encoded and written.
y int The y-coordinate of the pixel within a tile to be encoded and written.
z int The z-coordinate of the pixel within a tile to be encoded and written.
plane short The zero-based index of the sample plane.
return int
示例#1
0
        bool writeBufferToSeparateTiles(Tiff outImage, byte[] buf, int imagelength, int imagewidth, short spp)
        {
            byte[] obuf = new byte[outImage.TileSize()];

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

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

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

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

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

            int imagew = outImage.ScanlineSize();
            int tilew = outImage.TileRowSize();
            int iimagew = outImage.RasterScanlineSize();
            int iskew = iimagew - 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++)
                    {
                        /*
                         * Tile is clipped horizontally.  Calculate
                         * visible portion and skewing factors.
                         */
                        if (colb + tilew > imagew)
                        {
                            int width = imagew - colb;
                            int oskew = tilew - width;

                            cpContigBufToSeparateBuf(obuf, buf, bufp + (colb * spp) + s, nrow, width / bytes_per_sample, oskew, (oskew * spp) + iskew, spp, bytes_per_sample);
                        }
                        else
                            cpContigBufToSeparateBuf(obuf, buf, bufp + (colb * spp) + s, nrow, m_tilewidth, 0, iskew, spp, bytes_per_sample);

                        if (outImage.WriteTile(obuf, col, row, 0, s) < 0)
                        {
                            Tiff.Error(outImage.FileName(), "Error, can't write tile at {0} {1} sample {2}", col, row, s);
                            return false;
                        }
                    }

                    colb += tilew;
                }

                bufp += nrow * iimagew;
            }

            return true;
        }
示例#2
0
        bool writeBufferToContigTiles(Tiff outImage, byte[] buf, int imagelength, int imagewidth, short spp)
        {
            byte[] obuf = new byte[outImage.TileSize()];

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

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

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

            int bufp = 0;

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

                for (int col = 0; col < imagewidth; col += tw)
                {
                    /*
                     * Tile is clipped horizontally.  Calculate
                     * visible portion and skewing factors.
                     */
                    if (colb + tilew > imagew)
                    {
                        int width = imagew - colb;
                        int oskew = tilew - width;
                        cpStripToTile(obuf, 0, buf, bufp + colb, nrow, width, oskew, oskew + iskew);
                    }
                    else
                        cpStripToTile(obuf, 0, buf, bufp + colb, nrow, tilew, 0, iskew);

                    if (outImage.WriteTile(obuf, col, row, 0, 0) < 0)
                    {
                        Tiff.Error(outImage.FileName(), "Error, can't write tile at {0} {1}", col, row);
                        return false;
                    }

                    colb += tilew;
                }

                bufp += nrow * imagew;
            }

            return true;
        }