Changeset View
Changeset View
Standalone View
Standalone View
source/blender/imbuf/intern/tiff.c
| Show First 20 Lines • Show All 702 Lines • ▼ Show 20 Lines | int imb_savetiff(ImBuf *ibuf, const char *name, int flags) | ||||
| uint16 samplesperpixel, bitspersample; | uint16 samplesperpixel, bitspersample; | ||||
| size_t npixels; | size_t npixels; | ||||
| unsigned char *pixels = NULL; | unsigned char *pixels = NULL; | ||||
| unsigned char *from = NULL, *to = NULL; | unsigned char *from = NULL, *to = NULL; | ||||
| unsigned short *pixels16 = NULL, *to16 = NULL; | unsigned short *pixels16 = NULL, *to16 = NULL; | ||||
| float *fromf = NULL; | float *fromf = NULL; | ||||
| float xres, yres; | float xres, yres; | ||||
| int x, y, from_i, to_i, i; | int x, y, from_i, to_i, i; | ||||
| int cprs_mode = COMPRESSION_NONE; | |||||
| /* check for a valid number of bytes per pixel. Like the PNG writer, | /* check for a valid number of bytes per pixel. Like the PNG writer, | ||||
| * the TIFF writer supports 1, 3 or 4 bytes per pixel, corresponding | * the TIFF writer supports 1, 3 or 4 bytes per pixel, corresponding | ||||
| * to gray, RGB, RGBA respectively. */ | * to gray, RGB, RGBA respectively. */ | ||||
| samplesperpixel = (uint16)((ibuf->planes + 7) >> 3); | samplesperpixel = (uint16)((ibuf->planes + 7) >> 3); | ||||
| if ((samplesperpixel > 4) || (samplesperpixel == 2)) { | if ((samplesperpixel > 4) || (samplesperpixel == 2)) { | ||||
| fprintf(stderr, | fprintf(stderr, | ||||
| "imb_savetiff: unsupported number of bytes per " | "imb_savetiff: unsupported number of bytes per " | ||||
| "pixel: %d\n", samplesperpixel); | "pixel: %d\n", samplesperpixel); | ||||
| return (0); | return (0); | ||||
| } | } | ||||
| if ((ibuf->foptions.flag & TIF_16BIT) && ibuf->rect_float) | if ((ibuf->foptions.flag & TIF_16BIT) && ibuf->rect_float) | ||||
| bitspersample = 16; | bitspersample = 16; | ||||
| else | else | ||||
| bitspersample = 8; | bitspersample = 8; | ||||
| if (ibuf->foptions.flag & TIF_CPRS_DEFLATE) | |||||
| cprs_mode = COMPRESSION_DEFLATE; | |||||
| else if (ibuf->foptions.flag & TIF_CPRS_LZW) | |||||
| cprs_mode = COMPRESSION_LZW; | |||||
| else if (ibuf->foptions.flag & TIF_CPRS_PACKBITS) | |||||
| cprs_mode = COMPRESSION_PACKBITS; | |||||
| /* open TIFF file for writing */ | /* open TIFF file for writing */ | ||||
| if (flags & IB_mem) { | if (flags & IB_mem) { | ||||
| /* bork at the creation of a TIFF in memory */ | /* bork at the creation of a TIFF in memory */ | ||||
| fprintf(stderr, | fprintf(stderr, | ||||
| "imb_savetiff: creation of in-memory TIFF files is " | "imb_savetiff: creation of in-memory TIFF files is " | ||||
| "not yet supported.\n"); | "not yet supported.\n"); | ||||
| return (0); | return (0); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | for (y = 0; y < ibuf->y; y++) { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* write the actual TIFF file */ | /* write the actual TIFF file */ | ||||
| TIFFSetField(image, TIFFTAG_IMAGEWIDTH, ibuf->x); | TIFFSetField(image, TIFFTAG_IMAGEWIDTH, ibuf->x); | ||||
| TIFFSetField(image, TIFFTAG_IMAGELENGTH, ibuf->y); | TIFFSetField(image, TIFFTAG_IMAGELENGTH, ibuf->y); | ||||
| TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, ibuf->y); | TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, ibuf->y); | ||||
| TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_DEFLATE); | TIFFSetField(image, TIFFTAG_COMPRESSION, cprs_mode); | ||||
| TIFFSetField(image, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB); | TIFFSetField(image, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB); | ||||
| TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); | TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); | ||||
| if (ibuf->ppm[0] > 0.0 && ibuf->ppm[1] > 0.0) { | if (ibuf->ppm[0] > 0.0 && ibuf->ppm[1] > 0.0) { | ||||
| xres = (float)(ibuf->ppm[0] * 0.0254); | xres = (float)(ibuf->ppm[0] * 0.0254); | ||||
| yres = (float)(ibuf->ppm[1] * 0.0254); | yres = (float)(ibuf->ppm[1] * 0.0254); | ||||
| } | } | ||||
| Show All 25 Lines | |||||