xref: /haiku/src/add-ons/translators/jpeg2000/JPEG2000Translator.h (revision c44966dff2813393aba0d3f8cdfa46abb2595948)
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>
38*c44966dfSJérôme Duval #include <Catalog.h>
399949213aSStephan Aßmus #include <CheckBox.h>
409949213aSStephan Aßmus #include <FindDirectory.h>
419949213aSStephan Aßmus #include <Path.h>
429949213aSStephan Aßmus #include <Slider.h>
439949213aSStephan Aßmus #include <StringView.h>
44bdaaeb0cSStefano Ceccherini #include <TabView.h>
459949213aSStephan Aßmus #include <TranslationKit.h>
469949213aSStephan Aßmus #include <TranslatorAddOn.h>
479949213aSStephan Aßmus 
489949213aSStephan Aßmus #include <stdio.h>
499949213aSStephan Aßmus #include <stdlib.h>
509949213aSStephan Aßmus #include <string.h>
519949213aSStephan Aßmus 
5294a204f0SStephan Aßmus #include "BaseTranslator.h"
539949213aSStephan Aßmus #include "libjasper/jasper.h"
549949213aSStephan Aßmus 
559949213aSStephan Aßmus 
56*c44966dfSJérôme Duval #undef B_TRANSLATE_CONTEXT
57*c44966dfSJérôme Duval #define B_TRANSLATE_CONTEXT "JPEG2000Translator"
58*c44966dfSJérôme Duval 
599949213aSStephan Aßmus // Settings
6094a204f0SStephan Aßmus #define JP2_SETTINGS_FILE	"JPEG2000Translator"
6194a204f0SStephan Aßmus 
62*c44966dfSJérôme Duval #define JP2_SET_QUALITY B_TRANSLATE_MARK("quality")
63*c44966dfSJérôme Duval #define JP2_SET_GRAY1_AS_B_RGB24 B_TRANSLATE_MARK("24 from gray1")
64*c44966dfSJérôme Duval #define JP2_SET_GRAY8_AS_B_RGB32 B_TRANSLATE_MARK("32 from gray8")
65*c44966dfSJérôme Duval #define JP2_SET_JPC B_TRANSLATE_MARK("jpc")
669949213aSStephan Aßmus 
679949213aSStephan Aßmus // View messages
689949213aSStephan Aßmus #define VIEW_MSG_SET_QUALITY 'JSCQ'
699949213aSStephan Aßmus #define	VIEW_MSG_SET_GRAY1ASRGB24 'JSGR'
709949213aSStephan Aßmus #define	VIEW_MSG_SET_JPC 'JSJC'
719949213aSStephan Aßmus #define	VIEW_MSG_SET_GRAYASRGB32 'JSAC'
729949213aSStephan Aßmus 
739949213aSStephan Aßmus // View labels
74*c44966dfSJérôme Duval #define VIEW_LABEL_QUALITY B_TRANSLATE_MARK("Output quality")
75*c44966dfSJérôme Duval #define VIEW_LABEL_JPC B_TRANSLATE_MARK("Output only codestream (.jpc)")
76*c44966dfSJérôme Duval #define VIEW_LABEL_GRAY1ASRGB24 \
77*c44966dfSJérôme Duval 	B_TRANSLATE_MARK("Write black-and-white images as RGB24")
78*c44966dfSJérôme Duval #define	VIEW_LABEL_GRAYASRGB32 \
79*c44966dfSJérôme Duval 	B_TRANSLATE_MARK("Read greyscale images as RGB32")
809949213aSStephan Aßmus 
81117da2d7SAxel Dörfler 
82117da2d7SAxel Dörfler /*!
83117da2d7SAxel Dörfler 	Slider used in TranslatorView
84117da2d7SAxel Dörfler 	With status showing actual value
85117da2d7SAxel Dörfler */
86117da2d7SAxel Dörfler class SSlider : public BSlider {
879949213aSStephan Aßmus public:
8894a204f0SStephan Aßmus 	SSlider(const char* name, const char* label,
89117da2d7SAxel Dörfler 		BMessage* message, int32 minValue, int32 maxValue,
90117da2d7SAxel Dörfler 		orientation posture = B_HORIZONTAL,
91117da2d7SAxel Dörfler 		thumb_style thumbType = B_BLOCK_THUMB,
92117da2d7SAxel Dörfler 		uint32 flags = B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS);
936bda235aSStefano Ceccherini 	const char*	UpdateText() const;
949949213aSStephan Aßmus 
959949213aSStephan Aßmus private:
96117da2d7SAxel Dörfler 	mutable char fStatusLabel[12];
979949213aSStephan Aßmus };
989949213aSStephan Aßmus 
99117da2d7SAxel Dörfler //!	Configuration view for reading settings
10094a204f0SStephan Aßmus class TranslatorReadView : public BView {
1019949213aSStephan Aßmus public:
10294a204f0SStephan Aßmus 	TranslatorReadView(const char* name, TranslatorSettings* settings);
10394a204f0SStephan Aßmus 	~TranslatorReadView();
104117da2d7SAxel Dörfler 
105117da2d7SAxel Dörfler 	virtual void	AttachedToWindow();
106117da2d7SAxel Dörfler 	virtual void	MessageReceived(BMessage* message);
1079949213aSStephan Aßmus 
1089949213aSStephan Aßmus private:
10994a204f0SStephan Aßmus 	TranslatorSettings*	fSettings;
110117da2d7SAxel Dörfler 	BCheckBox*		fGrayAsRGB32;
1119949213aSStephan Aßmus };
1129949213aSStephan Aßmus 
113117da2d7SAxel Dörfler //! Configuration view for writing settings
11494a204f0SStephan Aßmus class TranslatorWriteView : public BView {
1159949213aSStephan Aßmus public:
11694a204f0SStephan Aßmus 	TranslatorWriteView(const char* name, TranslatorSettings* settings);
11794a204f0SStephan Aßmus 	~TranslatorWriteView();
118117da2d7SAxel Dörfler 
119117da2d7SAxel Dörfler 	virtual void	AttachedToWindow();
120117da2d7SAxel Dörfler 	virtual void	MessageReceived(BMessage* message);
1219949213aSStephan Aßmus 
1229949213aSStephan Aßmus private:
12394a204f0SStephan Aßmus 	TranslatorSettings*	fSettings;
124117da2d7SAxel Dörfler 	SSlider*		fQualitySlider;
125117da2d7SAxel Dörfler 	BCheckBox*		fGrayAsRGB24;
126117da2d7SAxel Dörfler 	BCheckBox*		fCodeStreamOnly;
1279949213aSStephan Aßmus };
1289949213aSStephan Aßmus 
12994a204f0SStephan Aßmus class TranslatorAboutView : public BView {
1309949213aSStephan Aßmus public:
13194a204f0SStephan Aßmus 	TranslatorAboutView(const char* name);
1329949213aSStephan Aßmus };
1339949213aSStephan Aßmus 
134117da2d7SAxel Dörfler //!	Configuration view
135bdaaeb0cSStefano Ceccherini class TranslatorView : public BTabView {
1369949213aSStephan Aßmus public:
13794a204f0SStephan Aßmus 	TranslatorView(const char* name, TranslatorSettings* settings);
13894a204f0SStephan Aßmus };
13994a204f0SStephan Aßmus 
14094a204f0SStephan Aßmus class JP2Translator : public BaseTranslator {
14194a204f0SStephan Aßmus public:
14294a204f0SStephan Aßmus 	JP2Translator();
14394a204f0SStephan Aßmus 	virtual status_t DerivedIdentify(BPositionIO* inSource,
14494a204f0SStephan Aßmus 		const translation_format* inFormat, BMessage* ioExtension,
14594a204f0SStephan Aßmus 		translator_info* outInfo, uint32 outType);
14694a204f0SStephan Aßmus 
14794a204f0SStephan Aßmus 	virtual status_t DerivedTranslate(BPositionIO* inSource,
14894a204f0SStephan Aßmus 		const translator_info* inInfo, BMessage* ioExtension,
14994a204f0SStephan Aßmus 		uint32 outType, BPositionIO* outDestination, int32 baseType);
15094a204f0SStephan Aßmus 
15194a204f0SStephan Aßmus 	virtual BView* NewConfigView(TranslatorSettings* settings);
15294a204f0SStephan Aßmus 
153117da2d7SAxel Dörfler 
1549949213aSStephan Aßmus private:
1559949213aSStephan Aßmus 	status_t Copy(BPositionIO* in, BPositionIO* out);
1569949213aSStephan Aßmus 	status_t Compress(BPositionIO* in, BPositionIO* out);
1579949213aSStephan Aßmus 	status_t Decompress(BPositionIO* in, BPositionIO* out);
15894a204f0SStephan Aßmus 
15994a204f0SStephan Aßmus 	status_t PopulateInfoFromFormat(translator_info* info,
16094a204f0SStephan Aßmus 		uint32 formatType, translator_id id = 0);
16194a204f0SStephan Aßmus 	status_t PopulateInfoFromFormat(translator_info* info,
16294a204f0SStephan Aßmus 		uint32 formatType, const translation_format* formats,
16394a204f0SStephan Aßmus 		int32 formatCount);
16494a204f0SStephan Aßmus };
16594a204f0SStephan Aßmus 
16694a204f0SStephan Aßmus status_t Error(jas_stream_t* stream, jas_image_t* image, jas_matrix_t** pixels,
16794a204f0SStephan Aßmus 	int32 pixels_count, jpr_uchar_t* scanline, status_t error = B_ERROR);
1689949213aSStephan Aßmus 
1699949213aSStephan Aßmus #endif // _JP2TRANSLATOR_H_
170