diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-05-13 18:27:12 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-05-13 18:27:12 +0400 |
commit | 05d004fd14876d9df0ca1028f77bebcad1580eff (patch) | |
tree | 2027a9e302367a58e8ac02cb6a2c032f3cb594d5 /source/blender/imbuf/intern/png.c | |
parent | 6786f92fe569cbed1ad9fbc12392cc54a3eb58d0 (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/png.c')
-rw-r--r-- | source/blender/imbuf/intern/png.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/source/blender/imbuf/intern/png.c b/source/blender/imbuf/intern/png.c index 200ff0af9af..6b6dcdb88af 100644 --- a/source/blender/imbuf/intern/png.c +++ b/source/blender/imbuf/intern/png.c @@ -257,6 +257,10 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags) } + if(ibuf->ppm[0] > 0.0 && ibuf->ppm[1] > 0.0) { + png_set_pHYs(png_ptr, info_ptr, (unsigned int)(ibuf->ppm[0] + 0.5), (unsigned int)(ibuf->ppm[1] + 0.5), PNG_RESOLUTION_METER); + } + // write the file header information png_write_info(png_ptr, info_ptr); @@ -384,7 +388,19 @@ struct ImBuf *imb_loadpng(unsigned char *mem, size_t size, int flags) if (ibuf) { ibuf->ftype = PNG; ibuf->profile = IB_PROFILE_SRGB; - } else { + + if (png_get_valid (png_ptr, info_ptr, PNG_INFO_pHYs)) { + int unit_type; + unsigned int xres, yres; + + if(png_get_pHYs(png_ptr, info_ptr, &xres, &yres, &unit_type)) + if(unit_type == PNG_RESOLUTION_METER) { + ibuf->ppm[0]= xres; + ibuf->ppm[1]= yres; + } + } + } + else { printf("Couldn't allocate memory for PNG image\n"); } |