Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 127026 | Differences between
and this patch

Collapse All | Expand All

(-)llimagej2coj_FL-1.13.3.57876.orig/llimagej2coj.cpp (-20 / +36 lines)
Lines 122-167 BOOL LLImageJ2COJ::decodeImpl(LLImageJ2C Link Here
122
122
123
	/* decode the stream and fill the image structure */
123
	/* decode the stream and fill the image structure */
124
	image = opj_decode(dinfo, cio);
124
	image = opj_decode(dinfo, cio);
125
	if(!image)
126
	{
127
		fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
128
		opj_destroy_decompress(dinfo);
129
		opj_cio_close(cio);
130
		return 1;
131
	}
132
125
133
	/* close the byte stream */
126
	/* close the byte stream */
134
	opj_cio_close(cio);
127
	opj_cio_close(cio);
135
128
136
137
	/* free remaining structures */
129
	/* free remaining structures */
138
	if(dinfo) {
130
	if(dinfo)
131
	{
139
		opj_destroy_decompress(dinfo);
132
		opj_destroy_decompress(dinfo);
140
	}
133
	}
141
134
135
	// The image decode failed if the return was NULL or the component
136
	// count was zero.  The latter is just a sanity check before we
137
	// dereference the array.
138
	if(!image || !image->numcomps)
139
	{
140
		fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
141
		return FALSE;
142
	}
143
142
	// Copy image data into our raw image format (instead of the separate channel format
144
	// Copy image data into our raw image format (instead of the separate channel format
143
	S32 width = 0;
144
	S32 height = 0;
145
145
146
	S32 img_components = image->numcomps;
146
	S32 img_components = image->numcomps;
147
	S32 channels = img_components - first_channel;
147
	S32 channels = img_components - first_channel;
148
	if( channels > max_channel_count )
148
	if( channels > max_channel_count )
149
	{
150
		channels = max_channel_count;
149
		channels = max_channel_count;
151
	}
150
152
	width = image->x1 - image->x0;
151
	// Component buffers are allocated in an image width by height buffer.
153
	height = image->y1 - image->y0;
152
	// The image placed in that buffer is ceil(width/2^factor) by
153
	// ceil(height/2^factor) and if the factor isn't zero it will be at the
154
	// top left of the buffer with black filled in the rest of the pixels.
155
	// It is integer math so the formual is written in ceildivpo2.
156
	// (Assuming all the components have the same width, height and
157
	// factor.)
158
	S32 comp_width = image->comps[0].w;
159
	S32 f=image->comps[0].factor;
160
	S32 width = ceildivpow2(image->x1 - image->x0, f);
161
	S32 height = ceildivpow2(image->y1 - image->y0, f);
154
	raw_image.resize(width, height, channels);
162
	raw_image.resize(width, height, channels);
155
	U8 *rawp = raw_image.getData();
163
	U8 *rawp = raw_image.getData();
156
164
157
	for (S32 comp = first_channel; comp < first_channel + channels; comp++)
165
	// first_channel is what channel to start copying from
166
	// dest is what channel to copy to.  first_channel comes from the
167
	// argument, dest always starts writing at channel zero.
168
	for (S32 comp = first_channel, dest=0; comp < first_channel + channels;
169
		comp++, dest++)
158
	{
170
	{
159
		S32 offset = comp;
171
		S32 offset = dest;
160
		for (S32 y = (height - 1); y >= 0; y--)
172
		for (S32 y = (height - 1); y >= 0; y--)
161
		{
173
		{
162
			for (S32 x = 0; x < width; x++)
174
			for (S32 x = 0; x < width; x++)
163
			{
175
			{
164
				rawp[offset] = image->comps[comp].data[y*width + x];
176
				rawp[offset] = image->comps[comp].data[y*comp_width + x];
165
				offset += channels;
177
				offset += channels;
166
			}
178
			}
167
		}
179
		}
Lines 323-328 BOOL LLImageJ2COJ::getMetadata(LLImageJ2 Link Here
323
	/* set decoding parameters to default values */
335
	/* set decoding parameters to default values */
324
	opj_set_default_decoder_parameters(&parameters);
336
	opj_set_default_decoder_parameters(&parameters);
325
337
338
	// Only decode what's required to get the size data.
339
	parameters.cp_limit_tags=OPJ_LIMIT_FOR_SIZE;
340
326
	//parameters.cp_reduce = mRawDiscardLevel;
341
	//parameters.cp_reduce = mRawDiscardLevel;
327
342
328
	/* decode the code-stream */
343
	/* decode the code-stream */
Lines 349-355 BOOL LLImageJ2COJ::getMetadata(LLImageJ2 Link Here
349
		fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
364
		fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
350
		opj_destroy_decompress(dinfo);
365
		opj_destroy_decompress(dinfo);
351
		opj_cio_close(cio);
366
		opj_cio_close(cio);
352
		return 1;
367
		return FALSE;
353
	}
368
	}
354
369
355
	/* close the byte stream */
370
	/* close the byte stream */
Lines 371-375 BOOL LLImageJ2COJ::getMetadata(LLImageJ2 Link Here
371
	base.setSize(width, height, img_components);
386
	base.setSize(width, height, img_components);
372
387
373
	/* free image data structure */
388
	/* free image data structure */
374
	opj_image_destroy(image);	return TRUE;
389
	opj_image_destroy(image);
390
	return TRUE;
375
}
391
}
(-)llimagej2coj_FL-1.13.3.57876.orig/llimagej2coj.h (+5 lines)
Lines 40-45 protected: Link Here
40
	/*virtual*/ BOOL getMetadata(LLImageJ2C &base);
40
	/*virtual*/ BOOL getMetadata(LLImageJ2C &base);
41
	/*virtual*/ BOOL decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decode_time, S32 first_channel, S32 max_channel_count);
41
	/*virtual*/ BOOL decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decode_time, S32 first_channel, S32 max_channel_count);
42
	/*virtual*/ BOOL encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, const char* comment_text, F32 encode_time=0.0);
42
	/*virtual*/ BOOL encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, const char* comment_text, F32 encode_time=0.0);
43
	int ceildivpow2(int a, int b)
44
	{
45
		// Divide a by b to the power of 2 and round upwards.
46
		return (a + (1 << b) - 1) >> b;
47
	}
43
48
44
	// Temporary variables for in-progress decodes...
49
	// Temporary variables for in-progress decodes...
45
	LLImageRaw *mRawImagep;
50
	LLImageRaw *mRawImagep;

Return to bug 127026