Lines Matching refs:tif

35 #define WRITECHECKSTRIPS(tif, module)				\  argument
36 (((tif)->tif_flags&TIFF_BEENWRITING) || TIFFWriteCheck((tif),0,module))
37 #define WRITECHECKTILES(tif, module) \ argument
38 (((tif)->tif_flags&TIFF_BEENWRITING) || TIFFWriteCheck((tif),1,module))
39 #define BUFFERCHECK(tif) \ argument
40 ((((tif)->tif_flags & TIFF_BUFFERSETUP) && tif->tif_rawdata) || \
41 TIFFWriteBufferSetup((tif), NULL, (tmsize_t) -1))
43 static int TIFFGrowStrips(TIFF* tif, uint32_t delta, const char* module);
44 static int TIFFAppendToStrip(TIFF* tif, uint32_t strip, uint8_t* data, tmsize_t cc);
47 TIFFWriteScanline(TIFF* tif, void* buf, uint32_t row, uint16_t sample) in TIFFWriteScanline() argument
54 if (!WRITECHECKSTRIPS(tif, module)) in TIFFWriteScanline()
61 if (!BUFFERCHECK(tif)) in TIFFWriteScanline()
63 tif->tif_flags |= TIFF_BUF4WRITE; /* not strictly sure this is right*/ in TIFFWriteScanline()
65 td = &tif->tif_dir; in TIFFWriteScanline()
72 TIFFErrorExt(tif->tif_clientdata, module, in TIFFWriteScanline()
84 TIFFErrorExt(tif->tif_clientdata, module, in TIFFWriteScanline()
99 if (strip >= td->td_nstrips && !TIFFGrowStrips(tif, 1, module)) in TIFFWriteScanline()
101 if (strip != tif->tif_curstrip) { in TIFFWriteScanline()
105 if (!TIFFFlushData(tif)) in TIFFWriteScanline()
107 tif->tif_curstrip = strip; in TIFFWriteScanline()
117 TIFFErrorExt(tif->tif_clientdata, module, "Zero strips per image"); in TIFFWriteScanline()
120 tif->tif_row = in TIFFWriteScanline()
122 if ((tif->tif_flags & TIFF_CODERSETUP) == 0) { in TIFFWriteScanline()
123 if (!(*tif->tif_setupencode)(tif)) in TIFFWriteScanline()
125 tif->tif_flags |= TIFF_CODERSETUP; in TIFFWriteScanline()
128 tif->tif_rawcc = 0; in TIFFWriteScanline()
129 tif->tif_rawcp = tif->tif_rawdata; in TIFFWriteScanline()
137 tif->tif_curoff = 0; in TIFFWriteScanline()
140 if (!(*tif->tif_preencode)(tif, sample)) in TIFFWriteScanline()
142 tif->tif_flags |= TIFF_POSTENCODE; in TIFFWriteScanline()
149 if (row != tif->tif_row) { in TIFFWriteScanline()
150 if (row < tif->tif_row) { in TIFFWriteScanline()
156 tif->tif_row = (strip % td->td_stripsperimage) * in TIFFWriteScanline()
158 tif->tif_rawcp = tif->tif_rawdata; in TIFFWriteScanline()
163 if (!(*tif->tif_seek)(tif, row - tif->tif_row)) in TIFFWriteScanline()
165 tif->tif_row = row; in TIFFWriteScanline()
169 tif->tif_postdecode(tif, (uint8_t*) buf, tif->tif_scanlinesize ); in TIFFWriteScanline()
171 status = (*tif->tif_encoderow)(tif, (uint8_t*) buf, in TIFFWriteScanline()
172 tif->tif_scanlinesize, sample); in TIFFWriteScanline()
175 tif->tif_row = row + 1; in TIFFWriteScanline()
183 static int _TIFFReserveLargeEnoughWriteBuffer(TIFF* tif, uint32_t strip_or_tile) in _TIFFReserveLargeEnoughWriteBuffer() argument
185 TIFFDirectory *td = &tif->tif_dir; in _TIFFReserveLargeEnoughWriteBuffer()
191 if( tif->tif_rawdatasize <= (tmsize_t)safe_buffer_size ) in _TIFFReserveLargeEnoughWriteBuffer()
193 if( !(TIFFWriteBufferSetup(tif, NULL, in _TIFFReserveLargeEnoughWriteBuffer()
200 tif->tif_curoff = 0; in _TIFFReserveLargeEnoughWriteBuffer()
212 TIFFWriteEncodedStrip(TIFF* tif, uint32_t strip, void* data, tmsize_t cc) in TIFFWriteEncodedStrip() argument
215 TIFFDirectory *td = &tif->tif_dir; in TIFFWriteEncodedStrip()
218 if (!WRITECHECKSTRIPS(tif, module)) in TIFFWriteEncodedStrip()
231 TIFFErrorExt(tif->tif_clientdata, module, in TIFFWriteEncodedStrip()
235 if (!TIFFGrowStrips(tif, 1, module)) in TIFFWriteEncodedStrip()
245 if (!BUFFERCHECK(tif)) in TIFFWriteEncodedStrip()
248 tif->tif_flags |= TIFF_BUF4WRITE; in TIFFWriteEncodedStrip()
249 tif->tif_curstrip = strip; in TIFFWriteEncodedStrip()
251 if( !_TIFFReserveLargeEnoughWriteBuffer(tif, strip) ) { in TIFFWriteEncodedStrip()
255 tif->tif_rawcc = 0; in TIFFWriteEncodedStrip()
256 tif->tif_rawcp = tif->tif_rawdata; in TIFFWriteEncodedStrip()
259 TIFFErrorExt(tif->tif_clientdata, module, "Zero strips per image"); in TIFFWriteEncodedStrip()
263 tif->tif_row = (strip % td->td_stripsperimage) * td->td_rowsperstrip; in TIFFWriteEncodedStrip()
264 if ((tif->tif_flags & TIFF_CODERSETUP) == 0) { in TIFFWriteEncodedStrip()
265 if (!(*tif->tif_setupencode)(tif)) in TIFFWriteEncodedStrip()
267 tif->tif_flags |= TIFF_CODERSETUP; in TIFFWriteEncodedStrip()
270 tif->tif_flags &= ~TIFF_POSTENCODE; in TIFFWriteEncodedStrip()
276 tif->tif_postdecode(tif, (uint8_t*) data, cc ); in TIFFWriteEncodedStrip()
278 if (!isFillOrder(tif, td->td_fillorder) && in TIFFWriteEncodedStrip()
279 (tif->tif_flags & TIFF_NOBITREV) == 0) in TIFFWriteEncodedStrip()
283 !TIFFAppendToStrip(tif, strip, (uint8_t*) data, cc)) in TIFFWriteEncodedStrip()
289 if (!(*tif->tif_preencode)(tif, sample)) in TIFFWriteEncodedStrip()
293 tif->tif_postdecode(tif, (uint8_t*) data, cc ); in TIFFWriteEncodedStrip()
295 if (!(*tif->tif_encodestrip)(tif, (uint8_t*) data, cc, sample)) in TIFFWriteEncodedStrip()
297 if (!(*tif->tif_postencode)(tif)) in TIFFWriteEncodedStrip()
299 if (!isFillOrder(tif, td->td_fillorder) && in TIFFWriteEncodedStrip()
300 (tif->tif_flags & TIFF_NOBITREV) == 0) in TIFFWriteEncodedStrip()
301 TIFFReverseBits(tif->tif_rawdata, tif->tif_rawcc); in TIFFWriteEncodedStrip()
302 if (tif->tif_rawcc > 0 && in TIFFWriteEncodedStrip()
303 !TIFFAppendToStrip(tif, strip, tif->tif_rawdata, tif->tif_rawcc)) in TIFFWriteEncodedStrip()
305 tif->tif_rawcc = 0; in TIFFWriteEncodedStrip()
306 tif->tif_rawcp = tif->tif_rawdata; in TIFFWriteEncodedStrip()
316 TIFFWriteRawStrip(TIFF* tif, uint32_t strip, void* data, tmsize_t cc) in TIFFWriteRawStrip() argument
319 TIFFDirectory *td = &tif->tif_dir; in TIFFWriteRawStrip()
321 if (!WRITECHECKSTRIPS(tif, module)) in TIFFWriteRawStrip()
334 TIFFErrorExt(tif->tif_clientdata, module, in TIFFWriteRawStrip()
346 if (!TIFFGrowStrips(tif, 1, module)) in TIFFWriteRawStrip()
349 tif->tif_curstrip = strip; in TIFFWriteRawStrip()
351 TIFFErrorExt(tif->tif_clientdata, module,"Zero strips per image"); in TIFFWriteRawStrip()
354 tif->tif_row = (strip % td->td_stripsperimage) * td->td_rowsperstrip; in TIFFWriteRawStrip()
355 return (TIFFAppendToStrip(tif, strip, (uint8_t*) data, cc) ? in TIFFWriteRawStrip()
364 TIFFWriteTile(TIFF* tif, void* buf, uint32_t x, uint32_t y, uint32_t z, uint16_t s) in TIFFWriteTile() argument
366 if (!TIFFCheckTile(tif, x, y, z, s)) in TIFFWriteTile()
374 return (TIFFWriteEncodedTile(tif, in TIFFWriteTile()
375 TIFFComputeTile(tif, x, y, z, s), buf, (tmsize_t)(-1))); in TIFFWriteTile()
391 TIFFWriteEncodedTile(TIFF* tif, uint32_t tile, void* data, tmsize_t cc) in TIFFWriteEncodedTile() argument
398 if (!WRITECHECKTILES(tif, module)) in TIFFWriteEncodedTile()
400 td = &tif->tif_dir; in TIFFWriteEncodedTile()
402 TIFFErrorExt(tif->tif_clientdata, module, "Tile %lu out of range, max %lu", in TIFFWriteEncodedTile()
411 if (!BUFFERCHECK(tif)) in TIFFWriteEncodedTile()
414 tif->tif_flags |= TIFF_BUF4WRITE; in TIFFWriteEncodedTile()
415 tif->tif_curtile = tile; in TIFFWriteEncodedTile()
417 if( !_TIFFReserveLargeEnoughWriteBuffer(tif, tile) ) { in TIFFWriteEncodedTile()
421 tif->tif_rawcc = 0; in TIFFWriteEncodedTile()
422 tif->tif_rawcp = tif->tif_rawdata; in TIFFWriteEncodedTile()
430 TIFFErrorExt(tif->tif_clientdata,module,"Zero tiles"); in TIFFWriteEncodedTile()
433 tif->tif_row = (tile % howmany32) * td->td_tilelength; in TIFFWriteEncodedTile()
436 TIFFErrorExt(tif->tif_clientdata,module,"Zero tiles"); in TIFFWriteEncodedTile()
439 tif->tif_col = (tile % howmany32) * td->td_tilewidth; in TIFFWriteEncodedTile()
441 if ((tif->tif_flags & TIFF_CODERSETUP) == 0) { in TIFFWriteEncodedTile()
442 if (!(*tif->tif_setupencode)(tif)) in TIFFWriteEncodedTile()
444 tif->tif_flags |= TIFF_CODERSETUP; in TIFFWriteEncodedTile()
446 tif->tif_flags &= ~TIFF_POSTENCODE; in TIFFWriteEncodedTile()
453 if ( cc < 1 || cc > tif->tif_tilesize) in TIFFWriteEncodedTile()
454 cc = tif->tif_tilesize; in TIFFWriteEncodedTile()
460 tif->tif_postdecode(tif, (uint8_t*) data, cc ); in TIFFWriteEncodedTile()
462 if (!isFillOrder(tif, td->td_fillorder) && in TIFFWriteEncodedTile()
463 (tif->tif_flags & TIFF_NOBITREV) == 0) in TIFFWriteEncodedTile()
467 !TIFFAppendToStrip(tif, tile, (uint8_t*) data, cc)) in TIFFWriteEncodedTile()
473 if (!(*tif->tif_preencode)(tif, sample)) in TIFFWriteEncodedTile()
476 tif->tif_postdecode(tif, (uint8_t*) data, cc ); in TIFFWriteEncodedTile()
478 if (!(*tif->tif_encodetile)(tif, (uint8_t*) data, cc, sample)) in TIFFWriteEncodedTile()
480 if (!(*tif->tif_postencode)(tif)) in TIFFWriteEncodedTile()
482 if (!isFillOrder(tif, td->td_fillorder) && in TIFFWriteEncodedTile()
483 (tif->tif_flags & TIFF_NOBITREV) == 0) in TIFFWriteEncodedTile()
484 TIFFReverseBits((uint8_t*)tif->tif_rawdata, tif->tif_rawcc); in TIFFWriteEncodedTile()
485 if (tif->tif_rawcc > 0 && !TIFFAppendToStrip(tif, tile, in TIFFWriteEncodedTile()
486 tif->tif_rawdata, tif->tif_rawcc)) in TIFFWriteEncodedTile()
488 tif->tif_rawcc = 0; in TIFFWriteEncodedTile()
489 tif->tif_rawcp = tif->tif_rawdata; in TIFFWriteEncodedTile()
503 TIFFWriteRawTile(TIFF* tif, uint32_t tile, void* data, tmsize_t cc) in TIFFWriteRawTile() argument
507 if (!WRITECHECKTILES(tif, module)) in TIFFWriteRawTile()
509 if (tile >= tif->tif_dir.td_nstrips) { in TIFFWriteRawTile()
510 TIFFErrorExt(tif->tif_clientdata, module, "Tile %lu out of range, max %lu", in TIFFWriteRawTile()
512 (unsigned long) tif->tif_dir.td_nstrips); in TIFFWriteRawTile()
515 return (TIFFAppendToStrip(tif, tile, (uint8_t*) data, cc) ? in TIFFWriteRawTile()
519 #define isUnspecified(tif, f) \ argument
520 (TIFFFieldSet(tif,f) && (tif)->tif_dir.td_imagelength == 0)
523 TIFFSetupStrips(TIFF* tif) in TIFFSetupStrips() argument
525 TIFFDirectory* td = &tif->tif_dir; in TIFFSetupStrips()
527 if (isTiled(tif)) in TIFFSetupStrips()
529 isUnspecified(tif, FIELD_TILEDIMENSIONS) ? in TIFFSetupStrips()
530 td->td_samplesperpixel : TIFFNumberOfTiles(tif); in TIFFSetupStrips()
533 isUnspecified(tif, FIELD_ROWSPERSTRIP) ? in TIFFSetupStrips()
534 td->td_samplesperpixel : TIFFNumberOfStrips(tif); in TIFFSetupStrips()
537 if( td->td_nstrips >= 0x80000000U / ((tif->tif_flags&TIFF_BIGTIFF)?0x8U:0x4U) ) in TIFFSetupStrips()
539 TIFFErrorExt(tif->tif_clientdata, "TIFFSetupStrips", in TIFFSetupStrips()
546 _TIFFCheckMalloc(tif, td->td_nstrips, sizeof (uint64_t), in TIFFSetupStrips()
549 _TIFFCheckMalloc(tif, td->td_nstrips, sizeof (uint64_t), in TIFFSetupStrips()
559 TIFFSetFieldBit(tif, FIELD_STRIPOFFSETS); in TIFFSetupStrips()
560 TIFFSetFieldBit(tif, FIELD_STRIPBYTECOUNTS); in TIFFSetupStrips()
572 TIFFWriteCheck(TIFF* tif, int tiles, const char* module) in TIFFWriteCheck() argument
574 if (tif->tif_mode == O_RDONLY) { in TIFFWriteCheck()
575 TIFFErrorExt(tif->tif_clientdata, module, "File not open for writing"); in TIFFWriteCheck()
578 if (tiles ^ isTiled(tif)) { in TIFFWriteCheck()
579 TIFFErrorExt(tif->tif_clientdata, module, tiles ? in TIFFWriteCheck()
585 _TIFFFillStriles( tif ); in TIFFWriteCheck()
597 if (!TIFFFieldSet(tif, FIELD_IMAGEDIMENSIONS)) { in TIFFWriteCheck()
598 TIFFErrorExt(tif->tif_clientdata, module, in TIFFWriteCheck()
602 if (tif->tif_dir.td_samplesperpixel == 1) { in TIFFWriteCheck()
609 if (!TIFFFieldSet(tif, FIELD_PLANARCONFIG)) in TIFFWriteCheck()
610 tif->tif_dir.td_planarconfig = PLANARCONFIG_CONTIG; in TIFFWriteCheck()
612 if (!TIFFFieldSet(tif, FIELD_PLANARCONFIG)) { in TIFFWriteCheck()
613 TIFFErrorExt(tif->tif_clientdata, module, in TIFFWriteCheck()
618 if (tif->tif_dir.td_stripoffset_p == NULL && !TIFFSetupStrips(tif)) { in TIFFWriteCheck()
619 tif->tif_dir.td_nstrips = 0; in TIFFWriteCheck()
620 TIFFErrorExt(tif->tif_clientdata, module, "No space for %s arrays", in TIFFWriteCheck()
621 isTiled(tif) ? "tile" : "strip"); in TIFFWriteCheck()
624 if (isTiled(tif)) in TIFFWriteCheck()
626 tif->tif_tilesize = TIFFTileSize(tif); in TIFFWriteCheck()
627 if (tif->tif_tilesize == 0) in TIFFWriteCheck()
631 tif->tif_tilesize = (tmsize_t)(-1); in TIFFWriteCheck()
632 tif->tif_scanlinesize = TIFFScanlineSize(tif); in TIFFWriteCheck()
633 if (tif->tif_scanlinesize == 0) in TIFFWriteCheck()
635 tif->tif_flags |= TIFF_BEENWRITING; in TIFFWriteCheck()
637 if( tif->tif_dir.td_stripoffset_entry.tdir_tag != 0 && in TIFFWriteCheck()
638 tif->tif_dir.td_stripoffset_entry.tdir_count == 0 && in TIFFWriteCheck()
639 tif->tif_dir.td_stripoffset_entry.tdir_type == 0 && in TIFFWriteCheck()
640 tif->tif_dir.td_stripoffset_entry.tdir_offset.toff_long8 == 0 && in TIFFWriteCheck()
641 tif->tif_dir.td_stripbytecount_entry.tdir_tag != 0 && in TIFFWriteCheck()
642 tif->tif_dir.td_stripbytecount_entry.tdir_count == 0 && in TIFFWriteCheck()
643 tif->tif_dir.td_stripbytecount_entry.tdir_type == 0 && in TIFFWriteCheck()
644 tif->tif_dir.td_stripbytecount_entry.tdir_offset.toff_long8 == 0 && in TIFFWriteCheck()
645 !(tif->tif_flags & TIFF_DIRTYDIRECT) ) in TIFFWriteCheck()
647 TIFFForceStrileArrayWriting(tif); in TIFFWriteCheck()
657 TIFFWriteBufferSetup(TIFF* tif, void* bp, tmsize_t size) in TIFFWriteBufferSetup() argument
661 if (tif->tif_rawdata) { in TIFFWriteBufferSetup()
662 if (tif->tif_flags & TIFF_MYBUFFER) { in TIFFWriteBufferSetup()
663 _TIFFfree(tif->tif_rawdata); in TIFFWriteBufferSetup()
664 tif->tif_flags &= ~TIFF_MYBUFFER; in TIFFWriteBufferSetup()
666 tif->tif_rawdata = NULL; in TIFFWriteBufferSetup()
669 size = (isTiled(tif) ? in TIFFWriteBufferSetup()
670 tif->tif_tilesize : TIFFStripSize(tif)); in TIFFWriteBufferSetup()
685 TIFFErrorExt(tif->tif_clientdata, module, "No space for output buffer"); in TIFFWriteBufferSetup()
688 tif->tif_flags |= TIFF_MYBUFFER; in TIFFWriteBufferSetup()
690 tif->tif_flags &= ~TIFF_MYBUFFER; in TIFFWriteBufferSetup()
691 tif->tif_rawdata = (uint8_t*) bp; in TIFFWriteBufferSetup()
692 tif->tif_rawdatasize = size; in TIFFWriteBufferSetup()
693 tif->tif_rawcc = 0; in TIFFWriteBufferSetup()
694 tif->tif_rawcp = tif->tif_rawdata; in TIFFWriteBufferSetup()
695 tif->tif_flags |= TIFF_BUFFERSETUP; in TIFFWriteBufferSetup()
703 TIFFGrowStrips(TIFF* tif, uint32_t delta, const char* module) in TIFFGrowStrips() argument
705 TIFFDirectory *td = &tif->tif_dir; in TIFFGrowStrips()
720 TIFFErrorExt(tif->tif_clientdata, module, "No space to expand strip arrays"); in TIFFGrowStrips()
730 tif->tif_flags |= TIFF_DIRTYDIRECT; in TIFFGrowStrips()
739 TIFFAppendToStrip(TIFF* tif, uint32_t strip, uint8_t* data, tmsize_t cc) in TIFFAppendToStrip() argument
742 TIFFDirectory *td = &tif->tif_dir; in TIFFAppendToStrip()
746 if (td->td_stripoffset_p[strip] == 0 || tif->tif_curoff == 0) { in TIFFAppendToStrip()
760 if (!SeekOK(tif, td->td_stripoffset_p[strip])) { in TIFFAppendToStrip()
761 TIFFErrorExt(tif->tif_clientdata, module, in TIFFAppendToStrip()
763 (unsigned long)tif->tif_row); in TIFFAppendToStrip()
773 td->td_stripoffset_p[strip] = TIFFSeekFile(tif, 0, SEEK_END); in TIFFAppendToStrip()
774 tif->tif_flags |= TIFF_DIRTYSTRIP; in TIFFAppendToStrip()
777 tif->tif_curoff = td->td_stripoffset_p[strip]; in TIFFAppendToStrip()
786 m = tif->tif_curoff+cc; in TIFFAppendToStrip()
787 if (!(tif->tif_flags&TIFF_BIGTIFF)) in TIFFAppendToStrip()
789 if ((m<tif->tif_curoff)||(m<(uint64_t)cc)) in TIFFAppendToStrip()
791 TIFFErrorExt(tif->tif_clientdata, module, "Maximum TIFF file size exceeded"); in TIFFAppendToStrip()
794 if (!WriteOK(tif, data, cc)) { in TIFFAppendToStrip()
795 TIFFErrorExt(tif->tif_clientdata, module, "Write error at scanline %lu", in TIFFAppendToStrip()
796 (unsigned long) tif->tif_row); in TIFFAppendToStrip()
799 tif->tif_curoff = m; in TIFFAppendToStrip()
803 tif->tif_flags |= TIFF_DIRTYSTRIP; in TIFFAppendToStrip()
814 TIFFFlushData1(TIFF* tif) in TIFFFlushData1() argument
816 if (tif->tif_rawcc > 0 && tif->tif_flags & TIFF_BUF4WRITE ) { in TIFFFlushData1()
817 if (!isFillOrder(tif, tif->tif_dir.td_fillorder) && in TIFFFlushData1()
818 (tif->tif_flags & TIFF_NOBITREV) == 0) in TIFFFlushData1()
819 TIFFReverseBits((uint8_t*)tif->tif_rawdata, in TIFFFlushData1()
820 tif->tif_rawcc); in TIFFFlushData1()
821 if (!TIFFAppendToStrip(tif, in TIFFFlushData1()
822 isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip, in TIFFFlushData1()
823 tif->tif_rawdata, tif->tif_rawcc)) in TIFFFlushData1()
828 tif->tif_rawcc = 0; in TIFFFlushData1()
829 tif->tif_rawcp = tif->tif_rawdata; in TIFFFlushData1()
832 tif->tif_rawcc = 0; in TIFFFlushData1()
833 tif->tif_rawcp = tif->tif_rawdata; in TIFFFlushData1()
845 TIFFSetWriteOffset(TIFF* tif, toff_t off) in TIFFSetWriteOffset() argument
847 tif->tif_curoff = off; in TIFFSetWriteOffset()