1/*
2
3Copyright (c) 2002-2003, Marcin 'Shard' Konicki
4All rights reserved.
5
6Redistribution and use in source and binary forms, with or without
7modification, 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
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28EVEN 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 <Catalog.h>
38#include <CheckBox.h>
39#include <FindDirectory.h>
40#include <Path.h>
41#include <Slider.h>
42#include <StringView.h>
43#include <TabView.h>
44#include <TranslationKit.h>
45#include <TranslatorAddOn.h>
46
47#include <setjmp.h>
48#include <stdio.h>
49#include <stdlib.h>
50#include <string.h>
51
52#include <jpeglib.h>
53
54#include "BaseTranslator.h"
55
56#undef B_TRANSLATION_CONTEXT
57#define B_TRANSLATION_CONTEXT "JPEGTranslator"
58
59// Settings
60#define SETTINGS_FILE	"JPEGTranslator"
61
62// View messages
63#define VIEW_MSG_SET_QUALITY 'JSCQ'
64#define VIEW_MSG_SET_SMOOTHING 'JSCS'
65#define VIEW_MSG_SET_PROGRESSIVE 'JSCP'
66#define VIEW_MSG_SET_OPTIMIZECOLORS 'JSBQ'
67#define	VIEW_MSG_SET_SMALLERFILE 'JSSF'
68#define	VIEW_MSG_SET_GRAY1ASRGB24 'JSGR'
69#define	VIEW_MSG_SET_ALWAYSRGB32 'JSAC'
70#define	VIEW_MSG_SET_PHOTOSHOPCMYK 'JSPC'
71#define	VIEW_MSG_SET_SHOWREADERRORBOX 'JSEB'
72
73// strings for use in TranslatorSettings
74#define JPEG_SET_SMOOTHING "smoothing"
75#define JPEG_SET_QUALITY "quality"
76#define JPEG_SET_PROGRESSIVE "progressive"
77#define JPEG_SET_OPT_COLORS "optimize"
78#define JPEG_SET_SMALL_FILES "filesSmaller"
79#define JPEG_SET_GRAY1_AS_RGB24 "gray"
80#define JPEG_SET_ALWAYS_RGB32 "always"
81#define JPEG_SET_PHOTOSHOP_CMYK "cmyk"
82#define JPEG_SET_SHOWREADWARNING "readWarning"
83
84
85/*!
86	Slider used in TranslatorView
87	With status showing actual value
88*/
89class SSlider : public BSlider {
90	public:
91		SSlider(const char* name, const char* label,
92			BMessage* message, int32 minValue, int32 maxValue,
93			orientation posture = B_HORIZONTAL,
94			thumb_style thumbType = B_BLOCK_THUMB,
95			uint32 flags = B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS);
96	virtual const char* UpdateText() const;
97
98	private:
99		mutable char fStatusLabel[12];
100};
101
102
103class JPEGTranslator : public BaseTranslator {
104	public:
105		JPEGTranslator();
106
107		virtual status_t DerivedIdentify(BPositionIO* inSource,
108			const translation_format* inFormat, BMessage* ioExtension,
109			translator_info* outInfo, uint32 outType);
110
111		virtual status_t DerivedTranslate(BPositionIO* inSource,
112			const translator_info* inInfo, BMessage* ioExtension,
113			uint32 outType, BPositionIO* outDestination, int32 baseType);
114
115		virtual BView* NewConfigView(TranslatorSettings* settings);
116
117	private:
118
119		status_t Copy(BPositionIO* in, BPositionIO* out);
120		status_t Compress(BPositionIO* in, BPositionIO* out,
121			const jmp_buf* longJumpBuffer);
122		status_t Decompress(BPositionIO* in, BPositionIO* out,
123			BMessage* ioExtension, const jmp_buf* longJumpBuffer);
124		status_t Error(j_common_ptr cinfo, status_t error = B_ERROR);
125
126		status_t PopulateInfoFromFormat(translator_info* info,
127			uint32 formatType, translator_id id = 0);
128		status_t PopulateInfoFromFormat(translator_info* info,
129			uint32 formatType, const translation_format* formats,
130			int32 formatCount);
131};
132
133
134class TranslatorReadView : public BView {
135	public:
136		TranslatorReadView(const char* name, TranslatorSettings* settings);
137		virtual ~TranslatorReadView();
138
139		virtual void	AttachedToWindow();
140		virtual void	MessageReceived(BMessage* message);
141
142	private:
143		TranslatorSettings* fSettings;
144		BCheckBox*		fAlwaysRGB32;
145		BCheckBox*		fPhotoshopCMYK;
146		BCheckBox*		fShowErrorBox;
147};
148
149
150class TranslatorWriteView : public BView {
151	public:
152		TranslatorWriteView(const char* name, TranslatorSettings* settings);
153		virtual ~TranslatorWriteView();
154
155		virtual void	AttachedToWindow();
156		virtual void	MessageReceived(BMessage* message);
157
158	private:
159		TranslatorSettings* fSettings;
160		SSlider*		fQualitySlider;
161		SSlider*		fSmoothingSlider;
162		BCheckBox*		fProgress;
163		BCheckBox*		fOptimizeColors;
164		BCheckBox*		fSmallerFile;
165		BCheckBox*		fGrayAsRGB24;
166};
167
168
169class TranslatorAboutView : public BView {
170	public:
171		TranslatorAboutView(const char* name);
172};
173
174
175class TranslatorView : public BTabView {
176	public:
177		TranslatorView(const char* name, TranslatorSettings* settings);
178
179	private:
180		BView* fAboutView;
181		BView* fReadView;
182		BView* fWriteView;
183};
184
185
186//---------------------------------------------------
187//	"Initializers" for jpeglib
188//	based on default ones,
189//	modified to work on BPositionIO instead of FILE
190//---------------------------------------------------
191EXTERN(void) be_jpeg_stdio_src(j_decompress_ptr cinfo, BPositionIO *infile);	// from "be_jdatasrc.cpp"
192EXTERN(void) be_jpeg_stdio_dest(j_compress_ptr cinfo, BPositionIO *outfile);	// from "be_jdatadst.cpp"
193
194#endif // _JPEGTRANSLATOR_H_
195
196