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> 3770d59669SSiarzhuk Zharski #include <Catalog.h> 389949213aSStephan Aßmus #include <CheckBox.h> 399949213aSStephan Aßmus #include <FindDirectory.h> 409949213aSStephan Aßmus #include <Path.h> 419949213aSStephan Aßmus #include <Slider.h> 429949213aSStephan Aßmus #include <StringView.h> 43b20d13f4SStefano Ceccherini #include <TabView.h> 449949213aSStephan Aßmus #include <TranslationKit.h> 459949213aSStephan Aßmus #include <TranslatorAddOn.h> 469949213aSStephan Aßmus 47dbc936acSStephan Aßmus #include <setjmp.h> 489949213aSStephan Aßmus #include <stdio.h> 499949213aSStephan Aßmus #include <stdlib.h> 509949213aSStephan Aßmus #include <string.h> 519949213aSStephan Aßmus 529949213aSStephan Aßmus #include <jpeglib.h> 539949213aSStephan Aßmus 54b98ef4f9SStephan Aßmus #include "BaseTranslator.h" 559949213aSStephan Aßmus 56*546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT 57*546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "JPEGTranslator" 5870d59669SSiarzhuk Zharski 599949213aSStephan Aßmus // Settings 60117da2d7SAxel Dörfler #define SETTINGS_FILE "JPEGTranslator" 619949213aSStephan Aßmus 629949213aSStephan Aßmus // View messages 639949213aSStephan Aßmus #define VIEW_MSG_SET_QUALITY 'JSCQ' 649949213aSStephan Aßmus #define VIEW_MSG_SET_SMOOTHING 'JSCS' 659949213aSStephan Aßmus #define VIEW_MSG_SET_PROGRESSIVE 'JSCP' 669949213aSStephan Aßmus #define VIEW_MSG_SET_OPTIMIZECOLORS 'JSBQ' 679949213aSStephan Aßmus #define VIEW_MSG_SET_SMALLERFILE 'JSSF' 689949213aSStephan Aßmus #define VIEW_MSG_SET_GRAY1ASRGB24 'JSGR' 699949213aSStephan Aßmus #define VIEW_MSG_SET_ALWAYSRGB32 'JSAC' 709949213aSStephan Aßmus #define VIEW_MSG_SET_PHOTOSHOPCMYK 'JSPC' 719949213aSStephan Aßmus #define VIEW_MSG_SET_SHOWREADERRORBOX 'JSEB' 729949213aSStephan Aßmus 73b98ef4f9SStephan Aßmus // strings for use in TranslatorSettings 74b98ef4f9SStephan Aßmus #define JPEG_SET_SMOOTHING "smoothing" 75b98ef4f9SStephan Aßmus #define JPEG_SET_QUALITY "quality" 76b98ef4f9SStephan Aßmus #define JPEG_SET_PROGRESSIVE "progressive" 77b98ef4f9SStephan Aßmus #define JPEG_SET_OPT_COLORS "optimize" 78b98ef4f9SStephan Aßmus #define JPEG_SET_SMALL_FILES "filesSmaller" 79b98ef4f9SStephan Aßmus #define JPEG_SET_GRAY1_AS_RGB24 "gray" 80b98ef4f9SStephan Aßmus #define JPEG_SET_ALWAYS_RGB32 "always" 81b98ef4f9SStephan Aßmus #define JPEG_SET_PHOTOSHOP_CMYK "cmyk" 82b98ef4f9SStephan Aßmus #define JPEG_SET_SHOWREADWARNING "readWarning" 839949213aSStephan Aßmus 849949213aSStephan Aßmus 858687ff64SAxel Dörfler /*! 868687ff64SAxel Dörfler Slider used in TranslatorView 878687ff64SAxel Dörfler With status showing actual value 888687ff64SAxel Dörfler */ 89d8e2fb50SAxel Dörfler class SSlider : public BSlider { 909949213aSStephan Aßmus public: 91b98ef4f9SStephan Aßmus SSlider(const char* name, const char* label, 928687ff64SAxel Dörfler BMessage* message, int32 minValue, int32 maxValue, 938687ff64SAxel Dörfler orientation posture = B_HORIZONTAL, 948687ff64SAxel Dörfler thumb_style thumbType = B_BLOCK_THUMB, 958687ff64SAxel Dörfler uint32 flags = B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS); 96b20d13f4SStefano Ceccherini virtual const char* UpdateText() const; 979949213aSStephan Aßmus 989949213aSStephan Aßmus private: 998687ff64SAxel Dörfler mutable char fStatusLabel[12]; 1009949213aSStephan Aßmus }; 1019949213aSStephan Aßmus 102b20d13f4SStefano Ceccherini 103b98ef4f9SStephan Aßmus class JPEGTranslator : public BaseTranslator { 1049949213aSStephan Aßmus public: 105b98ef4f9SStephan Aßmus JPEGTranslator(); 106b98ef4f9SStephan Aßmus 107b98ef4f9SStephan Aßmus virtual status_t DerivedIdentify(BPositionIO* inSource, 108b98ef4f9SStephan Aßmus const translation_format* inFormat, BMessage* ioExtension, 109b98ef4f9SStephan Aßmus translator_info* outInfo, uint32 outType); 110b98ef4f9SStephan Aßmus 111b98ef4f9SStephan Aßmus virtual status_t DerivedTranslate(BPositionIO* inSource, 112b98ef4f9SStephan Aßmus const translator_info* inInfo, BMessage* ioExtension, 113b98ef4f9SStephan Aßmus uint32 outType, BPositionIO* outDestination, int32 baseType); 114b98ef4f9SStephan Aßmus 115b98ef4f9SStephan Aßmus virtual BView* NewConfigView(TranslatorSettings* settings); 116b98ef4f9SStephan Aßmus 117b98ef4f9SStephan Aßmus private: 118b98ef4f9SStephan Aßmus 119b98ef4f9SStephan Aßmus status_t Copy(BPositionIO* in, BPositionIO* out); 120b98ef4f9SStephan Aßmus status_t Compress(BPositionIO* in, BPositionIO* out, 121b98ef4f9SStephan Aßmus const jmp_buf* longJumpBuffer); 122b98ef4f9SStephan Aßmus status_t Decompress(BPositionIO* in, BPositionIO* out, 123b98ef4f9SStephan Aßmus BMessage* ioExtension, const jmp_buf* longJumpBuffer); 124b98ef4f9SStephan Aßmus status_t Error(j_common_ptr cinfo, status_t error = B_ERROR); 125b98ef4f9SStephan Aßmus 126b98ef4f9SStephan Aßmus status_t PopulateInfoFromFormat(translator_info* info, 127b98ef4f9SStephan Aßmus uint32 formatType, translator_id id = 0); 128b98ef4f9SStephan Aßmus status_t PopulateInfoFromFormat(translator_info* info, 129b98ef4f9SStephan Aßmus uint32 formatType, const translation_format* formats, 130b98ef4f9SStephan Aßmus int32 formatCount); 1319949213aSStephan Aßmus }; 1329949213aSStephan Aßmus 133b98ef4f9SStephan Aßmus 134b98ef4f9SStephan Aßmus class TranslatorReadView : public BView { 1359949213aSStephan Aßmus public: 136b98ef4f9SStephan Aßmus TranslatorReadView(const char* name, TranslatorSettings* settings); 137b98ef4f9SStephan Aßmus virtual ~TranslatorReadView(); 1388687ff64SAxel Dörfler 1398687ff64SAxel Dörfler virtual void AttachedToWindow(); 1408687ff64SAxel Dörfler virtual void MessageReceived(BMessage* message); 1419949213aSStephan Aßmus 1429949213aSStephan Aßmus private: 143b98ef4f9SStephan Aßmus TranslatorSettings* fSettings; 1448687ff64SAxel Dörfler BCheckBox* fAlwaysRGB32; 1458687ff64SAxel Dörfler BCheckBox* fPhotoshopCMYK; 1468687ff64SAxel Dörfler BCheckBox* fShowErrorBox; 1479949213aSStephan Aßmus }; 1489949213aSStephan Aßmus 149b20d13f4SStefano Ceccherini 150b98ef4f9SStephan Aßmus class TranslatorWriteView : public BView { 1519949213aSStephan Aßmus public: 152b98ef4f9SStephan Aßmus TranslatorWriteView(const char* name, TranslatorSettings* settings); 153b98ef4f9SStephan Aßmus virtual ~TranslatorWriteView(); 1548687ff64SAxel Dörfler 1558687ff64SAxel Dörfler virtual void AttachedToWindow(); 1568687ff64SAxel Dörfler virtual void MessageReceived(BMessage* message); 1579949213aSStephan Aßmus 1589949213aSStephan Aßmus private: 159b98ef4f9SStephan Aßmus TranslatorSettings* fSettings; 1608687ff64SAxel Dörfler SSlider* fQualitySlider; 1618687ff64SAxel Dörfler SSlider* fSmoothingSlider; 1628687ff64SAxel Dörfler BCheckBox* fProgress; 1638687ff64SAxel Dörfler BCheckBox* fOptimizeColors; 1648687ff64SAxel Dörfler BCheckBox* fSmallerFile; 1658687ff64SAxel Dörfler BCheckBox* fGrayAsRGB24; 1669949213aSStephan Aßmus }; 1679949213aSStephan Aßmus 168b98ef4f9SStephan Aßmus 169b98ef4f9SStephan Aßmus class TranslatorAboutView : public BView { 1709949213aSStephan Aßmus public: 171b98ef4f9SStephan Aßmus TranslatorAboutView(const char* name); 1729949213aSStephan Aßmus }; 1739949213aSStephan Aßmus 174b98ef4f9SStephan Aßmus 175b20d13f4SStefano Ceccherini class TranslatorView : public BTabView { 1769949213aSStephan Aßmus public: 177b98ef4f9SStephan Aßmus TranslatorView(const char* name, TranslatorSettings* settings); 178d8e2fb50SAxel Dörfler 1799949213aSStephan Aßmus private: 180b98ef4f9SStephan Aßmus BView* fAboutView; 181b98ef4f9SStephan Aßmus BView* fReadView; 182b98ef4f9SStephan Aßmus BView* fWriteView; 1839949213aSStephan Aßmus }; 1849949213aSStephan Aßmus 1859949213aSStephan Aßmus 1869949213aSStephan Aßmus //--------------------------------------------------- 1879949213aSStephan Aßmus // "Initializers" for jpeglib 1889949213aSStephan Aßmus // based on default ones, 1899949213aSStephan Aßmus // modified to work on BPositionIO instead of FILE 1909949213aSStephan Aßmus //--------------------------------------------------- 1919949213aSStephan Aßmus EXTERN(void) be_jpeg_stdio_src(j_decompress_ptr cinfo, BPositionIO *infile); // from "be_jdatasrc.cpp" 1929949213aSStephan Aßmus EXTERN(void) be_jpeg_stdio_dest(j_compress_ptr cinfo, BPositionIO *outfile); // from "be_jdatadst.cpp" 1939949213aSStephan Aßmus 1949949213aSStephan Aßmus #endif // _JPEGTRANSLATOR_H_ 1952e49ff35SSiarzhuk Zharski 196