Coverage Report

Created: 2026-09-06 07:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/jasper/src/libjasper/jpc/jpc_mct.c
Line
Count
Source
1
/*
2
 * Copyright (c) 1999-2000 Image Power, Inc. and the University of
3
 *   British Columbia.
4
 * Copyright (c) 2001-2003 Michael David Adams.
5
 * All rights reserved.
6
 */
7
8
/* __START_OF_JASPER_LICENSE__
9
 * 
10
 * JasPer License Version 2.0
11
 * 
12
 * Copyright (c) 2001-2006 Michael David Adams
13
 * Copyright (c) 1999-2000 Image Power, Inc.
14
 * Copyright (c) 1999-2000 The University of British Columbia
15
 * 
16
 * All rights reserved.
17
 * 
18
 * Permission is hereby granted, free of charge, to any person (the
19
 * "User") obtaining a copy of this software and associated documentation
20
 * files (the "Software"), to deal in the Software without restriction,
21
 * including without limitation the rights to use, copy, modify, merge,
22
 * publish, distribute, and/or sell copies of the Software, and to permit
23
 * persons to whom the Software is furnished to do so, subject to the
24
 * following conditions:
25
 * 
26
 * 1.  The above copyright notices and this permission notice (which
27
 * includes the disclaimer below) shall be included in all copies or
28
 * substantial portions of the Software.
29
 * 
30
 * 2.  The name of a copyright holder shall not be used to endorse or
31
 * promote products derived from the Software without specific prior
32
 * written permission.
33
 * 
34
 * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
35
 * LICENSE.  NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
36
 * THIS DISCLAIMER.  THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
37
 * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
38
 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
39
 * PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.  IN NO
40
 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
41
 * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
42
 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
43
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
44
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.  NO ASSURANCES ARE
45
 * PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
46
 * THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
47
 * EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
48
 * BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
49
 * PROPERTY RIGHTS OR OTHERWISE.  AS A CONDITION TO EXERCISING THE RIGHTS
50
 * GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
51
 * ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY.  THE SOFTWARE
52
 * IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
53
 * SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
54
 * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
55
 * SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
56
 * THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
57
 * PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
58
 * RISK ACTIVITIES").  THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
59
 * EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
60
 * 
61
 * __END_OF_JASPER_LICENSE__
62
 */
63
64
/*
65
 * Multicomponent Transform Code
66
 *
67
 * $Id$
68
 */
69
70
/******************************************************************************\
71
* Includes.
72
\******************************************************************************/
73
74
#include "jpc_mct.h"
75
#include "jpc_fix.h"
76
77
#include "jasper/jas_seq.h"
78
79
#include <assert.h>
80
#include <math.h>
81
82
/******************************************************************************\
83
* Code.
84
\******************************************************************************/
85
86
/* Compute the forward RCT. */
87
88
void jpc_rct(jas_matrix_t *c0, jas_matrix_t *c1, jas_matrix_t *c2)
89
379
{
90
379
  int numrows;
91
379
  int numcols;
92
379
  int i;
93
379
  int j;
94
379
  jpc_fix_t *c0p;
95
379
  jpc_fix_t *c1p;
96
379
  jpc_fix_t *c2p;
97
98
379
  numrows = jas_matrix_numrows(c0);
99
379
  numcols = jas_matrix_numcols(c0);
100
101
  /* All three matrices must have the same dimensions. */
102
379
  assert(jas_matrix_numrows(c1) == numrows && jas_matrix_numcols(c1) == numcols
103
379
    && jas_matrix_numrows(c2) == numrows && jas_matrix_numcols(c2) == numcols);
104
105
157k
  for (i = 0; i < numrows; i++) {
106
157k
    c0p = jas_matrix_getref(c0, i, 0);
107
157k
    c1p = jas_matrix_getref(c1, i, 0);
108
157k
    c2p = jas_matrix_getref(c2, i, 0);
109
156M
    for (j = numcols; j > 0; --j) {
110
156M
      int r;
111
156M
      int g;
112
156M
      int b;
113
156M
      int y;
114
156M
      int u;
115
156M
      int v;
116
156M
      r = *c0p;
117
156M
      g = *c1p;
118
156M
      b = *c2p;
119
      //y = (r + (g << 1) + b) >> 2;
120
156M
      y = jpc_fix_asr(r + jpc_fix_asl(g, 1) + b, 2);
121
156M
      u = b - g;
122
156M
      v = r - g;
123
156M
      *c0p++ = y;
124
156M
      *c1p++ = u;
125
156M
      *c2p++ = v;
126
156M
    }
127
157k
  }
128
379
}
129
130
/* Compute the inverse RCT. */
131
132
void jpc_irct(jas_matrix_t *c0, jas_matrix_t *c1, jas_matrix_t *c2)
133
1.00k
{
134
1.00k
  int numrows;
135
1.00k
  int numcols;
136
1.00k
  int i;
137
1.00k
  int j;
138
1.00k
  jpc_fix_t *c0p;
139
1.00k
  jpc_fix_t *c1p;
140
1.00k
  jpc_fix_t *c2p;
141
142
1.00k
  numrows = jas_matrix_numrows(c0);
143
1.00k
  numcols = jas_matrix_numcols(c0);
144
145
  /* All three matrices must have the same dimensions. */
146
1.00k
  assert(jas_matrix_numrows(c1) == numrows && jas_matrix_numcols(c1) == numcols
147
1.00k
    && jas_matrix_numrows(c2) == numrows && jas_matrix_numcols(c2) == numcols);
148
149
108k
  for (i = 0; i < numrows; i++) {
150
107k
    c0p = jas_matrix_getref(c0, i, 0);
151
107k
    c1p = jas_matrix_getref(c1, i, 0);
152
107k
    c2p = jas_matrix_getref(c2, i, 0);
153
21.4M
    for (j = numcols; j > 0; --j) {
154
21.2M
      int r;
155
21.2M
      int g;
156
21.2M
      int b;
157
21.2M
      int y;
158
21.2M
      int u;
159
21.2M
      int v;
160
21.2M
      y = *c0p;
161
21.2M
      u = *c1p;
162
21.2M
      v = *c2p;
163
      //g = y - ((u + v) >> 2);
164
21.2M
      g = y - jpc_fix_asr(u + v, 2);
165
21.2M
      r = v + g;
166
21.2M
      b = u + g;
167
21.2M
      *c0p++ = r;
168
21.2M
      *c1p++ = g;
169
21.2M
      *c2p++ = b;
170
21.2M
    }
171
107k
  }
172
1.00k
}
173
174
void jpc_ict(jas_matrix_t *c0, jas_matrix_t *c1, jas_matrix_t *c2)
175
0
{
176
0
  int numrows;
177
0
  int numcols;
178
0
  int i;
179
0
  int j;
180
0
  jpc_fix_t r;
181
0
  jpc_fix_t g;
182
0
  jpc_fix_t b;
183
0
  jpc_fix_t y;
184
0
  jpc_fix_t u;
185
0
  jpc_fix_t v;
186
0
  jpc_fix_t *c0p;
187
0
  jpc_fix_t *c1p;
188
0
  jpc_fix_t *c2p;
189
190
0
  numrows = jas_matrix_numrows(c0);
191
0
  assert(jas_matrix_numrows(c1) == numrows && jas_matrix_numrows(c2) == numrows);
192
0
  numcols = jas_matrix_numcols(c0);
193
0
  assert(jas_matrix_numcols(c1) == numcols && jas_matrix_numcols(c2) == numcols);
194
0
  for (i = 0; i < numrows; ++i) {
195
0
    c0p = jas_matrix_getref(c0, i, 0);
196
0
    c1p = jas_matrix_getref(c1, i, 0);
197
0
    c2p = jas_matrix_getref(c2, i, 0);
198
0
    for (j = numcols; j > 0; --j) {
199
0
      r = *c0p;
200
0
      g = *c1p;
201
0
      b = *c2p;
202
0
      y = jpc_fix_add3(jpc_fix_mul(jpc_dbltofix(0.299), r), jpc_fix_mul(jpc_dbltofix(0.587), g),
203
0
        jpc_fix_mul(jpc_dbltofix(0.114), b));
204
0
      u = jpc_fix_add3(jpc_fix_mul(jpc_dbltofix(-0.16875), r), jpc_fix_mul(jpc_dbltofix(-0.33126), g),
205
0
        jpc_fix_mul(jpc_dbltofix(0.5), b));
206
0
      v = jpc_fix_add3(jpc_fix_mul(jpc_dbltofix(0.5), r), jpc_fix_mul(jpc_dbltofix(-0.41869), g),
207
0
        jpc_fix_mul(jpc_dbltofix(-0.08131), b));
208
0
      *c0p++ = y;
209
0
      *c1p++ = u;
210
0
      *c2p++ = v;
211
0
    }
212
0
  }
213
0
}
214
215
void jpc_iict(jas_matrix_t *c0, jas_matrix_t *c1, jas_matrix_t *c2)
216
2.11k
{
217
2.11k
  int numrows;
218
2.11k
  int numcols;
219
2.11k
  int i;
220
2.11k
  int j;
221
2.11k
  jpc_fix_t r;
222
2.11k
  jpc_fix_t g;
223
2.11k
  jpc_fix_t b;
224
2.11k
  jpc_fix_t y;
225
2.11k
  jpc_fix_t u;
226
2.11k
  jpc_fix_t v;
227
2.11k
  jpc_fix_t *c0p;
228
2.11k
  jpc_fix_t *c1p;
229
2.11k
  jpc_fix_t *c2p;
230
231
2.11k
  numrows = jas_matrix_numrows(c0);
232
2.11k
  assert(jas_matrix_numrows(c1) == numrows && jas_matrix_numrows(c2) == numrows);
233
2.11k
  numcols = jas_matrix_numcols(c0);
234
2.11k
  assert(jas_matrix_numcols(c1) == numcols && jas_matrix_numcols(c2) == numcols);
235
141k
  for (i = 0; i < numrows; ++i) {
236
139k
    c0p = jas_matrix_getref(c0, i, 0);
237
139k
    c1p = jas_matrix_getref(c1, i, 0);
238
139k
    c2p = jas_matrix_getref(c2, i, 0);
239
51.0M
    for (j = numcols; j > 0; --j) {
240
50.8M
      y = *c0p;
241
50.8M
      u = *c1p;
242
50.8M
      v = *c2p;
243
50.8M
      r = jpc_fix_add(y, jpc_fix_mul(jpc_dbltofix(1.402), v));
244
50.8M
      g = jpc_fix_add3(y, jpc_fix_mul(jpc_dbltofix(-0.34413), u),
245
50.8M
        jpc_fix_mul(jpc_dbltofix(-0.71414), v));
246
50.8M
      b = jpc_fix_add(y, jpc_fix_mul(jpc_dbltofix(1.772), u));
247
50.8M
      *c0p++ = r;
248
50.8M
      *c1p++ = g;
249
50.8M
      *c2p++ = b;
250
50.8M
    }
251
139k
  }
252
2.11k
}