[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12951] trunk/blender/source/blender/imbuf /intern/tiff.c: == Imbuf ==
Peter Schlaile
peter at schlaile.de
Thu Dec 20 00:14:15 CET 2007
Revision: 12951
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12951
Author: schlaile
Date: 2007-12-20 00:14:14 +0100 (Thu, 20 Dec 2007)
Log Message:
-----------
== Imbuf ==
The TIFF reader did error handling with assert which is a pretty bad
idea (tm).
This fixes the assert-crash, that the TIFF reader triggers, if one tries
to open a RAW-DV file within the compositor. (File extension is only
two characters long, which is enough for an assert... EVEN IF IT ISN'T
A TIFF FILE, WE ARE GOING TO OPEN. GRMBL)
Removed all other assertions and added proper error handling.
(using STDERR, where it belongs.)
Modified Paths:
--------------
trunk/blender/source/blender/imbuf/intern/tiff.c
Modified: trunk/blender/source/blender/imbuf/intern/tiff.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/tiff.c 2007-12-19 22:48:00 UTC (rev 12950)
+++ trunk/blender/source/blender/imbuf/intern/tiff.c 2007-12-19 23:14:14 UTC (rev 12951)
@@ -43,7 +43,6 @@
* used to compress images.
*/
-#include <assert.h>
#include <string.h>
#include "imbuf.h"
@@ -108,7 +107,6 @@
*
* @return: Number of bytes actually read.
* 0 = EOF.
- * -1 = Error (never returned).
*/
tsize_t imb_tiff_ReadProc(thandle_t handle, tdata_t data, tsize_t n)
{
@@ -118,8 +116,10 @@
/* get the pointer to the in-memory file */
mfile = IMB_TIFF_GET_MEMFILE(handle);
- assert(mfile != NULL);
- assert(mfile->mem != NULL);
+ if (!mfile || !mfile->mem) {
+ fprintf(stderr, "imb_tiff_ReadProc: !mfile || !mfile->mem!\n");
+ return 0;
+ }
/* find the actual number of bytes to read (copy) */
nCopy = n;
@@ -136,7 +136,6 @@
return (0);
/* all set -> do the read (copy) */
- assert(sizeof(unsigned char) == 1);
srcAddr = (void*)(&(mfile->mem[mfile->offset]));
memcpy((void*)data, srcAddr, nCopy);
mfile->offset += nCopy; /* advance file ptr by copied bytes */
@@ -180,8 +179,10 @@
/* get the pointer to the in-memory file */
mfile = IMB_TIFF_GET_MEMFILE(handle);
- assert(mfile != NULL);
- assert(mfile->mem != NULL);
+ if (!mfile || !mfile->mem) {
+ fprintf(stderr, "imb_tiff_SeekProc: !mfile || !mfile->mem!\n");
+ return (-1);
+ }
/* find the location we plan to seek to */
switch (whence) {
@@ -193,7 +194,9 @@
break;
default:
/* no other types are supported - return an error */
- printf("Unsupported TIFF SEEK type.\n");
+ fprintf(stderr,
+ "imb_tiff_SeekProc: "
+ "Unsupported TIFF SEEK type.\n");
return (-1);
}
@@ -222,8 +225,10 @@
/* get the pointer to the in-memory file */
mfile = IMB_TIFF_GET_MEMFILE(handle);
- assert(mfile != NULL);
- assert(mfile->mem != NULL); /* the file has not been closed yet */
+ if (!mfile || !mfile->mem) {
+ fprintf(stderr,"imb_tiff_CloseProc: !mfile || !mfile->mem!\n");
+ return (0);
+ }
/* virtually close the file */
mfile->mem = NULL;
@@ -246,8 +251,10 @@
/* get the pointer to the in-memory file */
mfile = IMB_TIFF_GET_MEMFILE(handle);
- assert(mfile != NULL);
- assert(mfile->mem != NULL);
+ if (!mfile || !mfile->mem) {
+ fprintf(stderr,"imb_tiff_SizeProc: !mfile || !mfile->mem!\n");
+ return (0);
+ }
/* return the size */
return (toff_t)(mfile->size);
@@ -317,7 +324,10 @@
memFile.size = size;
/* check whether or not we have a TIFF file */
- assert(size >= IMB_TIFF_NCB);
+ if (size < IMB_TIFF_NCB) {
+ fprintf(stderr, "imb_loadtiff: size < IMB_TIFF_NCB\n");
+ return NULL;
+ }
if (imb_is_a_tiff(mem) == 0)
return NULL;
@@ -340,7 +350,8 @@
if (ibuf) {
ibuf->ftype = TIF;
} else {
- printf("imb_loadtiff: could not allocate memory for TIFF " \
+ fprintf(stderr,
+ "imb_loadtiff: could not allocate memory for TIFF " \
"image.\n");
libtiff_TIFFClose(image);
return NULL;
@@ -362,7 +373,8 @@
success = libtiff_TIFFReadRGBAImage(
image, width, height, raster, 0);
if (!success) {
- printf("imb_loadtiff: This TIFF format is not " \
+ fprintf(stderr,
+ "imb_loadtiff: This TIFF format is not "
"currently supported by Blender.\n");
libtiff__TIFFfree(raster);
libtiff_TIFFClose(image);
@@ -378,7 +390,8 @@
/* this may not be entirely necessary, but is put here
* in case sizeof(unsigned int) is not a 32-bit
* quantity */
- printf("imb_loadtiff: using (slower) component-wise " \
+ fprintf(stderr,
+ "imb_loadtiff: using (slower) component-wise "
"buffer copy.\n");
to = (unsigned char*)ibuf->rect;
for (pixel_i=0; pixel_i < width*height; pixel_i++)
@@ -437,7 +450,8 @@
* to gray, RGB, RGBA respectively. */
samplesperpixel = (uint16)((ibuf->depth + 7) >> 3);
if ((samplesperpixel > 4) || (samplesperpixel == 2)) {
- printf("imb_savetiff: unsupported number of bytes per " \
+ fprintf(stderr,
+ "imb_savetiff: unsupported number of bytes per "
"pixel: %d\n", samplesperpixel);
return (0);
}
@@ -445,7 +459,8 @@
/* open TIFF file for writing */
if (flags & IB_mem) {
/* bork at the creation of a TIFF in memory */
- printf("imb_savetiff: creation of in-memory TIFF files is " \
+ fprintf(stderr,
+ "imb_savetiff: creation of in-memory TIFF files is "
"not yet supported.\n");
return (0);
} else {
@@ -453,7 +468,8 @@
image = libtiff_TIFFOpen(name, "w");
}
if (image == NULL) {
- printf("imb_savetiff: could not open TIFF for writing.\n");
+ fprintf(stderr,
+ "imb_savetiff: could not open TIFF for writing.\n");
return (0);
}
@@ -462,7 +478,8 @@
pixels = (unsigned char*)libtiff__TIFFmalloc(npixels *
samplesperpixel * sizeof(unsigned char));
if (pixels == NULL) {
- printf("imb_savetiff: could not allocate pixels array.\n");
+ fprintf(stderr,
+ "imb_savetiff: could not allocate pixels array.\n");
libtiff_TIFFClose(image);
return (0);
}
@@ -533,7 +550,8 @@
libtiff_TIFFSetField(image, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
if (libtiff_TIFFWriteEncodedStrip(image, 0, pixels,
ibuf->x*ibuf->y*samplesperpixel) == -1) {
- printf("imb_savetiff: Could not write encoded TIFF.\n");
+ fprintf(stderr,
+ "imb_savetiff: Could not write encoded TIFF.\n");
libtiff_TIFFClose(image);
libtiff__TIFFfree(pixels);
return (1);
More information about the Bf-blender-cvs
mailing list