diff options
Diffstat (limited to 'linden/indra/llimagej2coj/llimagej2coj.cpp')
-rw-r--r-- | linden/indra/llimagej2coj/llimagej2coj.cpp | 57 |
1 files changed, 44 insertions, 13 deletions
diff --git a/linden/indra/llimagej2coj/llimagej2coj.cpp b/linden/indra/llimagej2coj/llimagej2coj.cpp index 53acad5..3ca271c 100644 --- a/linden/indra/llimagej2coj/llimagej2coj.cpp +++ b/linden/indra/llimagej2coj/llimagej2coj.cpp | |||
@@ -12,12 +12,12 @@ | |||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | 12 | * ("GPL"), unless you have obtained a separate licensing agreement |
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | 13 | * ("Other License"), formally executed by you and Linden Lab. Terms of |
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | 14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or |
15 | * online at http://secondlife.com/developers/opensource/gplv2 | 15 | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 |
16 | * | 16 | * |
17 | * There are special exceptions to the terms and conditions of the GPL as | 17 | * There are special exceptions to the terms and conditions of the GPL as |
18 | * it is applied to this Source Code. View the full text of the exception | 18 | * it is applied to this Source Code. View the full text of the exception |
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | 19 | * in the file doc/FLOSS-exception.txt in this software distribution, or |
20 | * online at http://secondlife.com/developers/opensource/flossexception | 20 | * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception |
21 | * | 21 | * |
22 | * By copying, modifying or distributing this software, you acknowledge | 22 | * By copying, modifying or distributing this software, you acknowledge |
23 | * that you have read and understood your obligations described above, | 23 | * that you have read and understood your obligations described above, |
@@ -40,8 +40,10 @@ | |||
40 | 40 | ||
41 | const char* fallbackEngineInfoLLImageJ2CImpl() | 41 | const char* fallbackEngineInfoLLImageJ2CImpl() |
42 | { | 42 | { |
43 | return (std::string("OpenJPEG: " OPENJPEG_VERSION ", Runtime: ") | 43 | static std::string version_string = |
44 | + opj_version()).c_str(); | 44 | std::string("OpenJPEG: " OPENJPEG_VERSION ", Runtime: ") |
45 | + opj_version(); | ||
46 | return version_string.c_str(); | ||
45 | } | 47 | } |
46 | 48 | ||
47 | LLImageJ2CImpl* fallbackCreateLLImageJ2CImpl() | 49 | LLImageJ2CImpl* fallbackCreateLLImageJ2CImpl() |
@@ -183,15 +185,25 @@ BOOL LLImageJ2COJ::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decod | |||
183 | for (S32 comp = first_channel, dest=0; comp < first_channel + channels; | 185 | for (S32 comp = first_channel, dest=0; comp < first_channel + channels; |
184 | comp++, dest++) | 186 | comp++, dest++) |
185 | { | 187 | { |
186 | S32 offset = dest; | 188 | if (image->comps[comp].data) |
187 | for (S32 y = (height - 1); y >= 0; y--) | ||
188 | { | 189 | { |
189 | for (S32 x = 0; x < width; x++) | 190 | S32 offset = dest; |
191 | for (S32 y = (height - 1); y >= 0; y--) | ||
190 | { | 192 | { |
191 | rawp[offset] = image->comps[comp].data[y*comp_width + x]; | 193 | for (S32 x = 0; x < width; x++) |
192 | offset += channels; | 194 | { |
195 | rawp[offset] = image->comps[comp].data[y*comp_width + x]; | ||
196 | offset += channels; | ||
197 | } | ||
193 | } | 198 | } |
194 | } | 199 | } |
200 | else // Some rare OpenJPEG versions have this bug. | ||
201 | { | ||
202 | fprintf(stderr, "ERROR -> decodeImpl: failed to decode image! (NULL comp data - OpenJPEG bug)\n"); | ||
203 | opj_image_destroy(image); | ||
204 | |||
205 | return TRUE; // done | ||
206 | } | ||
195 | } | 207 | } |
196 | 208 | ||
197 | /* free image data structure */ | 209 | /* free image data structure */ |
@@ -219,10 +231,29 @@ BOOL LLImageJ2COJ::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, con | |||
219 | 231 | ||
220 | /* set encoding parameters to default values */ | 232 | /* set encoding parameters to default values */ |
221 | opj_set_default_encoder_parameters(¶meters); | 233 | opj_set_default_encoder_parameters(¶meters); |
222 | parameters.tcp_rates[0] = 0; | ||
223 | parameters.tcp_numlayers++; | ||
224 | parameters.cp_disto_alloc = 1; | ||
225 | parameters.cod_format = 0; | 234 | parameters.cod_format = 0; |
235 | parameters.cp_disto_alloc = 1; | ||
236 | |||
237 | if (reversible) | ||
238 | { | ||
239 | parameters.tcp_numlayers = 1; | ||
240 | parameters.tcp_rates[0] = 0.0f; | ||
241 | } | ||
242 | else | ||
243 | { | ||
244 | parameters.tcp_numlayers = 5; | ||
245 | parameters.tcp_rates[0] = 1920.0f; | ||
246 | parameters.tcp_rates[1] = 480.0f; | ||
247 | parameters.tcp_rates[2] = 120.0f; | ||
248 | parameters.tcp_rates[3] = 30.0f; | ||
249 | parameters.tcp_rates[4] = 10.0f; | ||
250 | parameters.irreversible = 1; | ||
251 | if (raw_image.getComponents() >= 3) | ||
252 | { | ||
253 | parameters.tcp_mct = 1; | ||
254 | } | ||
255 | } | ||
256 | |||
226 | if (!comment_text) | 257 | if (!comment_text) |
227 | { | 258 | { |
228 | parameters.cp_comment = ""; | 259 | parameters.cp_comment = ""; |
@@ -298,7 +329,7 @@ BOOL LLImageJ2COJ::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, con | |||
298 | cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0); | 329 | cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0); |
299 | 330 | ||
300 | /* encode the image */ | 331 | /* encode the image */ |
301 | bool bSuccess = opj_encode(cinfo, cio, image, parameters.index); | 332 | bool bSuccess = opj_encode(cinfo, cio, image, NULL); |
302 | if (!bSuccess) | 333 | if (!bSuccess) |
303 | { | 334 | { |
304 | opj_cio_close(cio); | 335 | opj_cio_close(cio); |