1 /* 2 3 Copyright (c) 2003, Marcin 'Shard' Konicki 4 All rights reserved. 5 6 Redistribution and use in source and binary forms, with or without 7 modification, 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 18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 20 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 22 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 23 OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 25 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 27 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 28 EVEN 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 <CheckBox.h> 39 #include <FindDirectory.h> 40 #include <Path.h> 41 #include <Slider.h> 42 #include <StringView.h> 43 #include <TabView.h> 44 #include <TranslationKit.h> 45 #include <TranslatorAddOn.h> 46 47 #include <stdio.h> 48 #include <stdlib.h> 49 #include <string.h> 50 51 #include "BaseTranslator.h" 52 #include "libjasper/jasper.h" 53 54 55 // Settings 56 #define JP2_SETTINGS_FILE "JPEG2000Translator" 57 58 #define JP2_SET_QUALITY "quality" 59 #define JP2_SET_GRAY1_AS_B_RGB24 "24 from gray1" 60 #define JP2_SET_GRAY8_AS_B_RGB32 "32 from gray8" 61 #define JP2_SET_JPC "jpc" 62 63 // View messages 64 #define VIEW_MSG_SET_QUALITY 'JSCQ' 65 #define VIEW_MSG_SET_GRAY1ASRGB24 'JSGR' 66 #define VIEW_MSG_SET_JPC 'JSJC' 67 #define VIEW_MSG_SET_GRAYASRGB32 'JSAC' 68 69 // View labels 70 #define VIEW_LABEL_QUALITY "Output quality" 71 #define VIEW_LABEL_JPC "Output only codestream (.jpc)" 72 #define VIEW_LABEL_GRAY1ASRGB24 "Write black-and-white images as RGB24" 73 #define VIEW_LABEL_GRAYASRGB32 "Read greyscale images as RGB32" 74 75 76 77 /*! 78 Slider used in TranslatorView 79 With status showing actual value 80 */ 81 class SSlider : public BSlider { 82 public: 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 90 private: 91 mutable char fStatusLabel[12]; 92 }; 93 94 //! Configuration view for reading settings 95 class TranslatorReadView : public BView { 96 public: 97 TranslatorReadView(const char* name, TranslatorSettings* settings); 98 ~TranslatorReadView(); 99 100 virtual void AttachedToWindow(); 101 virtual void MessageReceived(BMessage* message); 102 103 private: 104 TranslatorSettings* fSettings; 105 BCheckBox* fGrayAsRGB32; 106 }; 107 108 //! Configuration view for writing settings 109 class TranslatorWriteView : public BView { 110 public: 111 TranslatorWriteView(const char* name, TranslatorSettings* settings); 112 ~TranslatorWriteView(); 113 114 virtual void AttachedToWindow(); 115 virtual void MessageReceived(BMessage* message); 116 117 private: 118 TranslatorSettings* fSettings; 119 SSlider* fQualitySlider; 120 BCheckBox* fGrayAsRGB24; 121 BCheckBox* fCodeStreamOnly; 122 }; 123 124 class TranslatorAboutView : public BView { 125 public: 126 TranslatorAboutView(const char* name); 127 }; 128 129 //! Configuration view 130 class TranslatorView : public BTabView { 131 public: 132 TranslatorView(const char* name, TranslatorSettings* settings); 133 }; 134 135 class JP2Translator : public BaseTranslator { 136 public: 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 149 private: 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 status_t Error(jas_stream_t* stream, jas_image_t* image, jas_matrix_t** pixels, 162 int32 pixels_count, jpr_uchar_t* scanline, status_t error = B_ERROR); 163 164 #endif // _JP2TRANSLATOR_H_ 165