diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-03-13 11:16:53 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-03-13 11:16:53 +0400 |
commit | 2c8d3a969d11a5a40d34d51b5c0545267e7b6e90 (patch) | |
tree | d7be4b9a2ed2401ccefbbc9aa79c3df9bf5c7c4f /source/blender | |
parent | 0488af00fe95d9af32215d38394994013f09bb2b (diff) |
patch [#34604] Add DPI read write for BMP and OpenEXR format
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/imbuf/intern/bmp.c | 9 | ||||
-rw-r--r-- | source/blender/imbuf/intern/openexr/openexr_api.cpp | 10 |
2 files changed, 17 insertions, 2 deletions
diff --git a/source/blender/imbuf/intern/bmp.c b/source/blender/imbuf/intern/bmp.c index f19714dcd26..d850153f16e 100644 --- a/source/blender/imbuf/intern/bmp.c +++ b/source/blender/imbuf/intern/bmp.c @@ -126,6 +126,7 @@ struct ImBuf *imb_bmp_decode(unsigned char *mem, size_t size, int flags, char co int x, y, depth, skip, i; unsigned char *bmp, *rect; unsigned short col; + double xppm, yppm; (void)size; /* unused */ @@ -145,6 +146,8 @@ struct ImBuf *imb_bmp_decode(unsigned char *mem, size_t size, int flags, char co x = LITTLE_LONG(bmi.biWidth); y = LITTLE_LONG(bmi.biHeight); depth = LITTLE_SHORT(bmi.biBitCount); + xppm = LITTLE_LONG(bmi.biXPelsPerMeter); + yppm = LITTLE_LONG(bmi.biYPelsPerMeter); #if 0 printf("skip: %d, x: %d y: %d, depth: %d (%x)\n", skip, x, y, @@ -200,6 +203,8 @@ struct ImBuf *imb_bmp_decode(unsigned char *mem, size_t size, int flags, char co } if (ibuf) { + ibuf->ppm[0] = xppm; + ibuf->ppm[1] = yppm; ibuf->ftype = BMP; } @@ -251,8 +256,8 @@ int imb_savebmp(struct ImBuf *ibuf, const char *name, int flags) putShortLSB(24, ofile); putIntLSB(0, ofile); putIntLSB(bytesize + BMP_FILEHEADER_SIZE + sizeof(infoheader), ofile); - putIntLSB(0, ofile); - putIntLSB(0, ofile); + putIntLSB((int)(ibuf->ppm[0] + 0.5), ofile); + putIntLSB((int)(ibuf->ppm[1] + 0.5), ofile); putIntLSB(0, ofile); putIntLSB(0, ofile); diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp index 6a8f9236831..043bb8da83c 100644 --- a/source/blender/imbuf/intern/openexr/openexr_api.cpp +++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp @@ -85,6 +85,7 @@ _CRTIMP void __cdecl _invalid_parameter_noinfo(void) #include <ImfCompression.h> #include <ImfCompressionAttribute.h> #include <ImfStringAttribute.h> +#include <ImfStandardAttributes.h> using namespace Imf; using namespace Imath; @@ -302,6 +303,9 @@ static void openexr_header_metadata(Header *header, struct ImBuf *ibuf) for (info = ibuf->metadata; info; info = info->next) header->insert(info->key, StringAttribute(info->value)); + + if (ibuf->ppm[0] > 0.0f) + addXDensity(*header, ibuf->ppm[0] / 39.3700787f); /* 1 meter = 39.3700787 inches */ } static int imb_save_openexr_half(struct ImBuf *ibuf, const char *name, int flags) @@ -1144,6 +1148,12 @@ struct ImBuf *imb_load_openexr(unsigned char *mem, size_t size, int flags, char const int is_alpha = exr_has_alpha(file); ibuf = IMB_allocImBuf(width, height, is_alpha ? 32 : 24, 0); + + if (hasXDensity(file->header())) { + ibuf->ppm[0] = xDensity(file->header()) * 39.3700787f; + ibuf->ppm[1] = ibuf->ppm[0] * file->header().pixelAspectRatio(); + } + ibuf->ftype = OPENEXR; if (!(flags & IB_test)) { |