2 * Copyright (c) 2007, Digital Signal Processing Laboratory, Universit� degli studi di Perugia (UPG), Italy
\r
3 * All rights reserved.
\r
5 * Redistribution and use in source and binary forms, with or without
\r
6 * modification, are permitted provided that the following conditions
\r
8 * 1. Redistributions of source code must retain the above copyright
\r
9 * notice, this list of conditions and the following disclaimer.
\r
10 * 2. Redistributions in binary form must reproduce the above copyright
\r
11 * notice, this list of conditions and the following disclaimer in the
\r
12 * documentation and/or other materials provided with the distribution.
\r
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
\r
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
\r
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
\r
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
\r
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
\r
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
\r
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
\r
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
\r
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
\r
24 * POSSIBILITY OF SUCH DAMAGE.
\r
26 /////////////////////////////////////////////////////////////////////////////
\r
27 // Name: imagjpeg2000.cpp
\r
28 // Purpose: wxImage JPEG 2000 imagage rendering common functions
\r
29 // Author: Giuseppe Baruffa
\r
30 // RCS-ID: $Id: imagjpeg2000.cpp,v 0.00 2007/04/27 22:11:00 MW Exp $
\r
31 // Copyright: (c) Giuseppe Baruffa
\r
32 // Licence: wxWindows licence
\r
33 /////////////////////////////////////////////////////////////////////////////
\r
37 - At this point, we have the structure "opjimage" that is filled with decompressed
\r
38 data, as processed by the OpenJPEG decompression engine
\r
40 - We need to fill the class "image" with the proper pixel sample values
\r
47 // check components number
\r
48 if (m_components > opjimage->numcomps)
\r
49 m_components = opjimage->numcomps;
\r
51 // check image depth (only on the first one, for now)
\r
53 shiftbpp = opjimage->comps[m_components - 1].prec - 8;
\r
55 shiftbpp = opjimage->comps[0].prec - 8;
\r
57 // prepare image size
\r
59 image->Create(opjimage->comps[m_components - 1].w, opjimage->comps[m_components - 1].h, true);
\r
61 image->Create(opjimage->comps[0].w, opjimage->comps[0].h, true);
\r
63 // access image raw data
\r
64 image->SetMask(false);
\r
65 ptr = image->GetData();
\r
67 // workaround for components different from 1 or 3
\r
68 if ((opjimage->numcomps != 1) && (opjimage->numcomps != 3)) {
\r
71 #endif /* __WXGTK__ */
\r
72 wxLogMessage(wxT("JPEG2000: weird number of components"));
\r
75 #endif /* __WXGTK__ */
\r
78 tempcomps = opjimage->numcomps;
\r
80 // workaround for subsampled components
\r
81 for (c = 1; c < tempcomps; c++) {
\r
82 if ((opjimage->comps[c].w != opjimage->comps[c - 1].w) || (opjimage->comps[c].h != opjimage->comps[c - 1].h)) {
\r
88 // workaround for different precision components
\r
89 for (c = 1; c < tempcomps; c++) {
\r
90 if (opjimage->comps[c].bpp != opjimage->comps[c - 1].bpp) {
\r
96 // only one component selected
\r
100 // RGB color picture
\r
101 if (tempcomps == 3) {
\r
103 int *r = opjimage->comps[0].data;
\r
104 int *g = opjimage->comps[1].data;
\r
105 int *b = opjimage->comps[2].data;
\r
106 if (shiftbpp > 0) {
\r
107 for (row = 0; row < opjimage->comps[0].h; row++) {
\r
108 for (col = 0; col < opjimage->comps[0].w; col++) {
\r
110 *(ptr++) = (*(r++)) >> shiftbpp;
\r
111 *(ptr++) = (*(g++)) >> shiftbpp;
\r
112 *(ptr++) = (*(b++)) >> shiftbpp;
\r
117 } else if (shiftbpp < 0) {
\r
118 for (row = 0; row < opjimage->comps[0].h; row++) {
\r
119 for (col = 0; col < opjimage->comps[0].w; col++) {
\r
121 *(ptr++) = (*(r++)) << -shiftbpp;
\r
122 *(ptr++) = (*(g++)) << -shiftbpp;
\r
123 *(ptr++) = (*(b++)) << -shiftbpp;
\r
129 for (row = 0; row < opjimage->comps[0].h; row++) {
\r
130 for (col = 0; col < opjimage->comps[0].w; col++) {
\r
142 if (tempcomps == 1) {
\r
147 selcomp = m_components - 1;
\r
151 int *y = opjimage->comps[selcomp].data;
\r
152 if (shiftbpp > 0) {
\r
153 for (row = 0; row < opjimage->comps[selcomp].h; row++) {
\r
154 for (col = 0; col < opjimage->comps[selcomp].w; col++) {
\r
156 *(ptr++) = (*(y)) >> shiftbpp;
\r
157 *(ptr++) = (*(y)) >> shiftbpp;
\r
158 *(ptr++) = (*(y++)) >> shiftbpp;
\r
162 } else if (shiftbpp < 0) {
\r
163 for (row = 0; row < opjimage->comps[selcomp].h; row++) {
\r
164 for (col = 0; col < opjimage->comps[selcomp].w; col++) {
\r
166 *(ptr++) = (*(y)) << -shiftbpp;
\r
167 *(ptr++) = (*(y)) << -shiftbpp;
\r
168 *(ptr++) = (*(y++)) << -shiftbpp;
\r
173 for (row = 0; row < opjimage->comps[selcomp].h; row++) {
\r
174 for (col = 0; col < opjimage->comps[selcomp].w; col++) {
\r