Ticket #2117: jpegTranslator.patch

File jpegTranslator.patch, 40.0 KB (added by yourpalal, 9 years ago)

updated patch: added PopulateInfoFromFormat() method

  • src/add-ons/translators/jpeg/JPEGTranslator.cpp

     
    3131
    3232
    3333#include "JPEGTranslator.h"
    34 
     34#include "TranslatorWindow.h"
    3535#include "exif_parser.h"
    3636
     37#include <Alignment.h>
     38#include <GridLayoutBuilder.h>
     39#include <GroupLayoutBuilder.h>
    3740#include <TabView.h>
     41#include <TextView.h>
    3842
    3943
    4044#define MARKER_EXIF 0xe1
     
    5054#define B_TRANSLATOR_BITMAP_DESCRIPTION "Be Bitmap Format (JPEGTranslator)"
    5155
    5256// Translation Kit required globals
    53 char translatorName[] = "JPEG images";
    54 char translatorInfo[] =
     57char gTranslatorName[] = "JPEG images";
     58char gTranslatorInfo[] =
    5559    "©2002-2003, Marcin Konicki\n"
    5660    "©2005-2007, Haiku\n"
    5761    "\n"
    5862    "Based on IJG library ©  1994-2009, Thomas G. Lane, Guido Vollbeding.\n"
    5963    "          http://www.ijg.org/files/\n"
     64    "\n"
    6065    "with \"lossless\" encoding support patch by Ken Murchison\n"
    6166    "          http://www.oceana.com/ftp/ljpeg/\n"
    6267    "\n"
    6368    "With some colorspace conversion routines by Magnus Hellman\n"
    6469    "          http://www.bebits.com/app/802\n";
    6570
    66 int32 translatorVersion = 0x120;
     71int32 gTranslatorVersion = B_TRANSLATION_MAKE_VERSION(1, 2, 0);
    6772
    6873// Define the formats we know how to read
    69 translation_format inputFormats[] = {
     74const translation_format gInputFormats[] = {
    7075    { JPEG_FORMAT, B_TRANSLATOR_BITMAP, 0.5, 0.5,
    7176        JPEG_MIME_STRING, JPEG_DESCRIPTION },
    7277    { B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP, 0.5, 0.5,
    7378        B_TRANSLATOR_BITMAP_MIME_STRING, B_TRANSLATOR_BITMAP_DESCRIPTION },
    7479    {}
    7580};
     81const int gInputFormatCount = sizeof(gInputFormats) / sizeof(translation_format);
    7682
    7783// Define the formats we know how to write
    78 translation_format outputFormats[] = {
     84const translation_format gOutputFormats[] = {
    7985    { JPEG_FORMAT, B_TRANSLATOR_BITMAP, 0.5, 0.5,
    8086        JPEG_MIME_STRING, JPEG_DESCRIPTION },
    8187    { B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP, 0.5, 0.5,
    8288        B_TRANSLATOR_BITMAP_MIME_STRING, B_TRANSLATOR_BITMAP_DESCRIPTION },
    8389    {}
    8490};
     91const int gOutputFormatCount = sizeof(gOutputFormats) / sizeof(translation_format);
    8592
    86 // Main functions of translator :)
    87 static status_t Copy(BPositionIO *in, BPositionIO *out);
    88 static status_t Compress(BPositionIO *in, BPositionIO *out,
    89     const jmp_buf* longJumpBuffer);
    90 static status_t Decompress(BPositionIO *in, BPositionIO *out,
    91     BMessage* ioExtension, const jmp_buf* longJumpBuffer);
    92 static status_t Error(j_common_ptr cinfo, status_t error = B_ERROR);
    9393
     94TranSetting gSettings[] = {
     95    {JPEG_SET_SMOOTHING, TRAN_SETTING_INT32, 0},
     96    {JPEG_SET_QUALITY, TRAN_SETTING_INT32, 95},
     97    {JPEG_SET_PROGRESSIVE, TRAN_SETTING_BOOL, true},
     98    {JPEG_SET_OPT_COLORS, TRAN_SETTING_BOOL, true},
     99    {JPEG_SET_SMALL_FILES, TRAN_SETTING_BOOL, false},
     100    {JPEG_SET_GRAY1_AS_RGB24, TRAN_SETTING_BOOL, false},
     101    {JPEG_SET_ALWAYS_RGB32, TRAN_SETTING_BOOL, true},
     102    {JPEG_SET_PHOTOSHOP_CMYK, TRAN_SETTING_BOOL, true},
     103    {JPEG_SET_SHOWREADWARNING, TRAN_SETTING_BOOL, true}
     104};
     105const int gSettingsCount = sizeof(gSettings) / sizeof(TranSetting);
    94106
    95107
    96 //! Make settings to defaults
    97 void
    98 LoadDefaultSettings(jpeg_settings *settings)
    99 {
    100     settings->Smoothing = 0;
    101     settings->Quality = 95;
    102     settings->Progressive = true;
    103     settings->OptimizeColors = true;
    104     settings->SmallerFile = false;
    105     settings->B_GRAY1_as_B_RGB24 = false;
    106     settings->Always_B_RGB32 = true;
    107     settings->PhotoshopCMYK = true;
    108     settings->ShowReadWarningBox = true;
    109 }
    110 
    111 
    112 //! Save settings to config file
    113 void
    114 SaveSettings(jpeg_settings *settings)
    115 {
    116     // Make path to settings file
    117     BPath path;
    118     if (find_directory(B_USER_SETTINGS_DIRECTORY, &path, true) != B_OK)
    119         return;
    120 
    121     path.Append(SETTINGS_FILE);
    122 
    123     // Open settings file (create it if there's no file) and write settings         
    124     FILE *file = NULL;
    125     if ((file = fopen(path.Path(), "wb+"))) {
    126         fwrite(settings, sizeof(jpeg_settings), 1, file);
    127         fclose(file);
    128     }
    129 }
    130 
    131 
    132 /*!
    133     Load settings from config file
    134     If can't find it make them default and try to save
    135 */
    136 void
    137 LoadSettings(jpeg_settings *settings)
    138 {
    139     // Make path to settings file
    140     BPath path;
    141     if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) {
    142         LoadDefaultSettings(settings);
    143         return;
    144     }
    145 
    146     path.Append(SETTINGS_FILE);
    147 
    148     // Open settings file (create it if there's no file) and write settings         
    149     FILE *file = NULL;
    150     if ((file = fopen(path.Path(), "rb")) != NULL) {
    151         if (!fread(settings, sizeof(jpeg_settings), 1, file)) {
    152             // settings struct has changed size
    153             // Load default settings, and Save them
    154             fclose(file);
    155             LoadDefaultSettings(settings);
    156             SaveSettings(settings);
    157         } else
    158             fclose(file);
    159     } else if ((file = fopen(path.Path(), "wb+")) != NULL) {
    160         LoadDefaultSettings(settings);
    161         fwrite(settings, sizeof(jpeg_settings), 1, file);
    162         fclose(file);
    163     }
    164 }
    165 
    166 
     108namespace conversion{
    167109static bool
    168110x_flipped(int32 orientation)
    169111{
     
    263205    int32 index2 = 0;
    264206    int16 in_pixel;
    265207    while (index < inRowBytes) {
    266         in_pixel = in[index] | (in[index+1] << 8);
     208        in_pixel = in[index] | (in[index + 1] << 8);
    267209        index += 2;
    268210       
    269211        out[index2++] = (((in_pixel & 0x7c00)) >> 7) | (((in_pixel & 0x7c00)) >> 12);
     
    280222    int32 index2 = 0;
    281223    int16 in_pixel;
    282224    while (index < inRowBytes) {
    283         in_pixel = in[index+1] | (in[index] << 8);
     225        in_pixel = in[index + 1] | (in[index] << 8);
    284226        index += 2;
    285227       
    286228        out[index2++] = (((in_pixel & 0x7c00)) >> 7) | (((in_pixel & 0x7c00)) >> 12);
     
    297239    int32 index2 = 0;
    298240    int16 in_pixel;
    299241    while (index < inRowBytes) {
    300         in_pixel = in[index] | (in[index+1] << 8);
     242        in_pixel = in[index] | (in[index + 1] << 8);
    301243        index += 2;
    302244       
    303245        out[index2++] = (((in_pixel & 0xf800)) >> 8) | (((in_pixel & 0xf800)) >> 13);
     
    314256    int32 index2 = 0;
    315257    int16 in_pixel;
    316258    while (index < inRowBytes) {
    317         in_pixel = in[index+1] | (in[index] << 8);
     259        in_pixel = in[index + 1] | (in[index] << 8);
    318260        index += 2;
    319261       
    320262        out[index2++] = (((in_pixel & 0xf800)) >> 8) | (((in_pixel & 0xf800)) >> 13);
     
    330272    int32 index = 0;
    331273    int32 index2 = 0;
    332274    while (index < inRowBytes) {
    333         out[index2++] = in[index+2];
    334         out[index2++] = in[index+1];
     275        out[index2++] = in[index + 2];
     276        out[index2++] = in[index + 1];
    335277        out[index2++] = in[index];
    336278        index+=3;
    337279    }
     
    433375        out += xStep;
    434376    }
    435377}
    436 
    437 
    438 //  #pragma mark - SView
    439 
    440 
    441 SView::SView(BRect frame, const char *name)
    442     : BView(frame, name, B_FOLLOW_ALL, B_WILL_DRAW)
    443 {
    444     SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
    445     SetLowColor(ViewColor());
     378//  #pragma mark -
    446379}
    447380
    448381
    449 void
    450 SView::AttachedToWindow()
     382SSlider::SSlider(const char* name, const char* label,
     383        BMessage* message, int32 minValue, int32 maxValue, orientation posture,
     384        thumb_style thumbType, uint32 flags)
     385    : BSlider(name, label, message, minValue, maxValue,
     386        posture, thumbType, flags)
    451387{
    452     BView::AttachedToWindow();
    453     ResizeTo(Parent()->Bounds().Width(), Parent()->Bounds().Height());
    454 }
    455 
    456 
    457 //  #pragma mark -
    458 
    459 
    460 SSlider::SSlider(BRect frame, const char *name, const char *label,
    461         BMessage *message, int32 minValue, int32 maxValue, orientation posture,
    462         thumb_style thumbType, uint32 resizingMode, uint32 flags)
    463     : BSlider(frame, name, label, message, minValue, maxValue,
    464         posture, thumbType, resizingMode, flags)
    465 {
    466388    rgb_color barColor = { 0, 0, 229, 255 };
    467389    UseFillColor(true, &barColor);
    468390}
     
    477399}
    478400
    479401
    480 //! BSlider::ResizeToPreferred + Resize width if it's too small to show label and status
    481 void
    482 SSlider::ResizeToPreferred()
    483 {
    484     int32 width = (int32)ceil(StringWidth(Label()) + StringWidth("9999"));
    485     if (width < 230)
    486         width = 230;
    487 
    488     float w, h;
    489     GetPreferredSize(&w, &h);
    490     ResizeTo(width, h);
    491 }
    492 
    493 
    494402//  #pragma mark -
    495403
    496404
    497 TranslatorReadView::TranslatorReadView(BRect frame, const char *name,
    498     jpeg_settings *settings)
    499     : SView(frame, name),
     405TranslatorReadView::TranslatorReadView(const char* name,
     406    TranslatorSettings* settings)
     407    :
     408    BView(name, 0, new BGroupLayout(B_HORIZONTAL)),
    500409    fSettings(settings)
     410        // settings should already be Acquired()
    501411{
    502     BRect rect(5, 5, 30, 30);
    503     fAlwaysRGB32 = new BCheckBox(rect, "alwaysrgb32", VIEW_LABEL_ALWAYSRGB32,
     412    fAlwaysRGB32 = new BCheckBox("alwaysrgb32", VIEW_LABEL_ALWAYSRGB32,
    504413        new BMessage(VIEW_MSG_SET_ALWAYSRGB32));
    505     fAlwaysRGB32->SetFont(be_plain_font);
    506     if (fSettings->Always_B_RGB32)
    507         fAlwaysRGB32->SetValue(1);
     414    if (fSettings->SetGetBool(JPEG_SET_ALWAYS_RGB32, NULL))
     415        fAlwaysRGB32->SetValue(B_CONTROL_ON);
    508416
    509     AddChild(fAlwaysRGB32);
    510     fAlwaysRGB32->ResizeToPreferred();
    511     rect.OffsetBy(0, fAlwaysRGB32->Bounds().Height() + 5);
    512    
    513     fPhotoshopCMYK = new BCheckBox(rect, "photoshopCMYK", VIEW_LABEL_PHOTOSHOPCMYK,
     417    fPhotoshopCMYK = new BCheckBox("photoshopCMYK", VIEW_LABEL_PHOTOSHOPCMYK,
    514418        new BMessage(VIEW_MSG_SET_PHOTOSHOPCMYK));
    515     fPhotoshopCMYK->SetFont(be_plain_font);
    516     if (fSettings->PhotoshopCMYK)
    517         fPhotoshopCMYK->SetValue(1);
    518 
    519     AddChild(fPhotoshopCMYK);
    520     fPhotoshopCMYK->ResizeToPreferred();
    521     rect.OffsetBy(0, fPhotoshopCMYK->Bounds().Height() + 5);
     419    if (fSettings->SetGetBool(JPEG_SET_PHOTOSHOP_CMYK, NULL))
     420        fPhotoshopCMYK->SetValue(B_CONTROL_ON);
    522421   
    523     fShowErrorBox = new BCheckBox(rect, "error", VIEW_LABEL_SHOWREADERRORBOX,
     422    fShowErrorBox = new BCheckBox("error", VIEW_LABEL_SHOWREADERRORBOX,
    524423        new BMessage(VIEW_MSG_SET_SHOWREADERRORBOX));
    525     fShowErrorBox->SetFont(be_plain_font);
    526     if (fSettings->ShowReadWarningBox)
    527         fShowErrorBox->SetValue(1);
     424    if (fSettings->SetGetBool(JPEG_SET_SHOWREADWARNING, NULL))
     425        fShowErrorBox->SetValue(B_CONTROL_ON);
    528426
    529     AddChild(fShowErrorBox);
     427    float padding = 5.0f;
     428    AddChild(BGroupLayoutBuilder(B_VERTICAL, padding)
     429        .Add(fAlwaysRGB32)
     430        .Add(fPhotoshopCMYK)
     431        .Add(fShowErrorBox)
     432        .AddGlue()
     433        .SetInsets(padding, padding, padding, padding)
     434    );
    530435
    531     fShowErrorBox->ResizeToPreferred();
    532436}
    533437
    534438
     439TranslatorReadView::~TranslatorReadView()
     440{
     441    fSettings->Release();
     442}
     443
     444
    535445void
    536446TranslatorReadView::AttachedToWindow()
    537447{
    538     SView::AttachedToWindow();
     448    BView::AttachedToWindow();
    539449   
    540450    fAlwaysRGB32->SetTarget(this);
    541451    fPhotoshopCMYK->SetTarget(this);
     
    551461        {
    552462            int32 value;
    553463            if (message->FindInt32("be:value", &value) == B_OK) {
    554                 fSettings->Always_B_RGB32 = value;
    555                 SaveSettings(fSettings);
     464                bool boolValue = value;
     465                fSettings->SetGetBool(JPEG_SET_ALWAYS_RGB32, &boolValue);
     466                fSettings->SaveSettings();
    556467            }
    557468            break;
    558469        }
     
    560471        {
    561472            int32 value;
    562473            if (message->FindInt32("be:value", &value) == B_OK) {
    563                 fSettings->PhotoshopCMYK = value;
    564                 SaveSettings(fSettings);
     474                bool boolValue = value;
     475                fSettings->SetGetBool(JPEG_SET_PHOTOSHOP_CMYK, &boolValue);
     476                fSettings->SaveSettings();
    565477            }
    566478            break;
    567479        }
     
    569481        {
    570482            int32 value;
    571483            if (message->FindInt32("be:value", &value) == B_OK) {
    572                 fSettings->ShowReadWarningBox = value;
    573                 SaveSettings(fSettings);
     484                bool boolValue = value;
     485                fSettings->SetGetBool(JPEG_SET_SHOWREADWARNING, &boolValue);
     486                fSettings->SaveSettings();
    574487            }
    575488            break;
    576489        }
     
    584497//  #pragma mark - TranslatorWriteView
    585498
    586499
    587 TranslatorWriteView::TranslatorWriteView(BRect frame, const char *name,
    588     jpeg_settings *settings)
    589     : SView(frame, name),
     500TranslatorWriteView::TranslatorWriteView(const char* name,
     501    TranslatorSettings* settings)
     502    :
     503    BView(name, 0, new BGroupLayout(B_VERTICAL)),
    590504    fSettings(settings)
     505        // settings should already be Acquired()
    591506{
    592     BRect rect(10, 10, 20, 30);
    593     fQualitySlider = new SSlider(rect, "quality", VIEW_LABEL_QUALITY,
     507    fQualitySlider = new SSlider("quality", VIEW_LABEL_QUALITY,
    594508        new BMessage(VIEW_MSG_SET_QUALITY), 0, 100);
    595509    fQualitySlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
    596510    fQualitySlider->SetHashMarkCount(10);
    597511    fQualitySlider->SetLimitLabels("Low", "High");
    598     fQualitySlider->SetFont(be_plain_font);
    599     fQualitySlider->SetValue(fSettings->Quality);
    600     AddChild(fQualitySlider);
    601     fQualitySlider->ResizeToPreferred();
     512    fQualitySlider->SetValue(fSettings->SetGetInt32(JPEG_SET_QUALITY, NULL));
    602513
    603     rect.OffsetBy(0, fQualitySlider->Bounds().Height() + 5);
    604    
    605     fSmoothingSlider = new SSlider(rect, "smoothing", VIEW_LABEL_SMOOTHING,
     514    fSmoothingSlider = new SSlider("smoothing", VIEW_LABEL_SMOOTHING,
    606515        new BMessage(VIEW_MSG_SET_SMOOTHING), 0, 100);
    607516    fSmoothingSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
    608517    fSmoothingSlider->SetHashMarkCount(10);
    609518    fSmoothingSlider->SetLimitLabels("None", "High");
    610     fSmoothingSlider->SetFont(be_plain_font);
    611     fSmoothingSlider->SetValue(fSettings->Smoothing);
    612     AddChild(fSmoothingSlider);
    613     fSmoothingSlider->ResizeToPreferred();
     519    fSmoothingSlider->SetValue(
     520        fSettings->SetGetInt32(JPEG_SET_SMOOTHING, NULL));
    614521
    615     rect.OffsetBy(0, fSmoothingSlider->Bounds().Height() + 5);
    616    
    617     fProgress = new BCheckBox(rect, "progress", VIEW_LABEL_PROGRESSIVE,
     522    fProgress = new BCheckBox("progress", VIEW_LABEL_PROGRESSIVE,
    618523        new BMessage(VIEW_MSG_SET_PROGRESSIVE));
    619     fProgress->SetFont(be_plain_font);
    620     if (fSettings->Progressive)
    621         fProgress->SetValue(1);
     524    if (fSettings->SetGetBool(JPEG_SET_PROGRESSIVE, NULL))
     525        fProgress->SetValue(B_CONTROL_ON);
    622526
    623     AddChild(fProgress);
    624     fProgress->ResizeToPreferred();
    625    
    626     rect.OffsetBy(0, fProgress->Bounds().Height() + 5);
    627    
    628     fOptimizeColors = new BCheckBox(rect, "optimizecolors", VIEW_LABEL_OPTIMIZECOLORS,
    629         new BMessage(VIEW_MSG_SET_OPTIMIZECOLORS));
    630     fOptimizeColors->SetFont(be_plain_font);
    631     if (fSettings->OptimizeColors)
    632         fOptimizeColors->SetValue(1);
    633 
    634     AddChild(fOptimizeColors);
    635     fOptimizeColors->ResizeToPreferred();
    636     rect.OffsetBy(0, fOptimizeColors->Bounds().Height() + 5);
    637    
    638     fSmallerFile = new BCheckBox(rect, "smallerfile", VIEW_LABEL_SMALLERFILE,
     527    fSmallerFile = new BCheckBox("smallerfile", VIEW_LABEL_SMALLERFILE,
    639528        new BMessage(VIEW_MSG_SET_SMALLERFILE));
    640     fSmallerFile->SetFont(be_plain_font);
    641     if (fSettings->SmallerFile)
    642         fSmallerFile->SetValue(1);
    643     if (!fSettings->OptimizeColors)
     529    if (fSettings->SetGetBool(JPEG_SET_SMALL_FILES))
     530        fSmallerFile->SetValue(B_CONTROL_ON);
     531
     532    fOptimizeColors = new BCheckBox("optimizecolors", VIEW_LABEL_OPTIMIZECOLORS,
     533        new BMessage(VIEW_MSG_SET_OPTIMIZECOLORS));
     534    if (fSettings->SetGetBool(JPEG_SET_OPT_COLORS, NULL))
     535        fOptimizeColors->SetValue(B_CONTROL_ON);
     536    else
    644537        fSmallerFile->SetEnabled(false);
    645538
    646     AddChild(fSmallerFile);
    647     fSmallerFile->ResizeToPreferred();
    648     rect.OffsetBy(0, fSmallerFile->Bounds().Height() + 5);
    649    
    650     fGrayAsRGB24 = new BCheckBox(rect, "gray1asrgb24", VIEW_LABEL_GRAY1ASRGB24,
     539    fGrayAsRGB24 = new BCheckBox("gray1asrgb24", VIEW_LABEL_GRAY1ASRGB24,
    651540        new BMessage(VIEW_MSG_SET_GRAY1ASRGB24));
    652     fGrayAsRGB24->SetFont(be_plain_font);
    653     if (fSettings->B_GRAY1_as_B_RGB24)
    654         fGrayAsRGB24->SetValue(1);
     541    if (fSettings->SetGetBool(JPEG_SET_GRAY1_AS_RGB24))
     542        fGrayAsRGB24->SetValue(B_CONTROL_ON);
    655543
    656     AddChild(fGrayAsRGB24);
     544    float padding = 5.0f;
     545    AddChild(BGroupLayoutBuilder(B_VERTICAL, padding)
     546        .Add(fQualitySlider)
     547        .Add(fSmoothingSlider)
     548        .Add(fProgress)
     549        .Add(fOptimizeColors)
     550        .Add(fSmallerFile)
     551        .Add(fGrayAsRGB24)
     552        .AddGlue()
     553        .SetInsets(padding, padding, padding, padding)
     554    );
     555}
    657556
    658     fGrayAsRGB24->ResizeToPreferred();
     557
     558TranslatorWriteView::~TranslatorWriteView()
     559{
     560    fSettings->Release();
    659561}
    660562
    661563
    662564void
    663565TranslatorWriteView::AttachedToWindow()
    664566{
    665     SView::AttachedToWindow();
     567    BView::AttachedToWindow();
    666568   
    667569    fQualitySlider->SetTarget(this);
    668570    fSmoothingSlider->SetTarget(this);
     
    674576
    675577
    676578void
    677 TranslatorWriteView::MessageReceived(BMessage *message)
     579TranslatorWriteView::MessageReceived(BMessage* message)
    678580{
    679581    switch (message->what) {
    680582        case VIEW_MSG_SET_QUALITY:
    681583        {
    682584            int32 value;
    683585            if (message->FindInt32("be:value", &value) == B_OK) {
    684                 fSettings->Quality = value;
    685                 SaveSettings(fSettings);
     586                fSettings->SetGetInt32(JPEG_SET_QUALITY, &value);
     587                fSettings->SaveSettings();
    686588            }
    687589            break;
    688590        }
     
    690592        {
    691593            int32 value;
    692594            if (message->FindInt32("be:value", &value) == B_OK) {
    693                 fSettings->Smoothing = value;
    694                 SaveSettings(fSettings);
     595                fSettings->SetGetInt32(JPEG_SET_SMOOTHING, &value);
     596                fSettings->SaveSettings();
    695597            }
    696598            break;
    697599        }
     
    699601        {
    700602            int32 value;
    701603            if (message->FindInt32("be:value", &value) == B_OK) {
    702                 fSettings->Progressive = value;
    703                 SaveSettings(fSettings);
     604                bool boolValue = value;
     605                fSettings->SetGetBool(JPEG_SET_PROGRESSIVE, &boolValue);
     606                fSettings->SaveSettings();
    704607            }
    705608            break;
    706609        }
     
    708611        {
    709612            int32 value;
    710613            if (message->FindInt32("be:value", &value) == B_OK) {
    711                 fSettings->OptimizeColors = value;
    712                 SaveSettings(fSettings);
     614                bool boolValue = value;
     615                fSettings->SetGetBool(JPEG_SET_OPT_COLORS, &boolValue);
     616                fSmallerFile->SetEnabled(value);
     617                fSettings->SaveSettings();
    713618            }
    714             fSmallerFile->SetEnabled(fSettings->OptimizeColors);
    715619            break;
    716620        }
    717621        case VIEW_MSG_SET_SMALLERFILE:
    718622        {
    719623            int32 value;
    720624            if (message->FindInt32("be:value", &value) == B_OK) {
    721                 fSettings->SmallerFile = value;
    722                 SaveSettings(fSettings);
     625                bool boolValue = value;
     626                fSettings->SetGetBool(JPEG_SET_SMALL_FILES, &boolValue);
     627                fSettings->SaveSettings();
    723628            }
    724629            break;
    725630        }
     
    727632        {
    728633            int32 value;
    729634            if (message->FindInt32("be:value", &value) == B_OK) {
    730                 fSettings->B_GRAY1_as_B_RGB24 = value;
    731                 SaveSettings(fSettings);
     635                bool boolValue = value;
     636                fSettings->SetGetBool(JPEG_SET_GRAY1_AS_RGB24, &boolValue);
     637                fSettings->SaveSettings();
    732638            }
    733639            break;
    734640        }
     
    742648//  #pragma mark -
    743649
    744650
    745 TranslatorAboutView::TranslatorAboutView(BRect frame, const char *name)
    746     : SView(frame, name)
     651TranslatorAboutView::TranslatorAboutView(const char* name)
     652    :
     653    BView(name, 0, new BGroupLayout(B_VERTICAL))
    747654{
    748     BStringView *title = new BStringView(BRect(10, 0, 10, 0), "Title",
    749         translatorName);
     655    BAlignment labelAlignment = BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP);
     656    BStringView* title = new BStringView("Title", gTranslatorName);
    750657    title->SetFont(be_bold_font);
     658    title->SetExplicitAlignment(labelAlignment);
    751659
    752     AddChild(title);
    753     title->ResizeToPreferred();
    754 
    755     BRect rect = title->Bounds();
    756     float space = title->StringWidth("    ");
    757 
    758660    char versionString[16];
    759     sprintf(versionString, "v%d.%d.%d", (int)(translatorVersion >> 8),
    760         (int)((translatorVersion >> 4) & 0xf), (int)(translatorVersion & 0xf));
     661    sprintf(versionString, "v%d.%d.%d", (int)(gTranslatorVersion >> 8),
     662        (int)((gTranslatorVersion >> 4) & 0xf), (int)(gTranslatorVersion & 0xf));
    761663
    762     BStringView *version = new BStringView(BRect(rect.right + space, rect.top,
    763         rect.right+space, rect.top), "Version", versionString);
    764     version->SetFont(be_plain_font);
    765     version->SetFontSize(9);
    766     // Make version be in the same line as title
    767     version->ResizeToPreferred();
    768     version->MoveBy(0, rect.bottom-version->Frame().bottom);
     664    BStringView* version = new BStringView("Version", versionString);
     665    version->SetExplicitAlignment(labelAlignment);
    769666
    770     AddChild(version);
    771 
    772     // Now for each line in translatorInfo add a BStringView
    773     char* current = translatorInfo;
    774     int32 index = 1;
    775     BRect stringFrame = title->Frame();
    776     while (current != NULL && current[0]) {
    777         char text[128];
    778         char* newLine = strchr(current, '\n');
    779         if (newLine == NULL) {
    780             strlcpy(text, current, sizeof(text));
    781             current = NULL;
    782         } else {
    783             strlcpy(text, current, min_c((int32)sizeof(text), newLine + 1 - current));
    784             current = newLine + 1;
    785         }
    786         stringFrame.OffsetBy(0, stringFrame.Height() + 2);
    787         BStringView* string = new BStringView(stringFrame, "copyright", text);
    788         if (index > 3)
    789             string->SetFontSize(9);
    790         AddChild(string);
    791         string->ResizeToPreferred();
    792 
    793         index++;
    794     }
    795 
    796     ResizeToPreferred();
     667    BTextView* infoView = new BTextView("info");   
     668    infoView->SetText(gTranslatorInfo);
     669    infoView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
     670    infoView->MakeEditable(false);
     671   
     672    float padding = 5.0f;
     673    AddChild(BGroupLayoutBuilder(B_VERTICAL, padding)
     674        .Add(BGroupLayoutBuilder(B_HORIZONTAL, padding)
     675            .Add(title)
     676            .Add(version)
     677            .AddGlue()
     678        )
     679        .Add(infoView)
     680        .SetInsets(padding, padding, padding, padding)
     681    );
    797682}
    798683
    799684
    800 //  #pragma mark -
    801 
    802 
    803 TranslatorView::TranslatorView(BRect frame, const char *name)
    804     : BTabView(frame, name)
     685TranslatorView::TranslatorView(const char* name, TranslatorSettings* settings)
     686    :
     687    BTabView(name)
    805688{
    806     // Load settings to global settings struct
    807     LoadSettings(&fSettings);
     689    AddTab(new TranslatorWriteView("Write", settings->Acquire()));
     690    AddTab(new TranslatorReadView("Read", settings->Acquire()));
     691    AddTab(new TranslatorAboutView("About"));
    808692
    809     BRect contentSize = ContainerView()->Bounds();
    810     SView *view = new TranslatorWriteView(contentSize, "Write",
    811         &fSettings);
    812     AddTab(view);
    813     view = new TranslatorReadView(contentSize, "Read", &fSettings);
    814     AddTab(view);
    815     view = new TranslatorAboutView(contentSize, "About");
    816     AddTab(view);
    817 
    818     ResizeToPreferred();
    819 
    820     // Make TranslatorView resize itself with parent
    821     SetFlags(Flags() | B_FOLLOW_ALL);
     693    settings->Release();
     694   
     695    BFont font;
     696    GetFont(&font);
     697    SetExplicitPreferredSize(
     698        BSize((font.Size() * 380) / 12, (font.Size() * 250) / 12));
    822699}
    823700
    824701
    825 TranslatorView::~TranslatorView()
    826 {
    827 }
    828 
    829 
    830 //  #pragma mark -
    831 
    832 
    833 TranslatorWindow::TranslatorWindow(bool quitOnClose)
    834     : BWindow(BRect(100, 100, 100, 100), "JPEG Settings", B_TITLED_WINDOW,
    835         B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS)
    836 {
    837     BRect extent(0, 0, 0, 0);
    838     BView *config = NULL;
    839     MakeConfig(NULL, &config, &extent);
    840 
    841     AddChild(config);
    842     ResizeTo(extent.Width(), extent.Height());
    843 
    844     // Make application quit after this window close
    845     if (quitOnClose)
    846         SetFlags(Flags() | B_QUIT_ON_WINDOW_CLOSE);
    847 }
    848 
    849 
    850702//  #pragma mark - Translator Add-On
    851703
    852704
    853 
    854 /*! Hook to create and return our configuration view */
    855 status_t
    856 MakeConfig(BMessage *ioExtension, BView **outView, BRect *outExtent)
     705BView*
     706JPEGTranslator::NewConfigView(TranslatorSettings* settings)
    857707{
    858     *outView = new TranslatorView(BRect(0, 0, 320, 300), "TranslatorView");
    859     *outExtent = (*outView)->Frame();
    860     return B_OK;
     708    BView* configView = new TranslatorView("TranslatorView", settings);
     709    return configView;
    861710}
    862711
     712
    863713/*! Determine whether or not we can handle this data */
    864714status_t
    865 Identify(BPositionIO *inSource, const translation_format *inFormat,
    866     BMessage *ioExtension, translator_info *outInfo, uint32 outType)
     715JPEGTranslator::DerivedIdentify(BPositionIO* inSource,
     716    const translation_format* inFormat, BMessage* ioExtension,
     717    translator_info* outInfo, uint32 outType)
    867718{
    868719    if (outType != 0 && outType != B_TRANSLATOR_BITMAP && outType != JPEG_FORMAT)
    869720        return B_NO_TRANSLATOR;
     
    877728        return err;
    878729
    879730    if (B_BENDIAN_TO_HOST_INT32(((TranslatorBitmap *)header)->magic) == B_TRANSLATOR_BITMAP) {
    880         outInfo->type = inputFormats[1].type;
    881         outInfo->translator = 0;
    882         outInfo->group = inputFormats[1].group;
    883         outInfo->quality = inputFormats[1].quality;
    884         outInfo->capability = inputFormats[1].capability;
    885         strcpy(outInfo->name, inputFormats[1].name);
    886         strcpy(outInfo->MIME, inputFormats[1].MIME);
     731        if (PopulateInfoFromFormat(outInfo, B_TRANSLATOR_BITMAP) != B_OK)
     732            return B_NO_TRANSLATOR;
    887733    } else {
    888734        // First 3 bytes in jpg files are always the same from what i've seen so far
    889735        // check them
    890736        if (header[0] == (char)0xff && header[1] == (char)0xd8 && header[2] == (char)0xff) {
    891         /* this below would be safer but it slows down whole thing
    892        
    893             struct jpeg_decompress_struct cinfo;
    894             struct jpeg_error_mgr jerr;
    895             cinfo.err = jpeg_std_error(&jerr);
    896             jpeg_create_decompress(&cinfo);
    897             be_jpeg_stdio_src(&cinfo, inSource);
    898             // now try to read header
    899             // it can't be read before checking first 3 bytes
    900             // because it will hang up if there is no header (not jpeg file)
    901             int result = jpeg_read_header(&cinfo, FALSE);
    902             jpeg_destroy_decompress(&cinfo);
    903             if (result == JPEG_HEADER_OK) {
    904         */      outInfo->type = inputFormats[0].type;
    905                 outInfo->translator = 0;
    906                 outInfo->group = inputFormats[0].group;
    907                 outInfo->quality = inputFormats[0].quality;
    908                 outInfo->capability = inputFormats[0].capability;
    909                 strcpy(outInfo->name, inputFormats[0].name);
    910                 strcpy(outInfo->MIME, inputFormats[0].MIME);
    911                 return B_OK;
    912         /*  } else
     737            if (PopulateInfoFromFormat(outInfo, JPEG_FORMAT) != B_OK)
    913738                return B_NO_TRANSLATOR;
    914         */
     739
    915740        } else
    916741            return B_NO_TRANSLATOR;
    917742    }
     
    919744    return B_OK;
    920745}
    921746
    922 /*! Arguably the most important method in the add-on */
     747
    923748status_t
    924 Translate(BPositionIO *inSource, const translator_info *inInfo,
    925     BMessage *ioExtension, uint32 outType, BPositionIO *outDestination)
     749JPEGTranslator::DerivedTranslate(BPositionIO* inSource,
     750    const translator_info* inInfo, BMessage* ioExtension, uint32 outType,
     751    BPositionIO* outDestination, int32 baseType)
    926752{
    927753    // If no specific type was requested, convert to the interchange format
    928754    if (outType == 0)
     
    961787    return B_NO_TRANSLATOR;
    962788}
    963789
     790
    964791/*! The user has requested the same format for input and output, so just copy */
    965 static status_t
    966 Copy(BPositionIO *in, BPositionIO *out)
     792status_t
     793JPEGTranslator::Copy(BPositionIO* in, BPositionIO* out)
    967794{
    968795    int block_size = 65536;
    969     void *buffer = malloc(block_size);
     796    void* buffer = malloc(block_size);
    970797    char temp[1024];
    971798    if (buffer == NULL) {
    972799        buffer = temp;
     
    996823
    997824
    998825/*! Encode into the native format */
    999 static status_t
    1000 Compress(BPositionIO *in, BPositionIO *out, const jmp_buf* longJumpBuffer)
     826status_t
     827JPEGTranslator::Compress(BPositionIO* in, BPositionIO* out,
     828    const jmp_buf* longJumpBuffer)
    1001829{
    1002     // Load Settings
    1003     jpeg_settings settings;
    1004     LoadSettings(&settings);
     830    using namespace conversion;
    1005831
    1006832    // Read info about bitmap
    1007833    TranslatorBitmap header;
     
    1025851
    1026852    // Function pointer to convert function
    1027853    // It will point to proper function if needed
    1028     void (*converter)(uchar *inscanline, uchar *outscanline,
     854    void (*converter)(uchar* inscanline, uchar* outscanline,
    1029855        int32 inRowBytes) = NULL;
    1030856
    1031857    // Default color info
     
    1041867            break;
    1042868
    1043869        case B_GRAY1:
    1044             if (settings.B_GRAY1_as_B_RGB24) {
     870            if (fSettings->SetGetBool(JPEG_SET_GRAY1_AS_RGB24, NULL)) {
    1045871                converter = convert_from_gray1_to_24;
    1046872            } else {
    1047873                jpg_input_components = 1;
    1048874                jpg_color_space = JCS_GRAYSCALE;
    1049875                converter = convert_from_gray1_to_gray8;
    1050876            }
    1051             padding = in_row_bytes - (width/8);
     877            padding = in_row_bytes - (width / 8);
    1052878            break;
    1053879
    1054880        case B_GRAY8:
     
    1115941    // Set basic things needed for jpeg writing
    1116942    struct jpeg_compress_struct cinfo;
    1117943    struct jpeg_error_mgr jerr;
    1118     cinfo.err = be_jpeg_std_error(&jerr, &settings, longJumpBuffer);
     944    cinfo.err = be_jpeg_std_error(&jerr, fSettings, longJumpBuffer);
    1119945    jpeg_create_compress(&cinfo);
    1120946    be_jpeg_stdio_dest(&cinfo, out);
    1121947
     
    1131957
    1132958    // This is needed to prevent some colors loss
    1133959    // With it generated jpegs are as good as from Fireworks (at last! :D)
    1134     if (settings.OptimizeColors) {
     960    if (fSettings->SetGetBool(JPEG_SET_OPT_COLORS, NULL)) {
    1135961        int index = 0;
    1136962        while (index < cinfo.num_components) {
    1137963            cinfo.comp_info[index].h_samp_factor = 1;
     
    1139965            // This will make file smaller, but with worse quality more or less
    1140966            // like with 93%-94% (but it's subjective opinion) on tested images
    1141967            // but with smaller size (between 92% and 93% on tested images)
    1142             if (settings.SmallerFile)
     968            if (fSettings->SetGetBool(JPEG_SET_SMALL_FILES))
    1143969                cinfo.comp_info[index].quant_tbl_no = 1;
    1144970            // This will make bigger file, but also better quality ;]
    1145971            // from my tests it seems like useless - better quality with smaller
     
    1151977    }
    1152978
    1153979    // Set quality
    1154     jpeg_set_quality(&cinfo, settings.Quality, true);
     980    jpeg_set_quality(&cinfo, fSettings->SetGetInt32(JPEG_SET_QUALITY, NULL), true);
    1155981
    1156982    // Set progressive compression if needed
    1157983    // if not, turn on optimizing in libjpeg
    1158     if (settings.Progressive)
     984    if (fSettings->SetGetBool(JPEG_SET_PROGRESSIVE, NULL))
    1159985        jpeg_simple_progression(&cinfo);
    1160986    else
    1161987        cinfo.optimize_coding = TRUE;
    1162988
    1163989    // Set smoothing (effect like Blur)
    1164     cinfo.smoothing_factor = settings.Smoothing;
     990    cinfo.smoothing_factor = fSettings->SetGetInt32(JPEG_SET_SMOOTHING, NULL);
    1165991
    1166992    // Initialize compression
    1167993    jpeg_start_compress(&cinfo, TRUE);
     
    1169995    // Declare scanlines
    1170996    JSAMPROW in_scanline = NULL;
    1171997    JSAMPROW out_scanline = NULL;
    1172     JSAMPROW writeline; // Pointer to in_scanline (default) or out_scanline (if there will be conversion)
     998    JSAMPROW writeline;
     999        // Pointer to in_scanline (default) or out_scanline (if there will be conversion)
    11731000
    11741001    // Allocate scanline
    11751002    // Use libjpeg memory allocation functions, so in case of error it will free them itself
     
    12091036
    12101037
    12111038/*! Decode the native format */
    1212 static status_t
    1213 Decompress(BPositionIO *in, BPositionIO *out, BMessage* ioExtension,
    1214     const jmp_buf* longJumpBuffer)
     1039status_t
     1040JPEGTranslator::Decompress(BPositionIO* in, BPositionIO* out,
     1041    BMessage* ioExtension, const jmp_buf* longJumpBuffer)
    12151042{
    1216     // Load Settings
    1217     jpeg_settings settings;
    1218     LoadSettings(&settings);
     1043    using namespace conversion;
    12191044
    12201045    // Set basic things needed for jpeg reading
    12211046    struct jpeg_decompress_struct cinfo;
    12221047    struct jpeg_error_mgr jerr;
    1223     cinfo.err = be_jpeg_std_error(&jerr, &settings, longJumpBuffer);
     1048    cinfo.err = be_jpeg_std_error(&jerr, fSettings, longJumpBuffer);
    12241049    jpeg_create_decompress(&cinfo);
    12251050    be_jpeg_stdio_src(&cinfo, in);
    12261051
     
    12401065            if (ioExtension != NULL) {
    12411066                // Strip EXIF header from TIFF data
    12421067                ioExtension->AddData("exif", B_RAW_TYPE,
    1243                     (uint8 *)marker->data + 6, marker->data_length - 6);
     1068                    (uint8* )marker->data + 6, marker->data_length - 6);
    12441069            }
    12451070
    12461071            BMemoryIO io(marker->data + 6, marker->data_length - 6);
     
    12551080
    12561081    // Function pointer to convert function
    12571082    // It will point to proper function if needed
    1258     void (*converter)(uchar *inScanLine, uchar *outScanLine,
     1083    void (*converter)(uchar* inScanLine, uchar* outScanLine,
    12591084        int32 inRowBytes, int32 xStep) = convert_from_24_to_32;
    12601085
    12611086    // If color space isn't rgb
     
    12661091                break;
    12671092            case JCS_GRAYSCALE:     /* monochrome */
    12681093                // Check if user wants to read only as RGB32 or not
    1269                 if (!settings.Always_B_RGB32) {
     1094                if (!fSettings->SetGetBool(JPEG_SET_ALWAYS_RGB32, NULL)) {
    12701095                    // Grayscale
    12711096                    outColorSpace = B_GRAY8;
    12721097                    outColorComponents = 1;
     
    12881113                // Fall through to CMYK since we need the same settings
    12891114            case JCS_CMYK:      /* C/M/Y/K */
    12901115                // Use proper converter
    1291                 if (settings.PhotoshopCMYK)
     1116                if (fSettings->SetGetBool(JPEG_SET_PHOTOSHOP_CMYK))
    12921117                    converter = convert_from_CMYK_to_32_photoshop;
    12931118                else
    12941119                    converter = convert_from_CMYK_to_32;
     
    14121237    return B_OK;
    14131238}
    14141239
     1240/*! have the other PopulateInfoFromFormat() check both inputFormats & outputFormats */
     1241status_t
     1242JPEGTranslator::PopulateInfoFromFormat(translator_info* info,
     1243    uint32 formatType, translator_id id)
     1244{
     1245    int32 formatCount;
     1246    const translation_format* formats = OutputFormats(&formatCount);
     1247    for(int i = 0; i <= 1 ;formats = InputFormats(&formatCount), i++) {
     1248        if (PopulateInfoFromFormat(info, formatType,
     1249            formats, formatCount) == B_OK) {
     1250            info->translator = id;
     1251            return B_OK;
     1252        }
     1253    }
     1254
     1255    return B_ERROR;
     1256}
     1257
     1258
     1259status_t
     1260JPEGTranslator::PopulateInfoFromFormat(translator_info* info,
     1261    uint32 formatType, const translation_format* formats, int32 formatCount)
     1262{
     1263    for( int i = 0; i < formatCount; i++ ) {
     1264        if (formats[i].type == formatType) {
     1265            info->type = formatType;
     1266            info->group = formats[i].group;
     1267            info->quality = formats[i].quality;
     1268            info->capability = formats[i].capability;
     1269            strcpy(info->name, formats[i].name);
     1270            strcpy(info->MIME,  formats[i].MIME);
     1271            return B_OK;
     1272        }
     1273    }
     1274
     1275    return B_ERROR;
     1276}
     1277
    14151278/*!
    14161279    Frees jpeg alocated memory
    14171280    Returns given error (B_ERROR by default)
    14181281*/
    1419 static status_t
    1420 Error(j_common_ptr cinfo, status_t error)
     1282status_t
     1283JPEGTranslator::Error(j_common_ptr cinfo, status_t error)
    14211284{
    14221285    jpeg_destroy(cinfo);
    14231286    return error;
    14241287}
    14251288
    14261289
    1427 //  #pragma mark -
     1290JPEGTranslator::JPEGTranslator()
     1291    :
     1292    BaseTranslator(gTranslatorName, gTranslatorInfo, gTranslatorVersion,
     1293    gInputFormats, gInputFormatCount, gOutputFormats, gOutputFormatCount,
     1294    SETTINGS_FILE, gSettings, gSettingsCount,
     1295    B_TRANSLATOR_BITMAP, JPEG_FORMAT)
     1296{}
    14281297
    14291298
     1299BTranslator*
     1300make_nth_translator(int32 n, image_id you, uint32 flags, ...)
     1301{
     1302    if (!n)
     1303        return new JPEGTranslator();
     1304
     1305    return NULL;
     1306}
     1307
     1308
    14301309int
    14311310main(int, char**)
    14321311{
    14331312    BApplication app("application/x-vnd.Haiku-JPEGTranslator");
     1313    JPEGTranslator* translator = new JPEGTranslator();
     1314    if (LaunchTranslatorWindow(translator, gTranslatorName) == B_OK)
     1315        app.Run();
    14341316
    1435     TranslatorWindow *window = new TranslatorWindow();
    1436     window->Show();
    1437 
    1438     app.Run();
    14391317    return 0;
    14401318}
    14411319
  • src/add-ons/translators/jpeg/JPEGTranslator.h

     
    5050
    5151#include <jpeglib.h>
    5252
     53#include "BaseTranslator.h"
    5354
    5455// Settings
    5556#define SETTINGS_FILE   "JPEGTranslator"
     
    7677#define VIEW_LABEL_PHOTOSHOPCMYK "Use CMYK code with 0 for 100% ink coverage"
    7778#define VIEW_LABEL_SHOWREADERRORBOX "Show warning messages"
    7879
     80// strings for use in TranslatorSettings
     81#define JPEG_SET_SMOOTHING "smoothing"
     82#define JPEG_SET_QUALITY "quality"
     83#define JPEG_SET_PROGRESSIVE "progressive"
     84#define JPEG_SET_OPT_COLORS "optimize"
     85#define JPEG_SET_SMALL_FILES "filesSmaller"
     86#define JPEG_SET_GRAY1_AS_RGB24 "gray"
     87#define JPEG_SET_ALWAYS_RGB32 "always"
     88#define JPEG_SET_PHOTOSHOP_CMYK "cmyk"
     89#define JPEG_SET_SHOWREADWARNING "readWarning"
    7990
    80 //! Settings storage structure
    81 struct jpeg_settings {
    82     // compression
    83     uchar   Smoothing;          // default: 0
    84     uchar   Quality;            // default: 95
    85     bool    Progressive;        // default: true
    86     bool    OptimizeColors;     // default: true
    87     bool    SmallerFile;        // default: false   only used if (OptimizeColors == true)
    88     bool    B_GRAY1_as_B_RGB24; // default: false   if false gray1 converted to gray8, else to rgb24
    89     // decompression
    90     bool    Always_B_RGB32;     // default: true
    91     bool    PhotoshopCMYK;      // default: true
    92     bool    ShowReadWarningBox; // default: true
    93 };
    9491
    9592
    9693/*!
     
    9996*/
    10097class SSlider : public BSlider {
    10198    public:
    102                 SSlider(BRect frame, const char *name, const char *label,
    103                     BMessage *message, int32 minValue, int32 maxValue,
    104                     orientation posture = B_HORIZONTAL,
    105                     thumb_style thumbType = B_BLOCK_THUMB,
    106                     uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
    107                     uint32 flags = B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS);
     99        SSlider(const char* name, const char* label,
     100            BMessage* message, int32 minValue, int32 maxValue,
     101            orientation posture = B_HORIZONTAL,
     102            thumb_style thumbType = B_BLOCK_THUMB,
     103            uint32 flags = B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS);
    108104    virtual const char* UpdateText() const;
    109         void    ResizeToPreferred();
    110105
    111106    private:
    112107        mutable char fStatusLabel[12];
    113108};
    114109
    115110
    116 class SView : public BView {
    117 public:
    118     SView(BRect frame, const char *name);
    119     virtual void AttachedToWindow();
     111class JPEGTranslator : public BaseTranslator {
     112    public:
     113        JPEGTranslator();
     114
     115        virtual status_t DerivedIdentify(BPositionIO* inSource,
     116            const translation_format* inFormat, BMessage* ioExtension,
     117            translator_info* outInfo, uint32 outType);
     118           
     119        virtual status_t DerivedTranslate(BPositionIO* inSource,
     120            const translator_info* inInfo, BMessage* ioExtension,
     121            uint32 outType, BPositionIO* outDestination, int32 baseType);
     122           
     123        virtual BView* NewConfigView(TranslatorSettings* settings);
     124
     125    private:
     126   
     127        status_t Copy(BPositionIO* in, BPositionIO* out);
     128        status_t Compress(BPositionIO* in, BPositionIO* out,
     129            const jmp_buf* longJumpBuffer);
     130        status_t Decompress(BPositionIO* in, BPositionIO* out,
     131            BMessage* ioExtension, const jmp_buf* longJumpBuffer);
     132        status_t Error(j_common_ptr cinfo, status_t error = B_ERROR);
     133
     134        status_t PopulateInfoFromFormat(translator_info* info,
     135            uint32 formatType, translator_id id = 0);
     136        status_t PopulateInfoFromFormat(translator_info* info,
     137            uint32 formatType, const translation_format* formats,
     138            int32 formatCount);
    120139};
     140       
    121141
    122 //! Configuration view for reading settings
    123 class TranslatorReadView : public SView {
     142class TranslatorReadView : public BView {
    124143    public:
    125         TranslatorReadView(BRect frame, const char* name, jpeg_settings* settings);
     144        TranslatorReadView(const char* name, TranslatorSettings* settings);
     145        virtual ~TranslatorReadView();
    126146
    127147        virtual void    AttachedToWindow();
    128148        virtual void    MessageReceived(BMessage* message);
    129149
    130150    private:
    131         jpeg_settings*  fSettings;
     151        TranslatorSettings* fSettings;
    132152        BCheckBox*      fAlwaysRGB32;
    133153        BCheckBox*      fPhotoshopCMYK;
    134154        BCheckBox*      fShowErrorBox;
    135155};
    136156
    137157
    138 //! Configuration view for writing settings
    139 class TranslatorWriteView : public SView {
     158class TranslatorWriteView : public BView {
    140159    public:
    141         TranslatorWriteView(BRect frame, const char* name, jpeg_settings* settings);
     160        TranslatorWriteView(const char* name, TranslatorSettings* settings);
     161        virtual ~TranslatorWriteView();
    142162
    143163        virtual void    AttachedToWindow();
    144164        virtual void    MessageReceived(BMessage* message);
    145165
    146166    private:
    147         jpeg_settings*  fSettings;
     167        TranslatorSettings* fSettings;
    148168        SSlider*        fQualitySlider;
    149169        SSlider*        fSmoothingSlider;
    150170        BCheckBox*      fProgress;
     
    153173        BCheckBox*      fGrayAsRGB24;
    154174};
    155175
    156 class TranslatorAboutView : public SView {
     176
     177class TranslatorAboutView : public BView {
    157178    public:
    158         TranslatorAboutView(BRect frame, const char* name);
     179        TranslatorAboutView(const char* name);
    159180};
    160181
    161 //! Configuration view
     182
    162183class TranslatorView : public BTabView {
    163184    public:
    164         TranslatorView(BRect frame, const char *name);
    165         virtual ~TranslatorView();
     185        TranslatorView(const char* name, TranslatorSettings* settings);
    166186
    167187    private:
    168         jpeg_settings   fSettings;
     188        BView* fAboutView;
     189        BView* fReadView;
     190        BView* fWriteView;
    169191};
    170192
    171 //! Window used for configuration
    172 class TranslatorWindow : public BWindow {
    173     public:
    174         TranslatorWindow(bool quitOnClose = true);
    175 };
    176193
    177 
    178194//---------------------------------------------------
    179195//  "Initializers" for jpeglib
    180196//  based on default ones,
     
    190206//  (so user can decide to show dialog-boxes or not)
    191207//---------------------------------------------------
    192208EXTERN(struct jpeg_error_mgr *) be_jpeg_std_error (struct jpeg_error_mgr * err,
    193     jpeg_settings * settings, const jmp_buf* longJumpBuffer);
     209    TranslatorSettings * settings, const jmp_buf* longJumpBuffer);
    194210    // implemented in "be_jerror.cpp"
    195211
    196212#endif // _JPEGTRANSLATOR_H_
  • src/add-ons/translators/jpeg/Jamfile

     
    55SubDirSysHdrs [ FDirName $(SUBDIR) $(DOTDOT) raw ] ;
    66    # for TIFF.h and ReadHelper.h
    77
     8SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) shared ] ;
     9    #for BaseTranslator.h and friends
     10
    811UseLibraryHeaders jpeg ;
    912
    1013Translator JPEGTranslator :
     
    1316    be_jerror.cpp
    1417    exif_parser.cpp
    1518    JPEGTranslator.cpp
    16 
    17     : be translation libjpeg.so $(TARGET_LIBSTDC++)
     19    : be translation libtranslatorsutils.a libjpeg.so $(TARGET_LIBSTDC++)
    1820    : true
    1921;
    2022
  • src/add-ons/translators/jpeg/be_jerror.cpp

     
    4646#include <jconfig.h>
    4747#include <jerror.h>
    4848
    49 // JPEGTtanslator settings header to get SETTINGS struct
     49// JPEGTtanslator settings header to get settings stuff
    5050#include "JPEGTranslator.h"
     51#include "TranslatorSettings.h"
    5152
    5253
    5354// Since Translator doesn't use it's own error table, we can use error_mgr's
     
    109110 */
    110111
    111112GLOBAL(struct jpeg_error_mgr *)
    112 be_jpeg_std_error (struct jpeg_error_mgr * err, jpeg_settings *settings,
     113be_jpeg_std_error (struct jpeg_error_mgr * err, TranslatorSettings* settings,
    113114    const jmp_buf* longJumpBuffer)
    114115{
     116    settings->Acquire();
    115117    jpeg_std_error(err);
    116118
    117119    err->error_exit = be_error_exit;
    118120    err->output_message = be_output_message;
    119121
    120     err->ShowReadWarnings = settings->ShowReadWarningBox;
     122    err->ShowReadWarnings = settings->SetGetBool(JPEG_SET_SHOWREADWARNING, NULL);
    121123    memcpy(&(err->long_jump_buffer), longJumpBuffer, sizeof(jmp_buf));
    122124
     125    settings->Release();
    123126    return err;
    124127}