diff options
-rw-r--r-- | apps/plugins/lib/grey_core.c | 50 |
1 files changed, 21 insertions, 29 deletions
diff --git a/apps/plugins/lib/grey_core.c b/apps/plugins/lib/grey_core.c index 1326599574..143d09a6a6 100644 --- a/apps/plugins/lib/grey_core.c +++ b/apps/plugins/lib/grey_core.c | |||
@@ -253,41 +253,33 @@ static void invert_gvalues(void) | |||
253 | unsigned x = 0; | 253 | unsigned x = 0; |
254 | unsigned last_x; | 254 | unsigned last_x; |
255 | 255 | ||
256 | if (_grey_info.flags & GREY_BUFFERED) | 256 | /* Step 1: Calculate a transposed table for undoing the old mapping */ |
257 | { | 257 | for (i = 0; i < 256; i++) |
258 | fill_gvalues(); | ||
259 | grey_update(); | ||
260 | } | ||
261 | else /* Unbuffered - need crude reconstruction */ | ||
262 | { | 258 | { |
263 | /* Step 1: Calculate a transposed table for undoing the old mapping */ | 259 | last_x = x; |
264 | for (i = 0; i < 256; i++) | 260 | x = _grey_info.gvalue[i]; |
261 | if (x > last_x) | ||
265 | { | 262 | { |
266 | last_x = x; | 263 | rev_tab[last_x++] = (last_i + i) / 2; |
267 | x = _grey_info.gvalue[i]; | 264 | while (x > last_x) |
268 | if (x > last_x) | 265 | rev_tab[last_x++] = i; |
269 | { | 266 | last_i = i; |
270 | rev_tab[last_x++] = (last_i + i) / 2; | ||
271 | while (x > last_x) | ||
272 | rev_tab[last_x++] = i; | ||
273 | last_i = i; | ||
274 | } | ||
275 | } | 267 | } |
276 | rev_tab[last_x++] = (last_i + 255) / 2; | 268 | } |
277 | while (256 > last_x) | 269 | rev_tab[last_x++] = (last_i + 255) / 2; |
278 | rev_tab[last_x++] = 255; | 270 | while (256 > last_x) |
271 | rev_tab[last_x++] = 255; | ||
279 | 272 | ||
280 | /* Step 2: Calculate new mapping */ | 273 | /* Step 2: Calculate new mapping */ |
281 | fill_gvalues(); | 274 | fill_gvalues(); |
282 | 275 | ||
283 | /* Step 3: Transpose all pixel values */ | 276 | /* Step 3: Transpose all pixel values */ |
284 | val = _grey_info.values; | 277 | val = _grey_info.values; |
285 | end = val + _GREY_MULUQ(_grey_info.width, _grey_info.height); | 278 | end = val + _GREY_MULUQ(_grey_info.width, _grey_info.height); |
286 | 279 | ||
287 | do | 280 | do |
288 | *val = _grey_info.gvalue[rev_tab[*val]]; | 281 | *val = _grey_info.gvalue[rev_tab[*val]]; |
289 | while (++val < end); | 282 | while (++val < end); |
290 | } | ||
291 | } | 283 | } |
292 | #endif | 284 | #endif |
293 | 285 | ||