1 /*****************************************************************************/
3 // Written by Michael Wilber, Haiku Translation Kit Team
7 // The BaseTranslator class implements functionality common to most
8 // Translators so that this functionality need not be implemented over and
9 // over in each Translator.
12 // Copyright (c) 2004 Haiku, Inc.
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 /*****************************************************************************/
33 #ifndef BASE_TRANSLATOR_H
34 #define BASE_TRANSLATOR_H
36 #include <ByteOrder.h>
38 #include <GraphicsDefs.h>
39 #include <InterfaceDefs.h>
40 #include <Translator.h>
41 #include <TranslatorFormats.h>
42 #include <TranslationDefs.h>
44 #include "TranslatorSettings.h"
46 class BaseTranslator
: public BTranslator
{
48 BaseTranslator(const char *name
, const char *info
,
49 const int32 version
, const translation_format
*inFormats
,
50 int32 inCount
, const translation_format
*outFormats
, int32 outCount
,
51 const char *settingsFile
, const TranSetting
*defaults
, int32 defCount
,
52 uint32 tranGroup
, uint32 tranType
);
54 virtual const char *TranslatorName() const;
55 // returns the short name of the translator
57 virtual const char *TranslatorInfo() const;
58 // returns a verbose name/description for the translator
60 virtual int32
TranslatorVersion() const;
61 // returns the version of the translator
63 virtual const translation_format
*InputFormats(int32
*out_count
)
65 // returns the input formats and the count of input formats
66 // that this translator supports
68 virtual const translation_format
*OutputFormats(int32
*out_count
)
70 // returns the output formats and the count of output formats
71 // that this translator supports
73 virtual status_t
Identify(BPositionIO
*inSource
,
74 const translation_format
*inFormat
, BMessage
*ioExtension
,
75 translator_info
*outInfo
, uint32 outType
);
76 // determines whether or not this translator can convert the
77 // data in inSource to the type outType
79 virtual status_t
Translate(BPositionIO
*inSource
,
80 const translator_info
*inInfo
, BMessage
*ioExtension
,
81 uint32 outType
, BPositionIO
*outDestination
);
82 // this function is the whole point of the Translation Kit,
83 // it translates the data in inSource to outDestination
84 // using the format outType
86 virtual status_t
GetConfigurationMessage(BMessage
*ioExtension
);
87 // write the current state of the translator into
88 // the supplied BMessage object
90 virtual status_t
MakeConfigurationView(BMessage
*ioExtension
,
91 BView
**outView
, BRect
*outExtent
);
92 // creates and returns the view for displaying information
93 // about this translator
95 TranslatorSettings
*AcquireSettings();
97 // Functions to be implmemented by derived class
98 virtual status_t
DerivedIdentify(BPositionIO
*inSource
,
99 const translation_format
*inFormat
, BMessage
*ioExtension
,
100 translator_info
*outInfo
, uint32 outType
);
102 virtual status_t
DerivedTranslate(BPositionIO
*inSource
,
103 const translator_info
*inInfo
, BMessage
*ioExtension
,
104 uint32 outType
, BPositionIO
*outDestination
, int32 baseType
);
106 virtual status_t
DerivedCanHandleImageSize(float width
, float height
) const;
108 virtual BView
*NewConfigView(TranslatorSettings
*settings
);
112 status_t
BitsCheck(BPositionIO
*inSource
, BMessage
*ioExtension
,
115 status_t
BitsIdentify(BPositionIO
*inSource
,
116 const translation_format
*inFormat
, BMessage
*ioExtension
,
117 translator_info
*outInfo
, uint32 outType
);
119 status_t
identify_bits_header(BPositionIO
*inSource
,
120 translator_info
*outInfo
, TranslatorBitmap
*pheader
= NULL
);
122 status_t
BitsTranslate(BPositionIO
*inSource
,
123 const translator_info
*inInfo
, BMessage
*ioExtension
, uint32 outType
,
124 BPositionIO
*outDestination
);
126 status_t
translate_from_bits_to_bits(BPositionIO
*inSource
,
127 uint32 outType
, BPositionIO
*outDestination
);
129 virtual ~BaseTranslator();
130 // this is protected because the object is deleted by the
131 // Release() function instead of being deleted directly by
134 TranslatorSettings
*fSettings
;
140 const translation_format
*fInputFormats
;
142 const translation_format
*fOutputFormats
;
148 void translate_direct_copy(BPositionIO
*inSource
, BPositionIO
*outDestination
);
150 #endif // #ifndef BASE_TRANSLATOR_H