OpenJPH
Open-source implementation of JPEG2000 Part-15
Loading...
Searching...
No Matches
ojph_colour.cpp
Go to the documentation of this file.
1//***************************************************************************/
2// This software is released under the 2-Clause BSD license, included
3// below.
4//
5// Copyright (c) 2019, Aous Naman
6// Copyright (c) 2019, Kakadu Software Pty Ltd, Australia
7// Copyright (c) 2019, The University of New South Wales, Australia
8//
9// Redistribution and use in source and binary forms, with or without
10// modification, are permitted provided that the following conditions are
11// met:
12//
13// 1. Redistributions of source code must retain the above copyright
14// notice, this list of conditions and the following disclaimer.
15//
16// 2. Redistributions in binary form must reproduce the above copyright
17// notice, this list of conditions and the following disclaimer in the
18// documentation and/or other materials provided with the distribution.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
26// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31//***************************************************************************/
32// This file is part of the OpenJPH software implementation.
33// File: ojph_colour.cpp
34// Author: Aous Naman
35// Date: 28 August 2019
36//***************************************************************************/
37
38#include <cmath>
39#include <climits>
40#include <mutex>
41
42#include "ojph_defs.h"
43#include "ojph_arch.h"
44#include "ojph_mem.h"
45#include "ojph_colour.h"
46#include "ojph_colour_local.h"
47
48#include "ojph_params.h"
50
51namespace ojph {
52
53 // defined elsewhere
54 class line_buf;
55
56 namespace local {
57
60 (const line_buf *src_line, const ui32 src_line_offset,
61 line_buf *dst_line, const ui32 dst_line_offset,
62 si64 shift, ui32 width) = NULL;
63
66 (const line_buf *src_line, const ui32 src_line_offset,
67 line_buf *dst_line, ui32 bit_depth, bool is_signed, ui32 width,
68 const nlt_rec *rec) = NULL;
69
72 (const line_buf *src_line, const ui32 src_line_offset,
73 line_buf *dst_line, const ui32 dst_line_offset, ui32 bit_depth,
74 bool is_signed, ui32 width, const nlt_rec *rec) = NULL;
75
78 (const line_buf *src_line, const ui32 src_line_offset,
79 line_buf *dst_line, const ui32 dst_line_offset,
80 si64 shift, ui32 width) = NULL;
81
84 const line_buf *src_line, line_buf *dst_line, ui32 dst_line_offset,
85 ui32 bit_depth, bool is_signed, ui32 width) = NULL;
86
89 const line_buf *src_line, ui32 src_line_offset,
90 line_buf *dst_line, ui32 bit_depth, bool is_signed, ui32 width) = NULL;
91
94 const line_buf *src_line, line_buf *dst_line, ui32 dst_line_offset,
95 ui32 bit_depth, bool is_signed, ui32 width, const nlt_rec *rec) = NULL;
96
99 const line_buf *src_line, line_buf *dst_line, ui32 dst_line_offset,
100 ui32 bit_depth, bool is_signed, ui32 width) = NULL;
101
104 const line_buf *src_line, ui32 src_line_offset, line_buf *dst_line,
105 ui32 bit_depth, bool is_signed, ui32 width, const nlt_rec *rec) = NULL;
106
109 const line_buf *src_line, ui32 src_line_offset,
110 line_buf *dst_line, ui32 bit_depth, bool is_signed, ui32 width) = NULL;
111
114 (const line_buf* r, const line_buf* g, const line_buf* b,
115 line_buf* y, line_buf* cb, line_buf* cr, ui32 repeat) = NULL;
116
119 (const line_buf* r, const line_buf* g, const line_buf* b,
120 line_buf* y, line_buf* cb, line_buf* cr, ui32 repeat) = NULL;
121
124 (const float *r, const float *g, const float *b,
125 float *y, float *cb, float *cr, ui32 repeat) = NULL;
126
129 (const float *y, const float *cb, const float *cr,
130 float *r, float *g, float *b, ui32 repeat) = NULL;
131
134 {
135 static std::once_flag colour_transform_functions_init_flag;
136 std::call_once(colour_transform_functions_init_flag, []() {
137#if !defined(OJPH_ENABLE_WASM_SIMD) || !defined(OJPH_EMSCRIPTEN)
138
153
154 #ifndef OJPH_DISABLE_SIMD
155
156 #if (defined(OJPH_ARCH_X86_64) || defined(OJPH_ARCH_I386))
157
158 #ifndef OJPH_DISABLE_SSE
160 {
163 }
164 #endif // !OJPH_DISABLE_SSE
165
166 #ifndef OJPH_DISABLE_SSE2
168 {
181 }
182 #endif // !OJPH_DISABLE_SSE2
183
184 #ifndef OJPH_DISABLE_AVX
186 {
189 }
190 #endif // !OJPH_DISABLE_AVX
191
192 #ifndef OJPH_DISABLE_AVX2
194 {
207 }
208 #endif // !OJPH_DISABLE_AVX2
209
210 #elif defined(OJPH_ARCH_ARM)
211
212 #elif defined(OJPH_ARCH_PPC64LE)
213
215 {
216 // 128-bit VSX kernels; see ojph_simd_vsx.h
229 }
230
231 #endif // !(defined(OJPH_ARCH_X86_64) || defined(OJPH_ARCH_I386))
232
233 #endif // !OJPH_DISABLE_SIMD
234
235#else // OJPH_ENABLE_WASM_SIMD
236
251
252#endif // !OJPH_ENABLE_WASM_SIMD
253 });
254 }
255
257 const float CT_CNST::ALPHA_RF = 0.299f;
258 const float CT_CNST::ALPHA_GF = 0.587f;
259 const float CT_CNST::ALPHA_BF = 0.114f;
260 const float CT_CNST::BETA_CbF = float(0.5/(1-double(CT_CNST::ALPHA_BF)));
261 const float CT_CNST::BETA_CrF = float(0.5/(1-double(CT_CNST::ALPHA_RF)));
262 const float CT_CNST::GAMMA_CB2G =
263 float(2.0*double(ALPHA_BF)*(1.0-double(ALPHA_BF))/double(ALPHA_GF));
264 const float CT_CNST::GAMMA_CR2G =
265 float(2.0*double(ALPHA_RF)*(1.0-double(ALPHA_RF))/double(ALPHA_GF));
266 const float CT_CNST::GAMMA_CB2B = float(2.0 * (1.0 - double(ALPHA_BF)));
267 const float CT_CNST::GAMMA_CR2R = float(2.0 * (1.0 - double(ALPHA_RF)));
268
270
272 template<int NLT_TYPE>
273 static inline
275 line_buf *dst_line, ui32 dst_line_offset,
276 ui32 bit_depth, bool is_signed, ui32 width, const nlt_rec* rec)
277 {
278 assert((src_line->flags & line_buf::LFT_32BIT) &&
279 (src_line->flags & line_buf::LFT_INTEGER) == 0 &&
280 (dst_line->flags & line_buf::LFT_32BIT) &&
281 (dst_line->flags & line_buf::LFT_INTEGER));
282 ojph_unused(bit_depth);
283 ojph_unused(is_signed);
284
285 assert(rec->get_bit_depth() <= 32);
286 const float* sp = src_line->f32;
287 si32* dp = dst_line->i32 + dst_line_offset;
288
289 float mul = rec->multiplier;
290 float d_min = rec->fd_min;
291 float d_max = rec->fd_max;
292 float delta = rec->delta;
293 float inv_delta = rec->inv_delta;
294 float* lut = rec->dec_points;
295
296 if (rec->is_signed())
297 {
298 const si32 bias = (si32)((1ULL << (rec->get_bit_depth() - 1)) + 1);
299 const float half = (float)(1ULL << (rec->get_bit_depth() - 1));
300 for (int i = (int)width; i > 0; --i) {
301 float t = *sp++ + 0.5f; // convert to [0, 1]
302 t = ojph_max(t, d_min);
303 t = ojph_min(t, d_max);
304 ui32 k = (ui32)floorf((t - d_min) * inv_delta);
305 float d_k = d_min + (float)k * delta;
306 float t_k = lut[k];
307 float t_kp1 = lut[k + 1];
308 float z = t_k + (t - d_k) * inv_delta * (t_kp1 - t_k);
309
310 si32 v = ojph_round(z * mul - half);
311 if (NLT_TYPE == 4)
312 v = (v >= 0) ? v : (- v - bias);
313 *dp++ = v;
314 }
315 }
316 else
317 {
318 for (int i = (int)width; i > 0; --i) {
319 float t = *sp++ + 0.5f; // convert to [0, 1]
320 t = ojph_max(t, d_min);
321 t = ojph_min(t, d_max);
322 ui32 k = (ui32)floorf((t - d_min) * inv_delta);
323 float d_k = d_min + (float)k * delta;
324 float t_k = lut[k];
325 float t_kp1 = lut[k + 1];
326 float z = t_k + (t - d_k) * inv_delta * (t_kp1 - t_k);
327
328 si32 v = ojph_round(z * mul);
329 *dp++ = v;
330 }
331 }
332 }
333
336 line_buf *dst_line, ui32 dst_line_offset, ui32 bit_depth,
337 bool is_signed, ui32 width, const nlt_rec* rec)
338 {
339 using nl = nlt_rec::nonlinearity;
340 // if (rec->get_type() == nl::OJPH_NLT_NO_NLT)
341 // local_gen_irv_convert_to_integer_nlt0or3<false>(src_line, dst_line,
342 // dst_line_offset, bit_depth, is_signed, width);
343 // else
344 if (rec->get_type() == nl::OJPH_NLT_LUT_STYLE_NLT)
346 dst_line_offset, bit_depth, is_signed, width, rec);
347 // else if (rec->get_type() == nl::OJPH_NLT_BINARY_COMPLEMENT_NLT)
348 // local_gen_irv_convert_to_integer_nlt0or3<true>(src_line, dst_line,
349 // dst_line_offset, bit_depth, is_signed, width);
350 else if (rec->get_type() == nl::OJPH_NLT_BINARY_COMPLEMENT_PLUS_LUT)
352 dst_line_offset, bit_depth, is_signed, width, rec);
353 else
354 assert(0);
355 }
356
358 template<int NLT_TYPE>
359 static inline
361 ui32 src_line_offset, line_buf *dst_line,
362 ui32 bit_depth, bool is_signed, ui32 width, const nlt_rec* rec)
363 {
364 assert((src_line->flags & line_buf::LFT_32BIT) &&
365 (src_line->flags & line_buf::LFT_INTEGER) &&
366 (dst_line->flags & line_buf::LFT_32BIT) &&
367 (dst_line->flags & line_buf::LFT_INTEGER) == 0);
368 ojph_unused(is_signed);
369
370 assert(bit_depth <= 32);
371 float mul = (float)(1.0 / (double)(1ULL << bit_depth));
372 float d_min = rec->ft_min;
373 float d_max = rec->ft_max;
374 float delta = rec->delta;
375 float inv_delta = rec->inv_delta;
376 float* lut = rec->enc_points;
377
378 const si32* sp = src_line->i32 + src_line_offset;
379 float* dp = dst_line->f32;
380 if (rec->is_signed())
381 {
382 const si32 bias = (si32)((1ULL << (rec->get_bit_depth() - 1)) + 1);
383 for (int i = (int)width; i > 0; --i) {
384 si32 v = *sp++;
385 if (NLT_TYPE == 4)
386 v = (v >= 0) ? v : (- v - bias);
387 float t = (float)v * mul + 0.5f; // convert to [0, 1]
388 t = ojph_max(t, d_min);
389 t = ojph_min(t, d_max);
390 ui32 k = (ui32)floorf((t - d_min) * inv_delta);
391 float d_k = d_min + (float)k * delta;
392 float t_k = lut[k];
393 float t_kp1 = lut[k + 1];
394 float y = t_k + (t - d_k) * inv_delta * (t_kp1 - t_k);
395 *dp++ = y - 0.5f;
396 }
397 }
398 else
399 {
400 for (int i = (int)width; i > 0; --i) {
401 si32 v = *sp++;
402 float t = (float)v * mul; // it is in [0, 1]
403 t = ojph_max(t, d_min);
404 t = ojph_min(t, d_max);
405 ui32 k = (ui32)floorf((t - d_min) * inv_delta);
406 float d_k = d_min + (float)k * delta;
407 float t_k = lut[k];
408 float t_kp1 = lut[k + 1];
409 float y = t_k + (t - d_k) * inv_delta * (t_kp1 - t_k);
410 *dp++ = y - 0.5f;
411 }
412 }
413 }
414
417 ui32 src_line_offset, line_buf *dst_line, ui32 bit_depth,
418 bool is_signed, ui32 width, const nlt_rec* rec)
419 {
420 using nl = nlt_rec::nonlinearity;
421 // if (rec->get_type() == nl::OJPH_NLT_NO_NLT)
422 // local_gen_irv_convert_to_float_nlt0or3<false>(src_line,
423 // src_line_offset, dst_line, bit_depth, is_signed, width);
424 // else
425 if (rec->get_type() == nl::OJPH_NLT_LUT_STYLE_NLT)
427 src_line_offset, dst_line, bit_depth, is_signed, width, rec);
428 // else if (rec->get_type() == nl::OJPH_NLT_BINARY_COMPLEMENT_NLT)
429 // local_gen_irv_convert_to_float_nlt0or3<true>(src_line,
430 // src_line_offset, dst_line, bit_depth, is_signed, width);
431 else if (rec->get_type() == nl::OJPH_NLT_BINARY_COMPLEMENT_PLUS_LUT)
433 src_line_offset, dst_line, bit_depth, is_signed, width, rec);
434 else
435 assert(0);
436 }
437
439 // The LUT style nonlinearities, types 2 and 4, are implemented for the
440 // irreversible wavelet only. param_nlt::check_validity refuses to write a
441 // codestream that combines them with the reversible wavelet, so this entry
442 // point is unreachable while that check is in place.
445 const line_buf *src_line, const ui32 src_line_offset,
446 line_buf *dst_line, ui32 bit_depth, bool is_signed, ui32 width,
447 const nlt_rec* rec)
448 {
449 ojph_unused(src_line);
450 ojph_unused(src_line_offset);
451 ojph_unused(dst_line);
452 ojph_unused(bit_depth);
453 ojph_unused(is_signed);
454 ojph_unused(width);
455 ojph_unused(rec);
456 assert(0);
457 }
458
461 const line_buf *src_line, const ui32 src_line_offset,
462 line_buf *dst_line, const ui32 dst_line_offset,
463 ui32 bit_depth, bool is_signed, ui32 width, const nlt_rec* rec)
464 {
465 // A codestream can still carry a LUT style nonlinearity together with the
466 // reversible wavelet, because other encoders may produce one; this
467 // library cannot invert such a nonlinearity, so the samples are passed
468 // through unchanged. The caller was warned about that when the headers
469 // of the codestream were read, which is why this is not a failure here.
470 ojph_unused(src_line);
471 ojph_unused(src_line_offset);
472 ojph_unused(dst_line);
473 ojph_unused(dst_line_offset);
474 ojph_unused(bit_depth);
475 ojph_unused(is_signed);
476 ojph_unused(width);
477 ojph_unused(rec);
478 assert(0);
479 }
480
481#if !defined(OJPH_ENABLE_WASM_SIMD) || !defined(OJPH_EMSCRIPTEN)
482
485 const line_buf *src_line, const ui32 src_line_offset,
486 line_buf *dst_line, const ui32 dst_line_offset,
487 si64 shift, ui32 width)
488 {
489 if (src_line->flags & line_buf::LFT_32BIT)
490 {
491 if (dst_line->flags & line_buf::LFT_32BIT)
492 {
493 const si32 *sp = src_line->i32 + src_line_offset;
494 si32 *dp = dst_line->i32 + dst_line_offset;
495 si32 s = (si32)shift;
496 for (ui32 i = width; i > 0; --i)
497 *dp++ = *sp++ + s;
498 }
499 else
500 {
501 const si32 *sp = src_line->i32 + src_line_offset;
502 si64 *dp = dst_line->i64 + dst_line_offset;
503 for (ui32 i = width; i > 0; --i)
504 *dp++ = *sp++ + shift;
505 }
506 }
507 else
508 {
509 assert(src_line->flags & line_buf::LFT_64BIT);
510 assert(dst_line->flags & line_buf::LFT_32BIT);
511 const si64 *sp = src_line->i64 + src_line_offset;
512 si32 *dp = dst_line->i32 + dst_line_offset;
513 for (ui32 i = width; i > 0; --i)
514 *dp++ = (si32)(*sp++ + shift);
515 }
516 }
517
520 const line_buf *src_line, const ui32 src_line_offset,
521 line_buf *dst_line, const ui32 dst_line_offset,
522 si64 shift, ui32 width)
523 {
524 if (src_line->flags & line_buf::LFT_32BIT)
525 {
526 if (dst_line->flags & line_buf::LFT_32BIT)
527 {
528 const si32 *sp = src_line->i32 + src_line_offset;
529 si32 *dp = dst_line->i32 + dst_line_offset;
530 si32 s = (si32)shift;
531 for (ui32 i = width; i > 0; --i) {
532 const si32 v = *sp++;
533 *dp++ = v >= 0 ? v : (- v - s);
534 }
535 }
536 else
537 {
538 const si32 *sp = src_line->i32 + src_line_offset;
539 si64 *dp = dst_line->i64 + dst_line_offset;
540 for (ui32 i = width; i > 0; --i) {
541 const si64 v = *sp++;
542 *dp++ = v >= 0 ? v : (- v - shift);
543 }
544 }
545 }
546 else
547 {
548 assert(src_line->flags & line_buf::LFT_64BIT);
549 assert(dst_line->flags & line_buf::LFT_32BIT);
550 const si64 *sp = src_line->i64 + src_line_offset;
551 si32 *dp = dst_line->i32 + dst_line_offset;
552 for (ui32 i = width; i > 0; --i) {
553 const si64 v = *sp++;
554 *dp++ = (si32)(v >= 0 ? v : (- v - shift));
555 }
556 }
557 }
558
560 template<bool NLT_TYPE3>
561 static inline
563 line_buf *dst_line, ui32 dst_line_offset,
564 ui32 bit_depth, bool is_signed, ui32 width)
565 {
566 assert((src_line->flags & line_buf::LFT_32BIT) &&
567 (src_line->flags & line_buf::LFT_INTEGER) == 0 &&
568 (dst_line->flags & line_buf::LFT_32BIT) &&
569 (dst_line->flags & line_buf::LFT_INTEGER));
570
571 assert(bit_depth <= 32);
572 const float* sp = src_line->f32;
573 si32* dp = dst_line->i32 + dst_line_offset;
574 // There is the possibility that converting to integer will
575 // exceed the dynamic range of 32bit integer; therefore, care must be
576 // exercised.
577 // We look if the floating point number is outside the half-closed
578 // interval [-0.5f, 0.5f). If so, we limit the resulting integer
579 // to the maximum/minimum that number supports.
580 si32 neg_limit = (si32)INT_MIN >> (32 - bit_depth);
581 float mul = (float)(1ull << bit_depth);
582 float fl_up_lim = -(float)neg_limit; // val < upper
583 float fl_low_lim = (float)neg_limit; // val >= lower
584 si32 s32_up_lim = INT_MAX >> (32 - bit_depth);
585 si32 s32_low_lim = INT_MIN >> (32 - bit_depth);
586
587 if (is_signed)
588 {
589 const si32 bias = (si32)((1ULL << (bit_depth - 1)) + 1);
590 for (int i = (int)width; i > 0; --i) {
591 float t = *sp++ * mul;
592 si32 v = ojph_round(t);
593 v = t >= fl_low_lim ? v : s32_low_lim;
594 v = t < fl_up_lim ? v : s32_up_lim;
595 if (NLT_TYPE3)
596 v = (v >= 0) ? v : (- v - bias);
597 *dp++ = v;
598 }
599 }
600 else
601 {
602 const si32 half = (si32)(1ULL << (bit_depth - 1));
603 for (int i = (int)width; i > 0; --i) {
604 float t = *sp++ * mul;
605 si32 v = ojph_round(t);
606 v = t >= fl_low_lim ? v : s32_low_lim;
607 v = t < fl_up_lim ? v : s32_up_lim;
608 *dp++ = v + half;
609 }
610 }
611 }
612
615 line_buf *dst_line, ui32 dst_line_offset,
616 ui32 bit_depth, bool is_signed, ui32 width)
617 {
619 dst_line_offset, bit_depth, is_signed, width);
620 }
621
624 line_buf *dst_line, ui32 dst_line_offset,
625 ui32 bit_depth, bool is_signed, ui32 width)
626 {
628 dst_line_offset, bit_depth, is_signed, width);
629 }
630
632 template<bool NLT_TYPE3>
633 static inline
635 ui32 src_line_offset, line_buf *dst_line,
636 ui32 bit_depth, bool is_signed, ui32 width)
637 {
638 assert((src_line->flags & line_buf::LFT_32BIT) &&
639 (src_line->flags & line_buf::LFT_INTEGER) &&
640 (dst_line->flags & line_buf::LFT_32BIT) &&
641 (dst_line->flags & line_buf::LFT_INTEGER) == 0);
642
643 assert(bit_depth <= 32);
644 float mul = (float)(1.0 / (double)(1ULL << bit_depth));
645
646 const si32* sp = src_line->i32 + src_line_offset;
647 float* dp = dst_line->f32;
648 if (is_signed)
649 {
650 const si32 bias = (si32)((1ULL << (bit_depth - 1)) + 1);
651 for (int i = (int)width; i > 0; --i) {
652 si32 v = *sp++;
653 if (NLT_TYPE3)
654 v = (v >= 0) ? v : (- v - bias);
655 *dp++ = (float)v * mul;
656 }
657 }
658 else
659 {
660 const si32 half = (si32)(1ULL << (bit_depth - 1));
661 for (int i = (int)width; i > 0; --i) {
662 si32 v = *sp++;
663 v -= half;
664 *dp++ = (float)v * mul;
665 }
666 }
667 }
668
670 void gen_irv_convert_to_float(const line_buf *src_line,
671 ui32 src_line_offset, line_buf *dst_line,
672 ui32 bit_depth, bool is_signed, ui32 width)
673 {
674 local_gen_irv_convert_to_float_nlt0or3<false>(src_line, src_line_offset,
675 dst_line, bit_depth, is_signed, width);
676 }
677
680 ui32 src_line_offset, line_buf *dst_line,
681 ui32 bit_depth, bool is_signed, ui32 width)
682 {
683 local_gen_irv_convert_to_float_nlt0or3<true>(src_line, src_line_offset,
684 dst_line, bit_depth, is_signed, width);
685 }
686
689 const line_buf *r, const line_buf *g, const line_buf *b,
690 line_buf *y, line_buf *cb, line_buf *cr, ui32 repeat)
691 {
692 assert((y->flags & line_buf::LFT_INTEGER) &&
698
699 if (y->flags & line_buf::LFT_32BIT)
700 {
701 assert((y->flags & line_buf::LFT_32BIT) &&
702 (cb->flags & line_buf::LFT_32BIT) &&
703 (cr->flags & line_buf::LFT_32BIT) &&
704 (r->flags & line_buf::LFT_32BIT) &&
705 (g->flags & line_buf::LFT_32BIT) &&
707 const si32 *rp = r->i32, * gp = g->i32, * bp = b->i32;
708 si32 *yp = y->i32, * cbp = cb->i32, * crp = cr->i32;
709 for (ui32 i = repeat; i > 0; --i)
710 {
711 si32 rr = *rp++, gg = *gp++, bb = *bp++;
712 *yp++ = (rr + (gg << 1) + bb) >> 2;
713 *cbp++ = (bb - gg);
714 *crp++ = (rr - gg);
715 }
716 }
717 else
718 {
719 assert((y->flags & line_buf::LFT_64BIT) &&
720 (cb->flags & line_buf::LFT_64BIT) &&
721 (cr->flags & line_buf::LFT_64BIT) &&
722 (r->flags & line_buf::LFT_32BIT) &&
723 (g->flags & line_buf::LFT_32BIT) &&
725 const si32 *rp = r->i32, *gp = g->i32, *bp = b->i32;
726 si64 *yp = y->i64, *cbp = cb->i64, *crp = cr->i64;
727 for (ui32 i = repeat; i > 0; --i)
728 {
729 si64 rr = *rp++, gg = *gp++, bb = *bp++;
730 *yp++ = (rr + (gg << 1) + bb) >> 2;
731 *cbp++ = (bb - gg);
732 *crp++ = (rr - gg);
733 }
734 }
735 }
736
739 const line_buf *y, const line_buf *cb, const line_buf *cr,
740 line_buf *r, line_buf *g, line_buf *b, ui32 repeat)
741 {
742 assert((y->flags & line_buf::LFT_INTEGER) &&
748
749 if (y->flags & line_buf::LFT_32BIT)
750 {
751 assert((y->flags & line_buf::LFT_32BIT) &&
752 (cb->flags & line_buf::LFT_32BIT) &&
753 (cr->flags & line_buf::LFT_32BIT) &&
754 (r->flags & line_buf::LFT_32BIT) &&
755 (g->flags & line_buf::LFT_32BIT) &&
757 const si32 *yp = y->i32, *cbp = cb->i32, *crp = cr->i32;
758 si32 *rp = r->i32, *gp = g->i32, *bp = b->i32;
759 for (ui32 i = repeat; i > 0; --i)
760 {
761 si32 yy = *yp++, cbb = *cbp++, crr = *crp++;
762 si32 gg = yy - ((cbb + crr) >> 2);
763 *rp++ = crr + gg;
764 *gp++ = gg;
765 *bp++ = cbb + gg;
766 }
767 }
768 else
769 {
770 assert((y->flags & line_buf::LFT_64BIT) &&
771 (cb->flags & line_buf::LFT_64BIT) &&
772 (cr->flags & line_buf::LFT_64BIT) &&
773 (r->flags & line_buf::LFT_32BIT) &&
774 (g->flags & line_buf::LFT_32BIT) &&
776 const si64 *yp = y->i64, *cbp = cb->i64, *crp = cr->i64;
777 si32 *rp = r->i32, *gp = g->i32, *bp = b->i32;
778 for (ui32 i = repeat; i > 0; --i)
779 {
780 si64 yy = *yp++, cbb = *cbp++, crr = *crp++;
781 si64 gg = yy - ((cbb + crr) >> 2);
782 *rp++ = (si32)(crr + gg);
783 *gp++ = (si32)gg;
784 *bp++ = (si32)(cbb + gg);
785 }
786 }
787 }
788
790 void gen_ict_forward(const float *r, const float *g, const float *b,
791 float *y, float *cb, float *cr, ui32 repeat)
792 {
793 for (ui32 i = repeat; i > 0; --i)
794 {
795 *y = CT_CNST::ALPHA_RF * *r
796 + CT_CNST::ALPHA_GF * *g++
797 + CT_CNST::ALPHA_BF * *b;
798 *cb++ = CT_CNST::BETA_CbF * (*b++ - *y);
799 *cr++ = CT_CNST::BETA_CrF * (*r++ - *y++);
800 }
801 }
802
804 void gen_ict_backward(const float *y, const float *cb, const float *cr,
805 float *r, float *g, float *b, ui32 repeat)
806 {
807 for (ui32 i = repeat; i > 0; --i)
808 {
809 *g++ = *y - CT_CNST::GAMMA_CR2G * *cr - CT_CNST::GAMMA_CB2G * *cb;
810 *r++ = *y + CT_CNST::GAMMA_CR2R * *cr++;
811 *b++ = *y++ + CT_CNST::GAMMA_CB2B * *cb++;
812 }
813 }
814
815#endif // !OJPH_ENABLE_WASM_SIMD
816
817 }
818}
void gen_rev_decode_nlt(const line_buf *src_line, const ui32 src_line_offset, line_buf *dst_line, const ui32 dst_line_offset, ui32 bit_depth, bool is_signed, ui32 width, const nlt_rec *rec)
void sse2_rct_backward(const line_buf *y, const line_buf *cb, const line_buf *cr, line_buf *r, line_buf *g, line_buf *b, ui32 repeat)
void sse2_irv_convert_to_integer(const line_buf *src_line, line_buf *dst_line, ui32 dst_line_offset, ui32 bit_depth, bool is_signed, ui32 width)
void wasm_ict_backward(const float *y, const float *cb, const float *cr, float *r, float *g, float *b, ui32 repeat)
void wasm_irv_convert_to_integer(const line_buf *src_line, line_buf *dst_line, ui32 dst_line_offset, ui32 bit_depth, bool is_signed, ui32 width)
void avx2_rct_forward(const line_buf *r, const line_buf *g, const line_buf *b, line_buf *y, line_buf *cb, line_buf *cr, ui32 repeat)
void wasm_rev_convert_nlt_type3(const line_buf *src_line, const ui32 src_line_offset, line_buf *dst_line, const ui32 dst_line_offset, si64 shift, ui32 width)
void vsx_irv_convert_to_float_nlt_type3(const line_buf *src_line, ui32 src_line_offset, line_buf *dst_line, ui32 bit_depth, bool is_signed, ui32 width)
void wasm_irv_convert_to_integer_nlt_type3(const line_buf *src_line, line_buf *dst_line, ui32 dst_line_offset, ui32 bit_depth, bool is_signed, ui32 width)
void sse2_irv_convert_to_float_nlt_type3(const line_buf *src_line, ui32 src_line_offset, line_buf *dst_line, ui32 bit_depth, bool is_signed, ui32 width)
void(*) ict_forward(const float *r, const float *g, const float *b, float *y, float *cb, float *cr, ui32 repeat)
void sse2_irv_convert_to_integer_nlt_type3(const line_buf *src_line, line_buf *dst_line, ui32 dst_line_offset, ui32 bit_depth, bool is_signed, ui32 width)
void gen_rct_forward(const line_buf *r, const line_buf *g, const line_buf *b, line_buf *y, line_buf *cb, line_buf *cr, ui32 repeat)
void(*) rev_decode_nlt(const line_buf *src_line, const ui32 src_line_offset, line_buf *dst_line, const ui32 dst_line_offset, ui32 bit_depth, bool is_signed, ui32 width, const nlt_rec *rec)
void avx_ict_forward(const float *r, const float *g, const float *b, float *y, float *cb, float *cr, ui32 repeat)
void gen_rct_backward(const line_buf *y, const line_buf *cb, const line_buf *cr, line_buf *r, line_buf *g, line_buf *b, ui32 repeat)
void sse2_rev_convert(const line_buf *src_line, const ui32 src_line_offset, line_buf *dst_line, const ui32 dst_line_offset, si64 shift, ui32 width)
void vsx_ict_backward(const float *y, const float *cb, const float *cr, float *r, float *g, float *b, ui32 repeat)
void(*) irv_convert_to_float_nlt_type3(const line_buf *src_line, ui32 src_line_offset, line_buf *dst_line, ui32 bit_depth, bool is_signed, ui32 width)
void avx2_rct_backward(const line_buf *y, const line_buf *cb, const line_buf *cr, line_buf *r, line_buf *g, line_buf *b, ui32 repeat)
static void local_gen_irv_convert_to_float_nlt0or3(const line_buf *src_line, ui32 src_line_offset, line_buf *dst_line, ui32 bit_depth, bool is_signed, ui32 width)
void gen_irv_convert_to_integer(const line_buf *src_line, line_buf *dst_line, ui32 dst_line_offset, ui32 bit_depth, bool is_signed, ui32 width)
void(*) irv_convert_to_integer_nlt_type3(const line_buf *src_line, line_buf *dst_line, ui32 dst_line_offset, ui32 bit_depth, bool is_signed, ui32 width)
void sse2_rev_convert_nlt_type3(const line_buf *src_line, const ui32 src_line_offset, line_buf *dst_line, const ui32 dst_line_offset, si64 shift, ui32 width)
void(*) rev_convert_nlt_type3(const line_buf *src_line, const ui32 src_line_offset, line_buf *dst_line, const ui32 dst_line_offset, si64 shift, ui32 width)
void(*) irv_convert_to_float_nlt(const line_buf *src_line, ui32 src_line_offset, line_buf *dst_line, ui32 bit_depth, bool is_signed, ui32 width, const nlt_rec *rec)
void wasm_rev_convert(const line_buf *src_line, const ui32 src_line_offset, line_buf *dst_line, const ui32 dst_line_offset, si64 shift, ui32 width)
void gen_irv_convert_to_float(const line_buf *src_line, ui32 src_line_offset, line_buf *dst_line, ui32 bit_depth, bool is_signed, ui32 width)
void vsx_rev_convert_nlt_type3(const line_buf *src_line, const ui32 src_line_offset, line_buf *dst_line, const ui32 dst_line_offset, si64 shift, ui32 width)
void vsx_ict_forward(const float *r, const float *g, const float *b, float *y, float *cb, float *cr, ui32 repeat)
void init_colour_transform_functions()
void vsx_rct_backward(const line_buf *y, const line_buf *cb, const line_buf *cr, line_buf *r, line_buf *g, line_buf *b, ui32 repeat)
void gen_ict_forward(const float *r, const float *g, const float *b, float *y, float *cb, float *cr, ui32 repeat)
static void local_gen_irv_convert_to_integer_nlt2or4(const line_buf *src_line, line_buf *dst_line, ui32 dst_line_offset, ui32 bit_depth, bool is_signed, ui32 width, const nlt_rec *rec)
void(*) rct_forward(const line_buf *r, const line_buf *g, const line_buf *b, line_buf *y, line_buf *cb, line_buf *cr, ui32 repeat)
void(*) irv_convert_to_integer_nlt(const line_buf *src_line, line_buf *dst_line, ui32 dst_line_offset, ui32 bit_depth, bool is_signed, ui32 width, const nlt_rec *rec)
void(*) irv_convert_to_integer(const line_buf *src_line, line_buf *dst_line, ui32 dst_line_offset, ui32 bit_depth, bool is_signed, ui32 width)
void vsx_rev_convert(const line_buf *src_line, const ui32 src_line_offset, line_buf *dst_line, const ui32 dst_line_offset, si64 shift, ui32 width)
void gen_rev_convert_nlt_type3(const line_buf *src_line, const ui32 src_line_offset, line_buf *dst_line, const ui32 dst_line_offset, si64 shift, ui32 width)
void wasm_irv_convert_to_float_nlt_type3(const line_buf *src_line, ui32 src_line_offset, line_buf *dst_line, ui32 bit_depth, bool is_signed, ui32 width)
void sse_ict_forward(const float *r, const float *g, const float *b, float *y, float *cb, float *cr, ui32 repeat)
void avx2_rev_convert(const line_buf *src_line, const ui32 src_line_offset, line_buf *dst_line, const ui32 dst_line_offset, si64 shift, ui32 width)
void avx2_irv_convert_to_float(const line_buf *src_line, ui32 src_line_offset, line_buf *dst_line, ui32 bit_depth, bool is_signed, ui32 width)
void wasm_rct_backward(const line_buf *y, const line_buf *cb, const line_buf *cr, line_buf *r, line_buf *g, line_buf *b, ui32 repeat)
void avx2_irv_convert_to_integer_nlt(const line_buf *src_line, line_buf *dst_line, ui32 dst_line_offset, ui32 bit_depth, bool is_signed, ui32 width, const nlt_rec *rec)
void wasm_rct_forward(const line_buf *r, const line_buf *g, const line_buf *b, line_buf *y, line_buf *cb, line_buf *cr, ui32 repeat)
void(*) rev_convert(const line_buf *src_line, const ui32 src_line_offset, line_buf *dst_line, const ui32 dst_line_offset, si64 shift, ui32 width)
void gen_irv_convert_to_integer_nlt(const line_buf *src_line, line_buf *dst_line, ui32 dst_line_offset, ui32 bit_depth, bool is_signed, ui32 width, const nlt_rec *rec)
void wasm_ict_forward(const float *r, const float *g, const float *b, float *y, float *cb, float *cr, ui32 repeat)
void avx2_rev_convert_nlt_type3(const line_buf *src_line, const ui32 src_line_offset, line_buf *dst_line, const ui32 dst_line_offset, si64 shift, ui32 width)
void gen_ict_backward(const float *y, const float *cb, const float *cr, float *r, float *g, float *b, ui32 repeat)
void gen_rev_convert(const line_buf *src_line, const ui32 src_line_offset, line_buf *dst_line, const ui32 dst_line_offset, si64 shift, ui32 width)
void sse2_irv_convert_to_integer_nlt(const line_buf *src_line, line_buf *dst_line, ui32 dst_line_offset, ui32 bit_depth, bool is_signed, ui32 width, const nlt_rec *rec)
void(*) rev_encode_nlt(const line_buf *src_line, const ui32 src_line_offset, line_buf *dst_line, ui32 bit_depth, bool is_signed, ui32 width, const nlt_rec *rec)
void avx2_irv_convert_to_float_nlt(const line_buf *src_line, ui32 src_line_offset, line_buf *dst_line, ui32 bit_depth, bool is_signed, ui32 width, const nlt_rec *rec)
void(*) irv_convert_to_float(const line_buf *src_line, ui32 src_line_offset, line_buf *dst_line, ui32 bit_depth, bool is_signed, ui32 width)
void vsx_rct_forward(const line_buf *r, const line_buf *g, const line_buf *b, line_buf *y, line_buf *cb, line_buf *cr, ui32 repeat)
void avx2_irv_convert_to_integer(const line_buf *src_line, line_buf *dst_line, ui32 dst_line_offset, ui32 bit_depth, bool is_signed, ui32 width)
void avx2_irv_convert_to_float_nlt_type3(const line_buf *src_line, ui32 src_line_offset, line_buf *dst_line, ui32 bit_depth, bool is_signed, ui32 width)
void sse2_rct_forward(const line_buf *r, const line_buf *g, const line_buf *b, line_buf *y, line_buf *cb, line_buf *cr, ui32 repeat)
void sse2_irv_convert_to_float_nlt(const line_buf *src_line, ui32 src_line_offset, line_buf *dst_line, ui32 bit_depth, bool is_signed, ui32 width, const nlt_rec *rec)
static void local_gen_irv_convert_to_float_nlt2or4(const line_buf *src_line, ui32 src_line_offset, line_buf *dst_line, ui32 bit_depth, bool is_signed, ui32 width, const nlt_rec *rec)
void avx_ict_backward(const float *y, const float *cb, const float *cr, float *r, float *g, float *b, ui32 repeat)
void gen_irv_convert_to_float_nlt(const line_buf *src_line, ui32 src_line_offset, line_buf *dst_line, ui32 bit_depth, bool is_signed, ui32 width, const nlt_rec *rec)
void avx2_irv_convert_to_integer_nlt_type3(const line_buf *src_line, line_buf *dst_line, ui32 dst_line_offset, ui32 bit_depth, bool is_signed, ui32 width)
void(*) ict_backward(const float *y, const float *cb, const float *cr, float *r, float *g, float *b, ui32 repeat)
void vsx_irv_convert_to_float(const line_buf *src_line, ui32 src_line_offset, line_buf *dst_line, ui32 bit_depth, bool is_signed, ui32 width)
void vsx_irv_convert_to_integer(const line_buf *src_line, line_buf *dst_line, ui32 dst_line_offset, ui32 bit_depth, bool is_signed, ui32 width)
void wasm_irv_convert_to_float(const line_buf *src_line, ui32 src_line_offset, line_buf *dst_line, ui32 bit_depth, bool is_signed, ui32 width)
void gen_rev_encode_nlt(const line_buf *src_line, const ui32 src_line_offset, line_buf *dst_line, ui32 bit_depth, bool is_signed, ui32 width, const nlt_rec *rec)
void vsx_irv_convert_to_integer_nlt_type3(const line_buf *src_line, line_buf *dst_line, ui32 dst_line_offset, ui32 bit_depth, bool is_signed, ui32 width)
void sse_ict_backward(const float *y, const float *cb, const float *cr, float *r, float *g, float *b, ui32 repeat)
void(*) rct_backward(const line_buf *r, const line_buf *g, const line_buf *b, line_buf *y, line_buf *cb, line_buf *cr, ui32 repeat)
void gen_irv_convert_to_integer_nlt_type3(const line_buf *src_line, line_buf *dst_line, ui32 dst_line_offset, ui32 bit_depth, bool is_signed, ui32 width)
void gen_irv_convert_to_float_nlt_type3(const line_buf *src_line, ui32 src_line_offset, line_buf *dst_line, ui32 bit_depth, bool is_signed, ui32 width)
static void local_gen_irv_convert_to_integer_nlt0or3(const line_buf *src_line, line_buf *dst_line, ui32 dst_line_offset, ui32 bit_depth, bool is_signed, ui32 width)
void sse2_irv_convert_to_float(const line_buf *src_line, ui32 src_line_offset, line_buf *dst_line, ui32 bit_depth, bool is_signed, ui32 width)
int64_t si64
Definition ojph_defs.h:57
@ PPC_CPU_EXT_LEVEL_ARCH_2_07
Definition ojph_arch.h:180
OJPH_EXPORT int get_cpu_ext_level()
int32_t si32
Definition ojph_defs.h:55
uint32_t ui32
Definition ojph_defs.h:54
@ X86_CPU_EXT_LEVEL_AVX2
Definition ojph_arch.h:163
@ X86_CPU_EXT_LEVEL_AVX
Definition ojph_arch.h:162
@ X86_CPU_EXT_LEVEL_SSE2
Definition ojph_arch.h:157
@ X86_CPU_EXT_LEVEL_SSE
Definition ojph_arch.h:156
#define ojph_max(a, b)
Definition ojph_defs.h:73
#define ojph_min(a, b)
Definition ojph_defs.h:76
#define ojph_unused(x)
Definition ojph_defs.h:78
static const float GAMMA_CR2R
static const float BETA_CbF
static const float GAMMA_CB2B
static const float ALPHA_RF
static const float GAMMA_CB2G
static const float GAMMA_CR2G
static const float ALPHA_BF
static const float BETA_CrF
static const float ALPHA_GF
ojph::param_nlt::nonlinearity nonlinearity