xref: /haiku/src/add-ons/translators/jpeg2000/JPEG2000Translator.h (revision 93aeb8c3bc3f13cb1f282e3e749258a23790d947)
1 /*
2 
3 Copyright (c) 2003, Marcin 'Shard' Konicki
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
8 
9     * Redistributions of source code must retain the above copyright notice,
10       this list of conditions and the following disclaimer.
11     * Redistributions in binary form must reproduce the above copyright notice,
12       this list of conditions and the following disclaimer in the documentation and/or
13       other materials provided with the distribution.
14     * Name "Marcin Konicki", "Shard" or any combination of them,
15       must not be used to endorse or promote products derived from this
16       software without specific prior written permission from Marcin Konicki.
17 
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23 OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 */
31 
32 #ifndef _JP2TRANSLATOR_H_
33 #define _JP2TRANSLATOR_H_
34 
35 
36 //----------------------------------------------------------------------------
37 //
38 //	Include
39 //
40 //----------------------------------------------------------------------------
41 
42 #include <Alert.h>
43 #include <Application.h>
44 #include <CheckBox.h>
45 #include <FindDirectory.h>
46 #include <Path.h>
47 #include <Slider.h>
48 #include <StringView.h>
49 #include <TranslationKit.h>
50 #include <TranslatorAddOn.h>
51 
52 #include <stdio.h>
53 #include <stdlib.h>
54 #include <string.h>
55 
56 #include "libjasper/jasper.h"
57 
58 //----------------------------------------------------------------------------
59 //
60 //	Define & Global variables declaration
61 //
62 //----------------------------------------------------------------------------
63 
64 // Settings
65 #define SETTINGS_FILE	"OpenJPEG2000Translator"
66 #define SETTINGS_PATH	"/boot/home/config/settings"
67 
68 // View messages
69 #define VIEW_MSG_SET_QUALITY 'JSCQ'
70 #define	VIEW_MSG_SET_GRAY1ASRGB24 'JSGR'
71 #define	VIEW_MSG_SET_JPC 'JSJC'
72 #define	VIEW_MSG_SET_GRAYASRGB32 'JSAC'
73 
74 // View labels
75 #define VIEW_LABEL_QUALITY "Output quality"
76 #define VIEW_LABEL_GRAY1ASRGB24 "Write Black&White images as RGB24"
77 #define VIEW_LABEL_JPC "Output only codestream (.jpc)"
78 #define	VIEW_LABEL_GRAYASRGB32 "Read Greyscale images as RGB32"
79 
80 // This will be used true if Settings are running, else false
81 extern bool AreSettingsRunning;
82 
83 //----------------------------------------------------------------------------
84 //
85 //	Classes
86 //
87 //----------------------------------------------------------------------------
88 
89 //---------------------------------------------------
90 //	Settings storage structure
91 //---------------------------------------------------
92 struct SETTINGS
93 {
94 	// compression
95 	jpr_uchar_t	Quality;			// default: 25
96 	bool	JPC;				// default: false	// compress to JPC or JP2?
97 	bool	B_GRAY1_as_B_RGB24;	// default: false	// copress gray 1 as rgb24 or grayscale?
98 	// decompression
99 	bool	B_GRAY8_as_B_RGB32;	// default: true
100 };
101 
102 //---------------------------------------------------
103 //	Slider used in TranslatorView
104 //	With status showing actual value
105 //---------------------------------------------------
106 class SSlider : public BSlider
107 {
108 	public:
109 							SSlider(BRect frame, const char *name, const char *label, BMessage *message, int32 minValue, int32 maxValue, orientation posture = B_HORIZONTAL, thumb_style thumbType = B_BLOCK_THUMB, uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, uint32 flags = B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS);
110 		char*				UpdateText() const;
111 		void				ResizeToPreferred();
112 
113 	private:
114 		char				statusLabel[12];
115 };
116 
117 
118 //---------------------------------------------------
119 //	Basic view class with resizing to needed size
120 //---------------------------------------------------
121 class SView : public BView
122 {
123 	public:
124 							SView(const char *name, float x = 0, float y = 0)
125 								:BView( BRect(x,y,x,y), name, B_FOLLOW_NONE, B_WILL_DRAW)
126 								{
127 									preferredWidth = 0;
128 									preferredHeight = 0;
129 									SetViewColor( ui_color(B_PANEL_BACKGROUND_COLOR));
130 									SetFont(be_plain_font);
131 								};
132 		void				GetPreferredSize(float *width, float *height)
133 								{
134 									*width = preferredWidth;
135 									*height = preferredHeight;
136 								}
137 		inline float		GetPreferredWidth() { return preferredWidth; };
138 		inline float		GetPreferredHeight() { return preferredHeight; };
139 		inline void			ResizePreferredBy(float width, float height) { preferredWidth += width; preferredHeight += height; };
140 		inline void			ResizeToPreferred() { ResizeTo(preferredWidth, preferredHeight); };
141 		void				AddChild(BView *child, BView *before = NULL)
142 								{
143 									BView::AddChild(child, before);
144 									child->ResizeToPreferred();
145 									BRect frame = child->Frame();
146 									if (frame.right > preferredWidth)
147 										preferredWidth = frame.right;
148 									if (frame.bottom > preferredHeight)
149 										preferredHeight = frame.bottom;
150 								}
151 
152 	private:
153 		float				preferredWidth;
154 		float				preferredHeight;
155 };
156 
157 //---------------------------------------------------
158 //	Configuration view for reading settings
159 //---------------------------------------------------
160 class TranslatorReadView : public SView
161 {
162 	public:
163 							TranslatorReadView(const char *name, SETTINGS *settings, float x = 0, float y = 0);
164 		void				AttachedToWindow();
165 		void				MessageReceived(BMessage *message);
166 
167 	private:
168 		SETTINGS			*Settings;
169 		BCheckBox			*grayasrgb32;
170 };
171 
172 //---------------------------------------------------
173 //	Configuration view for writing settings
174 //---------------------------------------------------
175 class TranslatorWriteView : public SView
176 {
177 	public:
178 							TranslatorWriteView(const char *name, SETTINGS *settings, float x = 0, float y = 0);
179 		void				AttachedToWindow();
180 		void				MessageReceived(BMessage *message);
181 
182 	private:
183 		SETTINGS			*Settings;
184 		SSlider				*quality;
185 		BCheckBox			*gray1asrgb24;
186 		BCheckBox			*jpc;
187 };
188 
189 //---------------------------------------------------
190 //	About view
191 //---------------------------------------------------
192 class TranslatorAboutView : public SView
193 {
194 	public:
195 							TranslatorAboutView(const char *name, float x = 0, float y = 0);
196 };
197 
198 //---------------------------------------------------
199 //	Configuration view
200 //---------------------------------------------------
201 class TranslatorView : public SView
202 {
203 	public:
204 							TranslatorView(const char *name);
205 							~TranslatorView() { AreSettingsRunning = false; };
206 		void				AttachedToWindow();
207 		void				Draw(BRect updateRect);
208 		void				MouseDown(BPoint where);
209 
210 	private:
211 		SETTINGS			Settings;
212 		int32				tabWidth;
213 		int32				tabHeight;
214 		int32				activeChild;
215 };
216 
217 //---------------------------------------------------
218 //	Window used for configuration
219 //---------------------------------------------------
220 class TranslatorWindow : public BWindow
221 {
222 	public:
223 							TranslatorWindow(bool quit_on_close = true);
224 };
225 
226 
227 //----------------------------------------------------------------------------
228 //
229 //	Functions :: Settings
230 //
231 //----------------------------------------------------------------------------
232 
233 //---------------------------------------------------
234 //	Make Settings to defaults
235 //---------------------------------------------------
236 inline void
237 LoadDefaultSettings(SETTINGS *Settings)
238 {
239 	Settings->Quality = 25;
240 	Settings->JPC = false;
241 	Settings->B_GRAY1_as_B_RGB24 = false;
242 	Settings->B_GRAY8_as_B_RGB32 = true;
243 }
244 
245 //---------------------------------------------------
246 //	Save Settings to config file
247 //---------------------------------------------------
248 inline void
249 SaveSettings(SETTINGS *Settings)
250 {
251 	// Make path to settings file
252 	BPath path;
253 	if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) {
254 		path.SetTo(SETTINGS_PATH);
255 		path.Append(SETTINGS_FILE);
256 	} else
257 		path.Append(SETTINGS_FILE);
258 
259 	// Open settings file (create it if there's no file) and write settings
260 	FILE *file = NULL;
261 	if ((file = fopen( path.Path(), "wb+"))) {
262 		fwrite(Settings, sizeof(SETTINGS), 1, file);
263 		fclose(file);
264 	}
265 }
266 
267 //---------------------------------------------------
268 //	Return true if Settings were run, false if not
269 //---------------------------------------------------
270 inline bool
271 SettingsChangedAlert()
272 {
273 	// If settings view wasn't already initialized (settings not running)
274 	// and user wants to run settings
275 	if (!AreSettingsRunning && (new BAlert("Different settings file", "JPEG2000 settings were set to default because of incompatible settings file.", "Configure settings", "OK", NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go() == 0) {
276 		// Create settings window (with no quit on close!), launch it and wait until it's closed
277 		status_t err;
278 		TranslatorWindow *window = new TranslatorWindow(false);
279 		window->Show();
280 		wait_for_thread(window->Thread(), &err);
281 		return true;
282 	}
283 
284 	return false;
285 }
286 
287 //---------------------------------------------------
288 //	Load settings from config file
289 //	If can't find it make them default and try to save
290 //---------------------------------------------------
291 inline void
292 LoadSettings(SETTINGS *Settings)
293 {
294 	// Make path to settings file
295 	BPath path;
296 	if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) {
297 		path.SetTo(SETTINGS_PATH);
298 		path.Append(SETTINGS_FILE);
299 	} else
300 		path.Append(SETTINGS_FILE);
301 
302 	// Open settings file (create it if there's no file) and write settings
303 	FILE *file = NULL;
304 	if ((file = fopen( path.Path(), "rb"))) {
305 		if ( !fread(Settings, sizeof(SETTINGS), 1, file)) {
306 			// Settings struct has changed size
307 			// Load default settings, and Save them
308 			fclose(file);
309 			LoadDefaultSettings(Settings);
310 			SaveSettings(Settings);
311 			// Tell user settings were changed to default, and ask to run settings panel or not
312 			if (SettingsChangedAlert())
313 				// User configured settings, load them again
314 				LoadSettings(Settings);
315 		} else
316 			fclose(file);
317 	} else if ((file = fopen( path.Path(), "wb+"))) {
318 		LoadDefaultSettings(Settings);
319 		fwrite(Settings, sizeof(SETTINGS), 1, file);
320 		fclose(file);
321 		// Tell user settings were changed to default, and ask to run settings panel or not
322 		if (SettingsChangedAlert())
323 			// User configured settings, load them again
324 			LoadSettings(Settings);
325 	}
326 }
327 
328 
329 //----------------------------------------------------------------------------
330 //
331 //	Functions
332 //
333 //----------------------------------------------------------------------------
334 
335 //---------------------------------------------------
336 //	Main functions of translator :)
337 //---------------------------------------------------
338 status_t Copy(BPositionIO *in, BPositionIO *out);
339 status_t Compress(BPositionIO *in, BPositionIO *out);
340 status_t Decompress(BPositionIO *in, BPositionIO *out);
341 status_t Error(jas_stream_t *stream, jas_image_t *image, jas_matrix_t **pixels, int32 pixels_count, jpr_uchar_t *scanline, status_t error = B_ERROR);
342 
343 //---------------------------------------------------
344 //	Make RGB32 scanline from *pixels[3]
345 //---------------------------------------------------
346 inline void
347 read_rgb24_to_rgb32(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
348 {
349 	int32 index = 0;
350 	int32 x = 0;
351 	while (x < width)
352 	{
353 		scanline[index++] = (jpr_uchar_t)jas_matrix_getv(pixels[2], x);
354 		scanline[index++] = (jpr_uchar_t)jas_matrix_getv(pixels[1], x);
355 		scanline[index++] = (jpr_uchar_t)jas_matrix_getv(pixels[0], x);
356 		scanline[index++] = 255;
357 		x++;
358 	}
359 }
360 
361 //---------------------------------------------------
362 //	Make gray scanline from *pixels[1]
363 //---------------------------------------------------
364 inline void
365 read_gray_to_rgb32(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
366 {
367 	int32 index = 0;
368 	int32 x = 0;
369 	jpr_uchar_t color = 0;
370 	while (x < width)
371 	{
372 		color = (jpr_uchar_t)jas_matrix_getv(pixels[0], x++);
373 		scanline[index++] = color;
374 		scanline[index++] = color;
375 		scanline[index++] = color;
376 		scanline[index++] = 255;
377 	}
378 }
379 
380 //---------------------------------------------------
381 //	Make RGBA32 scanline from *pixels[4]
382 //	(just read data to scanline)
383 //---------------------------------------------------
384 inline void
385 read_rgba32(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
386 {
387 	int32 index = 0;
388 	int32 x = 0;
389 	while (x < width)
390 	{
391 		scanline[index++] = (jpr_uchar_t)jas_matrix_getv(pixels[2], x);
392 		scanline[index++] = (jpr_uchar_t)jas_matrix_getv(pixels[1], x);
393 		scanline[index++] = (jpr_uchar_t)jas_matrix_getv(pixels[0], x);
394 		scanline[index++] = (jpr_uchar_t)jas_matrix_getv(pixels[3], x);
395 		x++;
396 	}
397 }
398 
399 //---------------------------------------------------
400 //	Make gray scanline from *pixels[1]
401 //	(just read data to scanline)
402 //---------------------------------------------------
403 inline void
404 read_gray(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
405 {
406 	int32 x = 0;
407 	while (x < width)
408 	{
409 		scanline[x] = (jpr_uchar_t)jas_matrix_getv(pixels[0], x);
410 		x++;
411 	}
412 }
413 
414 //---------------------------------------------------
415 //	Make *pixels[1] from gray1 scanline
416 //---------------------------------------------------
417 inline void
418 write_gray1_to_gray(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
419 {
420 	int32 x = 0;
421 	int32 index = 0;
422 	while (x < (width/8))
423 	{
424 		unsigned char c = scanline[x++];
425 		for (int b = 128; b; b = b >> 1) {
426 			if (c & b)
427 				jas_matrix_setv(pixels[0], index++, 0);
428 			else
429 				jas_matrix_setv(pixels[0], index++, 255);
430 		}
431 	}
432 }
433 
434 //---------------------------------------------------
435 //	Make *pixels[3] from gray1 scanline
436 //---------------------------------------------------
437 inline void
438 write_gray1_to_rgb24(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
439 {
440 	int32 x = 0;
441 	int32 index = 0;
442 	while (x < (width/8))
443 	{
444 		unsigned char c = scanline[x++];
445 		for (int b = 128; b; b = b >> 1) {
446 			if (c & b) {
447 				jas_matrix_setv(pixels[0], index, 0);
448 				jas_matrix_setv(pixels[1], index, 0);
449 				jas_matrix_setv(pixels[2], index, 0);
450 			}
451 			else {
452 				jas_matrix_setv(pixels[0], index, 255);
453 				jas_matrix_setv(pixels[1], index, 255);
454 				jas_matrix_setv(pixels[2], index, 255);
455 			}
456 			index++;
457 		}
458 	}
459 }
460 
461 //---------------------------------------------------
462 //	Make *pixels[3] from cmap8 scanline
463 //---------------------------------------------------
464 inline void
465 write_cmap8_to_rgb24(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
466 {
467 	const color_map *map = system_colors();
468 	int32 x = 0;
469 	while (x < width)
470 	{
471 		rgb_color color = map->color_list[scanline[x]];
472 
473 		jas_matrix_setv(pixels[0], x, color.red);
474 		jas_matrix_setv(pixels[1], x, color.green);
475 		jas_matrix_setv(pixels[2], x, color.blue);
476 		x++;
477 	}
478 }
479 
480 //---------------------------------------------------
481 //	Make *pixels[1] from gray scanline
482 //	(just write data to pixels)
483 //---------------------------------------------------
484 inline void
485 write_gray(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
486 {
487 	int32 x = 0;
488 	while (x < width)
489 	{
490 		jas_matrix_setv(pixels[0], x, scanline[x]);
491 		x++;
492 	}
493 }
494 
495 //---------------------------------------------------
496 //	Make *pixels[3] from RGB15/RGBA15 scanline
497 //	(just write data to pixels)
498 //---------------------------------------------------
499 inline void
500 write_rgb15_to_rgb24(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
501 {
502 	int32 x = 0;
503 	int32 index = 0;
504 	int16 in_pixel;
505 	while (x < width) {
506 		in_pixel = scanline[index] | (scanline[index+1] << 8);
507 		index += 2;
508 
509 		jas_matrix_setv(pixels[0], x, (char)(((in_pixel & 0x7c00)) >> 7) | (((in_pixel & 0x7c00)) >> 12));
510 		jas_matrix_setv(pixels[1], x, (char)(((in_pixel & 0x3e0)) >> 2) | (((in_pixel & 0x3e0)) >> 7));
511 		jas_matrix_setv(pixels[2], x, (char)(((in_pixel & 0x1f)) << 3) | (((in_pixel & 0x1f)) >> 2));
512 		x++;
513 	}
514 }
515 
516 //---------------------------------------------------
517 //	Make *pixels[3] from RGB15/RGBA15 bigendian scanline
518 //	(just write data to pixels)
519 //---------------------------------------------------
520 inline void
521 write_rgb15b_to_rgb24(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
522 {
523 	int32 x = 0;
524 	int32 index = 0;
525 	int16 in_pixel;
526 	while (x < width) {
527 		in_pixel = scanline[index+1] | (scanline[index] << 8);
528 		index += 2;
529 
530 		jas_matrix_setv(pixels[0], x, (char)(((in_pixel & 0x7c00)) >> 7) | (((in_pixel & 0x7c00)) >> 12));
531 		jas_matrix_setv(pixels[1], x, (char)(((in_pixel & 0x3e0)) >> 2) | (((in_pixel & 0x3e0)) >> 7));
532 		jas_matrix_setv(pixels[2], x, (char)(((in_pixel & 0x1f)) << 3) | (((in_pixel & 0x1f)) >> 2));
533 		x++;
534 	}
535 }
536 
537 //---------------------------------------------------
538 //	Make *pixels[3] from RGB16/RGBA16 scanline
539 //	(just write data to pixels)
540 //---------------------------------------------------
541 inline void
542 write_rgb16_to_rgb24(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
543 {
544 	int32 x = 0;
545 	int32 index = 0;
546 	int16 in_pixel;
547 	while (x < width) {
548 		in_pixel = scanline[index] | (scanline[index+1] << 8);
549 		index += 2;
550 
551 		jas_matrix_setv(pixels[0], x, (char)(((in_pixel & 0xf800)) >> 8) | (((in_pixel & 0x7c00)) >> 12));
552 		jas_matrix_setv(pixels[1], x, (char)(((in_pixel & 0x7e0)) >> 3) | (((in_pixel & 0x7e0)) >> 9));
553 		jas_matrix_setv(pixels[2], x, (char)(((in_pixel & 0x1f)) << 3) | (((in_pixel & 0x1f)) >> 2));
554 		x++;
555 	}
556 }
557 
558 //---------------------------------------------------
559 //	Make *pixels[3] from RGB16/RGBA16 bigendian scanline
560 //	(just write data to pixels)
561 //---------------------------------------------------
562 inline void
563 write_rgb16b_to_rgb24(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
564 {
565 	int32 x = 0;
566 	int32 index = 0;
567 	int16 in_pixel;
568 	while (x < width) {
569 		in_pixel = scanline[index+1] | (scanline[index] << 8);
570 		index += 2;
571 
572 		jas_matrix_setv(pixels[0], x, (char)(((in_pixel & 0xf800)) >> 8) | (((in_pixel & 0xf800)) >> 13));
573 		jas_matrix_setv(pixels[1], x, (char)(((in_pixel & 0x7e0)) >> 3) | (((in_pixel & 0x7e0)) >> 9));
574 		jas_matrix_setv(pixels[2], x, (char)(((in_pixel & 0x1f)) << 3) | (((in_pixel & 0x1f)) >> 2));
575 		x++;
576 	}
577 }
578 
579 //---------------------------------------------------
580 //	Make *pixels[3] from RGB24 scanline
581 //	(just write data to pixels)
582 //---------------------------------------------------
583 inline void
584 write_rgb24(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
585 {
586 	int32 index = 0;
587 	int32 x = 0;
588 	while (x < width)
589 	{
590 		jas_matrix_setv(pixels[2], x, scanline[index++]);
591 		jas_matrix_setv(pixels[1], x, scanline[index++]);
592 		jas_matrix_setv(pixels[0], x, scanline[index++]);
593 		x++;
594 	}
595 }
596 
597 //---------------------------------------------------
598 //	Make *pixels[3] from RGB24 bigendian scanline
599 //	(just write data to pixels)
600 //---------------------------------------------------
601 inline void
602 write_rgb24b(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
603 {
604 	int32 index = 0;
605 	int32 x = 0;
606 	while (x < width)
607 	{
608 		jas_matrix_setv(pixels[0], x, scanline[index++]);
609 		jas_matrix_setv(pixels[1], x, scanline[index++]);
610 		jas_matrix_setv(pixels[2], x, scanline[index++]);
611 		x++;
612 	}
613 }
614 
615 //---------------------------------------------------
616 //	Make *pixels[3] from RGB32 scanline
617 //	(just write data to pixels)
618 //---------------------------------------------------
619 inline void
620 write_rgb32_to_rgb24(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
621 {
622 	int32 index = 0;
623 	int32 x = 0;
624 	while (x < width)
625 	{
626 		jas_matrix_setv(pixels[2], x, scanline[index++]);
627 		jas_matrix_setv(pixels[1], x, scanline[index++]);
628 		jas_matrix_setv(pixels[0], x, scanline[index++]);
629 		index++;
630 		x++;
631 	}
632 }
633 
634 //---------------------------------------------------
635 //	Make *pixels[3] from RGB32 bigendian scanline
636 //	(just write data to pixels)
637 //---------------------------------------------------
638 inline void
639 write_rgb32b_to_rgb24(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
640 {
641 	int32 index = 0;
642 	int32 x = 0;
643 	while (x < width)
644 	{
645 		index++;
646 		jas_matrix_setv(pixels[0], x, scanline[index++]);
647 		jas_matrix_setv(pixels[1], x, scanline[index++]);
648 		jas_matrix_setv(pixels[2], x, scanline[index++]);
649 		x++;
650 	}
651 }
652 
653 //---------------------------------------------------
654 //	Make *pixels[4] from RGBA32 scanline
655 //	(just write data to pixels)
656 //	!!! UNTESTED !!!
657 //---------------------------------------------------
658 inline void
659 write_rgba32(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
660 {
661 	int32 index = 0;
662 	int32 x = 0;
663 	while (x < width)
664 	{
665 		jas_matrix_setv(pixels[3], x, scanline[index++]);
666 		jas_matrix_setv(pixels[2], x, scanline[index++]);
667 		jas_matrix_setv(pixels[1], x, scanline[index++]);
668 		jas_matrix_setv(pixels[0], x, scanline[index++]);
669 		x++;
670 	}
671 }
672 
673 //---------------------------------------------------
674 //	Make *pixels[4] from RGBA32 bigendian scanline
675 //	(just write data to pixels)
676 //	!!! UNTESTED !!!
677 //---------------------------------------------------
678 inline void
679 write_rgba32b(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
680 {
681 	int32 index = 0;
682 	int32 x = 0;
683 	while (x < width)
684 	{
685 		jas_matrix_setv(pixels[0], x, scanline[index++]);
686 		jas_matrix_setv(pixels[1], x, scanline[index++]);
687 		jas_matrix_setv(pixels[2], x, scanline[index++]);
688 		jas_matrix_setv(pixels[3], x, scanline[index++]);
689 		x++;
690 	}
691 }
692 
693 #endif // _JP2TRANSLATOR_H_
694