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