Ticket #2117: jpeg2000.patch

File jpeg2000.patch, 39.2 KB (added by yourpalal, 9 years ago)

use Layout, BaseTranslator TranslatorSettings, etc..

  • src/add-ons/translators/jpeg2000/JPEG2000Translator.cpp

     
    3333#include "JPEG2000Translator.h"
    3434#include "jp2_cod.h"
    3535#include "jpc_cs.h"
     36#include "TranslatorWindow.h"
    3637
     38#include <GroupLayoutBuilder.h>
    3739#include <TabView.h>
     40#include <TextView.h>
    3841
    3942
    4043// Set these accordingly
     
    4750#define B_TRANSLATOR_BITMAP_MIME_STRING "image/x-be-bitmap"
    4851#define B_TRANSLATOR_BITMAP_DESCRIPTION "Be Bitmap Format (JPEG2000Translator)"
    4952
    50 // Translation Kit required globals
    51 char translatorName[] = "JPEG2000 images";
    52 char translatorInfo[] = "©2002-2003, Shard\n"
     53const char gTranslatorName[] = "JPEG2000 images";
     54const char gTranslatorInfo[] = "©2002-2003, Shard\n"
    5355    "©2005-2006, Haiku\n"
    5456    "\n"
    5557    "Based on JasPer library:\n"
     
    6163    "ImageMagick's jp2 codec was used as \"tutorial\".\n"
    6264    "          http://www.imagemagick.org/\n";
    6365
    64 int32 translatorVersion = 0x100;
     66int32 gTranslatorVersion = B_TRANSLATION_MAKE_VERSION(1, 0, 0);
    6567
    66 // Define the formats we know how to read
    67 translation_format inputFormats[] = {
     68translation_format gInputFormats[] = {
    6869    { JP2_FORMAT, B_TRANSLATOR_BITMAP, 0.5, 0.5,
    6970        JP2_MIME_STRING, JP2_DESCRIPTION },
    7071    { B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP, 0.5, 0.5,
    7172        B_TRANSLATOR_BITMAP_MIME_STRING, B_TRANSLATOR_BITMAP_DESCRIPTION },
    72     {},
    7373};
     74const int gInputFormatCount =
     75    sizeof(gInputFormats) / sizeof(translation_format);
    7476
    75 // Define the formats we know how to write
    76 translation_format outputFormats[] = {
     77translation_format gOutputFormats[] = {
    7778    { JP2_FORMAT, B_TRANSLATOR_BITMAP, 0.5, 0.5,
    7879        JP2_MIME_STRING, JP2_DESCRIPTION },
    7980    { B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP, 0.5, 0.5,
    8081        B_TRANSLATOR_BITMAP_MIME_STRING, B_TRANSLATOR_BITMAP_DESCRIPTION },
    81     {},
    8282};
     83const int gOutputFormatCount =
     84     sizeof(gOutputFormats) / sizeof(translation_format);
    8385
    8486
    85 //! Make settings to defaults
    86 void
    87 LoadDefaultSettings(jpeg_settings *settings)
    88 {
    89     settings->Quality = 25;
    90     settings->JPC = false;
    91     settings->B_GRAY1_as_B_RGB24 = false;
    92     settings->B_GRAY8_as_B_RGB32 = true;
    93 }
     87TranSetting gSettings[] = {
     88    {JP2_SET_QUALITY, TRAN_SETTING_INT32, 25},
     89    {JP2_SET_JPC, TRAN_SETTING_BOOL, false},
     90    {JP2_SET_GRAY1_AS_B_RGB24, TRAN_SETTING_BOOL, false},
     91    {JP2_SET_GRAY8_AS_B_RGB32, TRAN_SETTING_BOOL, true}
     92};
     93const int gSettingsCount = sizeof(gSettings) / sizeof(TranSetting) ;
    9494
    9595
    96 //! Save settings to config file
    97 void
    98 SaveSettings(jpeg_settings *settings)
    99 {
    100     // Make path to settings file
    101     BPath path;
    102     if (find_directory(B_USER_SETTINGS_DIRECTORY, &path, true) != B_OK)
    103         return;
    104 
    105     path.Append(SETTINGS_FILE);
    106 
    107     // Open settings file (create it if there's no file) and write settings         
    108     FILE *file = NULL;
    109     if ((file = fopen(path.Path(), "wb+"))) {
    110         fwrite(settings, sizeof(jpeg_settings), 1, file);
    111         fclose(file);
    112     }
    113 }
    114 
    115 
    116 /*!
    117     Load settings from config file
    118     If can't find it make them default and try to save
    119 */
    120 void
    121 LoadSettings(jpeg_settings *settings)
    122 {
    123     // Make path to settings file
    124     BPath path;
    125     if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) {
    126         LoadDefaultSettings(settings);
    127         return;
    128     }
    129 
    130     path.Append(SETTINGS_FILE);
    131 
    132     // Open settings file (create it if there's no file) and write settings         
    133     FILE *file = NULL;
    134     if ((file = fopen(path.Path(), "rb"))) {
    135         if (!fread(settings, sizeof(jpeg_settings), 1, file)) {
    136             // settings struct has changed size
    137             // Load default settings, and Save them
    138             fclose(file);
    139             LoadDefaultSettings(settings);
    140             SaveSettings(settings);
    141         } else
    142             fclose(file);
    143     } else if ((file = fopen(path.Path(), "wb+"))) {
    144         LoadDefaultSettings(settings);
    145         fwrite(settings, sizeof(jpeg_settings), 1, file);
    146         fclose(file);
    147     }
    148 }
    149 
    150 
    151 //  #pragma mark - conversion routines
    152 
    153 
     96namespace conversion{
    15497//! Make RGB32 scanline from *pixels[3]
    15598inline void
    156 read_rgb24_to_rgb32(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
     99read_rgb24_to_rgb32(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
    157100{
    158101    int32 index = 0;
    159102    int32 x = 0;
     
    169112
    170113//! Make gray scanline from *pixels[1]
    171114inline void
    172 read_gray_to_rgb32(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
     115read_gray_to_rgb32(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
    173116{
    174117    int32 index = 0;
    175118    int32 x = 0;
     
    189132    (just read data to scanline)
    190133*/
    191134inline void
    192 read_rgba32(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
     135read_rgba32(jas_matrix_t** pixels, jpr_uchar_t *scanline, int width)
    193136{
    194137    int32 index = 0;
    195138    int32 x = 0;
     
    208151    (just read data to scanline)
    209152*/
    210153inline void
    211 read_gray(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
     154read_gray(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
    212155{
    213156    int32 x = 0;
    214157    while (x < width) {
     
    220163
    221164//! Make *pixels[1] from gray1 scanline
    222165inline void
    223 write_gray1_to_gray(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
     166write_gray1_to_gray(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
    224167{
    225168    int32 x = 0;
    226169    int32 index = 0;
     
    238181
    239182//! Make *pixels[3] from gray1 scanline
    240183inline void
    241 write_gray1_to_rgb24(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
     184write_gray1_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
    242185{
    243186    int32 x = 0;
    244187    int32 index = 0;
    245     while (x < (width/8)) {
     188    while (x < (width / 8)) {
    246189        unsigned char c = scanline[x++];
    247190        for (int b = 128; b; b = b >> 1) {
    248191            if (c & b) {
     
    262205
    263206//! Make *pixels[3] from cmap8 scanline
    264207inline void
    265 write_cmap8_to_rgb24(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
     208write_cmap8_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
    266209{
    267     const color_map *map = system_colors();
     210    const color_map* map = system_colors();
    268211    int32 x = 0;
    269212    while (x < width) {
    270213        rgb_color color = map->color_list[scanline[x]];
     
    282225    (just write data to pixels)
    283226*/
    284227inline void
    285 write_gray(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
     228write_gray(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
    286229{
    287230    int32 x = 0;
    288231    while (x < width) {
     
    297240    (just write data to pixels)
    298241*/
    299242inline void
    300 write_rgb15_to_rgb24(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
     243write_rgb15_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
    301244{
    302245    int32 x = 0;
    303246    int32 index = 0;
     
    306249        in_pixel = scanline[index] | (scanline[index+1] << 8);
    307250        index += 2;
    308251
    309         jas_matrix_setv(pixels[0], x, (char)(((in_pixel & 0x7c00)) >> 7) | (((in_pixel & 0x7c00)) >> 12));
    310         jas_matrix_setv(pixels[1], x, (char)(((in_pixel & 0x3e0)) >> 2) | (((in_pixel & 0x3e0)) >> 7));
    311         jas_matrix_setv(pixels[2], x, (char)(((in_pixel & 0x1f)) << 3) | (((in_pixel & 0x1f)) >> 2));
     252        jas_matrix_setv(pixels[0], x, (char)(((in_pixel & 0x7c00)) >> 7)
     253            | (((in_pixel & 0x7c00)) >> 12));
     254        jas_matrix_setv(pixels[1], x, (char)(((in_pixel & 0x3e0)) >> 2)
     255            | (((in_pixel & 0x3e0)) >> 7));
     256        jas_matrix_setv(pixels[2], x, (char)(((in_pixel & 0x1f)) << 3)
     257            | (((in_pixel & 0x1f)) >> 2));
    312258        x++;
    313259    }
    314260}
     
    319265    (just write data to pixels)
    320266*/
    321267inline void
    322 write_rgb15b_to_rgb24(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
     268write_rgb15b_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
    323269{
    324270    int32 x = 0;
    325271    int32 index = 0;
    326272    int16 in_pixel;
    327273    while (x < width) {
    328         in_pixel = scanline[index+1] | (scanline[index] << 8);
     274        in_pixel = scanline[index + 1] | (scanline[index] << 8);
    329275        index += 2;
    330276
    331         jas_matrix_setv(pixels[0], x, (char)(((in_pixel & 0x7c00)) >> 7) | (((in_pixel & 0x7c00)) >> 12));
    332         jas_matrix_setv(pixels[1], x, (char)(((in_pixel & 0x3e0)) >> 2) | (((in_pixel & 0x3e0)) >> 7));
    333         jas_matrix_setv(pixels[2], x, (char)(((in_pixel & 0x1f)) << 3) | (((in_pixel & 0x1f)) >> 2));
     277        jas_matrix_setv(pixels[0], x, (char)(((in_pixel & 0x7c00)) >> 7)
     278            | (((in_pixel & 0x7c00)) >> 12));
     279        jas_matrix_setv(pixels[1], x, (char)(((in_pixel & 0x3e0)) >> 2)
     280            | (((in_pixel & 0x3e0)) >> 7));
     281        jas_matrix_setv(pixels[2], x, (char)(((in_pixel & 0x1f)) << 3)
     282            | (((in_pixel & 0x1f)) >> 2));
    334283        x++;
    335284    }
    336285}
     
    341290    (just write data to pixels)
    342291*/
    343292inline void
    344 write_rgb16_to_rgb24(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
     293write_rgb16_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
    345294{
    346295    int32 x = 0;
    347296    int32 index = 0;
     
    350299        in_pixel = scanline[index] | (scanline[index+1] << 8);
    351300        index += 2;
    352301
    353         jas_matrix_setv(pixels[0], x, (char)(((in_pixel & 0xf800)) >> 8) | (((in_pixel & 0x7c00)) >> 12));
    354         jas_matrix_setv(pixels[1], x, (char)(((in_pixel & 0x7e0)) >> 3) | (((in_pixel & 0x7e0)) >> 9));
    355         jas_matrix_setv(pixels[2], x, (char)(((in_pixel & 0x1f)) << 3) | (((in_pixel & 0x1f)) >> 2));
     302        jas_matrix_setv(pixels[0], x, (char)(((in_pixel & 0xf800)) >> 8)
     303            | (((in_pixel & 0x7c00)) >> 12));
     304        jas_matrix_setv(pixels[1], x, (char)(((in_pixel & 0x7e0)) >> 3)
     305            | (((in_pixel & 0x7e0)) >> 9));
     306        jas_matrix_setv(pixels[2], x, (char)(((in_pixel & 0x1f)) << 3)
     307            | (((in_pixel & 0x1f)) >> 2));
    356308        x++;
    357309    }
    358310}
     
    363315    (just write data to pixels)
    364316*/
    365317inline void
    366 write_rgb16b_to_rgb24(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
     318write_rgb16b_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
    367319{
    368320    int32 x = 0;
    369321    int32 index = 0;
    370322    int16 in_pixel;
    371323    while (x < width) {
    372         in_pixel = scanline[index+1] | (scanline[index] << 8);
     324        in_pixel = scanline[index + 1] | (scanline[index] << 8);
    373325        index += 2;
    374326
    375         jas_matrix_setv(pixels[0], x, (char)(((in_pixel & 0xf800)) >> 8) | (((in_pixel & 0xf800)) >> 13));
    376         jas_matrix_setv(pixels[1], x, (char)(((in_pixel & 0x7e0)) >> 3) | (((in_pixel & 0x7e0)) >> 9));
    377         jas_matrix_setv(pixels[2], x, (char)(((in_pixel & 0x1f)) << 3) | (((in_pixel & 0x1f)) >> 2));
     327        jas_matrix_setv(pixels[0], x, (char)(((in_pixel & 0xf800)) >> 8)
     328            | (((in_pixel & 0xf800)) >> 13));
     329        jas_matrix_setv(pixels[1], x, (char)(((in_pixel & 0x7e0)) >> 3)
     330            | (((in_pixel & 0x7e0)) >> 9));
     331        jas_matrix_setv(pixels[2], x, (char)(((in_pixel & 0x1f)) << 3)
     332            | (((in_pixel & 0x1f)) >> 2));
    378333        x++;
    379334    }
    380335}
     
    385340    (just write data to pixels)
    386341*/
    387342inline void
    388 write_rgb24(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
     343write_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
    389344{
    390345    int32 index = 0;
    391346    int32 x = 0;
     
    403358    (just write data to pixels)
    404359*/
    405360inline void
    406 write_rgb24b(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
     361write_rgb24b(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
    407362{
    408363    int32 index = 0;
    409364    int32 x = 0;
     
    421376    (just write data to pixels)
    422377*/
    423378inline void
    424 write_rgb32_to_rgb24(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
     379write_rgb32_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
    425380{
    426381    int32 index = 0;
    427382    int32 x = 0;
     
    440395    (just write data to pixels)
    441396*/
    442397inline void
    443 write_rgb32b_to_rgb24(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
     398write_rgb32b_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
    444399{
    445400    int32 index = 0;
    446401    int32 x = 0;
     
    460415    !!! UNTESTED !!!
    461416*/
    462417inline void
    463 write_rgba32(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
     418write_rgba32(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
    464419{
    465420    int32 index = 0;
    466421    int32 x = 0;
     
    480435    !!! UNTESTED !!!
    481436*/
    482437inline void
    483 write_rgba32b(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)
     438write_rgba32b(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
    484439{
    485440    int32 index = 0;
    486441    int32 x = 0;
     
    495450}
    496451
    497452
     453}// end namespace conversion
     454
     455
    498456//  #pragma mark -  jasper I/O
    499457
    500458
    501459static int
    502 Read(jas_stream_obj_t *object, char *buffer, const int length)
     460Read(jas_stream_obj_t* object, char* buffer, const int length)
    503461{
    504462    return (*(BPositionIO**)object)->Read(buffer, length);
    505463}
    506464
    507465
    508466static int
    509 Write(jas_stream_obj_t *object, char *buffer, const int length)
     467Write(jas_stream_obj_t* object, char* buffer, const int length)
    510468{
    511469    return (*(BPositionIO**)object)->Write(buffer, length);
    512470}
    513471
    514472
    515473static long
    516 Seek(jas_stream_obj_t *object, long offset, int origin)
     474Seek(jas_stream_obj_t* object, long offset, int origin)
    517475{
    518476    return (*(BPositionIO**)object)->Seek(offset, origin);
    519477}
    520478
    521479
    522480static int
    523 Close(jas_stream_obj_t *object)
     481Close(jas_stream_obj_t* object)
    524482{
    525483    return 0;
    526484}
     
    534492};
    535493
    536494
    537 static jas_stream_t *
     495static jas_stream_t*
    538496jas_stream_positionIOopen(BPositionIO *positionIO)
    539497{
    540     jas_stream_t *stream;
     498    jas_stream_t* stream;
    541499
    542500    stream = (jas_stream_t *)malloc(sizeof(jas_stream_t));
    543501    if (stream == (jas_stream_t *)NULL)
     
    564522}
    565523
    566524
    567 //  #pragma mark - SView
    568 
    569 
    570 SView::SView(BRect frame, const char *name)
    571     : BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW)
    572 {
    573     SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
    574     SetLowColor(ViewColor());
    575 
    576     SetFont(be_plain_font);
    577 }
    578 
    579 
    580 void
    581 SView::AttachedToWindow()
    582 {
    583     BView::AttachedToWindow();
    584     ResizeTo(Parent()->Bounds().Width(), Parent()->Bounds().Height());
    585 }
    586 
    587 
    588525//  #pragma mark -
    589526
    590527
    591 SSlider::SSlider(BRect frame, const char *name, const char *label,
    592         BMessage *message, int32 minValue, int32 maxValue, orientation posture,
    593         thumb_style thumbType, uint32 resizingMode, uint32 flags)
    594     : BSlider(frame, name, label, message, minValue, maxValue,
    595         posture, thumbType, resizingMode, flags)
     528SSlider::SSlider(const char* name, const char* label,
     529        BMessage* message, int32 minValue, int32 maxValue, orientation posture,
     530        thumb_style thumbType, uint32 flags)
     531    :
     532    BSlider(name, label, message, minValue, maxValue,
     533        posture, thumbType, flags)
    596534{
    597535    rgb_color barColor = { 0, 0, 229, 255 };
    598536    UseFillColor(true, &barColor);
     
    608546}
    609547
    610548
    611 //! BSlider::ResizeToPreferred + Resize width if it's too small to show label
    612 // and status
    613 void
    614 SSlider::ResizeToPreferred()
    615 {
    616     int32 width = (int32)ceil(StringWidth(Label()) + StringWidth("9999"));
    617     if (width < 230)
    618         width = 230;
    619 
    620     float w, h;
    621     GetPreferredSize(&w, &h);
    622     ResizeTo(width, h);
    623 }
    624 
    625 
    626549//  #pragma mark -
    627550
    628551
    629 TranslatorReadView::TranslatorReadView(BRect frame, const char *name,
    630     jpeg_settings *settings)
    631     : SView(frame, name),
     552TranslatorReadView::TranslatorReadView(const char* name,
     553    TranslatorSettings* settings)
     554    :
     555    BView(name, 0, new BGroupLayout(B_VERTICAL)),
    632556    fSettings(settings)
    633557{
    634     fGrayAsRGB32 = new BCheckBox(BRect(10, 10, 40, 40), "grayasrgb32",
    635         VIEW_LABEL_GRAYASRGB32, new BMessage(VIEW_MSG_SET_GRAYASRGB32));
    636     fGrayAsRGB32->SetFont(be_plain_font);
    637     if (fSettings->B_GRAY8_as_B_RGB32)
    638         fGrayAsRGB32->SetValue(1);
     558    fGrayAsRGB32 = new BCheckBox("grayasrgb32", VIEW_LABEL_GRAYASRGB32,
     559        new BMessage(VIEW_MSG_SET_GRAYASRGB32));
     560    if (fSettings->SetGetBool(JP2_SET_GRAY8_AS_B_RGB32))
     561        fGrayAsRGB32->SetValue(B_CONTROL_ON);
    639562
    640     AddChild(fGrayAsRGB32);
    641     fGrayAsRGB32->ResizeToPreferred();
     563    float padding = 10.0f;
     564    AddChild(BGroupLayoutBuilder(B_VERTICAL)
     565        .Add(fGrayAsRGB32)
     566        .AddGlue()
     567        .SetInsets(padding, padding, padding, padding)
     568    );
    642569}
    643570
    644571
     572TranslatorReadView::~TranslatorReadView()
     573{
     574    fSettings->Release();
     575}
     576
     577
    645578void
    646579TranslatorReadView::AttachedToWindow()
    647580{
    648     SView::AttachedToWindow();
    649581    fGrayAsRGB32->SetTarget(this);
    650582}
    651583
    652584
    653585void
    654 TranslatorReadView::MessageReceived(BMessage *message)
     586TranslatorReadView::MessageReceived(BMessage* message)
    655587{
    656588    switch (message->what) {
    657589        case VIEW_MSG_SET_GRAYASRGB32:
    658590        {
    659591            int32 value;
    660592            if (message->FindInt32("be:value", &value) == B_OK) {
    661                 fSettings->B_GRAY8_as_B_RGB32 = value;
    662                 SaveSettings(fSettings);
     593                bool boolValue = value;
     594                fSettings->SetGetBool(JP2_SET_GRAY8_AS_B_RGB32, &boolValue);
     595                fSettings->SaveSettings();
    663596            }
    664597            break;
    665598        }
     
    673606//  #pragma mark - TranslatorWriteView
    674607
    675608
    676 TranslatorWriteView::TranslatorWriteView(BRect frame, const char *name,
    677     jpeg_settings *settings)
    678     : SView(frame, name),
     609TranslatorWriteView::TranslatorWriteView(const char* name,
     610    TranslatorSettings* settings)
     611    :
     612    BView(name, 0, new BGroupLayout(B_VERTICAL)),
    679613    fSettings(settings)
    680614{
    681     BRect rect(10, 10, 10, 40);
    682     fQualitySlider = new SSlider(rect, "quality",
    683         VIEW_LABEL_QUALITY, new BMessage(VIEW_MSG_SET_QUALITY), 0, 100);
     615    fQualitySlider = new SSlider("quality", VIEW_LABEL_QUALITY,
     616        new BMessage(VIEW_MSG_SET_QUALITY), 0, 100);
    684617    fQualitySlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
    685618    fQualitySlider->SetHashMarkCount(10);
    686619    fQualitySlider->SetLimitLabels("Low", "High");
    687     fQualitySlider->SetFont(be_plain_font);
    688     fQualitySlider->SetValue(fSettings->Quality);
    689     AddChild(fQualitySlider);
    690     fQualitySlider->ResizeToPreferred();
     620    fQualitySlider->SetValue(fSettings->SetGetInt32(JP2_SET_QUALITY));
    691621
    692     rect.OffsetBy(0, fQualitySlider->Bounds().Height() + 10);
    693 
    694     fGrayAsRGB24 = new BCheckBox(rect, "gray1asrgb24",
    695         VIEW_LABEL_GRAY1ASRGB24,
     622    fGrayAsRGB24 = new BCheckBox("gray1asrgb24", VIEW_LABEL_GRAY1ASRGB24,
    696623        new BMessage(VIEW_MSG_SET_GRAY1ASRGB24));
    697     fGrayAsRGB24->SetFont(be_plain_font);
    698     if (fSettings->B_GRAY1_as_B_RGB24)
    699         fGrayAsRGB24->SetValue(1);
     624    if (fSettings->SetGetBool(JP2_SET_GRAY1_AS_B_RGB24))
     625        fGrayAsRGB24->SetValue(B_CONTROL_ON);
    700626
    701     AddChild(fGrayAsRGB24);
    702     fGrayAsRGB24->ResizeToPreferred();
    703 
    704     rect.OffsetBy(0, fGrayAsRGB24->Bounds().Height() + 10);
     627    fCodeStreamOnly = new BCheckBox("codestreamonly", VIEW_LABEL_JPC,
     628        new BMessage(VIEW_MSG_SET_JPC));
     629    if (fSettings->SetGetBool(JP2_SET_JPC))
     630        fCodeStreamOnly->SetValue(B_CONTROL_ON);
    705631   
    706     fCodeStreamOnly = new BCheckBox(rect, "codestreamonly",
    707         VIEW_LABEL_JPC, new BMessage(VIEW_MSG_SET_JPC));
    708     fCodeStreamOnly->SetFont(be_plain_font);
    709     if (fSettings->JPC)
    710         fCodeStreamOnly->SetValue(1);
     632    float padding = 10.0f;
     633    AddChild(BGroupLayoutBuilder(B_VERTICAL, padding)
     634        .Add(fQualitySlider)
     635        .Add(fGrayAsRGB24)
     636        .Add(fCodeStreamOnly)
     637        .AddGlue()
     638        .SetInsets(padding, padding, padding, padding)
     639    );
     640}
    711641
    712     AddChild(fCodeStreamOnly);
    713    
    714     fCodeStreamOnly->ResizeToPreferred();
     642
     643TranslatorWriteView::~TranslatorWriteView()
     644{
     645    fSettings->Release();
    715646}
    716647
    717648
    718649void
    719650TranslatorWriteView::AttachedToWindow()
    720651{
    721     SView::AttachedToWindow();
    722    
    723652    fQualitySlider->SetTarget(this);
    724653    fGrayAsRGB24->SetTarget(this);
    725654    fCodeStreamOnly->SetTarget(this);
     
    727656
    728657
    729658void
    730 TranslatorWriteView::MessageReceived(BMessage *message)
     659TranslatorWriteView::MessageReceived(BMessage* message)
    731660{
    732661    switch (message->what) {
    733662        case VIEW_MSG_SET_QUALITY:
    734663        {
    735664            int32 value;
    736665            if (message->FindInt32("be:value", &value) == B_OK) {
    737                 fSettings->Quality = value;
    738                 SaveSettings(fSettings);
     666                fSettings->SetGetInt32(JP2_SET_QUALITY, &value);
     667                fSettings->SaveSettings();
    739668            }
    740669            break;
    741670        }
     
    743672        {
    744673            int32 value;
    745674            if (message->FindInt32("be:value", &value) == B_OK) {
    746                 fSettings->B_GRAY1_as_B_RGB24 = value;
    747                 SaveSettings(fSettings);
     675                bool boolValue = value;
     676                fSettings->SetGetBool(JP2_SET_GRAY1_AS_B_RGB24, &boolValue);
     677                fSettings->SaveSettings();
    748678            }
    749679            break;
    750680        }
     
    752682        {
    753683            int32 value;
    754684            if (message->FindInt32("be:value", &value) == B_OK) {
    755                 fSettings->JPC = value;
    756                 SaveSettings(fSettings);
     685                bool boolValue = value;
     686                fSettings->SetGetBool(JP2_SET_JPC, &boolValue);
     687                fSettings->SaveSettings();
    757688            }
    758689            break;
    759690        }
     
    767698//  #pragma mark -
    768699
    769700
    770 TranslatorAboutView::TranslatorAboutView(BRect frame, const char *name)
    771     : SView(frame, name)
     701TranslatorAboutView::TranslatorAboutView(const char* name)
     702    :
     703    BView(name, 0, new BGroupLayout(B_VERTICAL))
    772704{
    773     BStringView *title = new BStringView(BRect(10, 0, 10, 0), "Title",
    774         translatorName);
     705    BAlignment labelAlignment = BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP);
     706    BStringView* title = new BStringView("Title", gTranslatorName);
    775707    title->SetFont(be_bold_font);
     708    title->SetExplicitAlignment(labelAlignment);
    776709
    777     AddChild(title);
    778     title->ResizeToPreferred();
    779 
    780     BRect rect = title->Bounds();
    781     float space = title->StringWidth("    ");
    782 
    783710    char versionString[16];
    784     sprintf(versionString, "v%d.%d.%d", (int)(translatorVersion >> 8),
    785         (int)((translatorVersion >> 4) & 0xf), (int)(translatorVersion & 0xf));
     711    sprintf(versionString, "v%d.%d.%d", (int)(gTranslatorVersion >> 8),
     712        (int)((gTranslatorVersion >> 4) & 0xf), (int)(gTranslatorVersion & 0xf));
    786713
    787     BStringView *version = new BStringView(BRect(rect.right+space, rect.top,
    788         rect.right+space, rect.top), "Version", versionString);
    789     version->SetFont(be_plain_font);
    790     version->SetFontSize(9);
    791     // Make version be in the same line as title
    792     version->ResizeToPreferred();
    793     version->MoveBy(0, rect.bottom-version->Frame().bottom);
     714    BStringView* version = new BStringView("Version", versionString);
     715    version->SetExplicitAlignment(labelAlignment);
    794716
    795     AddChild(version);
     717    BTextView* infoView = new BTextView("info");   
     718    infoView->SetText(gTranslatorInfo);
     719    infoView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
     720    infoView->MakeEditable(false);
    796721   
    797     version->ResizeToPreferred();
    798    
    799     BRect stringFrame = title->Frame();
    800     // Now for each line in translatorInfo add a BStringView
    801     char* current = translatorInfo;
    802     int32 index = 1;
    803     while (current != NULL && current[0]) {
    804         char text[128];
    805         char* newLine = strchr(current, '\n');
    806         if (newLine == NULL) {
    807             strlcpy(text, current, sizeof(text));
    808             current = NULL;
    809         } else {
    810             strlcpy(text, current, min_c((int32)sizeof(text),
    811                 newLine + 1 - current));
    812             current = newLine + 1;
    813         }
    814        
    815         stringFrame.OffsetBy(0, stringFrame.Height() + 2);
    816         BStringView* string = new BStringView(stringFrame, "copyright",
    817             text);
    818         if (index > 3)
    819             string->SetFontSize(9);
    820         AddChild(string);
    821         string->ResizeToPreferred();
    822 
    823         index++;
    824     }
     722    float padding = 10.0f;
     723    AddChild(BGroupLayoutBuilder(B_VERTICAL, padding)
     724        .Add(BGroupLayoutBuilder(B_HORIZONTAL, padding)
     725            .Add(title)
     726            .Add(version)
     727            .AddGlue()
     728        )
     729        .Add(infoView)
     730        .SetInsets(padding, padding, padding, padding)
     731    );
    825732}
    826733
    827734
    828735//  #pragma mark -
    829736
    830737
    831 TranslatorView::TranslatorView(BRect frame, const char *name)
    832     : BTabView(frame, name)
     738TranslatorView::TranslatorView(const char* name, TranslatorSettings* settings)
     739    :
     740    BTabView(name)
    833741{
    834     // Load settings to global settings struct
    835     LoadSettings(&fSettings);
    836    
    837     BRect contentSize = ContainerView()->Bounds();
    838     SView *view = new TranslatorWriteView(contentSize, "Write",
    839         &fSettings);
    840     AddTab(view);
    841     view = new TranslatorReadView(contentSize, "Read", &fSettings);
    842     AddTab(view);
    843     view = new TranslatorAboutView(contentSize, "About");
    844     AddTab(view);
    845    
    846     ResizeToPreferred();
    847    
    848     // Make TranslatorView resize itself with parent
    849     SetFlags(Flags() | B_FOLLOW_ALL);
    850 }
     742    AddTab(new TranslatorWriteView("Write", settings->Acquire()));
     743    AddTab(new TranslatorReadView("Read", settings->Acquire()));
     744    AddTab(new TranslatorAboutView("About"));
    851745
     746    settings->Release();
    852747
    853 TranslatorView::~TranslatorView()
    854 {
     748    BFont font;
     749    GetFont(&font);
     750    SetExplicitPreferredSize(
     751        BSize((font.Size() * 380) / 12, (font.Size() * 250) / 12));
    855752}
    856753
    857754
    858755//  #pragma mark -
    859756
    860 
    861 TranslatorWindow::TranslatorWindow(bool quitOnClose)
    862     : BWindow(BRect(100, 100, 100, 100), "JPEG Settings", B_TITLED_WINDOW,
    863         B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS)
     757BView*
     758JP2Translator::NewConfigView(TranslatorSettings* settings)
    864759{
    865     BRect extent(0, 0, 0, 0);
    866     BView *config = NULL;
    867     MakeConfig(NULL, &config, &extent);
    868 
    869     AddChild(config);
    870     ResizeTo(extent.Width(), extent.Height());
    871 
    872     // Make application quit after this window close
    873     if (quitOnClose)
    874         SetFlags(Flags() | B_QUIT_ON_WINDOW_CLOSE);
     760    BView* outView = new TranslatorView("TranslatorView", settings);
     761    return outView;
    875762}
    876763
    877764
    878 //  #pragma mark -
    879 
    880 
    881 //! Hook to create and return our configuration view
    882 status_t
    883 MakeConfig(BMessage *ioExtension, BView **outView, BRect *outExtent)
     765JP2Translator::JP2Translator()
     766    :
     767    BaseTranslator(gTranslatorName, gTranslatorInfo, gTranslatorVersion,
     768        gInputFormats, gInputFormatCount,
     769        gOutputFormats, gOutputFormatCount, JP2_SETTINGS_FILE,
     770        gSettings, gSettingsCount, B_TRANSLATOR_BITMAP, JP2_FORMAT)
    884771{
    885     *outView = new TranslatorView(BRect(0, 0, 300, 250), "TranslatorView");
    886     *outExtent = (*outView)->Frame();
    887     return B_OK;
    888772}
    889773
    890774
    891775//! Determine whether or not we can handle this data
    892776status_t
    893 Identify(BPositionIO *inSource, const translation_format *inFormat,
    894     BMessage *ioExtension, translator_info *outInfo, uint32 outType)
     777JP2Translator::DerivedIdentify(BPositionIO* inSource,
     778    const translation_format* inFormat, BMessage* ioExtension,
     779    translator_info* outInfo, uint32 outType)
    895780{
    896781    if ((outType != 0) && (outType != B_TRANSLATOR_BITMAP)
    897782        && outType != JP2_FORMAT)
     
    908793
    909794    if (B_BENDIAN_TO_HOST_INT32(((TranslatorBitmap *)header)->magic)
    910795        == B_TRANSLATOR_BITMAP) {
    911         outInfo->type = inputFormats[1].type;
    912         outInfo->translator = 0;
    913         outInfo->group = inputFormats[1].group;
    914         outInfo->quality = inputFormats[1].quality;
    915         outInfo->capability = inputFormats[1].capability;
    916         strcpy(outInfo->name, inputFormats[1].name);
    917         strcpy(outInfo->MIME, inputFormats[1].MIME);
     796        if (PopulateInfoFromFormat(outInfo, B_TRANSLATOR_BITMAP) != B_OK)
     797            return B_NO_TRANSLATOR;
    918798    } else {
    919799        if ((((header[4] << 24) | (header[5] << 16) | (header[6] << 8)
    920800            | header[7]) == JP2_BOX_JP) // JP2
    921801            || (header[0] == (JPC_MS_SOC >> 8) && header[1]
    922802            == (JPC_MS_SOC & 0xff)))    // JPC
    923803        {
    924             outInfo->type = inputFormats[0].type;
    925             outInfo->translator = 0;
    926             outInfo->group = inputFormats[0].group;
    927             outInfo->quality = inputFormats[0].quality;
    928             outInfo->capability = inputFormats[0].capability;
    929             strcpy(outInfo->name, inputFormats[0].name);
    930             strcpy(outInfo->MIME, inputFormats[0].MIME);
    931             return B_OK;
     804            if (PopulateInfoFromFormat(outInfo, JP2_FORMAT) != B_OK)
     805                return B_NO_TRANSLATOR;
    932806        } else
    933807            return B_NO_TRANSLATOR;
    934808    }
     
    937811}
    938812
    939813
    940 //! Arguably the most important method in the add-on
    941814status_t
    942 Translate(BPositionIO *inSource, const translator_info *inInfo,
    943     BMessage *ioExtension, uint32 outType, BPositionIO *outDestination)
     815JP2Translator::DerivedTranslate(BPositionIO* inSource,
     816    const translator_info* inInfo, BMessage* ioExtension, uint32 outType,
     817    BPositionIO* outDestination, int32 baseType)
    944818{
    945819    // If no specific type was requested, convert to the interchange format
    946820    if (outType == 0)
     
    960834
    961835//! The user has requested the same format for input and output, so just copy
    962836status_t
    963 Copy(BPositionIO *in, BPositionIO *out)
     837JP2Translator::Copy(BPositionIO* in, BPositionIO* out)
    964838{
    965839    int block_size = 65536;
    966     void *buffer = malloc(block_size);
     840    void* buffer = malloc(block_size);
    967841    char temp[1024];
    968842    if (buffer == NULL) {
    969843        buffer = temp;
     
    996870
    997871//! Encode into the native format
    998872status_t
    999 Compress(BPositionIO *in, BPositionIO *out)
     873JP2Translator::Compress(BPositionIO* in, BPositionIO* out)
    1000874{
    1001     // Load settings
    1002     jpeg_settings settings;
    1003     LoadSettings(&settings);
     875    using namespace conversion;
    1004876
    1005877    // Read info about bitmap
    1006878    TranslatorBitmap header;
     
    1024896
    1025897    // Function pointer to write function
    1026898    // It MUST point to proper function
    1027     void (*converter)(jas_matrix_t **pixels, jpr_uchar_t *inscanline,
     899    void (*converter)(jas_matrix_t** pixels, jpr_uchar_t* inscanline,
    1028900        int width) = write_rgba32;
    1029901
    1030902    // Default color info
     
    1033905
    1034906    switch ((color_space)B_BENDIAN_TO_HOST_INT32(header.colors)) {
    1035907        case B_GRAY1:
    1036             if (settings.B_GRAY1_as_B_RGB24) {
     908            if (fSettings->SetGetBool(JP2_SET_GRAY1_AS_B_RGB24)) {
    1037909                converter = write_gray1_to_rgb24;
    1038910            } else {
    1039911                out_color_components = 1;
     
    1117989            return B_ERROR;
    1118990    }
    1119991
    1120     jas_image_t *image;
    1121     jas_stream_t *outs;
    1122     jas_matrix_t *pixels[4];
     992    jas_image_t* image;
     993    jas_stream_t* outs;
     994    jas_matrix_t* pixels[4];
    1123995    jas_image_cmptparm_t component_info[4];
    1124996
    1125997    if (jas_init())
     
    11571029    for (y = 0; y < (long)height; y++) {
    11581030        err = in->Read(in_scanline, in_row_bytes);
    11591031        if (err < in_row_bytes) {
    1160             return (err < B_OK) ?
    1161                 Error(outs, image, pixels, out_color_components, in_scanline,
    1162                     err)
     1032            return (err < B_OK) ? Error(outs, image, pixels,
     1033                    out_color_components, in_scanline, err)
    11631034                : Error(outs, image, pixels, out_color_components, in_scanline,
    11641035                    B_ERROR);
    11651036        }
     
    11731044    }
    11741045
    11751046    char opts[16];
    1176     sprintf(opts, "rate=%1f", (float)settings.Quality / 100.0);
    1177     if (jas_image_encode(image, outs, jas_image_strtofmt(settings.JPC ?
    1178         (char*)"jpc" : (char*)"jp2"), opts)) {
    1179         return Error(outs, image, pixels, out_color_components, in_scanline, err);
     1047    sprintf(opts, "rate=%1f",
     1048        (float)fSettings->SetGetInt32(JP2_SET_QUALITY) / 100.0);
     1049
     1050    if (jas_image_encode(image, outs, jas_image_strtofmt(
     1051            fSettings->SetGetBool(JP2_SET_JPC) ?
     1052                (char*)"jpc" : (char*)"jp2"), opts)) {
     1053        return Error(outs, image, pixels,
     1054            out_color_components, in_scanline, err);
    11801055    }
    11811056
    11821057    free(in_scanline);
     
    11941069
    11951070//! Decode the native format
    11961071status_t
    1197 Decompress(BPositionIO *in, BPositionIO *out)
     1072JP2Translator::Decompress(BPositionIO* in, BPositionIO* out)
    11981073{
    1199     jpeg_settings settings;
    1200     LoadSettings(&settings);
     1074    using namespace conversion;
    12011075
    1202     jas_image_t *image;
    1203     jas_stream_t *ins;
    1204     jas_matrix_t *pixels[4];
     1076    jas_image_t* image;
     1077    jas_stream_t* ins;
     1078    jas_matrix_t* pixels[4];
    12051079
    12061080    if (jas_init())
    12071081        return B_ERROR;
     
    12191093
    12201094    // Function pointer to read function
    12211095    // It MUST point to proper function
    1222     void (*converter)(jas_matrix_t **pixels, jpr_uchar_t *outscanline,
     1096    void (*converter)(jas_matrix_t** pixels, jpr_uchar_t* outscanline,
    12231097        int width) = NULL;
    12241098
    12251099    switch (jas_image_colorspace(image)) {
     
    12371111            }
    12381112            break;
    12391113        case JAS_IMAGE_CS_GRAY:
    1240             if (settings.B_GRAY8_as_B_RGB32) {
     1114            if (fSettings->SetGetBool(JP2_SET_GRAY8_AS_B_RGB32)) {
    12411115                out_color_space = B_RGB32;
    12421116                out_color_components = 4;
    12431117                converter = read_gray_to_rgb32;
     
    12661140        // NOTE: things will go wrong if "out_row_bytes" wouldn't fit into 32 bits
    12671141
    12681142    // !!! Initialize this bounds rect to the size of your image
    1269     BRect bounds(0, 0, width-1, height-1);
     1143    BRect bounds(0, 0, width - 1, height - 1);
    12701144
     1145
    12711146    // Fill out the B_TRANSLATOR_BITMAP's header
    12721147    TranslatorBitmap header;
    12731148    header.magic = B_HOST_TO_BENDIAN_INT32(B_TRANSLATOR_BITMAP);
     
    12941169    for (i = 0; i < (long)in_color_components; i++) {
    12951170        pixels[i] = jas_matrix_create(1, (unsigned int)width);
    12961171        if (pixels[i] == (jas_matrix_t *)NULL)
    1297             return Error(ins, image, pixels, i+1, out_scanline, B_ERROR);
     1172            return Error(ins, image, pixels, i + 1, out_scanline, B_ERROR);
    12981173    }
    12991174
    13001175    int32 y = 0;
     
    13081183
    13091184        err = out->Write(out_scanline, out_row_bytes);
    13101185        if (err < out_row_bytes) {
    1311             return (err < B_OK) ?
    1312                 Error(ins, image, pixels, in_color_components, out_scanline,
    1313                     err)
     1186            return (err < B_OK) ? Error(ins, image, pixels, in_color_components,
     1187                out_scanline, err)
    13141188                : Error(ins, image, pixels, in_color_components, out_scanline,
    13151189                    B_ERROR);
    13161190        }
     
    13291203}
    13301204
    13311205
     1206/*! searches in both inputFormats & outputFormats */
     1207status_t
     1208JP2Translator::PopulateInfoFromFormat(translator_info* info,
     1209    uint32 formatType, translator_id id)
     1210{
     1211    int32 formatCount;
     1212    const translation_format* formats = OutputFormats(&formatCount);
     1213
     1214    for (int i = 0; i <= 1; formats = InputFormats(&formatCount), i++) {
     1215        if (PopulateInfoFromFormat(info, formatType,
     1216            formats, formatCount) == B_OK) {
     1217            info->translator = id;
     1218            return B_OK;
     1219        }
     1220    }
     1221
     1222    return B_ERROR;
     1223}
     1224
     1225
     1226status_t
     1227JP2Translator::PopulateInfoFromFormat(translator_info* info,
     1228    uint32 formatType, const translation_format* formats, int32 formatCount)
     1229{
     1230    for (int i = 0; i < formatCount; i++) {
     1231        if (formats[i].type == formatType) {
     1232            info->type = formatType;
     1233            info->group = formats[i].group;
     1234            info->quality = formats[i].quality;
     1235            info->capability = formats[i].capability;
     1236            strcpy(info->name, formats[i].name);
     1237            strcpy(info->MIME,  formats[i].MIME);
     1238            return B_OK;
     1239        }
     1240    }
     1241
     1242    return B_ERROR;
     1243}
     1244
     1245
    13321246/*!
    13331247    Frees jpeg alocated memory
    13341248    Returns given error (B_ERROR by default)
    13351249*/
    13361250status_t
    1337 Error(jas_stream_t *stream, jas_image_t *image, jas_matrix_t **pixels,
    1338     int32 pixels_count, jpr_uchar_t *scanline, status_t error)
     1251Error(jas_stream_t* stream, jas_image_t* image, jas_matrix_t** pixels,
     1252    int32 pixels_count, jpr_uchar_t* scanline, status_t error)
    13391253{
    13401254    if (pixels) {
    13411255        int32 i;
     
    13581272
    13591273//  #pragma mark -
    13601274
     1275BTranslator*
     1276make_nth_translator(int32 n, image_id you, uint32 flags, ...)
     1277{
     1278    if (!n)
     1279        return new JP2Translator();
    13611280
     1281    return NULL;
     1282}
     1283
     1284
    13621285int
    13631286main()
    13641287{
    13651288    BApplication app("application/x-vnd.Haiku-JPEG2000Translator");
     1289    JP2Translator* translator = new JP2Translator();
     1290    if (LaunchTranslatorWindow(translator, gTranslatorName) == B_OK)
     1291        app.Run();
    13661292
    1367     TranslatorWindow *window = new TranslatorWindow();
    1368     window->Show();
    1369 
    1370     app.Run();
    13711293    return 0;
    13721294}
    13731295
  • src/add-ons/translators/jpeg2000/JPEG2000Translator.h

     
    4848#include <stdlib.h>
    4949#include <string.h>
    5050
     51#include "BaseTranslator.h"
    5152#include "libjasper/jasper.h"
    5253
    5354
    5455// Settings
    55 #define SETTINGS_FILE   "JPEG2000Translator"
     56#define JP2_SETTINGS_FILE   "JPEG2000Translator"
    5657
     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
    5763// View messages
    5864#define VIEW_MSG_SET_QUALITY 'JSCQ'
    5965#define VIEW_MSG_SET_GRAY1ASRGB24 'JSGR'
     
    6268
    6369// View labels
    6470#define VIEW_LABEL_QUALITY "Output quality"
     71#define VIEW_LABEL_JPC "Output only codestream (.jpc)"
    6572#define VIEW_LABEL_GRAY1ASRGB24 "Write black-and-white images as RGB24"
    66 #define VIEW_LABEL_JPC "Output only codestream (.jpc)"
    6773#define VIEW_LABEL_GRAYASRGB32 "Read greyscale images as RGB32"
    6874
    6975
    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 };
    7976
    80 
    8177/*!
    8278    Slider used in TranslatorView
    8379    With status showing actual value
    8480*/
    8581class 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();
     82public:
     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;
    9589
    96     private:
    97         mutable char fStatusLabel[12];
     90private:
     91    mutable char fStatusLabel[12];
    9892};
    9993
    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 
    10794//! Configuration view for reading settings
    108 class TranslatorReadView : public SView {
    109     public:
    110         TranslatorReadView(BRect rect, const char* name, jpeg_settings* settings);
     95class TranslatorReadView : public BView {
     96public:
     97    TranslatorReadView(const char* name, TranslatorSettings* settings);
     98    ~TranslatorReadView();
    11199
    112         virtual void    AttachedToWindow();
    113         virtual void    MessageReceived(BMessage* message);
     100    virtual void    AttachedToWindow();
     101    virtual void    MessageReceived(BMessage* message);
    114102
    115     private:
    116         jpeg_settings*  fSettings;
    117         BCheckBox*      fGrayAsRGB32;
     103private:
     104    TranslatorSettings* fSettings;
     105    BCheckBox*      fGrayAsRGB32;
    118106};
    119107
    120108//! Configuration view for writing settings
    121 class TranslatorWriteView : public SView {
    122     public:
    123         TranslatorWriteView(BRect rect, const char* name, jpeg_settings* settings);
     109class TranslatorWriteView : public BView {
     110public:
     111    TranslatorWriteView(const char* name, TranslatorSettings* settings);
     112    ~TranslatorWriteView();
    124113
    125         virtual void    AttachedToWindow();
    126         virtual void    MessageReceived(BMessage* message);
     114    virtual void    AttachedToWindow();
     115    virtual void    MessageReceived(BMessage* message);
    127116
    128     private:
    129         jpeg_settings*  fSettings;
    130         SSlider*        fQualitySlider;
    131         BCheckBox*      fGrayAsRGB24;
    132         BCheckBox*      fCodeStreamOnly;
     117private:
     118    TranslatorSettings* fSettings;
     119    SSlider*        fQualitySlider;
     120    BCheckBox*      fGrayAsRGB24;
     121    BCheckBox*      fCodeStreamOnly;
    133122};
    134123
    135 class TranslatorAboutView : public SView {
    136     public:
    137         TranslatorAboutView(BRect rect, const char* name);
     124class TranslatorAboutView : public BView {
     125public:
     126    TranslatorAboutView(const char* name);
    138127};
    139128
    140129//! Configuration view
    141130class TranslatorView : public BTabView {
    142     public:
    143         TranslatorView(BRect rect, const char *name);
    144         virtual ~TranslatorView();
    145 
    146     private:
    147         jpeg_settings   fSettings;
     131public:
     132    TranslatorView(const char* name, TranslatorSettings* settings);
    148133};
    149134
    150 //! Window used for configuration
    151 class TranslatorWindow : public BWindow {
    152     public:
    153         TranslatorWindow(bool quitOnClose = true);
     135class JP2Translator : public BaseTranslator {
     136public:
     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
     149private:
     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);
    154159};
    155160
     161status_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);
    156163
    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 
    163164#endif // _JP2TRANSLATOR_H_
  • src/add-ons/translators/jpeg2000/Jamfile

     
    44
    55SubDirSysHdrs [ FDirName $(SUBDIR) libjasper ] ;
    66
     7SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) shared ] ;
     8    #for BaseTranslator.h and friends
     9
    710# Exclude unwanted formats
    811CCFLAGS += -DEXCLUDE_MIF_SUPPORT
    912    -DEXCLUDE_PNM_SUPPORT
     
    6669
    6770    $(jasper_files)
    6871
    69     : be translation $(TARGET_LIBSUPC++)
     72    : be translation libtranslatorsutils.a $(TARGET_LIBSUPC++)
    7073    : true
    7174;
    7275