diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-07-12 18:57:24 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-07-12 18:57:24 +0400 |
commit | a470640f2e88c0997b12600b9de652da6aac7444 (patch) | |
tree | 37d6fb2b66755ac8b753f064e7d66f9e4c029da5 /source/blender/imbuf | |
parent | 731824c464e03b133ea9698c2d74dbb8e7f890be (diff) |
sequencer float conversion was only using rgb -> float conversion inconsistantly, some places used colorspace conversion, some not.
Added IMB_float_from_rect_simple() for the sequencer to use.
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r-- | source/blender/imbuf/IMB_imbuf.h | 3 | ||||
-rw-r--r-- | source/blender/imbuf/intern/divers.c | 71 |
2 files changed, 74 insertions, 0 deletions
diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h index 37399c9d68a..07b99dddfa5 100644 --- a/source/blender/imbuf/IMB_imbuf.h +++ b/source/blender/imbuf/IMB_imbuf.h @@ -319,6 +319,9 @@ void IMB_de_interlace(struct ImBuf *ibuf); void IMB_interlace(struct ImBuf *ibuf); void IMB_rect_from_float(struct ImBuf *ibuf); void IMB_float_from_rect(struct ImBuf *ibuf); +void IMB_float_from_rect_simple(struct ImBuf *ibuf); /* no profile conversion */ +/* note, check that the conversion exists, only some are supported */ +void IMB_convert_profile(struct ImBuf *ibuf, int profile); /** * Change the ordering of the color bytes pointed to by rect from diff --git a/source/blender/imbuf/intern/divers.c b/source/blender/imbuf/intern/divers.c index 0cc4346041f..7b3a07f10ad 100644 --- a/source/blender/imbuf/intern/divers.c +++ b/source/blender/imbuf/intern/divers.c @@ -222,3 +222,74 @@ void IMB_float_from_rect(struct ImBuf *ibuf) } } +/* no profile conversion */ +void IMB_float_from_rect_simple(struct ImBuf *ibuf) +{ + int profile = IB_PROFILE_NONE; + + /* no color management: + * don't disturb the existing profiles */ + SWAP(int, ibuf->profile, profile); + + IMB_float_from_rect(ibuf); + + SWAP(int, ibuf->profile, profile); +} + +void IMB_convert_profile(struct ImBuf *ibuf, int profile) +{ + int ok= FALSE; + int i; + + unsigned char *rct= (unsigned char *)ibuf->rect; + float *rctf= ibuf->rect_float; + + if(ibuf->profile == profile) + return; + + if(ELEM(ibuf->profile, IB_PROFILE_NONE, IB_PROFILE_SRGB)) { /* from */ + if(profile == IB_PROFILE_LINEAR_RGB) { /* to */ + if(ibuf->rect_float) { + for (i = ibuf->x * ibuf->y; i > 0; i--, rctf+=4) { + rctf[0]= srgb_to_linearrgb(rctf[0]); + rctf[1]= srgb_to_linearrgb(rctf[1]); + rctf[2]= srgb_to_linearrgb(rctf[2]); + } + } + if(ibuf->rect) { + for (i = ibuf->x * ibuf->y; i > 0; i--, rct+=4) { + rctf[0]= (unsigned char)((srgb_to_linearrgb((float)rctf[0]/255.0f) * 255.0f) + 0.5f); + rctf[1]= (unsigned char)((srgb_to_linearrgb((float)rctf[1]/255.0f) * 255.0f) + 0.5f); + rctf[2]= (unsigned char)((srgb_to_linearrgb((float)rctf[2]/255.0f) * 255.0f) + 0.5f); + } + } + ok= TRUE; + } + } + else if (ibuf->profile == IB_PROFILE_LINEAR_RGB) { /* from */ + if(ELEM(profile, IB_PROFILE_NONE, IB_PROFILE_SRGB)) { /* to */ + if(ibuf->rect_float) { + for (i = ibuf->x * ibuf->y; i > 0; i--, rctf+=4) { + rctf[0]= linearrgb_to_srgb(rctf[0]); + rctf[1]= linearrgb_to_srgb(rctf[1]); + rctf[2]= linearrgb_to_srgb(rctf[2]); + } + } + if(ibuf->rect) { + for (i = ibuf->x * ibuf->y; i > 0; i--, rct+=4) { + rctf[0]= (unsigned char)((linearrgb_to_srgb((float)rctf[0]/255.0f) * 255.0f) + 0.5f); + rctf[1]= (unsigned char)((linearrgb_to_srgb((float)rctf[1]/255.0f) * 255.0f) + 0.5f); + rctf[2]= (unsigned char)((linearrgb_to_srgb((float)rctf[2]/255.0f) * 255.0f) + 0.5f); + } + } + ok= TRUE; + } + } + + if(ok==FALSE){ + printf("IMB_convert_profile: failed profile conversion %d -> %d\n", ibuf->profile, profile); + return; + } + + ibuf->profile= profile; +} |