1/*
2
3Copyright (c) 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
32#ifndef _JP2TRANSLATOR_H_
33#define _JP2TRANSLATOR_H_
34
35
36#include <Alert.h>
37#include <Application.h>
38#include <Catalog.h>
39#include <CheckBox.h>
40#include <FindDirectory.h>
41#include <Path.h>
42#include <Slider.h>
43#include <StringView.h>
44#include <TabView.h>
45#include <TranslationKit.h>
46#include <TranslatorAddOn.h>
47
48#include <stdio.h>
49#include <stdlib.h>
50#include <string.h>
51
52#include "BaseTranslator.h"
53#include "jasper/jasper.h"
54
55// jasper includes stdbool
56#undef bool
57
58
59#undef B_TRANSLATION_CONTEXT
60#define B_TRANSLATION_CONTEXT "JPEG2000Translator"
61
62// Settings
63#define JP2_SETTINGS_FILE	"JPEG2000Translator"
64
65#define JP2_SET_QUALITY "quality"
66#define JP2_SET_GRAY1_AS_B_RGB24 "24 from gray1"
67#define JP2_SET_GRAY8_AS_B_RGB32 "32 from gray8"
68#define JP2_SET_JPC "jpc"
69
70// View messages
71#define VIEW_MSG_SET_QUALITY 'JSCQ'
72#define	VIEW_MSG_SET_GRAY1ASRGB24 'JSGR'
73#define	VIEW_MSG_SET_JPC 'JSJC'
74#define	VIEW_MSG_SET_GRAYASRGB32 'JSAC'
75
76
77/*!
78	Slider used in TranslatorView
79	With status showing actual value
80*/
81class SSlider : public BSlider {
82public:
83	SSlider(const char* name, const char* label,
84		BMessage* message, int32 minValue, int32 maxValue,
85		orientation posture = B_HORIZONTAL,
86		thumb_style thumbType = B_BLOCK_THUMB,
87		uint32 flags = B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS);
88	const char*	UpdateText() const;
89
90private:
91	mutable char fStatusLabel[12];
92};
93
94//!	Configuration view for reading settings
95class TranslatorReadView : public BView {
96public:
97	TranslatorReadView(const char* name, TranslatorSettings* settings);
98	~TranslatorReadView();
99
100	virtual void	AttachedToWindow();
101	virtual void	MessageReceived(BMessage* message);
102
103private:
104	TranslatorSettings*	fSettings;
105	BCheckBox*		fGrayAsRGB32;
106};
107
108//! Configuration view for writing settings
109class TranslatorWriteView : public BView {
110public:
111	TranslatorWriteView(const char* name, TranslatorSettings* settings);
112	~TranslatorWriteView();
113
114	virtual void	AttachedToWindow();
115	virtual void	MessageReceived(BMessage* message);
116
117private:
118	TranslatorSettings*	fSettings;
119	SSlider*		fQualitySlider;
120	BCheckBox*		fGrayAsRGB24;
121	BCheckBox*		fCodeStreamOnly;
122};
123
124class TranslatorAboutView : public BView {
125public:
126	TranslatorAboutView(const char* name);
127};
128
129//!	Configuration view
130class TranslatorView : public BTabView {
131public:
132	TranslatorView(const char* name, TranslatorSettings* settings);
133};
134
135class JP2Translator : public BaseTranslator {
136public:
137	JP2Translator();
138	virtual status_t DerivedIdentify(BPositionIO* inSource,
139		const translation_format* inFormat, BMessage* ioExtension,
140		translator_info* outInfo, uint32 outType);
141
142	virtual status_t DerivedTranslate(BPositionIO* inSource,
143		const translator_info* inInfo, BMessage* ioExtension,
144		uint32 outType, BPositionIO* outDestination, int32 baseType);
145
146	virtual BView* NewConfigView(TranslatorSettings* settings);
147
148
149private:
150	status_t Copy(BPositionIO* in, BPositionIO* out);
151	status_t Compress(BPositionIO* in, BPositionIO* out);
152	status_t Decompress(BPositionIO* in, BPositionIO* out);
153
154	status_t PopulateInfoFromFormat(translator_info* info,
155		uint32 formatType, translator_id id = 0);
156	status_t PopulateInfoFromFormat(translator_info* info,
157		uint32 formatType, const translation_format* formats,
158		int32 formatCount);
159};
160
161
162status_t Error(jas_stream_t* stream, jas_image_t* image, jas_matrix_t** pixels,
163	int32 pixels_count, uchar* scanline, status_t error = B_ERROR);
164
165#endif // _JP2TRANSLATOR_H_
166