xref: /haiku/src/add-ons/translators/jpeg2000/JPEG2000Translator.h (revision 16d5c24e533eb14b7b8a99ee9f3ec9ba66335b1e)
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 <CheckBox.h>
39 #include <FindDirectory.h>
40 #include <Path.h>
41 #include <Slider.h>
42 #include <StringView.h>
43 #include <TranslationKit.h>
44 #include <TranslatorAddOn.h>
45 
46 #include <stdio.h>
47 #include <stdlib.h>
48 #include <string.h>
49 
50 #include "libjasper/jasper.h"
51 
52 
53 // Settings
54 #define SETTINGS_FILE	"JPEG2000Translator"
55 
56 // View messages
57 #define VIEW_MSG_SET_QUALITY 'JSCQ'
58 #define	VIEW_MSG_SET_GRAY1ASRGB24 'JSGR'
59 #define	VIEW_MSG_SET_JPC 'JSJC'
60 #define	VIEW_MSG_SET_GRAYASRGB32 'JSAC'
61 
62 // View labels
63 #define VIEW_LABEL_QUALITY "Output quality"
64 #define VIEW_LABEL_GRAY1ASRGB24 "Write Black&White images as RGB24"
65 #define VIEW_LABEL_JPC "Output only codestream (.jpc)"
66 #define	VIEW_LABEL_GRAYASRGB32 "Read Greyscale images as RGB32"
67 
68 
69 //!	Settings storage structure
70 struct jpeg_settings {
71 	// compression
72 	jpr_uchar_t	Quality;			// default: 25
73 	bool	JPC;				// default: false	// compress to JPC or JP2?
74 	bool	B_GRAY1_as_B_RGB24;	// default: false	// copress gray 1 as rgb24 or grayscale?
75 	// decompression
76 	bool	B_GRAY8_as_B_RGB32;	// default: true
77 };
78 
79 
80 /*!
81 	Slider used in TranslatorView
82 	With status showing actual value
83 */
84 class SSlider : public BSlider {
85 	public:
86 				SSlider(BRect frame, const char *name, const char *label,
87 					BMessage *message, int32 minValue, int32 maxValue,
88 					orientation posture = B_HORIZONTAL,
89 					thumb_style thumbType = B_BLOCK_THUMB,
90 					uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
91 					uint32 flags = B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS);
92 		const char*	UpdateText() const;
93 		void	ResizeToPreferred();
94 
95 	private:
96 		mutable char fStatusLabel[12];
97 };
98 
99 //!	Basic view class with resizing to needed size
100 class SView : public BView {
101 	public:
102 		SView(const char* name, float x = 0, float y = 0);
103 
104 		virtual void	GetPreferredSize(float* _width, float* _height);
105 		virtual void	ResizeToPreferred();
106 
107 		void			AddChild(BView* child, BView* before = NULL);
108 
109 		float			GetPreferredWidth()
110 							{ return fPreferredWidth; }
111 		float			GetPreferredHeight()
112 							{ return fPreferredHeight; }
113 		void			ResizePreferredBy(float width, float height);
114 
115 	private:
116 		float			fPreferredWidth;
117 		float			fPreferredHeight;
118 };
119 
120 //!	Configuration view for reading settings
121 class TranslatorReadView : public SView {
122 	public:
123 		TranslatorReadView(const char* name, jpeg_settings* settings,
124 			float x = 0, float y = 0);
125 
126 		virtual void	AttachedToWindow();
127 		virtual void	MessageReceived(BMessage* message);
128 
129 	private:
130 		jpeg_settings*	fSettings;
131 		BCheckBox*		fGrayAsRGB32;
132 };
133 
134 //! Configuration view for writing settings
135 class TranslatorWriteView : public SView {
136 	public:
137 		TranslatorWriteView(const char* name, jpeg_settings* settings,
138 			float x = 0, float y = 0);
139 
140 		virtual void	AttachedToWindow();
141 		virtual void	MessageReceived(BMessage* message);
142 
143 	private:
144 		jpeg_settings*	fSettings;
145 		SSlider*		fQualitySlider;
146 		BCheckBox*		fGrayAsRGB24;
147 		BCheckBox*		fCodeStreamOnly;
148 };
149 
150 class TranslatorAboutView : public SView {
151 	public:
152 		TranslatorAboutView(const char* name, float x = 0, float y = 0);
153 };
154 
155 //!	Configuration view
156 class TranslatorView : public SView {
157 	public:
158 		TranslatorView(const char *name);
159 		virtual ~TranslatorView();
160 
161 		virtual void	AttachedToWindow();
162 		virtual void	Draw(BRect updateRect);
163 		virtual void	MouseDown(BPoint where);
164 
165 	private:
166 		BRect			_TabFrame(int32 index) const;
167 
168 		jpeg_settings	fSettings;
169 		BList			fTabs;
170 		int32			fTabWidth;
171 		int32			fTabHeight;
172 		int32			fActiveChild;
173 };
174 
175 //!	Window used for configuration
176 class TranslatorWindow : public BWindow {
177 	public:
178 		TranslatorWindow(bool quitOnClose = true);
179 };
180 
181 
182 // Main functions of translator :)
183 status_t Copy(BPositionIO *in, BPositionIO *out);
184 status_t Compress(BPositionIO *in, BPositionIO *out);
185 status_t Decompress(BPositionIO *in, BPositionIO *out);
186 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);
187 
188 #endif // _JP2TRANSLATOR_H_
189