LEFT | RIGHT |
1 /* | 1 /* |
2 * | 2 * |
3 * ***** BEGIN GPL LICENSE BLOCK ***** | 3 * ***** BEGIN GPL LICENSE BLOCK ***** |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or | 5 * This program is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU General Public License | 6 * modify it under the terms of the GNU General Public License |
7 * as published by the Free Software Foundation; either version 2 | 7 * as published by the Free Software Foundation; either version 2 |
8 * of the License, or (at your option) any later version. | 8 * of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This program is distributed in the hope that it will be useful, | 10 * This program is distributed in the hope that it will be useful, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 IMB_freeImBuf(tbuf1); | 100 IMB_freeImBuf(tbuf1); |
101 IMB_freeImBuf(tbuf2); | 101 IMB_freeImBuf(tbuf2); |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 | 105 |
106 /* assume converting from linear float to sRGB byte */ | 106 /* assume converting from linear float to sRGB byte */ |
107 void IMB_rect_from_float(struct ImBuf *ibuf) | 107 void IMB_rect_from_float(struct ImBuf *ibuf) |
108 { | 108 { |
109 /* quick method to convert floatbuf to byte */ | 109 /* quick method to convert floatbuf to byte */ |
110 » float *srcFloatPxl = (float *)ibuf->rect_float; | 110 » float *tof = (float *)ibuf->rect_float; |
111 // int do_dither = ibuf->dither != 0.f; | 111 // int do_dither = ibuf->dither != 0.f; |
112 float dither= ibuf->dither / 255.0f; | 112 float dither= ibuf->dither / 255.0f; |
113 float srgb[4]; | 113 float srgb[4]; |
114 int i, channels= ibuf->channels; | 114 int i, channels= ibuf->channels; |
115 short profile= ibuf->profile; | 115 short profile= ibuf->profile; |
116 » unsigned char *dstBytePxl = (unsigned char *) ibuf->rect; | 116 » unsigned char *to = (unsigned char *) ibuf->rect; |
117 »······· | 117 »······· |
118 » if(srcFloatPxl==NULL) return; | 118 » if(tof==NULL) return; |
119 » if(dstBytePxl==NULL) { | 119 » if(to==NULL) { |
120 imb_addrectImBuf(ibuf); | 120 imb_addrectImBuf(ibuf); |
121 » » dstBytePxl = (unsigned char *) ibuf->rect; | 121 » » to = (unsigned char *) ibuf->rect; |
122 } | 122 } |
123 ········ | 123 ········ |
124 if(channels==1) { | 124 if(channels==1) { |
125 » » for (i = ibuf->x * ibuf->y; i > 0; i--, dstBytePxl+=4, srcFloatP
xl++) | 125 » » for (i = ibuf->x * ibuf->y; i > 0; i--, to+=4, tof++) |
126 » » » dstBytePxl[1]= dstBytePxl[2]= dstBytePxl[3]= dstBytePxl[
0] = FTOCHAR(srcFloatPxl[0]); | 126 » » » to[1]= to[2]= to[3]= to[0] = FTOCHAR(tof[0]); |
127 } | 127 } |
128 else if (profile == IB_PROFILE_LINEAR_RGB) { | 128 else if (profile == IB_PROFILE_LINEAR_RGB) { |
129 if(channels == 3) { | 129 if(channels == 3) { |
130 » » » for (i = ibuf->x * ibuf->y; i > 0; i--, dstBytePxl+=4, s
rcFloatPxl+=3) { | 130 » » » for (i = ibuf->x * ibuf->y; i > 0; i--, to+=4, tof+=3) { |
131 » » » » srgb[0]= linearrgb_to_srgb(srcFloatPxl[0]); | 131 » » » » srgb[0]= linearrgb_to_srgb(tof[0]); |
132 » » » » srgb[1]= linearrgb_to_srgb(srcFloatPxl[1]); | 132 » » » » srgb[1]= linearrgb_to_srgb(tof[1]); |
133 » » » » srgb[2]= linearrgb_to_srgb(srcFloatPxl[2]); | 133 » » » » srgb[2]= linearrgb_to_srgb(tof[2]); |
134 | 134 |
135 » » » » dstBytePxl[0] = FTOCHAR(srgb[0]); | 135 » » » » to[0] = FTOCHAR(srgb[0]); |
136 » » » » dstBytePxl[1] = FTOCHAR(srgb[1]); | 136 » » » » to[1] = FTOCHAR(srgb[1]); |
137 » » » » dstBytePxl[2] = FTOCHAR(srgb[2]); | 137 » » » » to[2] = FTOCHAR(srgb[2]); |
138 » » » » dstBytePxl[3] = 255; | 138 » » » » to[3] = 255; |
139 } | 139 } |
140 } | 140 } |
141 else if (channels == 4) { | 141 else if (channels == 4) { |
142 if (dither != 0.f) { | 142 if (dither != 0.f) { |
143 » » » » for (i = ibuf->x * ibuf->y; i > 0; i--, dstByteP
xl+=4, srcFloatPxl+=4) { | 143 » » » » for (i = ibuf->x * ibuf->y; i > 0; i--, to+=4, t
of+=4) { |
144 const float d = (BLI_frand()-0.5f)*dithe
r; | 144 const float d = (BLI_frand()-0.5f)*dithe
r; |
145 ········································ | 145 ········································ |
146 » » » » » srgb[0]= d + linearrgb_to_srgb(srcFloatP
xl[0]); | 146 » » » » » srgb[0]= d + linearrgb_to_srgb(tof[0]); |
147 » » » » » srgb[1]= d + linearrgb_to_srgb(srcFloatP
xl[1]); | 147 » » » » » srgb[1]= d + linearrgb_to_srgb(tof[1]); |
148 » » » » » srgb[2]= d + linearrgb_to_srgb(srcFloatP
xl[2]); | 148 » » » » » srgb[2]= d + linearrgb_to_srgb(tof[2]); |
149 » » » » » srgb[3]= d + srcFloatPxl[3];· | 149 » » » » » srgb[3]= d + tof[3];· |
150 ········································ | 150 ········································ |
151 » » » » » dstBytePxl[0] = FTOCHAR(srgb[0]); | 151 » » » » » to[0] = FTOCHAR(srgb[0]); |
152 » » » » » dstBytePxl[1] = FTOCHAR(srgb[1]); | 152 » » » » » to[1] = FTOCHAR(srgb[1]); |
153 » » » » » dstBytePxl[2] = FTOCHAR(srgb[2]); | 153 » » » » » to[2] = FTOCHAR(srgb[2]); |
154 » » » » » dstBytePxl[3] = FTOCHAR(srgb[3]); | 154 » » » » » to[3] = FTOCHAR(srgb[3]); |
155 } | 155 } |
156 } else { | 156 } else { |
157 » » » » floatbuf_to_srgb_byte(srcFloatPxl, dstBytePxl, 0
, ibuf->x, 0, ibuf->y, ibuf->x); | 157 » » » » floatbuf_to_srgb_byte(tof, to, 0, ibuf->x, 0, ib
uf->y, ibuf->x); |
158 } | 158 } |
159 } | 159 } |
160 } | 160 } |
161 else if(ELEM(profile, IB_PROFILE_NONE, IB_PROFILE_SRGB)) { | 161 else if(ELEM(profile, IB_PROFILE_NONE, IB_PROFILE_SRGB)) { |
162 if(channels==3) { | 162 if(channels==3) { |
163 » » » for (i = ibuf->x * ibuf->y; i > 0; i--, dstBytePxl+=4, s
rcFloatPxl+=3) { | 163 » » » for (i = ibuf->x * ibuf->y; i > 0; i--, to+=4, tof+=3) { |
164 » » » » dstBytePxl[0] = FTOCHAR(srcFloatPxl[0]); | 164 » » » » to[0] = FTOCHAR(tof[0]); |
165 » » » » dstBytePxl[1] = FTOCHAR(srcFloatPxl[1]); | 165 » » » » to[1] = FTOCHAR(tof[1]); |
166 » » » » dstBytePxl[2] = FTOCHAR(srcFloatPxl[2]); | 166 » » » » to[2] = FTOCHAR(tof[2]); |
167 » » » » dstBytePxl[3] = 255; | 167 » » » » to[3] = 255; |
168 } | 168 } |
169 } | 169 } |
170 else { | 170 else { |
171 if (dither != 0.f) { | 171 if (dither != 0.f) { |
172 » » » » for (i = ibuf->x * ibuf->y; i > 0; i--, dstByteP
xl+=4, srcFloatPxl+=4) { | 172 » » » » for (i = ibuf->x * ibuf->y; i > 0; i--, to+=4, t
of+=4) { |
173 const float d = (BLI_frand()-0.5f)*dithe
r; | 173 const float d = (BLI_frand()-0.5f)*dithe
r; |
174 float col[4]; | 174 float col[4]; |
175 | 175 |
176 » » » » » col[0]= d + srcFloatPxl[0]; | 176 » » » » » col[0]= d + tof[0]; |
177 » » » » » col[1]= d + srcFloatPxl[1]; | 177 » » » » » col[1]= d + tof[1]; |
178 » » » » » col[2]= d + srcFloatPxl[2]; | 178 » » » » » col[2]= d + tof[2]; |
179 » » » » » col[3]= d + srcFloatPxl[3]; | 179 » » » » » col[3]= d + tof[3]; |
180 | 180 |
181 » » » » » dstBytePxl[0] = FTOCHAR(col[0]); | 181 » » » » » to[0] = FTOCHAR(col[0]); |
182 » » » » » dstBytePxl[1] = FTOCHAR(col[1]); | 182 » » » » » to[1] = FTOCHAR(col[1]); |
183 » » » » » dstBytePxl[2] = FTOCHAR(col[2]); | 183 » » » » » to[2] = FTOCHAR(col[2]); |
184 » » » » » dstBytePxl[3] = FTOCHAR(col[3]); | 184 » » » » » to[3] = FTOCHAR(col[3]); |
185 } | 185 } |
186 } else { | 186 } else { |
187 » » » » for (i = ibuf->x * ibuf->y; i > 0; i--, dstByteP
xl+=4, srcFloatPxl+=4) { | 187 » » » » for (i = ibuf->x * ibuf->y; i > 0; i--, to+=4, t
of+=4) { |
188 » » » » » dstBytePxl[0] = FTOCHAR(srcFloatPxl[0]); | 188 » » » » » to[0] = FTOCHAR(tof[0]); |
189 » » » » » dstBytePxl[1] = FTOCHAR(srcFloatPxl[1]); | 189 » » » » » to[1] = FTOCHAR(tof[1]); |
190 » » » » » dstBytePxl[2] = FTOCHAR(srcFloatPxl[2]); | 190 » » » » » to[2] = FTOCHAR(tof[2]); |
191 » » » » » dstBytePxl[3] = FTOCHAR(srcFloatPxl[3]); | 191 » » » » » to[3] = FTOCHAR(tof[3]); |
192 } | 192 } |
193 } | 193 } |
194 } | 194 } |
195 } | 195 } |
196 /* ensure user flag is reset */ | 196 /* ensure user flag is reset */ |
197 ibuf->userflags &= ~IB_RECT_INVALID; | 197 ibuf->userflags &= ~IB_RECT_INVALID; |
198 } | 198 } |
199 | 199 |
200 · | 200 · |
201 | 201 |
202 /*converts from linear float to sRGB byte for part of the texture, buffer will h
old the changed part*/ | 202 /* converts from linear float to sRGB byte for part of the texture, buffer will
hold the changed part */ |
203 void IMB_partial_rect_from_float(struct ImBuf *ibuf,float *buffer, int x, int y,
int w, int h) | 203 void IMB_partial_rect_from_float(struct ImBuf *ibuf,float *buffer, int x, int y,
int w, int h) |
204 { | 204 { |
205 » /*indices to source and destination image pixels*/ | 205 » /* indices to source and destination image pixels */ |
206 float *srcFloatPxl; | 206 float *srcFloatPxl; |
207 unsigned char *dstBytePxl; | 207 unsigned char *dstBytePxl; |
208 » /*buffer index will fill buffer*/ | 208 » /* buffer index will fill buffer */ |
209 float *bufferIndex; | 209 float *bufferIndex; |
210 | 210 |
211 » /*convenience pointers to start of image buffers*/ | 211 » /* convenience pointers to start of image buffers */ |
212 float *init_srcFloatPxl = (float *)ibuf->rect_float; | 212 float *init_srcFloatPxl = (float *)ibuf->rect_float; |
213 unsigned char *init_dstBytePxl = (unsigned char *) ibuf->rect; | 213 unsigned char *init_dstBytePxl = (unsigned char *) ibuf->rect; |
214 | 214 |
215 » /*Dithering factor*/ | 215 » /* Dithering factor */ |
216 float dither= ibuf->dither / 255.0f; | 216 float dither= ibuf->dither / 255.0f; |
217 » /*respective attributes of image*/ | 217 » /* respective attributes of image */ |
218 short profile= ibuf->profile; | 218 short profile= ibuf->profile; |
219 int channels= ibuf->channels; | 219 int channels= ibuf->channels; |
220 ········ | 220 ········ |
221 int i, j; | 221 int i, j; |
222 ········ | 222 ········ |
223 /* | 223 /* |
224 if called -only- from GPU_paint_update_image this test will neve
r fail | 224 if called -only- from GPU_paint_update_image this test will neve
r fail |
225 but leaving it here for better or worse | 225 but leaving it here for better or worse |
226 */ | 226 */ |
227 if(init_srcFloatPxl==NULL || (buffer == NULL)){ | 227 if(init_srcFloatPxl==NULL || (buffer == NULL)){ |
(...skipping 14 matching lines...) Expand all Loading... |
242 } | 242 } |
243 } | 243 } |
244 } | 244 } |
245 else if (profile == IB_PROFILE_LINEAR_RGB) { | 245 else if (profile == IB_PROFILE_LINEAR_RGB) { |
246 if(channels == 3) { | 246 if(channels == 3) { |
247 for (j = 0; j < h; j++){ | 247 for (j = 0; j < h; j++){ |
248 bufferIndex = buffer + w*j*4; | 248 bufferIndex = buffer + w*j*4; |
249 dstBytePxl = init_dstBytePxl + (ibuf->x*(y + j)
+ x)*4; | 249 dstBytePxl = init_dstBytePxl + (ibuf->x*(y + j)
+ x)*4; |
250 srcFloatPxl = init_srcFloatPxl + (ibuf->x*(y + j
) + x)*3; | 250 srcFloatPxl = init_srcFloatPxl + (ibuf->x*(y + j
) + x)*3; |
251 for(i = 0; i < w; i++, dstBytePxl+=4, srcFloatP
xl+=3, bufferIndex += 4) { | 251 for(i = 0; i < w; i++, dstBytePxl+=4, srcFloatP
xl+=3, bufferIndex += 4) { |
252 | 252 » » » » » linearrgb_to_srgb_v3_v3(bufferIndex, src
FloatPxl); |
253 » » » » » bufferIndex[0]= linearrgb_to_srgb(srcFlo
atPxl[0]); | 253 » » » » » F3TOCHAR4(bufferIndex, dstBytePxl); |
254 » » » » » bufferIndex[1]= linearrgb_to_srgb(srcFlo
atPxl[1]); | |
255 » » » » » bufferIndex[2]= linearrgb_to_srgb(srcFlo
atPxl[2]); | |
256 bufferIndex[3]= 1.0; | 254 bufferIndex[3]= 1.0; |
257 | |
258 dstBytePxl[0] = FTOCHAR(bufferIndex[0]); | |
259 dstBytePxl[1] = FTOCHAR(bufferIndex[1]); | |
260 dstBytePxl[2] = FTOCHAR(bufferIndex[2]); | |
261 dstBytePxl[3] = 255; | |
262 } | 255 } |
263 } | 256 } |
264 } | 257 } |
265 else if (channels == 4) { | 258 else if (channels == 4) { |
266 if (dither != 0.f) { | 259 if (dither != 0.f) { |
267 for (j = 0; j < h; j++){ | 260 for (j = 0; j < h; j++){ |
268 bufferIndex = buffer + w*j*4; | 261 bufferIndex = buffer + w*j*4; |
269 dstBytePxl = init_dstBytePxl + (ibuf->x*
(y + j) + x)*4; | 262 dstBytePxl = init_dstBytePxl + (ibuf->x*
(y + j) + x)*4; |
270 srcFloatPxl = init_srcFloatPxl + (ibuf->
x*(y + j) + x)*4; | 263 srcFloatPxl = init_srcFloatPxl + (ibuf->
x*(y + j) + x)*4; |
271 for(i = 0; i < w; i++, dstBytePxl+=4, s
rcFloatPxl+=4, bufferIndex+=4) { | 264 for(i = 0; i < w; i++, dstBytePxl+=4, s
rcFloatPxl+=4, bufferIndex+=4) { |
272 const float d = (BLI_frand()-0.5
f)*dither; | 265 const float d = (BLI_frand()-0.5
f)*dither; |
273 | 266 » » » » » » linearrgb_to_srgb_v3_v3(bufferIn
dex, srcFloatPxl); |
274 » » » » » » bufferIndex[0]= d + linearrgb_to
_srgb(srcFloatPxl[0]); | 267 » » » » » » bufferIndex[3] = srcFloatPxl[3]; |
275 » » » » » » bufferIndex[1]= d + linearrgb_to
_srgb(srcFloatPxl[1]); | 268 » » » » » » add_v4_fl(bufferIndex, d); |
276 » » » » » » bufferIndex[2]= d + linearrgb_to
_srgb(srcFloatPxl[2]); | 269 » » » » » » F4TOCHAR4(bufferIndex, dstBytePx
l); |
277 » » » » » » bufferIndex[3]= d + srcFloatPxl[
3]; | |
278 | |
279 » » » » » » dstBytePxl[0] = FTOCHAR(bufferIn
dex[0]); | |
280 » » » » » » dstBytePxl[1] = FTOCHAR(bufferIn
dex[1]); | |
281 » » » » » » dstBytePxl[2] = FTOCHAR(bufferIn
dex[2]); | |
282 » » » » » » dstBytePxl[3] = FTOCHAR(bufferIn
dex[3]); | |
283 } | 270 } |
284 } | 271 } |
285 } else { | 272 } else { |
286 for (j = 0; j < h; j++){ | 273 for (j = 0; j < h; j++){ |
287 bufferIndex = buffer + w*j*4; | 274 bufferIndex = buffer + w*j*4; |
288 dstBytePxl = init_dstBytePxl + (ibuf->x*
(y + j) + x)*4; | 275 dstBytePxl = init_dstBytePxl + (ibuf->x*
(y + j) + x)*4; |
289 srcFloatPxl = init_srcFloatPxl + (ibuf->
x*(y + j) + x)*4; | 276 srcFloatPxl = init_srcFloatPxl + (ibuf->
x*(y + j) + x)*4; |
290 for(i = 0; i < w; i++, dstBytePxl+=4, s
rcFloatPxl+=4, bufferIndex+=4) { | 277 for(i = 0; i < w; i++, dstBytePxl+=4, s
rcFloatPxl+=4, bufferIndex+=4) { |
291 » » » » » » bufferIndex[0]= linearrgb_to_srg
b(srcFloatPxl[0]); | 278 » » » » » » linearrgb_to_srgb_v3_v3(bufferIn
dex, srcFloatPxl); |
292 » » » » » » bufferIndex[1]= linearrgb_to_srg
b(srcFloatPxl[1]); | |
293 » » » » » » bufferIndex[2]= linearrgb_to_srg
b(srcFloatPxl[2]); | |
294 bufferIndex[3]= srcFloatPxl[3]; | 279 bufferIndex[3]= srcFloatPxl[3]; |
295 | 280 » » » » » » F4TOCHAR4(bufferIndex, dstBytePx
l); |
296 » » » » » » dstBytePxl[0] = FTOCHAR(bufferIn
dex[0]); | |
297 » » » » » » dstBytePxl[1] = FTOCHAR(bufferIn
dex[1]); | |
298 » » » » » » dstBytePxl[2] = FTOCHAR(bufferIn
dex[2]); | |
299 » » » » » » dstBytePxl[3] = FTOCHAR(bufferIn
dex[3]); | |
300 } | 281 } |
301 } | 282 } |
302 } | 283 } |
303 } | 284 } |
304 } | 285 } |
305 else if(ELEM(profile, IB_PROFILE_NONE, IB_PROFILE_SRGB)) { | 286 else if(ELEM(profile, IB_PROFILE_NONE, IB_PROFILE_SRGB)) { |
306 if(channels==3) { | 287 if(channels==3) { |
307 for (j = 0; j < h; j++){ | 288 for (j = 0; j < h; j++){ |
308 bufferIndex = buffer + w*j*4; | 289 bufferIndex = buffer + w*j*4; |
309 dstBytePxl = init_dstBytePxl + (ibuf->x*(y + j)
+ x)*4; | 290 dstBytePxl = init_dstBytePxl + (ibuf->x*(y + j)
+ x)*4; |
310 srcFloatPxl = init_srcFloatPxl + (ibuf->x*(y + j
) + x)*3; | 291 srcFloatPxl = init_srcFloatPxl + (ibuf->x*(y + j
) + x)*3; |
311 for(i = 0; i < w; i++, dstBytePxl+=4, srcFloatP
xl+=3, bufferIndex+=4) { | 292 for(i = 0; i < w; i++, dstBytePxl+=4, srcFloatP
xl+=3, bufferIndex+=4) { |
312 » » » » » dstBytePxl[0] = FTOCHAR(bufferIndex[0] =
srcFloatPxl[0]); | 293 » » » » » copy_v3_v3(bufferIndex, srcFloatPxl); |
313 » » » » » dstBytePxl[1] = FTOCHAR(bufferIndex[1] =
srcFloatPxl[1]); | 294 » » » » » F3TOCHAR4(bufferIndex, dstBytePxl); |
314 » » » » » dstBytePxl[2] = FTOCHAR(bufferIndex[2] =
srcFloatPxl[2]); | |
315 » » » » » dstBytePxl[3] = 255; | |
316 bufferIndex[3] = 1.0; | 295 bufferIndex[3] = 1.0; |
317 } | 296 } |
318 } | 297 } |
319 } | 298 } |
320 else { | 299 else { |
321 if (dither != 0.f) { | 300 if (dither != 0.f) { |
322 for (j = 0; j < h; j++){ | 301 for (j = 0; j < h; j++){ |
323 bufferIndex = buffer + w*j*4; | 302 bufferIndex = buffer + w*j*4; |
324 dstBytePxl = init_dstBytePxl + (ibuf->x*
(y + j) + x)*4; | 303 dstBytePxl = init_dstBytePxl + (ibuf->x*
(y + j) + x)*4; |
325 srcFloatPxl = init_srcFloatPxl + (ibuf->
x*(y + j) + x)*4; | 304 srcFloatPxl = init_srcFloatPxl + (ibuf->
x*(y + j) + x)*4; |
326 for(i = 0; i < w; i++, dstBytePxl+=4, s
rcFloatPxl+=4, bufferIndex+=4) { | 305 for(i = 0; i < w; i++, dstBytePxl+=4, s
rcFloatPxl+=4, bufferIndex+=4) { |
327 const float d = (BLI_frand()-0.5
f)*dither; | 306 const float d = (BLI_frand()-0.5
f)*dither; |
328 | 307 » » » » » » copy_v4_v4(bufferIndex, srcFloat
Pxl); |
329 » » » » » » bufferIndex[0]= d + srcFloatPxl[
0]; | 308 » » » » » » add_v4_fl(bufferIndex,d); |
330 » » » » » » bufferIndex[1]= d + srcFloatPxl[
1]; | 309 » » » » » » F4TOCHAR4(bufferIndex, dstBytePx
l); |
331 » » » » » » bufferIndex[2]= d + srcFloatPxl[
2]; | |
332 » » » » » » bufferIndex[3]= d + srcFloatPxl[
3]; | |
333 | |
334 » » » » » » dstBytePxl[0] = FTOCHAR(bufferIn
dex[0]); | |
335 » » » » » » dstBytePxl[1] = FTOCHAR(bufferIn
dex[1]); | |
336 » » » » » » dstBytePxl[2] = FTOCHAR(bufferIn
dex[2]); | |
337 » » » » » » dstBytePxl[3] = FTOCHAR(bufferIn
dex[3]); | |
338 } | 310 } |
339 } | 311 } |
340 } else { | 312 } else { |
341 for (j = 0; j < h; j++){ | 313 for (j = 0; j < h; j++){ |
342 bufferIndex = buffer + w*j*4; | 314 bufferIndex = buffer + w*j*4; |
343 dstBytePxl = init_dstBytePxl + (ibuf->x*
(y + j) + x)*4; | 315 dstBytePxl = init_dstBytePxl + (ibuf->x*
(y + j) + x)*4; |
344 srcFloatPxl = init_srcFloatPxl + (ibuf->
x*(y + j) + x)*4; | 316 srcFloatPxl = init_srcFloatPxl + (ibuf->
x*(y + j) + x)*4; |
345 for(i = 0; i < w; i++, dstBytePxl+=4, s
rcFloatPxl+=4, bufferIndex+=4) { | 317 for(i = 0; i < w; i++, dstBytePxl+=4, s
rcFloatPxl+=4, bufferIndex+=4) { |
346 » » » » » » dstBytePxl[0] = FTOCHAR(bufferIn
dex[0] = srcFloatPxl[0]); | 318 » » » » » » copy_v4_v4(bufferIndex, srcFloat
Pxl); |
347 » » » » » » dstBytePxl[1] = FTOCHAR(bufferIn
dex[1] = srcFloatPxl[1]); | 319 » » » » » » F4TOCHAR4(bufferIndex, dstBytePx
l); |
348 » » » » » » dstBytePxl[2] = FTOCHAR(bufferIn
dex[2] = srcFloatPxl[2]); | |
349 » » » » » » dstBytePxl[3] = FTOCHAR(bufferIn
dex[3] = srcFloatPxl[3]); | |
350 } | 320 } |
351 } | 321 } |
352 } | 322 } |
353 } | 323 } |
354 } | 324 } |
355 /* ensure user flag is reset */ | 325 /* ensure user flag is reset */ |
356 ibuf->userflags &= ~IB_RECT_INVALID; | 326 ibuf->userflags &= ~IB_RECT_INVALID; |
357 } | 327 } |
358 | 328 |
359 /*Create a new float buffer containing color corrected colors from an Imbuf*/ | 329 static void imb_float_from_rect_nonlinear(struct ImBuf *ibuf, float *fbuf) |
360 void IMB_float_color_corrected_from_float_rect(struct ImBuf *ibuf, float *buffer
) | 330 { |
361 { | 331 » float *tof = fbuf; |
362 » /*indices to source image pixels*/ | |
363 » float *srcFloatPxl = (float *)ibuf->rect_float; | |
364 » /*buffer index will fill buffer*/ | |
365 » float *bufferIndex = buffer; | |
366 | |
367 » /*Dithering factor*/ | |
368 » float dither= ibuf->dither / 255.0f; | |
369 | |
370 » /*respective attributes of image*/ | |
371 » short profile= ibuf->profile; | |
372 » int channels= ibuf->channels; | |
373 »······· | |
374 » int w = ibuf->x; | |
375 » int h = ibuf->y; | |
376 int i; | 332 int i; |
377 »······· | 333 » unsigned char *to = (unsigned char *) ibuf->rect; |
378 » if(srcFloatPxl==NULL || (buffer == NULL)){ | |
379 » » return; | |
380 » } | |
381 | |
382 » if(channels==1) { | |
383 » » for(i = 0; i < w*h; i++, srcFloatPxl++, bufferIndex+=4) { | |
384 » » » bufferIndex[0] = bufferIndex[1] = bufferIndex[2] = buffe
rIndex[3] = srcFloatPxl[0]; | |
385 » » } | |
386 » } | |
387 » else if (profile == IB_PROFILE_LINEAR_RGB) { | |
388 » » if(channels == 3) { | |
389 » » » » for(i = 0; i < w*h; i++, srcFloatPxl+=3, buffer
Index += 4) { | |
390 | |
391 » » » » » bufferIndex[0]= linearrgb_to_srgb(srcFlo
atPxl[0]); | |
392 » » » » » bufferIndex[1]= linearrgb_to_srgb(srcFlo
atPxl[1]); | |
393 » » » » » bufferIndex[2]= linearrgb_to_srgb(srcFlo
atPxl[2]); | |
394 » » » » » bufferIndex[3]= 1.0; | |
395 » » » » } | |
396 » » » } | |
397 » » else if (channels == 4) { | |
398 » » » if (dither != 0.f) { | |
399 » » » » for(i = 0; i < w*h; i++, srcFloatPxl+=4, buffer
Index+=4) { | |
400 » » » » » const float d = (BLI_frand()-0.5f)*dithe
r; | |
401 | |
402 » » » » » bufferIndex[0]= d + linearrgb_to_srgb(sr
cFloatPxl[0]); | |
403 » » » » » bufferIndex[1]= d + linearrgb_to_srgb(sr
cFloatPxl[1]); | |
404 » » » » » bufferIndex[2]= d + linearrgb_to_srgb(sr
cFloatPxl[2]); | |
405 » » » » » bufferIndex[3]= d + srcFloatPxl[3]; | |
406 » » » » } | |
407 | |
408 » » » } else { | |
409 » » » » for(i = 0; i < w*h; i++, srcFloatPxl+=4, buffer
Index+=4) { | |
410 » » » » » bufferIndex[0]= linearrgb_to_srgb(srcFlo
atPxl[0]); | |
411 » » » » » bufferIndex[1]= linearrgb_to_srgb(srcFlo
atPxl[1]); | |
412 » » » » » bufferIndex[2]= linearrgb_to_srgb(srcFlo
atPxl[2]); | |
413 » » » » » bufferIndex[3]= srcFloatPxl[3]; | |
414 » » » » } | |
415 » » » } | |
416 » » } | |
417 » }else if(ELEM(profile, IB_PROFILE_NONE, IB_PROFILE_SRGB)) { | |
418 » » if(channels==3) { | |
419 » » » for(i = 0; i < w*h; i++, srcFloatPxl+=3, bufferIndex+=4
) { | |
420 » » » » bufferIndex[0] = srcFloatPxl[0]; | |
421 » » » » bufferIndex[1] = srcFloatPxl[1]; | |
422 » » » » bufferIndex[2] = srcFloatPxl[2]; | |
423 » » » » bufferIndex[3] = 1.0; | |
424 » » » } | |
425 » » } | |
426 » » else { | |
427 » » » if (dither != 0.f) { | |
428 » » » » for(i = 0; i < w*h; i++, srcFloatPxl+=4, buffer
Index+=4) { | |
429 » » » » » const float d = (BLI_frand()-0.5f)*dithe
r; | |
430 | |
431 » » » » » bufferIndex[0]= d + srcFloatPxl[0]; | |
432 » » » » » bufferIndex[1]= d + srcFloatPxl[1]; | |
433 » » » » » bufferIndex[2]= d + srcFloatPxl[2]; | |
434 » » » » » bufferIndex[3]= d + srcFloatPxl[3]; | |
435 » » » » } | |
436 » » » } else { | |
437 » » » » for(i = 0; i < w*h; i++, srcFloatPxl+=4, buffer
Index+=4) { | |
438 » » » » » bufferIndex[0] = srcFloatPxl[0]; | |
439 » » » » » bufferIndex[1] = srcFloatPxl[1]; | |
440 » » » » » bufferIndex[2] = srcFloatPxl[2]; | |
441 » » » » » bufferIndex[3] = srcFloatPxl[3]; | |
442 » » » » } | |
443 » » » } | |
444 » » } | |
445 » } | |
446 } | |
447 | |
448 static void imb_float_from_rect_nonlinear(struct ImBuf *ibuf, float *fbuf) | |
449 { | |
450 » float *dstFloatPxl = fbuf; | |
451 » int i; | |
452 » unsigned char *srcBytePxl = (unsigned char *) ibuf->rect; | |
453 | 334 |
454 for (i = ibuf->x * ibuf->y; i > 0; i--)· | 335 for (i = ibuf->x * ibuf->y; i > 0; i--)· |
455 { | 336 { |
456 » » dstFloatPxl[0] = ((float)srcBytePxl[0])*(1.0f/255.0f); | 337 » » tof[0] = ((float)to[0])*(1.0f/255.0f); |
457 » » dstFloatPxl[1] = ((float)srcBytePxl[1])*(1.0f/255.0f); | 338 » » tof[1] = ((float)to[1])*(1.0f/255.0f); |
458 » » dstFloatPxl[2] = ((float)srcBytePxl[2])*(1.0f/255.0f); | 339 » » tof[2] = ((float)to[2])*(1.0f/255.0f); |
459 » » dstFloatPxl[3] = ((float)srcBytePxl[3])*(1.0f/255.0f); | 340 » » tof[3] = ((float)to[3])*(1.0f/255.0f); |
460 » » srcBytePxl += 4;· | 341 » » to += 4;· |
461 » » dstFloatPxl += 4; | 342 » » tof += 4; |
462 } | 343 } |
463 } | 344 } |
464 | 345 |
465 | 346 |
466 static void imb_float_from_rect_linear(struct ImBuf *ibuf, float *fbuf) | 347 static void imb_float_from_rect_linear(struct ImBuf *ibuf, float *fbuf) |
467 { | 348 { |
468 » float *srcFloatPxl = fbuf; | 349 » float *tof = fbuf; |
469 int i; | 350 int i; |
470 » unsigned char *dstBytePxl = (unsigned char *) ibuf->rect; | 351 » unsigned char *to = (unsigned char *) ibuf->rect; |
471 | 352 |
472 for (i = ibuf->x * ibuf->y; i > 0; i--)· | 353 for (i = ibuf->x * ibuf->y; i > 0; i--)· |
473 { | 354 { |
474 » » srcFloatPxl[0] = srgb_to_linearrgb(((float)dstBytePxl[0])*(1.0f/
255.0f)); | 355 » » tof[0] = srgb_to_linearrgb(((float)to[0])*(1.0f/255.0f)); |
475 » » srcFloatPxl[1] = srgb_to_linearrgb(((float)dstBytePxl[1])*(1.0f/
255.0f)); | 356 » » tof[1] = srgb_to_linearrgb(((float)to[1])*(1.0f/255.0f)); |
476 » » srcFloatPxl[2] = srgb_to_linearrgb(((float)dstBytePxl[2])*(1.0f/
255.0f)); | 357 » » tof[2] = srgb_to_linearrgb(((float)to[2])*(1.0f/255.0f)); |
477 » » srcFloatPxl[3] = ((float)dstBytePxl[3])*(1.0f/255.0f); | 358 » » tof[3] = ((float)to[3])*(1.0f/255.0f); |
478 » » dstBytePxl += 4;· | 359 » » to += 4;· |
479 » » srcFloatPxl += 4; | 360 » » tof += 4; |
480 } | 361 } |
481 } | 362 } |
482 | 363 |
483 void IMB_float_from_rect(struct ImBuf *ibuf) | 364 void IMB_float_from_rect(struct ImBuf *ibuf) |
484 { | 365 { |
485 /* quick method to convert byte to floatbuf */ | 366 /* quick method to convert byte to floatbuf */ |
486 if(ibuf->rect==NULL) return; | 367 if(ibuf->rect==NULL) return; |
487 if(ibuf->rect_float==NULL) { | 368 if(ibuf->rect_float==NULL) { |
488 if (imb_addrectfloatImBuf(ibuf) == 0) return; | 369 if (imb_addrectfloatImBuf(ibuf) == 0) return; |
489 } | 370 } |
(...skipping 22 matching lines...) Expand all Loading... |
512 int ok= FALSE; | 393 int ok= FALSE; |
513 int i; | 394 int i; |
514 | 395 |
515 unsigned char *rct= (unsigned char *)ibuf->rect; | 396 unsigned char *rct= (unsigned char *)ibuf->rect; |
516 float *rctf= ibuf->rect_float; | 397 float *rctf= ibuf->rect_float; |
517 | 398 |
518 if(ibuf->profile == profile) | 399 if(ibuf->profile == profile) |
519 return; | 400 return; |
520 | 401 |
521 if(ELEM(ibuf->profile, IB_PROFILE_NONE, IB_PROFILE_SRGB)) { /* from */ | 402 if(ELEM(ibuf->profile, IB_PROFILE_NONE, IB_PROFILE_SRGB)) { /* from */ |
522 » » if(profile == IB_PROFILE_LINEAR_RGB) { /* dstBytePxl */ | 403 » » if(profile == IB_PROFILE_LINEAR_RGB) { /* to */ |
523 if(ibuf->rect_float) { | 404 if(ibuf->rect_float) { |
524 for (i = ibuf->x * ibuf->y; i > 0; i--, rctf+=4)
{ | 405 for (i = ibuf->x * ibuf->y; i > 0; i--, rctf+=4)
{ |
525 rctf[0]= srgb_to_linearrgb(rctf[0]); | 406 rctf[0]= srgb_to_linearrgb(rctf[0]); |
526 rctf[1]= srgb_to_linearrgb(rctf[1]); | 407 rctf[1]= srgb_to_linearrgb(rctf[1]); |
527 rctf[2]= srgb_to_linearrgb(rctf[2]); | 408 rctf[2]= srgb_to_linearrgb(rctf[2]); |
528 } | 409 } |
529 } | 410 } |
530 if(ibuf->rect) { | 411 if(ibuf->rect) { |
531 for (i = ibuf->x * ibuf->y; i > 0; i--, rct+=4)
{ | 412 for (i = ibuf->x * ibuf->y; i > 0; i--, rct+=4)
{ |
532 rct[0]= (unsigned char)((srgb_to_linearr
gb((float)rct[0]/255.0f) * 255.0f) + 0.5f); | 413 rct[0]= (unsigned char)((srgb_to_linearr
gb((float)rct[0]/255.0f) * 255.0f) + 0.5f); |
533 rct[1]= (unsigned char)((srgb_to_linearr
gb((float)rct[1]/255.0f) * 255.0f) + 0.5f); | 414 rct[1]= (unsigned char)((srgb_to_linearr
gb((float)rct[1]/255.0f) * 255.0f) + 0.5f); |
534 rct[2]= (unsigned char)((srgb_to_linearr
gb((float)rct[2]/255.0f) * 255.0f) + 0.5f); | 415 rct[2]= (unsigned char)((srgb_to_linearr
gb((float)rct[2]/255.0f) * 255.0f) + 0.5f); |
535 } | 416 } |
536 } | 417 } |
537 ok= TRUE; | 418 ok= TRUE; |
538 } | 419 } |
539 } | 420 } |
540 else if (ibuf->profile == IB_PROFILE_LINEAR_RGB) { /* from */ | 421 else if (ibuf->profile == IB_PROFILE_LINEAR_RGB) { /* from */ |
541 » » if(ELEM(profile, IB_PROFILE_NONE, IB_PROFILE_SRGB)) { /* dstByte
Pxl */ | 422 » » if(ELEM(profile, IB_PROFILE_NONE, IB_PROFILE_SRGB)) { /* to */ |
542 if(ibuf->rect_float) { | 423 if(ibuf->rect_float) { |
543 for (i = ibuf->x * ibuf->y; i > 0; i--, rctf+=4)
{ | 424 for (i = ibuf->x * ibuf->y; i > 0; i--, rctf+=4)
{ |
544 rctf[0]= linearrgb_to_srgb(rctf[0]); | 425 rctf[0]= linearrgb_to_srgb(rctf[0]); |
545 rctf[1]= linearrgb_to_srgb(rctf[1]); | 426 rctf[1]= linearrgb_to_srgb(rctf[1]); |
546 rctf[2]= linearrgb_to_srgb(rctf[2]); | 427 rctf[2]= linearrgb_to_srgb(rctf[2]); |
547 } | 428 } |
548 } | 429 } |
549 if(ibuf->rect) { | 430 if(ibuf->rect) { |
550 for (i = ibuf->x * ibuf->y; i > 0; i--, rct+=4)
{ | 431 for (i = ibuf->x * ibuf->y; i > 0; i--, rct+=4)
{ |
551 rct[0]= (unsigned char)((linearrgb_to_sr
gb((float)rct[0]/255.0f) * 255.0f) + 0.5f); | 432 rct[0]= (unsigned char)((linearrgb_to_sr
gb((float)rct[0]/255.0f) * 255.0f) + 0.5f); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 linearrgb_to_srgb_rgba_rgba_buf(fbuf, ibuf->rect
_float, ibuf->x * ibuf->y); | 483 linearrgb_to_srgb_rgba_rgba_buf(fbuf, ibuf->rect
_float, ibuf->x * ibuf->y); |
603 } | 484 } |
604 else { /* nonlin -> lin */ | 485 else { /* nonlin -> lin */ |
605 srgb_to_linearrgb_rgba_rgba_buf(fbuf, ibuf->rect
_float, ibuf->x * ibuf->y); | 486 srgb_to_linearrgb_rgba_rgba_buf(fbuf, ibuf->rect
_float, ibuf->x * ibuf->y); |
606 } | 487 } |
607 } | 488 } |
608 | 489 |
609 return fbuf; | 490 return fbuf; |
610 } | 491 } |
611 } | 492 } |
LEFT | RIGHT |