1 /*****************************************************************************/ 2 // BaseTranslator 3 // Written by Michael Wilber, Haiku Translation Kit Team 4 // 5 // BaseTranslator.h 6 // 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. 10 // 11 // 12 // Copyright (c) 2004 Haiku, Inc. 13 // 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: 20 // 21 // The above copyright notice and this permission notice shall be included 22 // in all copies or substantial portions of the Software. 23 // 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 /*****************************************************************************/ 32 33 #ifndef BASE_TRANSLATOR_H 34 #define BASE_TRANSLATOR_H 35 36 #include <ByteOrder.h> 37 #include <DataIO.h> 38 #include <GraphicsDefs.h> 39 #include <InterfaceDefs.h> 40 #include <Translator.h> 41 #include <TranslatorFormats.h> 42 #include <TranslationDefs.h> 43 #include <View.h> 44 #include "TranslatorSettings.h" 45 46 class BaseTranslator : public BTranslator { 47 public: 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); 53 54 virtual const char *TranslatorName() const; 55 // returns the short name of the translator 56 57 virtual const char *TranslatorInfo() const; 58 // returns a verbose name/description for the translator 59 60 virtual int32 TranslatorVersion() const; 61 // returns the version of the translator 62 63 virtual const translation_format *InputFormats(int32 *out_count) 64 const; 65 // returns the input formats and the count of input formats 66 // that this translator supports 67 68 virtual const translation_format *OutputFormats(int32 *out_count) 69 const; 70 // returns the output formats and the count of output formats 71 // that this translator supports 72 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 78 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 85 86 virtual status_t GetConfigurationMessage(BMessage *ioExtension); 87 // write the current state of the translator into 88 // the supplied BMessage object 89 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 94 95 TranslatorSettings *AcquireSettings(); 96 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); 101 102 virtual status_t DerivedTranslate(BPositionIO *inSource, 103 const translator_info *inInfo, BMessage *ioExtension, 104 uint32 outType, BPositionIO *outDestination, int32 baseType); 105 106 virtual status_t DerivedCanHandleImageSize(float width, float height) const; 107 108 virtual BView *NewConfigView(TranslatorSettings *settings); 109 110 111 protected: 112 status_t BitsCheck(BPositionIO *inSource, BMessage *ioExtension, 113 uint32 &outType); 114 115 status_t BitsIdentify(BPositionIO *inSource, 116 const translation_format *inFormat, BMessage *ioExtension, 117 translator_info *outInfo, uint32 outType); 118 119 status_t identify_bits_header(BPositionIO *inSource, 120 translator_info *outInfo, TranslatorBitmap *pheader = NULL); 121 122 status_t BitsTranslate(BPositionIO *inSource, 123 const translator_info *inInfo, BMessage *ioExtension, uint32 outType, 124 BPositionIO *outDestination); 125 126 status_t translate_from_bits_to_bits(BPositionIO *inSource, 127 uint32 outType, BPositionIO *outDestination); 128 129 virtual ~BaseTranslator(); 130 // this is protected because the object is deleted by the 131 // Release() function instead of being deleted directly by 132 // the user 133 134 TranslatorSettings *fSettings; 135 136 private: 137 int32 fVersion; 138 char *fName; 139 char *fInfo; 140 const translation_format *fInputFormats; 141 int32 fInputCount; 142 const translation_format *fOutputFormats; 143 int32 fOutputCount; 144 uint32 fTranGroup; 145 uint32 fTranType; 146 }; 147 148 void translate_direct_copy(BPositionIO *inSource, BPositionIO *outDestination); 149 150 #endif // #ifndef BASE_TRANSLATOR_H 151 152