| OLD | NEW |
| 1 /* $Id: tif_pixarlog.c,v 1.39 2012-12-10 17:27:13 tgl Exp $ */ | 1 /* $Id: tif_pixarlog.c,v 1.39 2012-12-10 17:27:13 tgl Exp $ */ |
| 2 | 2 |
| 3 /* | 3 /* |
| 4 * Copyright (c) 1996-1997 Sam Leffler | 4 * Copyright (c) 1996-1997 Sam Leffler |
| 5 * Copyright (c) 1996 Pixar | 5 * Copyright (c) 1996 Pixar |
| 6 * | 6 * |
| 7 * Permission to use, copy, modify, distribute, and sell this software and | 7 * Permission to use, copy, modify, distribute, and sell this software and |
| 8 * its documentation for any purpose is hereby granted without fee, provided | 8 * its documentation for any purpose is hereby granted without fee, provided |
| 9 * that (i) the above copyright notices and this permission notice appear in | 9 * that (i) the above copyright notices and this permission notice appear in |
| 10 * all copies of the software and related documentation, and (ii) the names of | 10 * all copies of the software and related documentation, and (ii) the names of |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 } | 450 } |
| 451 } | 451 } |
| 452 | 452 |
| 453 /* | 453 /* |
| 454 * State block for each open TIFF | 454 * State block for each open TIFF |
| 455 * file using PixarLog compression/decompression. | 455 * file using PixarLog compression/decompression. |
| 456 */ | 456 */ |
| 457 typedef struct { | 457 typedef struct { |
| 458 TIFFPredictorState predict; | 458 TIFFPredictorState predict; |
| 459 z_stream stream; | 459 z_stream stream; |
| 460 tmsize_t tbuf_size; /* only set/used on reading for now *
/ |
| 460 uint16 *tbuf; | 461 uint16 *tbuf; |
| 461 uint16 stride; | 462 uint16 stride; |
| 462 int state; | 463 int state; |
| 463 int user_datafmt; | 464 int user_datafmt; |
| 464 int quality; | 465 int quality; |
| 465 #define PLSTATE_INIT 1 | 466 #define PLSTATE_INIT 1 |
| 466 | 467 |
| 467 TIFFVSetMethod vgetparent; /* super-class method */ | 468 TIFFVSetMethod vgetparent; /* super-class method */ |
| 468 TIFFVSetMethod vsetparent; /* super-class method */ | 469 TIFFVSetMethod vsetparent; /* super-class method */ |
| 469 | 470 |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 td->td_samplesperpixel : 1); | 686 td->td_samplesperpixel : 1); |
| 686 tbuf_size = multiply_ms(multiply_ms(multiply_ms(sp->stride, td->td_image
width), | 687 tbuf_size = multiply_ms(multiply_ms(multiply_ms(sp->stride, td->td_image
width), |
| 687 td->td_rowsperstrip), sizeof(uint16)); | 688 td->td_rowsperstrip), sizeof(uint16)); |
| 688 /* add one more stride in case input ends mid-stride */ | 689 /* add one more stride in case input ends mid-stride */ |
| 689 tbuf_size = add_ms(tbuf_size, sizeof(uint16) * sp->stride); | 690 tbuf_size = add_ms(tbuf_size, sizeof(uint16) * sp->stride); |
| 690 if (tbuf_size == 0) | 691 if (tbuf_size == 0) |
| 691 return (0); /* TODO: this is an error return without error rep
ort through TIFFErrorExt */ | 692 return (0); /* TODO: this is an error return without error rep
ort through TIFFErrorExt */ |
| 692 sp->tbuf = (uint16 *) _TIFFmalloc(tbuf_size); | 693 sp->tbuf = (uint16 *) _TIFFmalloc(tbuf_size); |
| 693 if (sp->tbuf == NULL) | 694 if (sp->tbuf == NULL) |
| 694 return (0); | 695 return (0); |
| 696 sp->tbuf_size = tbuf_size; |
| 695 if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN) | 697 if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN) |
| 696 sp->user_datafmt = PixarLogGuessDataFmt(td); | 698 sp->user_datafmt = PixarLogGuessDataFmt(td); |
| 697 if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN) { | 699 if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN) { |
| 698 TIFFErrorExt(tif->tif_clientdata, module, | 700 TIFFErrorExt(tif->tif_clientdata, module, |
| 699 "PixarLog compression can't handle bits depth/data forma
t combination (depth: %d)", | 701 "PixarLog compression can't handle bits depth/data forma
t combination (depth: %d)", |
| 700 td->td_bitspersample); | 702 td->td_bitspersample); |
| 701 return (0); | 703 return (0); |
| 702 } | 704 } |
| 703 | 705 |
| 704 if (inflateInit(&sp->stream) != Z_OK) { | 706 if (inflateInit(&sp->stream) != Z_OK) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 774 assert(sizeof(sp->stream.avail_out)==4); /* if this assert gets raised, | 776 assert(sizeof(sp->stream.avail_out)==4); /* if this assert gets raised, |
| 775 we need to simplify this code to reflect a ZLib that is likely updat
ed | 777 we need to simplify this code to reflect a ZLib that is likely updat
ed |
| 776 to deal with 8byte memory sizes, though this code will respond | 778 to deal with 8byte memory sizes, though this code will respond |
| 777 apropriately even before we simplify it */ | 779 apropriately even before we simplify it */ |
| 778 sp->stream.avail_out = (uInt) (nsamples * sizeof(uint16)); | 780 sp->stream.avail_out = (uInt) (nsamples * sizeof(uint16)); |
| 779 if (sp->stream.avail_out != nsamples * sizeof(uint16)) | 781 if (sp->stream.avail_out != nsamples * sizeof(uint16)) |
| 780 { | 782 { |
| 781 TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with
buffers this size"); | 783 TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with
buffers this size"); |
| 782 return (0); | 784 return (0); |
| 783 } | 785 } |
| 786 /* Check that we will not fill more than what was allocated */ |
| 787 if (sp->stream.avail_out > sp->tbuf_size) |
| 788 { |
| 789 TIFFErrorExt(tif->tif_clientdata, module, "sp->stream.avail_out
> sp->tbuf_size"); |
| 790 return (0); |
| 791 } |
| 784 do { | 792 do { |
| 785 int state = inflate(&sp->stream, Z_PARTIAL_FLUSH); | 793 int state = inflate(&sp->stream, Z_PARTIAL_FLUSH); |
| 786 if (state == Z_STREAM_END) { | 794 if (state == Z_STREAM_END) { |
| 787 break; /* XXX */ | 795 break; /* XXX */ |
| 788 } | 796 } |
| 789 if (state == Z_DATA_ERROR) { | 797 if (state == Z_DATA_ERROR) { |
| 790 TIFFErrorExt(tif->tif_clientdata, module, | 798 TIFFErrorExt(tif->tif_clientdata, module, |
| 791 "Decoding error at scanline %lu, %s", | 799 "Decoding error at scanline %lu, %s", |
| 792 (unsigned long) tif->tif_row, sp->stream.msg); | 800 (unsigned long) tif->tif_row, sp->stream.msg); |
| 793 if (inflateSync(&sp->stream) != Z_OK) | 801 if (inflateSync(&sp->stream) != Z_OK) |
| (...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1433 #endif /* PIXARLOG_SUPPORT */ | 1441 #endif /* PIXARLOG_SUPPORT */ |
| 1434 | 1442 |
| 1435 /* vim: set ts=8 sts=8 sw=8 noet: */ | 1443 /* vim: set ts=8 sts=8 sw=8 noet: */ |
| 1436 /* | 1444 /* |
| 1437 * Local Variables: | 1445 * Local Variables: |
| 1438 * mode: c | 1446 * mode: c |
| 1439 * c-basic-offset: 8 | 1447 * c-basic-offset: 8 |
| 1440 * fill-column: 78 | 1448 * fill-column: 78 |
| 1441 * End: | 1449 * End: |
| 1442 */ | 1450 */ |
| OLD | NEW |