19949213aSStephan Aßmus /* 29949213aSStephan Aßmus 39949213aSStephan Aßmus Copyright (c) 2002-2003, Marcin 'Shard' Konicki 49949213aSStephan Aßmus All rights reserved. 59949213aSStephan Aßmus 69949213aSStephan Aßmus Redistribution and use in source and binary forms, with or without 79949213aSStephan Aßmus modification, are permitted provided that the following conditions are met: 89949213aSStephan Aßmus 99949213aSStephan Aßmus * Redistributions of source code must retain the above copyright notice, 109949213aSStephan Aßmus this list of conditions and the following disclaimer. 119949213aSStephan Aßmus * Redistributions in binary form must reproduce the above copyright notice, 129949213aSStephan Aßmus this list of conditions and the following disclaimer in the documentation and/or 139949213aSStephan Aßmus other materials provided with the distribution. 149949213aSStephan Aßmus * Name "Marcin Konicki", "Shard" or any combination of them, 159949213aSStephan Aßmus must not be used to endorse or promote products derived from this 169949213aSStephan Aßmus software without specific prior written permission from Marcin Konicki. 179949213aSStephan Aßmus 189949213aSStephan Aßmus THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 199949213aSStephan Aßmus ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 209949213aSStephan Aßmus THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 219949213aSStephan Aßmus ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 229949213aSStephan Aßmus BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 239949213aSStephan Aßmus OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 249949213aSStephan Aßmus PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 259949213aSStephan Aßmus OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 269949213aSStephan Aßmus WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 279949213aSStephan Aßmus OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 289949213aSStephan Aßmus EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 299949213aSStephan Aßmus 309949213aSStephan Aßmus */ 319949213aSStephan Aßmus #ifndef _JPEGTRANSLATOR_H_ 329949213aSStephan Aßmus #define _JPEGTRANSLATOR_H_ 339949213aSStephan Aßmus 349949213aSStephan Aßmus 359949213aSStephan Aßmus #include <Alert.h> 369949213aSStephan Aßmus #include <Application.h> 379949213aSStephan Aßmus #include <CheckBox.h> 389949213aSStephan Aßmus #include <FindDirectory.h> 399949213aSStephan Aßmus #include <Path.h> 409949213aSStephan Aßmus #include <Slider.h> 419949213aSStephan Aßmus #include <StringView.h> 429949213aSStephan Aßmus #include <TranslationKit.h> 439949213aSStephan Aßmus #include <TranslatorAddOn.h> 449949213aSStephan Aßmus 45dbc936acSStephan Aßmus #include <setjmp.h> 469949213aSStephan Aßmus #include <stdio.h> 479949213aSStephan Aßmus #include <stdlib.h> 489949213aSStephan Aßmus #include <string.h> 499949213aSStephan Aßmus 509949213aSStephan Aßmus #include <jpeglib.h> 519949213aSStephan Aßmus 529949213aSStephan Aßmus 539949213aSStephan Aßmus // Settings 54117da2d7SAxel Dörfler #define SETTINGS_FILE "JPEGTranslator" 559949213aSStephan Aßmus 569949213aSStephan Aßmus // View messages 579949213aSStephan Aßmus #define VIEW_MSG_SET_QUALITY 'JSCQ' 589949213aSStephan Aßmus #define VIEW_MSG_SET_SMOOTHING 'JSCS' 599949213aSStephan Aßmus #define VIEW_MSG_SET_PROGRESSIVE 'JSCP' 609949213aSStephan Aßmus #define VIEW_MSG_SET_OPTIMIZECOLORS 'JSBQ' 619949213aSStephan Aßmus #define VIEW_MSG_SET_SMALLERFILE 'JSSF' 629949213aSStephan Aßmus #define VIEW_MSG_SET_GRAY1ASRGB24 'JSGR' 639949213aSStephan Aßmus #define VIEW_MSG_SET_ALWAYSRGB32 'JSAC' 649949213aSStephan Aßmus #define VIEW_MSG_SET_PHOTOSHOPCMYK 'JSPC' 659949213aSStephan Aßmus #define VIEW_MSG_SET_SHOWREADERRORBOX 'JSEB' 669949213aSStephan Aßmus 679949213aSStephan Aßmus // View labels 689949213aSStephan Aßmus #define VIEW_LABEL_QUALITY "Output quality" 699949213aSStephan Aßmus #define VIEW_LABEL_SMOOTHING "Output smoothing strength" 709949213aSStephan Aßmus #define VIEW_LABEL_PROGRESSIVE "Use progressive compression" 719949213aSStephan Aßmus #define VIEW_LABEL_OPTIMIZECOLORS "Prevent colors 'washing out'" 729949213aSStephan Aßmus #define VIEW_LABEL_SMALLERFILE "Make file smaller (sligthtly worse quality)" 739949213aSStephan Aßmus #define VIEW_LABEL_GRAY1ASRGB24 "Write Black&White images as RGB24" 749949213aSStephan Aßmus #define VIEW_LABEL_ALWAYSRGB32 "Read Greyscale images as RGB32" 759949213aSStephan Aßmus #define VIEW_LABEL_PHOTOSHOPCMYK "Use CMYK code with 0 for 100% ink coverage" 769949213aSStephan Aßmus #define VIEW_LABEL_SHOWREADERRORBOX "Show warning messages" 779949213aSStephan Aßmus 789949213aSStephan Aßmus 798687ff64SAxel Dörfler //! Settings storage structure 80d8e2fb50SAxel Dörfler struct jpeg_settings { 819949213aSStephan Aßmus // compression 829949213aSStephan Aßmus uchar Smoothing; // default: 0 839949213aSStephan Aßmus uchar Quality; // default: 95 849949213aSStephan Aßmus bool Progressive; // default: true 859949213aSStephan Aßmus bool OptimizeColors; // default: true 869949213aSStephan Aßmus bool SmallerFile; // default: false only used if (OptimizeColors == true) 879949213aSStephan Aßmus bool B_GRAY1_as_B_RGB24; // default: false if false gray1 converted to gray8, else to rgb24 889949213aSStephan Aßmus // decompression 899949213aSStephan Aßmus bool Always_B_RGB32; // default: true 909949213aSStephan Aßmus bool PhotoshopCMYK; // default: true 919949213aSStephan Aßmus bool ShowReadWarningBox; // default: true 929949213aSStephan Aßmus }; 939949213aSStephan Aßmus 948687ff64SAxel Dörfler 958687ff64SAxel Dörfler /*! 968687ff64SAxel Dörfler Slider used in TranslatorView 978687ff64SAxel Dörfler With status showing actual value 988687ff64SAxel Dörfler */ 99d8e2fb50SAxel Dörfler class SSlider : public BSlider { 1009949213aSStephan Aßmus public: 1018687ff64SAxel Dörfler SSlider(BRect frame, const char *name, const char *label, 1028687ff64SAxel Dörfler BMessage *message, int32 minValue, int32 maxValue, 1038687ff64SAxel Dörfler orientation posture = B_HORIZONTAL, 1048687ff64SAxel Dörfler thumb_style thumbType = B_BLOCK_THUMB, 1058687ff64SAxel Dörfler uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, 1068687ff64SAxel Dörfler uint32 flags = B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS); 1079949213aSStephan Aßmus char* UpdateText() const; 1089949213aSStephan Aßmus void ResizeToPreferred(); 1099949213aSStephan Aßmus 1109949213aSStephan Aßmus private: 1118687ff64SAxel Dörfler mutable char fStatusLabel[12]; 1129949213aSStephan Aßmus }; 1139949213aSStephan Aßmus 1148687ff64SAxel Dörfler //! Basic view class with resizing to needed size 115d8e2fb50SAxel Dörfler class SView : public BView { 1169949213aSStephan Aßmus public: 1178687ff64SAxel Dörfler SView(const char* name, float x = 0, float y = 0); 1188687ff64SAxel Dörfler 1198687ff64SAxel Dörfler virtual void GetPreferredSize(float* _width, float* _height); 1208687ff64SAxel Dörfler virtual void ResizeToPreferred(); 1218687ff64SAxel Dörfler 1228687ff64SAxel Dörfler void AddChild(BView* child, BView* before = NULL); 1238687ff64SAxel Dörfler 1248687ff64SAxel Dörfler float GetPreferredWidth() 1258687ff64SAxel Dörfler { return fPreferredWidth; } 1268687ff64SAxel Dörfler float GetPreferredHeight() 1278687ff64SAxel Dörfler { return fPreferredHeight; } 1288687ff64SAxel Dörfler void ResizePreferredBy(float width, float height); 1299949213aSStephan Aßmus 1309949213aSStephan Aßmus private: 1318687ff64SAxel Dörfler float fPreferredWidth; 1328687ff64SAxel Dörfler float fPreferredHeight; 1339949213aSStephan Aßmus }; 1349949213aSStephan Aßmus 1358687ff64SAxel Dörfler //! Configuration view for reading settings 136d8e2fb50SAxel Dörfler class TranslatorReadView : public SView { 1379949213aSStephan Aßmus public: 1388687ff64SAxel Dörfler TranslatorReadView(const char* name, jpeg_settings* settings, 1398687ff64SAxel Dörfler float x = 0, float y = 0); 1408687ff64SAxel Dörfler 1418687ff64SAxel Dörfler virtual void AttachedToWindow(); 1428687ff64SAxel Dörfler virtual void MessageReceived(BMessage* message); 1439949213aSStephan Aßmus 1449949213aSStephan Aßmus private: 145d8e2fb50SAxel Dörfler jpeg_settings* fSettings; 1468687ff64SAxel Dörfler BCheckBox* fAlwaysRGB32; 1478687ff64SAxel Dörfler BCheckBox* fPhotoshopCMYK; 1488687ff64SAxel Dörfler BCheckBox* fShowErrorBox; 1499949213aSStephan Aßmus }; 1509949213aSStephan Aßmus 1518687ff64SAxel Dörfler //! Configuration view for writing settings 152d8e2fb50SAxel Dörfler class TranslatorWriteView : public SView { 1539949213aSStephan Aßmus public: 1548687ff64SAxel Dörfler TranslatorWriteView(const char* name, jpeg_settings* settings, 1558687ff64SAxel Dörfler float x = 0, float y = 0); 1568687ff64SAxel Dörfler 1578687ff64SAxel Dörfler virtual void AttachedToWindow(); 1588687ff64SAxel Dörfler virtual void MessageReceived(BMessage* message); 1599949213aSStephan Aßmus 1609949213aSStephan Aßmus private: 161d8e2fb50SAxel Dörfler jpeg_settings* fSettings; 1628687ff64SAxel Dörfler SSlider* fQualitySlider; 1638687ff64SAxel Dörfler SSlider* fSmoothingSlider; 1648687ff64SAxel Dörfler BCheckBox* fProgress; 1658687ff64SAxel Dörfler BCheckBox* fOptimizeColors; 1668687ff64SAxel Dörfler BCheckBox* fSmallerFile; 1678687ff64SAxel Dörfler BCheckBox* fGrayAsRGB24; 1689949213aSStephan Aßmus }; 1699949213aSStephan Aßmus 170d8e2fb50SAxel Dörfler class TranslatorAboutView : public SView { 1719949213aSStephan Aßmus public: 1729949213aSStephan Aßmus TranslatorAboutView(const char* name, float x = 0, float y = 0); 1739949213aSStephan Aßmus }; 1749949213aSStephan Aßmus 1758687ff64SAxel Dörfler //! Configuration view 176d8e2fb50SAxel Dörfler class TranslatorView : public SView { 1779949213aSStephan Aßmus public: 1789949213aSStephan Aßmus TranslatorView(const char *name); 1798687ff64SAxel Dörfler virtual ~TranslatorView(); 180d8e2fb50SAxel Dörfler 1818687ff64SAxel Dörfler virtual void AttachedToWindow(); 1828687ff64SAxel Dörfler virtual void Draw(BRect updateRect); 1838687ff64SAxel Dörfler virtual void MouseDown(BPoint where); 1849949213aSStephan Aßmus 1859949213aSStephan Aßmus private: 1868687ff64SAxel Dörfler BRect _TabFrame(int32 index) const; 1878687ff64SAxel Dörfler 188d8e2fb50SAxel Dörfler jpeg_settings fSettings; 1898687ff64SAxel Dörfler BList fTabs; 190d8e2fb50SAxel Dörfler int32 fTabWidth; 191d8e2fb50SAxel Dörfler int32 fTabHeight; 192d8e2fb50SAxel Dörfler int32 fActiveChild; 1939949213aSStephan Aßmus }; 1949949213aSStephan Aßmus 195117da2d7SAxel Dörfler //! Window used for configuration 196d8e2fb50SAxel Dörfler class TranslatorWindow : public BWindow { 1979949213aSStephan Aßmus public: 198d8e2fb50SAxel Dörfler TranslatorWindow(bool quitOnClose = true); 1999949213aSStephan Aßmus }; 2009949213aSStephan Aßmus 2019949213aSStephan Aßmus 2029949213aSStephan Aßmus //--------------------------------------------------- 2039949213aSStephan Aßmus // "Initializers" for jpeglib 2049949213aSStephan Aßmus // based on default ones, 2059949213aSStephan Aßmus // modified to work on BPositionIO instead of FILE 2069949213aSStephan Aßmus //--------------------------------------------------- 2079949213aSStephan Aßmus EXTERN(void) be_jpeg_stdio_src(j_decompress_ptr cinfo, BPositionIO *infile); // from "be_jdatasrc.cpp" 2089949213aSStephan Aßmus EXTERN(void) be_jpeg_stdio_dest(j_compress_ptr cinfo, BPositionIO *outfile); // from "be_jdatadst.cpp" 2099949213aSStephan Aßmus 2109949213aSStephan Aßmus //--------------------------------------------------- 2119949213aSStephan Aßmus // Error output functions 2129949213aSStephan Aßmus // based on the one from jerror.c 2139949213aSStephan Aßmus // modified to use settings 2149949213aSStephan Aßmus // (so user can decide to show dialog-boxes or not) 2159949213aSStephan Aßmus //--------------------------------------------------- 216*b91634cbSStephan Aßmus EXTERN(struct jpeg_error_mgr *) be_jpeg_std_error (struct jpeg_error_mgr * err, 217*b91634cbSStephan Aßmus jpeg_settings * settings, const jmp_buf* longJumpBuffer); 218*b91634cbSStephan Aßmus // implemented in "be_jerror.cpp" 219117da2d7SAxel Dörfler 2209949213aSStephan Aßmus #endif // _JPEGTRANSLATOR_H_ 221