diff options
Diffstat (limited to 'source/blender/imbuf/intern')
-rw-r--r-- | source/blender/imbuf/intern/amiga.c | 1 | ||||
-rw-r--r-- | source/blender/imbuf/intern/bmp.c | 1 | ||||
-rw-r--r-- | source/blender/imbuf/intern/dds/dds_api.cpp | 1 | ||||
-rw-r--r-- | source/blender/imbuf/intern/divers.c | 75 | ||||
-rw-r--r-- | source/blender/imbuf/intern/hamx.c | 1 | ||||
-rw-r--r-- | source/blender/imbuf/intern/iris.c | 1 | ||||
-rw-r--r-- | source/blender/imbuf/intern/jpeg.c | 1 | ||||
-rw-r--r-- | source/blender/imbuf/intern/openexr/openexr_api.cpp | 3 | ||||
-rw-r--r-- | source/blender/imbuf/intern/png.c | 1 | ||||
-rw-r--r-- | source/blender/imbuf/intern/radiance_hdr.c | 1 | ||||
-rw-r--r-- | source/blender/imbuf/intern/readimage.c | 1 | ||||
-rw-r--r-- | source/blender/imbuf/intern/targa.c | 1 | ||||
-rw-r--r-- | source/blender/imbuf/intern/tiff.c | 1 |
13 files changed, 59 insertions, 30 deletions
diff --git a/source/blender/imbuf/intern/amiga.c b/source/blender/imbuf/intern/amiga.c index f84740826ae..91638a7ea72 100644 --- a/source/blender/imbuf/intern/amiga.c +++ b/source/blender/imbuf/intern/amiga.c @@ -452,6 +452,7 @@ struct ImBuf *imb_loadamiga(int *iffmem,int flags) if (ibuf == 0) return (0); ibuf->ftype = (ftype | AMI); + ibuf->profile = IB_PROFILE_SRGB; if (cmap){ ibuf->mincol = 0; diff --git a/source/blender/imbuf/intern/bmp.c b/source/blender/imbuf/intern/bmp.c index 141b8a985cf..ada5fcebf73 100644 --- a/source/blender/imbuf/intern/bmp.c +++ b/source/blender/imbuf/intern/bmp.c @@ -175,6 +175,7 @@ struct ImBuf *imb_bmp_decode(unsigned char *mem, int size, int flags) if (ibuf) { ibuf->ftype = BMP; + ibuf->profile = IB_PROFILE_SRGB; } return(ibuf); diff --git a/source/blender/imbuf/intern/dds/dds_api.cpp b/source/blender/imbuf/intern/dds/dds_api.cpp index cf2f6c16d08..d7ff4761605 100644 --- a/source/blender/imbuf/intern/dds/dds_api.cpp +++ b/source/blender/imbuf/intern/dds/dds_api.cpp @@ -101,6 +101,7 @@ struct ImBuf *imb_load_dds(unsigned char *mem, int size, int flags) if (ibuf == 0) return(0); /* memory allocation failed */ ibuf->ftype = DDS; + ibuf->profile = IB_PROFILE_SRGB; if ((flags & IB_test) == 0) { if (!imb_addrectImBuf(ibuf)) return(ibuf); diff --git a/source/blender/imbuf/intern/divers.c b/source/blender/imbuf/intern/divers.c index 35be1f716e6..bcf913e6caf 100644 --- a/source/blender/imbuf/intern/divers.c +++ b/source/blender/imbuf/intern/divers.c @@ -175,12 +175,14 @@ void IMB_gamwarp(struct ImBuf *ibuf, double gamma) } +/* assume converting from linear float to sRGB byte */ void IMB_rect_from_float(struct ImBuf *ibuf) { /* quick method to convert floatbuf to byte */ float *tof = (float *)ibuf->rect_float; - float dither= ibuf->dither; - float srgb[3]; + int do_dither = ibuf->dither != 0.f; + float dither= ibuf->dither / 255.0; + float srgb[4]; int i, channels= ibuf->channels; short profile= ibuf->profile; unsigned char *to = (unsigned char *) ibuf->rect; @@ -195,7 +197,7 @@ void IMB_rect_from_float(struct ImBuf *ibuf) for (i = ibuf->x * ibuf->y; i > 0; i--, to+=4, tof++) to[1]= to[2]= to[3]= to[0] = FTOCHAR(tof[0]); } - else if (profile == IB_PROFILE_SRGB) { + else if (profile == IB_PROFILE_LINEAR_RGB) { if(channels == 3) { for (i = ibuf->x * ibuf->y; i > 0; i--, to+=4, tof+=3) { srgb[0]= linearrgb_to_srgb(tof[0]); @@ -209,10 +211,26 @@ void IMB_rect_from_float(struct ImBuf *ibuf) } } else if (channels == 4) { - floatbuf_to_srgb_byte(tof, to, 0, ibuf->x, 0, ibuf->y, ibuf->x); + if (dither != 0.f) { + for (i = ibuf->x * ibuf->y; i > 0; i--, to+=4, tof+=4) { + const float d = (BLI_frand()-0.5)*dither; + + srgb[0]= d + linearrgb_to_srgb(tof[0]); + srgb[1]= d + linearrgb_to_srgb(tof[1]); + srgb[2]= d + linearrgb_to_srgb(tof[2]); + srgb[3]= d + tof[3]; + + to[0] = FTOCHAR(srgb[0]); + to[1] = FTOCHAR(srgb[1]); + to[2] = FTOCHAR(srgb[2]); + to[3] = FTOCHAR(srgb[3]); + } + } else { + floatbuf_to_srgb_byte(tof, to, 0, ibuf->x, 0, ibuf->y, ibuf->x); + } } } - else if(ELEM(profile, IB_PROFILE_NONE, IB_PROFILE_LINEAR_RGB) && dither==0.0f) { + else if(ELEM(profile, IB_PROFILE_NONE, IB_PROFILE_SRGB)) { if(channels==3) { for (i = ibuf->x * ibuf->y; i > 0; i--, to+=4, tof+=3) { to[0] = FTOCHAR(tof[0]); @@ -222,32 +240,26 @@ void IMB_rect_from_float(struct ImBuf *ibuf) } } else { - for (i = ibuf->x * ibuf->y; i > 0; i--, to+=4, tof+=4) { - to[0] = FTOCHAR(tof[0]); - to[1] = FTOCHAR(tof[1]); - to[2] = FTOCHAR(tof[2]); - to[3] = FTOCHAR(tof[3]); + if (dither != 0.f) { + float col[3]; + for (i = ibuf->x * ibuf->y; i > 0; i--, to+=4, tof+=4) { + const float d = (BLI_frand()-0.5)*dither; + const float col[4] = {d+tof[0], d+tof[1], d+tof[2], d+tof[3]}; + to[0] = FTOCHAR(col[0]); + to[1] = FTOCHAR(col[1]); + to[2] = FTOCHAR(col[2]); + to[3] = FTOCHAR(col[3]); + } + } else { + for (i = ibuf->x * ibuf->y; i > 0; i--, to+=4, tof+=4) { + to[0] = FTOCHAR(tof[0]); + to[1] = FTOCHAR(tof[1]); + to[2] = FTOCHAR(tof[2]); + to[3] = FTOCHAR(tof[3]); + } } } } - else { - float dither_value, col; - dither= dither/255.0f; - for (i = ibuf->x * ibuf->y; i > 0; i--) { - dither_value = (BLI_frand()-0.5)*dither; - col= tof[0] + dither_value; - to[0] = FTOCHAR(col); - col= tof[1] + dither_value; - to[1] = FTOCHAR(col); - col= tof[2] + dither_value; - to[2] = FTOCHAR(col); - col= tof[3] + dither_value; - to[3] = FTOCHAR(col); - - to += 4; - tof += 4; - } - } } void IMB_float_from_rect(struct ImBuf *ibuf) @@ -263,8 +275,11 @@ void IMB_float_from_rect(struct ImBuf *ibuf) tof = ibuf->rect_float; } - if (ibuf->profile == IB_PROFILE_SRGB) { - /* convert from srgb to linear rgb */ + /* Float bufs should be stored linear */ + + if (ibuf->profile != IB_PROFILE_NONE) { + /* if the image has been given a profile then we're working + * with color management in mind, so convert it to linear space */ for (i = ibuf->x * ibuf->y; i > 0; i--) { diff --git a/source/blender/imbuf/intern/hamx.c b/source/blender/imbuf/intern/hamx.c index 258c196fcdf..222604121f9 100644 --- a/source/blender/imbuf/intern/hamx.c +++ b/source/blender/imbuf/intern/hamx.c @@ -387,6 +387,7 @@ struct ImBuf *imb_loadanim(int *iffmem, int flags) if (ibuf==0) return (0); ibuf->ftype = (Anim | adat.type); + ibuf->profile = IB_PROFILE_SRGB; ibuf->xorig = adat.xorig; ibuf->yorig = adat.yorig; ibuf->flags = flags; diff --git a/source/blender/imbuf/intern/iris.c b/source/blender/imbuf/intern/iris.c index 7b8c383ddb9..4389eea8939 100644 --- a/source/blender/imbuf/intern/iris.c +++ b/source/blender/imbuf/intern/iris.c @@ -494,6 +494,7 @@ struct ImBuf *imb_loadiris(unsigned char *mem, int flags) } ibuf->ftype = IMAGIC; + ibuf->profile = IB_PROFILE_SRGB; if (flags & IB_ttob) IMB_flipy(ibuf); test_endian_zbuf(ibuf); diff --git a/source/blender/imbuf/intern/jpeg.c b/source/blender/imbuf/intern/jpeg.c index 2df522ff4a2..2b2d17784e2 100644 --- a/source/blender/imbuf/intern/jpeg.c +++ b/source/blender/imbuf/intern/jpeg.c @@ -416,6 +416,7 @@ next_stamp_marker: jpeg_destroy((j_common_ptr) cinfo); ibuf->ftype = ibuf_ftype; + ibuf->profile = IB_PROFILE_SRGB; } return(ibuf); diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp index a780727b1a2..18462121810 100644 --- a/source/blender/imbuf/intern/openexr/openexr_api.cpp +++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp @@ -933,6 +933,9 @@ struct ImBuf *imb_load_openexr(unsigned char *mem, int size, int flags) ibuf = IMB_allocImBuf(width, height, 32, 0, 0); ibuf->ftype = OPENEXR; + + /* openEXR is linear as per EXR spec */ + ibuf->profile = IB_PROFILE_LINEAR_RGB; if (!(flags & IB_test)) { diff --git a/source/blender/imbuf/intern/png.c b/source/blender/imbuf/intern/png.c index 3d42eafe623..724f209884c 100644 --- a/source/blender/imbuf/intern/png.c +++ b/source/blender/imbuf/intern/png.c @@ -368,6 +368,7 @@ struct ImBuf *imb_loadpng(unsigned char *mem, int size, int flags) if (ibuf) { ibuf->ftype = PNG; + ibuf->profile = IB_PROFILE_SRGB; } else { printf("Couldn't allocate memory for PNG image\n"); } diff --git a/source/blender/imbuf/intern/radiance_hdr.c b/source/blender/imbuf/intern/radiance_hdr.c index 69c4970df38..5acde1232fd 100644 --- a/source/blender/imbuf/intern/radiance_hdr.c +++ b/source/blender/imbuf/intern/radiance_hdr.c @@ -204,6 +204,7 @@ struct ImBuf *imb_loadhdr(unsigned char *mem, int size, int flags) if (ibuf==NULL) return NULL; ibuf->ftype = RADHDR; + ibuf->profile = IB_PROFILE_LINEAR_RGB; ibuf->xorig = ibuf->yorig = 0; if (flags & IB_test) return ibuf; diff --git a/source/blender/imbuf/intern/readimage.c b/source/blender/imbuf/intern/readimage.c index 61254944001..ce3d6f9ce91 100644 --- a/source/blender/imbuf/intern/readimage.c +++ b/source/blender/imbuf/intern/readimage.c @@ -161,6 +161,7 @@ ImBuf *IMB_ibImageFromMemory(int *mem, int size, int flags) { ibuf = imb_cocoaLoadImage((uchar *)mem, size, flags); if(ibuf) { ibuf->ftype = TIF; + ibuf->profile = IB_PROFILE_SRGB; return ibuf; } #else diff --git a/source/blender/imbuf/intern/targa.c b/source/blender/imbuf/intern/targa.c index acc3e06448f..9e6a774e4e5 100644 --- a/source/blender/imbuf/intern/targa.c +++ b/source/blender/imbuf/intern/targa.c @@ -569,6 +569,7 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, int mem_size, int flags) if (ibuf == 0) return(0); ibuf->ftype = TGA; + ibuf->profile = IB_PROFILE_SRGB; ibuf->xorig = tga.xorig; ibuf->yorig = tga.yorig; mem = mem + 18 + tga.numid; diff --git a/source/blender/imbuf/intern/tiff.c b/source/blender/imbuf/intern/tiff.c index b2465d6cc2f..0a81e903d05 100644 --- a/source/blender/imbuf/intern/tiff.c +++ b/source/blender/imbuf/intern/tiff.c @@ -347,6 +347,7 @@ struct ImBuf *imb_loadtiff(unsigned char *mem, int size, int flags) ibuf = IMB_allocImBuf(width, height, 8*bytesperpixel, 0, 0); if (ibuf) { ibuf->ftype = TIF; + ibuf->profile = IB_PROFILE_SRGB; } else { fprintf(stderr, "imb_loadtiff: could not allocate memory for TIFF " \ |