Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-05-13 18:27:12 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-05-13 18:27:12 +0400
commit05d004fd14876d9df0ca1028f77bebcad1580eff (patch)
tree2027a9e302367a58e8ac02cb6a2c032f3cb594d5 /source/blender/imbuf/intern/tiff.c
parent6786f92fe569cbed1ad9fbc12392cc54a3eb58d0 (diff)
support for reading/writing image resolution (dpi), for PNG and TIFF,
only RNA access currently 'image.resolution'.
Diffstat (limited to 'source/blender/imbuf/intern/tiff.c')
-rw-r--r--source/blender/imbuf/intern/tiff.c39
1 files changed, 36 insertions, 3 deletions
diff --git a/source/blender/imbuf/intern/tiff.c b/source/blender/imbuf/intern/tiff.c
index 67d20d56466..36130aa0dbf 100644
--- a/source/blender/imbuf/intern/tiff.c
+++ b/source/blender/imbuf/intern/tiff.c
@@ -354,6 +354,25 @@ static void scanline_separate_32bit(float *rectf, float *fbuf, int scanline_w, i
rectf[i*4 + chan] = fbuf[i];
}
+static void imb_read_tiff_resolution(ImBuf *ibuf, TIFF *image)
+{
+ uint16 unit;
+ float xres;
+ float yres;
+
+ TIFFGetFieldDefaulted(image, TIFFTAG_RESOLUTIONUNIT, &unit);
+ TIFFGetFieldDefaulted(image, TIFFTAG_XRESOLUTION, &xres);
+ TIFFGetFieldDefaulted(image, TIFFTAG_YRESOLUTION, &yres);
+
+ if(unit == RESUNIT_CENTIMETER) {
+ ibuf->ppm[0]= (double)xres * 100.0;
+ ibuf->ppm[1]= (double)yres * 100.0;
+ }
+ else {
+ ibuf->ppm[0]= (double)xres / 0.0254;
+ ibuf->ppm[1]= (double)yres / 0.0254;
+ }
+}
/*
* Use the libTIFF scanline API to read a TIFF image.
@@ -369,10 +388,13 @@ static int imb_read_tiff_pixels(ImBuf *ibuf, TIFF *image, int premul)
int ib_flag=0, row, chan;
float *fbuf=NULL;
unsigned short *sbuf=NULL;
-
+
TIFFGetField(image, TIFFTAG_BITSPERSAMPLE, &bitspersample);
TIFFGetField(image, TIFFTAG_SAMPLESPERPIXEL, &spp); /* number of 'channels' */
TIFFGetField(image, TIFFTAG_PLANARCONFIG, &config);
+
+ imb_read_tiff_resolution(ibuf, image);
+
scanline = TIFFScanlineSize(image);
if (bitspersample == 32) {
@@ -658,6 +680,7 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags)
unsigned char *from = NULL, *to = NULL;
unsigned short *pixels16 = NULL, *to16 = NULL;
float *fromf = NULL;
+ float xres, yres;
int x, y, from_i, to_i, i;
int extraSampleTypes[1] = { EXTRASAMPLE_ASSOCALPHA };
@@ -783,8 +806,18 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags)
TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_DEFLATE);
TIFFSetField(image, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);
TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
- TIFFSetField(image, TIFFTAG_XRESOLUTION, 150.0);
- TIFFSetField(image, TIFFTAG_YRESOLUTION, 150.0);
+
+
+ if(ibuf->ppm[0] > 0.0 && ibuf->ppm[1] > 0.0) {
+ xres= (float)(ibuf->ppm[0] * 0.0254);
+ yres= (float)(ibuf->ppm[1] * 0.0254);
+ }
+ else {
+ xres= yres= 150.0f;
+ }
+
+ TIFFSetField(image, TIFFTAG_XRESOLUTION, xres);
+ TIFFSetField(image, TIFFTAG_YRESOLUTION, yres);
TIFFSetField(image, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
if(TIFFWriteEncodedStrip(image, 0,
(bitspersample == 16)? (unsigned char*)pixels16: pixels,