xref: /haiku/src/add-ons/translators/jpeg2000/JPEG2000Translator.h (revision 2b76973fa2401f7a5edf68e6470f3d3210cbcff3)
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 #include <Alert.h>
37 #include <Application.h>
38 #include <Catalog.h>
39 #include <CheckBox.h>
40 #include <FindDirectory.h>
41 #include <Path.h>
42 #include <Slider.h>
43 #include <StringView.h>
44 #include <TabView.h>
45 #include <TranslationKit.h>
46 #include <TranslatorAddOn.h>
47 
48 #include <stdio.h>
49 #include <stdlib.h>
50 #include <string.h>
51 
52 #include "BaseTranslator.h"
53 #include "libjasper/jasper.h"
54 
55 
56 #undef B_TRANSLATION_CONTEXT
57 #define B_TRANSLATION_CONTEXT "JPEG2000Translator"
58 
59 // Settings
60 #define JP2_SETTINGS_FILE	"JPEG2000Translator"
61 
62 #define JP2_SET_QUALITY "quality"
63 #define JP2_SET_GRAY1_AS_B_RGB24 "24 from gray1"
64 #define JP2_SET_GRAY8_AS_B_RGB32 "32 from gray8"
65 #define JP2_SET_JPC "jpc"
66 
67 // View messages
68 #define VIEW_MSG_SET_QUALITY 'JSCQ'
69 #define	VIEW_MSG_SET_GRAY1ASRGB24 'JSGR'
70 #define	VIEW_MSG_SET_JPC 'JSJC'
71 #define	VIEW_MSG_SET_GRAYASRGB32 'JSAC'
72 
73 
74 /*!
75 	Slider used in TranslatorView
76 	With status showing actual value
77 */
78 class SSlider : public BSlider {
79 public:
80 	SSlider(const char* name, const char* label,
81 		BMessage* message, int32 minValue, int32 maxValue,
82 		orientation posture = B_HORIZONTAL,
83 		thumb_style thumbType = B_BLOCK_THUMB,
84 		uint32 flags = B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS);
85 	const char*	UpdateText() const;
86 
87 private:
88 	mutable char fStatusLabel[12];
89 };
90 
91 //!	Configuration view for reading settings
92 class TranslatorReadView : public BView {
93 public:
94 	TranslatorReadView(const char* name, TranslatorSettings* settings);
95 	~TranslatorReadView();
96 
97 	virtual void	AttachedToWindow();
98 	virtual void	MessageReceived(BMessage* message);
99 
100 private:
101 	TranslatorSettings*	fSettings;
102 	BCheckBox*		fGrayAsRGB32;
103 };
104 
105 //! Configuration view for writing settings
106 class TranslatorWriteView : public BView {
107 public:
108 	TranslatorWriteView(const char* name, TranslatorSettings* settings);
109 	~TranslatorWriteView();
110 
111 	virtual void	AttachedToWindow();
112 	virtual void	MessageReceived(BMessage* message);
113 
114 private:
115 	TranslatorSettings*	fSettings;
116 	SSlider*		fQualitySlider;
117 	BCheckBox*		fGrayAsRGB24;
118 	BCheckBox*		fCodeStreamOnly;
119 };
120 
121 class TranslatorAboutView : public BView {
122 public:
123 	TranslatorAboutView(const char* name);
124 };
125 
126 //!	Configuration view
127 class TranslatorView : public BTabView {
128 public:
129 	TranslatorView(const char* name, TranslatorSettings* settings);
130 };
131 
132 class JP2Translator : public BaseTranslator {
133 public:
134 	JP2Translator();
135 	virtual status_t DerivedIdentify(BPositionIO* inSource,
136 		const translation_format* inFormat, BMessage* ioExtension,
137 		translator_info* outInfo, uint32 outType);
138 
139 	virtual status_t DerivedTranslate(BPositionIO* inSource,
140 		const translator_info* inInfo, BMessage* ioExtension,
141 		uint32 outType, BPositionIO* outDestination, int32 baseType);
142 
143 	virtual BView* NewConfigView(TranslatorSettings* settings);
144 
145 
146 private:
147 	status_t Copy(BPositionIO* in, BPositionIO* out);
148 	status_t Compress(BPositionIO* in, BPositionIO* out);
149 	status_t Decompress(BPositionIO* in, BPositionIO* out);
150 
151 	status_t PopulateInfoFromFormat(translator_info* info,
152 		uint32 formatType, translator_id id = 0);
153 	status_t PopulateInfoFromFormat(translator_info* info,
154 		uint32 formatType, const translation_format* formats,
155 		int32 formatCount);
156 };
157 
158 status_t Error(jas_stream_t* stream, jas_image_t* image, jas_matrix_t** pixels,
159 	int32 pixels_count, jpr_uchar_t* scanline, status_t error = B_ERROR);
160 
161 #endif // _JP2TRANSLATOR_H_
162