Engauge Digitizer  2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
Jpeg2000Color.cpp File Reference
#include <assert.h>
#include <math.h>
#include <qmath.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "Jpeg2000Color.h"
Include dependency graph for Jpeg2000Color.cpp:

Go to the source code of this file.

Functions

void sycc_to_rgb (int offset, int upb, int y, int cb, int cr, int *out_r, int *out_g, int *out_b)
 
void sycc444_to_rgb (opj_image_t *img)
 
void sycc422_to_rgb (opj_image_t *img)
 
void sycc420_to_rgb (opj_image_t *img)
 
void color_sycc_to_rgb (opj_image_t *img)
 

Function Documentation

void color_sycc_to_rgb ( opj_image_t *  img)

Definition at line 237 of file Jpeg2000Color.cpp.

238 {
239  if(img->numcomps < 3)
240  {
241  img->color_space = OPJ_CLRSPC_GRAY;
242  return;
243  }
244 
245  if((img->comps[0].dx == 1)
246  && (img->comps[1].dx == 2)
247  && (img->comps[2].dx == 2)
248  && (img->comps[0].dy == 1)
249  && (img->comps[1].dy == 2)
250  && (img->comps[2].dy == 2))/* horizontal and vertical sub-sample */
251  {
252  sycc420_to_rgb(img);
253  }
254  else {
255  if((img->comps[0].dx == 1)
256  && (img->comps[1].dx == 2)
257  && (img->comps[2].dx == 2)
258  && (img->comps[0].dy == 1)
259  && (img->comps[1].dy == 1)
260  && (img->comps[2].dy == 1))/* horizontal sub-sample only */
261  {
262  sycc422_to_rgb(img);
263  }
264  else {
265  if((img->comps[0].dx == 1)
266  && (img->comps[1].dx == 1)
267  && (img->comps[2].dx == 1)
268  && (img->comps[0].dy == 1)
269  && (img->comps[1].dy == 1)
270  && (img->comps[2].dy == 1))/* no sub-sample */
271  {
272  sycc444_to_rgb(img);
273  }
274  else
275  {
276  fprintf(stderr,"%s:%d:color_sycc_to_rgb\n\tCAN NOT CONVERT\n",
277  __FILE__,__LINE__);
278  return;
279  }
280  }
281  }
282  img->color_space = OPJ_CLRSPC_SRGB;
283 }/* color_sycc_to_rgb() */
void sycc420_to_rgb(opj_image_t *img)
void sycc444_to_rgb(opj_image_t *img)
void sycc422_to_rgb(opj_image_t *img)
void sycc420_to_rgb ( opj_image_t *  img)

Definition at line 170 of file Jpeg2000Color.cpp.

171 {
172  int *d0, *d1, *d2, *r, *g, *b, *nr, *ng, *nb;
173  const int *y, *cb, *cr, *ny;
174  int maxw, maxh, max, offset, upb;
175  int i, j;
176 
177  i = qFloor (img->comps[0].prec);
178  offset = 1<<(i - 1); upb = (1<<i)-1;
179 
180  maxw = qFloor (img->comps[0].w);
181  maxh = qFloor (img->comps[0].h);
182  max = maxw * maxh;
183 
184  y = img->comps[0].data;
185  cb = img->comps[1].data;
186  cr = img->comps[2].data;
187 
188  d0 = r = static_cast<int*> (malloc(sizeof(int) * static_cast<size_t> (max)));
189  d1 = g = static_cast<int*> (malloc(sizeof(int) * static_cast<size_t> (max)));
190  d2 = b = static_cast<int*> (malloc(sizeof(int) * static_cast<size_t> (max)));
191 
192  for(i=0; i < maxh; i += 2)
193  {
194  ny = y + maxw;
195  nr = r + maxw; ng = g + maxw; nb = b + maxw;
196 
197  for(j=0; j < maxw; j += 2)
198  {
199  sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
200 
201  ++y; ++r; ++g; ++b;
202 
203  sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
204 
205  ++y; ++r; ++g; ++b;
206 
207  sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb);
208 
209  ++ny; ++nr; ++ng; ++nb;
210 
211  sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb);
212 
213  ++ny; ++nr; ++ng; ++nb; ++cb; ++cr;
214  }
215  y += maxw; r += maxw; g += maxw; b += maxw;
216  }
217  free(img->comps[0].data); img->comps[0].data = d0;
218  free(img->comps[1].data); img->comps[1].data = d1;
219  free(img->comps[2].data); img->comps[2].data = d2;
220 
221 #if defined(USE_JPWL) || defined(USE_MJ2)
222  img->comps[1].w = maxw; img->comps[1].h = maxh;
223  img->comps[2].w = maxw; img->comps[2].h = maxh;
224 #else
225  img->comps[1].w = static_cast<OPJ_UINT32> (maxw);
226  img->comps[1].h = static_cast<OPJ_UINT32> (maxh);
227  img->comps[2].w = static_cast<OPJ_UINT32> (maxw);
228  img->comps[2].h = static_cast<OPJ_UINT32> (maxh);
229 #endif
230  img->comps[1].dx = img->comps[0].dx;
231  img->comps[2].dx = img->comps[0].dx;
232  img->comps[1].dy = img->comps[0].dy;
233  img->comps[2].dy = img->comps[0].dy;
234 
235 }/* sycc420_to_rgb() */
void sycc_to_rgb(int offset, int upb, int y, int cb, int cr, int *out_r, int *out_g, int *out_b)
void sycc422_to_rgb ( opj_image_t *  img)

Definition at line 115 of file Jpeg2000Color.cpp.

116 {
117  int *d0, *d1, *d2, *r, *g, *b;
118  const int *y, *cb, *cr;
119  int maxw, maxh, max, offset, upb;
120  int i, j;
121 
122  i = qFloor (img->comps[0].prec);
123  offset = 1<<(i - 1); upb = (1<<i)-1;
124 
125  maxw = qFloor (img->comps[0].w);
126  maxh = qFloor (img->comps[0].h);
127  max = maxw * maxh;
128 
129  y = img->comps[0].data;
130  cb = img->comps[1].data;
131  cr = img->comps[2].data;
132 
133  d0 = r = static_cast<int*> (malloc(sizeof(int) * static_cast<size_t> (max)));
134  d1 = g = static_cast<int*> (malloc(sizeof(int) * static_cast<size_t> (max)));
135  d2 = b = static_cast<int*> (malloc(sizeof(int) * static_cast<size_t> (max)));
136 
137  for(i=0; i < maxh; ++i)
138  {
139  for(j=0; j < maxw; j += 2)
140  {
141  sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
142 
143  ++y; ++r; ++g; ++b;
144 
145  sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
146 
147  ++y; ++r; ++g; ++b; ++cb; ++cr;
148  }
149  }
150  free(img->comps[0].data); img->comps[0].data = d0;
151  free(img->comps[1].data); img->comps[1].data = d1;
152  free(img->comps[2].data); img->comps[2].data = d2;
153 
154 #if defined(USE_JPWL) || defined(USE_MJ2)
155  img->comps[1].w = maxw; img->comps[1].h = maxh;
156  img->comps[2].w = maxw; img->comps[2].h = maxh;
157 #else
158  img->comps[1].w = static_cast<OPJ_UINT32> (maxw);
159  img->comps[1].h = static_cast<OPJ_UINT32> (maxh);
160  img->comps[2].w = static_cast<OPJ_UINT32> (maxw);
161  img->comps[2].h = static_cast<OPJ_UINT32> (maxh);
162 #endif
163  img->comps[1].dx = img->comps[0].dx;
164  img->comps[2].dx = img->comps[0].dx;
165  img->comps[1].dy = img->comps[0].dy;
166  img->comps[2].dy = img->comps[0].dy;
167 
168 }/* sycc422_to_rgb() */
void sycc_to_rgb(int offset, int upb, int y, int cb, int cr, int *out_r, int *out_g, int *out_b)
void sycc444_to_rgb ( opj_image_t *  img)

Definition at line 82 of file Jpeg2000Color.cpp.

83 {
84  int *d0, *d1, *d2, *r, *g, *b;
85  const int *y, *cb, *cr;
86  int maxw, maxh, max, i, offset, upb;
87 
88  i = qFloor (img->comps[0].prec);
89  offset = 1<<(i - 1); upb = (1<<i)-1;
90 
91  maxw = qFloor (img->comps[0].w);
92  maxh = qFloor (img->comps[0].h);
93  max = maxw * maxh;
94 
95  y = img->comps[0].data;
96  cb = img->comps[1].data;
97  cr = img->comps[2].data;
98 
99  d0 = r = static_cast<int*> (malloc(sizeof(int) * static_cast<size_t> (max)));
100  d1 = g = static_cast<int*> (malloc(sizeof(int) * static_cast<size_t> (max)));
101  d2 = b = static_cast<int*> (malloc(sizeof(int) * static_cast<size_t> (max)));
102 
103  for(i = 0; i < max; ++i)
104  {
105  sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
106 
107  ++y; ++cb; ++cr; ++r; ++g; ++b;
108  }
109  free(img->comps[0].data); img->comps[0].data = d0;
110  free(img->comps[1].data); img->comps[1].data = d1;
111  free(img->comps[2].data); img->comps[2].data = d2;
112 
113 }/* sycc444_to_rgb() */
void sycc_to_rgb(int offset, int upb, int y, int cb, int cr, int *out_r, int *out_g, int *out_b)
void sycc_to_rgb ( int  offset,
int  upb,
int  y,
int  cb,
int  cr,
int *  out_r,
int *  out_g,
int *  out_b 
)

Definition at line 66 of file Jpeg2000Color.cpp.

68 {
69  int r, g, b;
70 
71  cb -= offset; cr -= offset;
72  r = y + qFloor (1.402 * double (cr));
73  if(r < 0) r = 0; else if(r > upb) r = upb; *out_r = r;
74 
75  g = y - qFloor (0.344 * double (cb) + 0.714 * double (cr));
76  if(g < 0) g = 0; else if(g > upb) g = upb; *out_g = g;
77 
78  b = y + qFloor (1.772 * double (cb));
79  if(b < 0) b = 0; else if(b > upb) b = upb; *out_b = b;
80 }