xref: /haiku/src/add-ons/translators/jpeg/JPEGTranslator.h (revision d25503d3dbd8e3f526fd0a9bdd884b8e43c1b794)
1 /*
2 
3 Copyright (c) 2002-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 #ifndef _JPEGTRANSLATOR_H_
32 #define _JPEGTRANSLATOR_H_
33 
34 
35 #include <Alert.h>
36 #include <Application.h>
37 #include <CheckBox.h>
38 #include <FindDirectory.h>
39 #include <Path.h>
40 #include <Slider.h>
41 #include <StringView.h>
42 #include <TabView.h>
43 #include <TranslationKit.h>
44 #include <TranslatorAddOn.h>
45 
46 #include <setjmp.h>
47 #include <stdio.h>
48 #include <stdlib.h>
49 #include <string.h>
50 
51 #include <jpeglib.h>
52 
53 
54 // Settings
55 #define SETTINGS_FILE	"JPEGTranslator"
56 
57 // View messages
58 #define VIEW_MSG_SET_QUALITY 'JSCQ'
59 #define VIEW_MSG_SET_SMOOTHING 'JSCS'
60 #define VIEW_MSG_SET_PROGRESSIVE 'JSCP'
61 #define VIEW_MSG_SET_OPTIMIZECOLORS 'JSBQ'
62 #define	VIEW_MSG_SET_SMALLERFILE 'JSSF'
63 #define	VIEW_MSG_SET_GRAY1ASRGB24 'JSGR'
64 #define	VIEW_MSG_SET_ALWAYSRGB32 'JSAC'
65 #define	VIEW_MSG_SET_PHOTOSHOPCMYK 'JSPC'
66 #define	VIEW_MSG_SET_SHOWREADERRORBOX 'JSEB'
67 
68 // View labels
69 #define VIEW_LABEL_QUALITY "Output quality"
70 #define VIEW_LABEL_SMOOTHING "Output smoothing strength"
71 #define VIEW_LABEL_PROGRESSIVE "Use progressive compression"
72 #define VIEW_LABEL_OPTIMIZECOLORS "Prevent colors 'washing out'"
73 #define	VIEW_LABEL_SMALLERFILE "Make file smaller (sligthtly worse quality)"
74 #define	VIEW_LABEL_GRAY1ASRGB24 "Write Black&White images as RGB24"
75 #define	VIEW_LABEL_ALWAYSRGB32 "Read Greyscale images as RGB32"
76 #define	VIEW_LABEL_PHOTOSHOPCMYK "Use CMYK code with 0 for 100% ink coverage"
77 #define	VIEW_LABEL_SHOWREADERRORBOX "Show warning messages"
78 
79 
80 //!	Settings storage structure
81 struct jpeg_settings {
82 	// compression
83 	uchar	Smoothing;			// default: 0
84 	uchar	Quality;			// default: 95
85 	bool	Progressive;		// default: true
86 	bool	OptimizeColors;		// default: true
87 	bool	SmallerFile;		// default: false	only used if (OptimizeColors == true)
88 	bool	B_GRAY1_as_B_RGB24;	// default: false	if false gray1 converted to gray8, else to rgb24
89 	// decompression
90 	bool	Always_B_RGB32;		// default: true
91 	bool	PhotoshopCMYK;		// default: true
92 	bool	ShowReadWarningBox;	// default: true
93 };
94 
95 
96 /*!
97 	Slider used in TranslatorView
98 	With status showing actual value
99 */
100 class SSlider : public BSlider {
101 	public:
102 				SSlider(BRect frame, const char *name, const char *label,
103 					BMessage *message, int32 minValue, int32 maxValue,
104 					orientation posture = B_HORIZONTAL,
105 					thumb_style thumbType = B_BLOCK_THUMB,
106 					uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
107 					uint32 flags = B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS);
108 	virtual const char* UpdateText() const;
109 		void	ResizeToPreferred();
110 
111 	private:
112 		mutable char fStatusLabel[12];
113 };
114 
115 
116 class SView : public BView {
117 public:
118 	SView(BRect frame, const char *name);
119 	virtual void AttachedToWindow();
120 };
121 
122 //!	Configuration view for reading settings
123 class TranslatorReadView : public SView {
124 	public:
125 		TranslatorReadView(BRect frame, const char* name, jpeg_settings* settings);
126 
127 		virtual void	AttachedToWindow();
128 		virtual void	MessageReceived(BMessage* message);
129 
130 	private:
131 		jpeg_settings*	fSettings;
132 		BCheckBox*		fAlwaysRGB32;
133 		BCheckBox*		fPhotoshopCMYK;
134 		BCheckBox*		fShowErrorBox;
135 };
136 
137 
138 //! Configuration view for writing settings
139 class TranslatorWriteView : public SView {
140 	public:
141 		TranslatorWriteView(BRect frame, const char* name, jpeg_settings* settings);
142 
143 		virtual void	AttachedToWindow();
144 		virtual void	MessageReceived(BMessage* message);
145 
146 	private:
147 		jpeg_settings*	fSettings;
148 		SSlider*		fQualitySlider;
149 		SSlider*		fSmoothingSlider;
150 		BCheckBox*		fProgress;
151 		BCheckBox*		fOptimizeColors;
152 		BCheckBox*		fSmallerFile;
153 		BCheckBox*		fGrayAsRGB24;
154 };
155 
156 class TranslatorAboutView : public SView {
157 	public:
158 		TranslatorAboutView(BRect frame, const char* name);
159 };
160 
161 //!	Configuration view
162 class TranslatorView : public BTabView {
163 	public:
164 		TranslatorView(BRect frame, const char *name);
165 		virtual ~TranslatorView();
166 
167 		virtual void	AttachedToWindow();
168 		virtual void	Select(int32 index);
169 
170 	private:
171 		jpeg_settings	fSettings;
172 };
173 
174 //!	Window used for configuration
175 class TranslatorWindow : public BWindow {
176 	public:
177 		TranslatorWindow(bool quitOnClose = true);
178 };
179 
180 
181 //---------------------------------------------------
182 //	"Initializers" for jpeglib
183 //	based on default ones,
184 //	modified to work on BPositionIO instead of FILE
185 //---------------------------------------------------
186 EXTERN(void) be_jpeg_stdio_src(j_decompress_ptr cinfo, BPositionIO *infile);	// from "be_jdatasrc.cpp"
187 EXTERN(void) be_jpeg_stdio_dest(j_compress_ptr cinfo, BPositionIO *outfile);	// from "be_jdatadst.cpp"
188 
189 //---------------------------------------------------
190 //	Error output functions
191 //	based on the one from jerror.c
192 //	modified to use settings
193 //	(so user can decide to show dialog-boxes or not)
194 //---------------------------------------------------
195 EXTERN(struct jpeg_error_mgr *) be_jpeg_std_error (struct jpeg_error_mgr * err,
196 	jpeg_settings * settings, const jmp_buf* longJumpBuffer);
197 	// implemented in "be_jerror.cpp"
198 
199 #endif // _JPEGTRANSLATOR_H_
200