// Encode the supplied data and write it to the // specified tile. There must be space for the // data. The function clamps individual writes // to a tile to the tile size, but does not (and // can not) check that multiple writes to the same // tile do not write more than tile size data. // // NB: Image length must be setup before writing; this // interface does not support automatically growing // the image on each write (as TIFFWriteScanline does). public static int TIFFWriteEncodedTile(TIFF tif, uint tile, byte[] data, int cc) { string module="TIFFWriteEncodedTile"; ushort sample; if(!((tif.tif_flags&TIF_FLAGS.TIFF_BEENWRITING)!=0||TIFFWriteCheck(tif, true, module))) return -1; TIFFDirectory td=tif.tif_dir; if(tile>=td.td_nstrips) { TIFFErrorExt(tif.tif_clientdata, module, "{0}: Tile {1} out of range, max {2}", tif.tif_name, tile, td.td_nstrips); return -1; } // Handle delayed allocation of data buffer. This // permits it to be sized more intelligently (using // directory information). if(!BUFFERCHECK(tif)) return -1; tif.tif_curtile=tile; tif.tif_rawcc=0; tif.tif_rawcp=0;; if(td.td_stripbytecount[tile]>0) { // if we are writing over existing tiles, zero length. td.td_stripbytecount[tile]=0; // this forces TIFFAppendToStrip() to do a seek. tif.tif_curoff=0; } // Compute tiles per row & per column to compute // current row and column tif.tif_row=(tile%TIFFhowmany(td.td_imagelength, td.td_tilelength))*td.td_tilelength; tif.tif_col=(tile%TIFFhowmany(td.td_imagewidth, td.td_tilewidth))*td.td_tilewidth; if((tif.tif_flags&TIF_FLAGS.TIFF_CODERSETUP)==0) { if(!tif.tif_setupencode(tif)) return -1; tif.tif_flags|=TIF_FLAGS.TIFF_CODERSETUP; } tif.tif_flags&=~TIF_FLAGS.TIFF_POSTENCODE; sample=(ushort)(tile/td.td_stripsperimage); if(!tif.tif_preencode(tif, sample)) return -1; // Clamp write amount to the tile size. This is mostly // done so that callers can pass in some large number // (e.g. -1) and have the tile size used instead. if(cc<1||cc>tif.tif_tilesize) cc=tif.tif_tilesize; // swab if needed - note that source buffer will be altered tif.tif_postdecode(tif, data, 0, cc); if(!tif.tif_encodetile(tif, data, cc, sample)) return 0; if(!tif.tif_postencode(tif)) return -1; if(!isFillOrder(tif, td.td_fillorder)&&(tif.tif_flags&TIF_FLAGS.TIFF_NOBITREV)==0) TIFFReverseBits(tif.tif_rawdata, tif.tif_rawcc); if(tif.tif_rawcc>0&&!TIFFAppendToStrip(tif, tile, tif.tif_rawdata, tif.tif_rawcc)) return -1; tif.tif_rawcc=0; tif.tif_rawcp=0; return cc; }
// Encode the supplied data and write it to the // specified tile. There must be space for the // data. The function clamps individual writes // to a tile to the tile size, but does not (and // can not) check that multiple writes to the same // tile do not write more than tile size data. // // NB: Image length must be setup before writing; this // interface does not support automatically growing // the image on each write (as TIFFWriteScanline does). public static int TIFFWriteEncodedTile(TIFF tif, uint tile, byte[] data, int cc) { string module = "TIFFWriteEncodedTile"; ushort sample; if (!((tif.tif_flags & TIF_FLAGS.TIFF_BEENWRITING) != 0 || TIFFWriteCheck(tif, true, module))) { return(-1); } TIFFDirectory td = tif.tif_dir; if (tile >= td.td_nstrips) { TIFFErrorExt(tif.tif_clientdata, module, "{0}: Tile {1} out of range, max {2}", tif.tif_name, tile, td.td_nstrips); return(-1); } // Handle delayed allocation of data buffer. This // permits it to be sized more intelligently (using // directory information). if (!BUFFERCHECK(tif)) { return(-1); } tif.tif_curtile = tile; tif.tif_rawcc = 0; tif.tif_rawcp = 0;; if (td.td_stripbytecount[tile] > 0) { // if we are writing over existing tiles, zero length. td.td_stripbytecount[tile] = 0; // this forces TIFFAppendToStrip() to do a seek. tif.tif_curoff = 0; } // Compute tiles per row & per column to compute // current row and column tif.tif_row = (tile % TIFFhowmany(td.td_imagelength, td.td_tilelength)) * td.td_tilelength; tif.tif_col = (tile % TIFFhowmany(td.td_imagewidth, td.td_tilewidth)) * td.td_tilewidth; if ((tif.tif_flags & TIF_FLAGS.TIFF_CODERSETUP) == 0) { if (!tif.tif_setupencode(tif)) { return(-1); } tif.tif_flags |= TIF_FLAGS.TIFF_CODERSETUP; } tif.tif_flags &= ~TIF_FLAGS.TIFF_POSTENCODE; sample = (ushort)(tile / td.td_stripsperimage); if (!tif.tif_preencode(tif, sample)) { return(-1); } // Clamp write amount to the tile size. This is mostly // done so that callers can pass in some large number // (e.g. -1) and have the tile size used instead. if (cc < 1 || cc > tif.tif_tilesize) { cc = tif.tif_tilesize; } // swab if needed - note that source buffer will be altered tif.tif_postdecode(tif, data, 0, cc); if (!tif.tif_encodetile(tif, data, cc, sample)) { return(0); } if (!tif.tif_postencode(tif)) { return(-1); } if (!isFillOrder(tif, td.td_fillorder) && (tif.tif_flags & TIF_FLAGS.TIFF_NOBITREV) == 0) { TIFFReverseBits(tif.tif_rawdata, tif.tif_rawcc); } if (tif.tif_rawcc > 0 && !TIFFAppendToStrip(tif, tile, tif.tif_rawdata, tif.tif_rawcc)) { return(-1); } tif.tif_rawcc = 0; tif.tif_rawcp = 0; return(cc); }