xref: /haiku/src/add-ons/translators/jpeg2000/JPEG2000Translator.h (revision 94a204f083efcdfde918177393ae56e5bd968e7b)
19949213aSStephan Aßmus /*
29949213aSStephan Aßmus 
39949213aSStephan Aßmus Copyright (c) 2003, Marcin 'Shard' Konicki
49949213aSStephan Aßmus All rights reserved.
59949213aSStephan Aßmus 
69949213aSStephan Aßmus Redistribution and use in source and binary forms, with or without
79949213aSStephan Aßmus modification, are permitted provided that the following conditions are met:
89949213aSStephan Aßmus 
99949213aSStephan Aßmus     * Redistributions of source code must retain the above copyright notice,
109949213aSStephan Aßmus       this list of conditions and the following disclaimer.
119949213aSStephan Aßmus     * Redistributions in binary form must reproduce the above copyright notice,
129949213aSStephan Aßmus       this list of conditions and the following disclaimer in the documentation and/or
139949213aSStephan Aßmus       other materials provided with the distribution.
149949213aSStephan Aßmus     * Name "Marcin Konicki", "Shard" or any combination of them,
159949213aSStephan Aßmus       must not be used to endorse or promote products derived from this
169949213aSStephan Aßmus       software without specific prior written permission from Marcin Konicki.
179949213aSStephan Aßmus 
189949213aSStephan Aßmus THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
199949213aSStephan Aßmus ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
209949213aSStephan Aßmus THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
219949213aSStephan Aßmus ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
229949213aSStephan Aßmus BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
239949213aSStephan Aßmus OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
249949213aSStephan Aßmus PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
259949213aSStephan Aßmus OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
269949213aSStephan Aßmus WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
279949213aSStephan Aßmus OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
289949213aSStephan Aßmus EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
299949213aSStephan Aßmus 
309949213aSStephan Aßmus */
319949213aSStephan Aßmus 
329949213aSStephan Aßmus #ifndef _JP2TRANSLATOR_H_
339949213aSStephan Aßmus #define _JP2TRANSLATOR_H_
349949213aSStephan Aßmus 
359949213aSStephan Aßmus 
369949213aSStephan Aßmus #include <Alert.h>
379949213aSStephan Aßmus #include <Application.h>
389949213aSStephan Aßmus #include <CheckBox.h>
399949213aSStephan Aßmus #include <FindDirectory.h>
409949213aSStephan Aßmus #include <Path.h>
419949213aSStephan Aßmus #include <Slider.h>
429949213aSStephan Aßmus #include <StringView.h>
43bdaaeb0cSStefano Ceccherini #include <TabView.h>
449949213aSStephan Aßmus #include <TranslationKit.h>
459949213aSStephan Aßmus #include <TranslatorAddOn.h>
469949213aSStephan Aßmus 
479949213aSStephan Aßmus #include <stdio.h>
489949213aSStephan Aßmus #include <stdlib.h>
499949213aSStephan Aßmus #include <string.h>
509949213aSStephan Aßmus 
51*94a204f0SStephan Aßmus #include "BaseTranslator.h"
529949213aSStephan Aßmus #include "libjasper/jasper.h"
539949213aSStephan Aßmus 
549949213aSStephan Aßmus 
559949213aSStephan Aßmus // Settings
56*94a204f0SStephan Aßmus #define JP2_SETTINGS_FILE	"JPEG2000Translator"
57*94a204f0SStephan Aßmus 
58*94a204f0SStephan Aßmus #define JP2_SET_QUALITY "quality"
59*94a204f0SStephan Aßmus #define JP2_SET_GRAY1_AS_B_RGB24 "24 from gray1"
60*94a204f0SStephan Aßmus #define JP2_SET_GRAY8_AS_B_RGB32 "32 from gray8"
61*94a204f0SStephan Aßmus #define JP2_SET_JPC "jpc"
629949213aSStephan Aßmus 
639949213aSStephan Aßmus // View messages
649949213aSStephan Aßmus #define VIEW_MSG_SET_QUALITY 'JSCQ'
659949213aSStephan Aßmus #define	VIEW_MSG_SET_GRAY1ASRGB24 'JSGR'
669949213aSStephan Aßmus #define	VIEW_MSG_SET_JPC 'JSJC'
679949213aSStephan Aßmus #define	VIEW_MSG_SET_GRAYASRGB32 'JSAC'
689949213aSStephan Aßmus 
699949213aSStephan Aßmus // View labels
709949213aSStephan Aßmus #define VIEW_LABEL_QUALITY "Output quality"
719949213aSStephan Aßmus #define VIEW_LABEL_JPC "Output only codestream (.jpc)"
72*94a204f0SStephan Aßmus #define VIEW_LABEL_GRAY1ASRGB24 "Write black-and-white images as RGB24"
73fcc3e627SStephan Aßmus #define	VIEW_LABEL_GRAYASRGB32 "Read greyscale images as RGB32"
749949213aSStephan Aßmus 
759949213aSStephan Aßmus 
76117da2d7SAxel Dörfler 
77117da2d7SAxel Dörfler /*!
78117da2d7SAxel Dörfler 	Slider used in TranslatorView
79117da2d7SAxel Dörfler 	With status showing actual value
80117da2d7SAxel Dörfler */
81117da2d7SAxel Dörfler class SSlider : public BSlider {
829949213aSStephan Aßmus public:
83*94a204f0SStephan Aßmus 	SSlider(const char* name, const char* label,
84117da2d7SAxel Dörfler 		BMessage* message, int32 minValue, int32 maxValue,
85117da2d7SAxel Dörfler 		orientation posture = B_HORIZONTAL,
86117da2d7SAxel Dörfler 		thumb_style thumbType = B_BLOCK_THUMB,
87117da2d7SAxel Dörfler 		uint32 flags = B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS);
886bda235aSStefano Ceccherini 	const char*	UpdateText() const;
899949213aSStephan Aßmus 
909949213aSStephan Aßmus private:
91117da2d7SAxel Dörfler 	mutable char fStatusLabel[12];
929949213aSStephan Aßmus };
939949213aSStephan Aßmus 
94117da2d7SAxel Dörfler //!	Configuration view for reading settings
95*94a204f0SStephan Aßmus class TranslatorReadView : public BView {
969949213aSStephan Aßmus public:
97*94a204f0SStephan Aßmus 	TranslatorReadView(const char* name, TranslatorSettings* settings);
98*94a204f0SStephan Aßmus 	~TranslatorReadView();
99117da2d7SAxel Dörfler 
100117da2d7SAxel Dörfler 	virtual void	AttachedToWindow();
101117da2d7SAxel Dörfler 	virtual void	MessageReceived(BMessage* message);
1029949213aSStephan Aßmus 
1039949213aSStephan Aßmus private:
104*94a204f0SStephan Aßmus 	TranslatorSettings*	fSettings;
105117da2d7SAxel Dörfler 	BCheckBox*		fGrayAsRGB32;
1069949213aSStephan Aßmus };
1079949213aSStephan Aßmus 
108117da2d7SAxel Dörfler //! Configuration view for writing settings
109*94a204f0SStephan Aßmus class TranslatorWriteView : public BView {
1109949213aSStephan Aßmus public:
111*94a204f0SStephan Aßmus 	TranslatorWriteView(const char* name, TranslatorSettings* settings);
112*94a204f0SStephan Aßmus 	~TranslatorWriteView();
113117da2d7SAxel Dörfler 
114117da2d7SAxel Dörfler 	virtual void	AttachedToWindow();
115117da2d7SAxel Dörfler 	virtual void	MessageReceived(BMessage* message);
1169949213aSStephan Aßmus 
1179949213aSStephan Aßmus private:
118*94a204f0SStephan Aßmus 	TranslatorSettings*	fSettings;
119117da2d7SAxel Dörfler 	SSlider*		fQualitySlider;
120117da2d7SAxel Dörfler 	BCheckBox*		fGrayAsRGB24;
121117da2d7SAxel Dörfler 	BCheckBox*		fCodeStreamOnly;
1229949213aSStephan Aßmus };
1239949213aSStephan Aßmus 
124*94a204f0SStephan Aßmus class TranslatorAboutView : public BView {
1259949213aSStephan Aßmus public:
126*94a204f0SStephan Aßmus 	TranslatorAboutView(const char* name);
1279949213aSStephan Aßmus };
1289949213aSStephan Aßmus 
129117da2d7SAxel Dörfler //!	Configuration view
130bdaaeb0cSStefano Ceccherini class TranslatorView : public BTabView {
1319949213aSStephan Aßmus public:
132*94a204f0SStephan Aßmus 	TranslatorView(const char* name, TranslatorSettings* settings);
133*94a204f0SStephan Aßmus };
134*94a204f0SStephan Aßmus 
135*94a204f0SStephan Aßmus class JP2Translator : public BaseTranslator {
136*94a204f0SStephan Aßmus public:
137*94a204f0SStephan Aßmus 	JP2Translator();
138*94a204f0SStephan Aßmus 	virtual status_t DerivedIdentify(BPositionIO* inSource,
139*94a204f0SStephan Aßmus 		const translation_format* inFormat, BMessage* ioExtension,
140*94a204f0SStephan Aßmus 		translator_info* outInfo, uint32 outType);
141*94a204f0SStephan Aßmus 
142*94a204f0SStephan Aßmus 	virtual status_t DerivedTranslate(BPositionIO* inSource,
143*94a204f0SStephan Aßmus 		const translator_info* inInfo, BMessage* ioExtension,
144*94a204f0SStephan Aßmus 		uint32 outType, BPositionIO* outDestination, int32 baseType);
145*94a204f0SStephan Aßmus 
146*94a204f0SStephan Aßmus 	virtual BView* NewConfigView(TranslatorSettings* settings);
147*94a204f0SStephan Aßmus 
148117da2d7SAxel Dörfler 
1499949213aSStephan Aßmus private:
1509949213aSStephan Aßmus 	status_t Copy(BPositionIO* in, BPositionIO* out);
1519949213aSStephan Aßmus 	status_t Compress(BPositionIO* in, BPositionIO* out);
1529949213aSStephan Aßmus 	status_t Decompress(BPositionIO* in, BPositionIO* out);
153*94a204f0SStephan Aßmus 
154*94a204f0SStephan Aßmus 	status_t PopulateInfoFromFormat(translator_info* info,
155*94a204f0SStephan Aßmus 		uint32 formatType, translator_id id = 0);
156*94a204f0SStephan Aßmus 	status_t PopulateInfoFromFormat(translator_info* info,
157*94a204f0SStephan Aßmus 		uint32 formatType, const translation_format* formats,
158*94a204f0SStephan Aßmus 		int32 formatCount);
159*94a204f0SStephan Aßmus };
160*94a204f0SStephan Aßmus 
161*94a204f0SStephan Aßmus status_t Error(jas_stream_t* stream, jas_image_t* image, jas_matrix_t** pixels,
162*94a204f0SStephan Aßmus 	int32 pixels_count, jpr_uchar_t* scanline, status_t error = B_ERROR);
1639949213aSStephan Aßmus 
1649949213aSStephan Aßmus #endif // _JP2TRANSLATOR_H_
165