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 "libjasper/jasper.h" 52 53 54 // Settings 55 #define SETTINGS_FILE "JPEG2000Translator" 56 57 // View messages 58 #define VIEW_MSG_SET_QUALITY 'JSCQ' 59 #define VIEW_MSG_SET_GRAY1ASRGB24 'JSGR' 60 #define VIEW_MSG_SET_JPC 'JSJC' 61 #define VIEW_MSG_SET_GRAYASRGB32 'JSAC' 62 63 // View labels 64 #define VIEW_LABEL_QUALITY "Output quality" 65 #define VIEW_LABEL_GRAY1ASRGB24 "Write Black&White images as RGB24" 66 #define VIEW_LABEL_JPC "Output only codestream (.jpc)" 67 #define VIEW_LABEL_GRAYASRGB32 "Read Greyscale images as RGB32" 68 69 70 //! Settings storage structure 71 struct jpeg_settings { 72 // compression 73 jpr_uchar_t Quality; // default: 25 74 bool JPC; // default: false // compress to JPC or JP2? 75 bool B_GRAY1_as_B_RGB24; // default: false // copress gray 1 as rgb24 or grayscale? 76 // decompression 77 bool B_GRAY8_as_B_RGB32; // default: true 78 }; 79 80 81 /*! 82 Slider used in TranslatorView 83 With status showing actual value 84 */ 85 class SSlider : public BSlider { 86 public: 87 SSlider(BRect frame, const char *name, const char *label, 88 BMessage *message, int32 minValue, int32 maxValue, 89 orientation posture = B_HORIZONTAL, 90 thumb_style thumbType = B_BLOCK_THUMB, 91 uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, 92 uint32 flags = B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS); 93 const char* UpdateText() const; 94 void ResizeToPreferred(); 95 96 private: 97 mutable char fStatusLabel[12]; 98 }; 99 100 //! Basic view class with resizing to needed size 101 class SView : public BView { 102 public: 103 SView(BRect rect, const char* name); 104 virtual void AttachedToWindow(); 105 }; 106 107 //! Configuration view for reading settings 108 class TranslatorReadView : public SView { 109 public: 110 TranslatorReadView(BRect rect, const char* name, jpeg_settings* settings); 111 112 virtual void AttachedToWindow(); 113 virtual void MessageReceived(BMessage* message); 114 115 private: 116 jpeg_settings* fSettings; 117 BCheckBox* fGrayAsRGB32; 118 }; 119 120 //! Configuration view for writing settings 121 class TranslatorWriteView : public SView { 122 public: 123 TranslatorWriteView(BRect rect, const char* name, jpeg_settings* settings); 124 125 virtual void AttachedToWindow(); 126 virtual void MessageReceived(BMessage* message); 127 128 private: 129 jpeg_settings* fSettings; 130 SSlider* fQualitySlider; 131 BCheckBox* fGrayAsRGB24; 132 BCheckBox* fCodeStreamOnly; 133 }; 134 135 class TranslatorAboutView : public SView { 136 public: 137 TranslatorAboutView(BRect rect, const char* name); 138 }; 139 140 //! Configuration view 141 class TranslatorView : public BTabView { 142 public: 143 TranslatorView(BRect rect, const char *name); 144 virtual ~TranslatorView(); 145 146 private: 147 jpeg_settings fSettings; 148 }; 149 150 //! Window used for configuration 151 class TranslatorWindow : public BWindow { 152 public: 153 TranslatorWindow(bool quitOnClose = true); 154 }; 155 156 157 // Main functions of translator :) 158 status_t Copy(BPositionIO *in, BPositionIO *out); 159 status_t Compress(BPositionIO *in, BPositionIO *out); 160 status_t Decompress(BPositionIO *in, BPositionIO *out); 161 status_t Error(jas_stream_t *stream, jas_image_t *image, jas_matrix_t **pixels, int32 pixels_count, jpr_uchar_t *scanline, status_t error = B_ERROR); 162 163 #endif // _JP2TRANSLATOR_H_ 164