Ticket #2117: jpegTranslator.patch
File jpegTranslator.patch, 40.0 KB (added by , 14 years ago) |
---|
-
src/add-ons/translators/jpeg/JPEGTranslator.cpp
31 31 32 32 33 33 #include "JPEGTranslator.h" 34 34 #include "TranslatorWindow.h" 35 35 #include "exif_parser.h" 36 36 37 #include <Alignment.h> 38 #include <GridLayoutBuilder.h> 39 #include <GroupLayoutBuilder.h> 37 40 #include <TabView.h> 41 #include <TextView.h> 38 42 39 43 40 44 #define MARKER_EXIF 0xe1 … … 50 54 #define B_TRANSLATOR_BITMAP_DESCRIPTION "Be Bitmap Format (JPEGTranslator)" 51 55 52 56 // Translation Kit required globals 53 char translatorName[] = "JPEG images";54 char translatorInfo[] =57 char gTranslatorName[] = "JPEG images"; 58 char gTranslatorInfo[] = 55 59 "©2002-2003, Marcin Konicki\n" 56 60 "©2005-2007, Haiku\n" 57 61 "\n" 58 62 "Based on IJG library © 1994-2009, Thomas G. Lane, Guido Vollbeding.\n" 59 63 " http://www.ijg.org/files/\n" 64 "\n" 60 65 "with \"lossless\" encoding support patch by Ken Murchison\n" 61 66 " http://www.oceana.com/ftp/ljpeg/\n" 62 67 "\n" 63 68 "With some colorspace conversion routines by Magnus Hellman\n" 64 69 " http://www.bebits.com/app/802\n"; 65 70 66 int32 translatorVersion = 0x120;71 int32 gTranslatorVersion = B_TRANSLATION_MAKE_VERSION(1, 2, 0); 67 72 68 73 // Define the formats we know how to read 69 translation_format inputFormats[] = {74 const translation_format gInputFormats[] = { 70 75 { JPEG_FORMAT, B_TRANSLATOR_BITMAP, 0.5, 0.5, 71 76 JPEG_MIME_STRING, JPEG_DESCRIPTION }, 72 77 { B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP, 0.5, 0.5, 73 78 B_TRANSLATOR_BITMAP_MIME_STRING, B_TRANSLATOR_BITMAP_DESCRIPTION }, 74 79 {} 75 80 }; 81 const int gInputFormatCount = sizeof(gInputFormats) / sizeof(translation_format); 76 82 77 83 // Define the formats we know how to write 78 translation_format outputFormats[] = {84 const translation_format gOutputFormats[] = { 79 85 { JPEG_FORMAT, B_TRANSLATOR_BITMAP, 0.5, 0.5, 80 86 JPEG_MIME_STRING, JPEG_DESCRIPTION }, 81 87 { B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP, 0.5, 0.5, 82 88 B_TRANSLATOR_BITMAP_MIME_STRING, B_TRANSLATOR_BITMAP_DESCRIPTION }, 83 89 {} 84 90 }; 91 const int gOutputFormatCount = sizeof(gOutputFormats) / sizeof(translation_format); 85 92 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);93 93 94 TranSetting 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 }; 105 const int gSettingsCount = sizeof(gSettings) / sizeof(TranSetting); 94 106 95 107 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 108 namespace conversion{ 167 109 static bool 168 110 x_flipped(int32 orientation) 169 111 { … … 263 205 int32 index2 = 0; 264 206 int16 in_pixel; 265 207 while (index < inRowBytes) { 266 in_pixel = in[index] | (in[index +1] << 8);208 in_pixel = in[index] | (in[index + 1] << 8); 267 209 index += 2; 268 210 269 211 out[index2++] = (((in_pixel & 0x7c00)) >> 7) | (((in_pixel & 0x7c00)) >> 12); … … 280 222 int32 index2 = 0; 281 223 int16 in_pixel; 282 224 while (index < inRowBytes) { 283 in_pixel = in[index +1] | (in[index] << 8);225 in_pixel = in[index + 1] | (in[index] << 8); 284 226 index += 2; 285 227 286 228 out[index2++] = (((in_pixel & 0x7c00)) >> 7) | (((in_pixel & 0x7c00)) >> 12); … … 297 239 int32 index2 = 0; 298 240 int16 in_pixel; 299 241 while (index < inRowBytes) { 300 in_pixel = in[index] | (in[index +1] << 8);242 in_pixel = in[index] | (in[index + 1] << 8); 301 243 index += 2; 302 244 303 245 out[index2++] = (((in_pixel & 0xf800)) >> 8) | (((in_pixel & 0xf800)) >> 13); … … 314 256 int32 index2 = 0; 315 257 int16 in_pixel; 316 258 while (index < inRowBytes) { 317 in_pixel = in[index +1] | (in[index] << 8);259 in_pixel = in[index + 1] | (in[index] << 8); 318 260 index += 2; 319 261 320 262 out[index2++] = (((in_pixel & 0xf800)) >> 8) | (((in_pixel & 0xf800)) >> 13); … … 330 272 int32 index = 0; 331 273 int32 index2 = 0; 332 274 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]; 335 277 out[index2++] = in[index]; 336 278 index+=3; 337 279 } … … 433 375 out += xStep; 434 376 } 435 377 } 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 - 446 379 } 447 380 448 381 449 void 450 SView::AttachedToWindow() 382 SSlider::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) 451 387 { 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 {466 388 rgb_color barColor = { 0, 0, 229, 255 }; 467 389 UseFillColor(true, &barColor); 468 390 } … … 477 399 } 478 400 479 401 480 //! BSlider::ResizeToPreferred + Resize width if it's too small to show label and status481 void482 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 494 402 // #pragma mark - 495 403 496 404 497 TranslatorReadView::TranslatorReadView(BRect frame, const char *name, 498 jpeg_settings *settings) 499 : SView(frame, name), 405 TranslatorReadView::TranslatorReadView(const char* name, 406 TranslatorSettings* settings) 407 : 408 BView(name, 0, new BGroupLayout(B_HORIZONTAL)), 500 409 fSettings(settings) 410 // settings should already be Acquired() 501 411 { 502 BRect rect(5, 5, 30, 30); 503 fAlwaysRGB32 = new BCheckBox(rect, "alwaysrgb32", VIEW_LABEL_ALWAYSRGB32, 412 fAlwaysRGB32 = new BCheckBox("alwaysrgb32", VIEW_LABEL_ALWAYSRGB32, 504 413 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); 508 416 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, 514 418 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); 522 421 523 fShowErrorBox = new BCheckBox( rect,"error", VIEW_LABEL_SHOWREADERRORBOX,422 fShowErrorBox = new BCheckBox("error", VIEW_LABEL_SHOWREADERRORBOX, 524 423 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); 528 426 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 ); 530 435 531 fShowErrorBox->ResizeToPreferred();532 436 } 533 437 534 438 439 TranslatorReadView::~TranslatorReadView() 440 { 441 fSettings->Release(); 442 } 443 444 535 445 void 536 446 TranslatorReadView::AttachedToWindow() 537 447 { 538 SView::AttachedToWindow();448 BView::AttachedToWindow(); 539 449 540 450 fAlwaysRGB32->SetTarget(this); 541 451 fPhotoshopCMYK->SetTarget(this); … … 551 461 { 552 462 int32 value; 553 463 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(); 556 467 } 557 468 break; 558 469 } … … 560 471 { 561 472 int32 value; 562 473 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(); 565 477 } 566 478 break; 567 479 } … … 569 481 { 570 482 int32 value; 571 483 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(); 574 487 } 575 488 break; 576 489 } … … 584 497 // #pragma mark - TranslatorWriteView 585 498 586 499 587 TranslatorWriteView::TranslatorWriteView(BRect frame, const char *name, 588 jpeg_settings *settings) 589 : SView(frame, name), 500 TranslatorWriteView::TranslatorWriteView(const char* name, 501 TranslatorSettings* settings) 502 : 503 BView(name, 0, new BGroupLayout(B_VERTICAL)), 590 504 fSettings(settings) 505 // settings should already be Acquired() 591 506 { 592 BRect rect(10, 10, 20, 30); 593 fQualitySlider = new SSlider(rect, "quality", VIEW_LABEL_QUALITY, 507 fQualitySlider = new SSlider("quality", VIEW_LABEL_QUALITY, 594 508 new BMessage(VIEW_MSG_SET_QUALITY), 0, 100); 595 509 fQualitySlider->SetHashMarks(B_HASH_MARKS_BOTTOM); 596 510 fQualitySlider->SetHashMarkCount(10); 597 511 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)); 602 513 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, 606 515 new BMessage(VIEW_MSG_SET_SMOOTHING), 0, 100); 607 516 fSmoothingSlider->SetHashMarks(B_HASH_MARKS_BOTTOM); 608 517 fSmoothingSlider->SetHashMarkCount(10); 609 518 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)); 614 521 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, 618 523 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); 622 526 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, 639 528 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 644 537 fSmallerFile->SetEnabled(false); 645 538 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, 651 540 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); 655 543 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 } 657 556 658 fGrayAsRGB24->ResizeToPreferred(); 557 558 TranslatorWriteView::~TranslatorWriteView() 559 { 560 fSettings->Release(); 659 561 } 660 562 661 563 662 564 void 663 565 TranslatorWriteView::AttachedToWindow() 664 566 { 665 SView::AttachedToWindow();567 BView::AttachedToWindow(); 666 568 667 569 fQualitySlider->SetTarget(this); 668 570 fSmoothingSlider->SetTarget(this); … … 674 576 675 577 676 578 void 677 TranslatorWriteView::MessageReceived(BMessage *message)579 TranslatorWriteView::MessageReceived(BMessage* message) 678 580 { 679 581 switch (message->what) { 680 582 case VIEW_MSG_SET_QUALITY: 681 583 { 682 584 int32 value; 683 585 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(); 686 588 } 687 589 break; 688 590 } … … 690 592 { 691 593 int32 value; 692 594 if (message->FindInt32("be:value", &value) == B_OK) { 693 fSettings->S moothing = value;694 SaveSettings(fSettings);595 fSettings->SetGetInt32(JPEG_SET_SMOOTHING, &value); 596 fSettings->SaveSettings(); 695 597 } 696 598 break; 697 599 } … … 699 601 { 700 602 int32 value; 701 603 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(); 704 607 } 705 608 break; 706 609 } … … 708 611 { 709 612 int32 value; 710 613 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(); 713 618 } 714 fSmallerFile->SetEnabled(fSettings->OptimizeColors);715 619 break; 716 620 } 717 621 case VIEW_MSG_SET_SMALLERFILE: 718 622 { 719 623 int32 value; 720 624 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(); 723 628 } 724 629 break; 725 630 } … … 727 632 { 728 633 int32 value; 729 634 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(); 732 638 } 733 639 break; 734 640 } … … 742 648 // #pragma mark - 743 649 744 650 745 TranslatorAboutView::TranslatorAboutView(BRect frame, const char *name) 746 : SView(frame, name) 651 TranslatorAboutView::TranslatorAboutView(const char* name) 652 : 653 BView(name, 0, new BGroupLayout(B_VERTICAL)) 747 654 { 748 B StringView *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); 750 657 title->SetFont(be_bold_font); 658 title->SetExplicitAlignment(labelAlignment); 751 659 752 AddChild(title);753 title->ResizeToPreferred();754 755 BRect rect = title->Bounds();756 float space = title->StringWidth(" ");757 758 660 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)); 761 663 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); 769 666 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 ); 797 682 } 798 683 799 684 800 // #pragma mark - 801 802 803 TranslatorView::TranslatorView(BRect frame, const char *name) 804 : BTabView(frame, name) 685 TranslatorView::TranslatorView(const char* name, TranslatorSettings* settings) 686 : 687 BTabView(name) 805 688 { 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")); 808 692 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)); 822 699 } 823 700 824 701 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 close845 if (quitOnClose)846 SetFlags(Flags() | B_QUIT_ON_WINDOW_CLOSE);847 }848 849 850 702 // #pragma mark - Translator Add-On 851 703 852 704 853 854 /*! Hook to create and return our configuration view */ 855 status_t 856 MakeConfig(BMessage *ioExtension, BView **outView, BRect *outExtent) 705 BView* 706 JPEGTranslator::NewConfigView(TranslatorSettings* settings) 857 707 { 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; 861 710 } 862 711 712 863 713 /*! Determine whether or not we can handle this data */ 864 714 status_t 865 Identify(BPositionIO *inSource, const translation_format *inFormat, 866 BMessage *ioExtension, translator_info *outInfo, uint32 outType) 715 JPEGTranslator::DerivedIdentify(BPositionIO* inSource, 716 const translation_format* inFormat, BMessage* ioExtension, 717 translator_info* outInfo, uint32 outType) 867 718 { 868 719 if (outType != 0 && outType != B_TRANSLATOR_BITMAP && outType != JPEG_FORMAT) 869 720 return B_NO_TRANSLATOR; … … 877 728 return err; 878 729 879 730 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; 887 733 } else { 888 734 // First 3 bytes in jpg files are always the same from what i've seen so far 889 735 // check them 890 736 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) 913 738 return B_NO_TRANSLATOR; 914 */ 739 915 740 } else 916 741 return B_NO_TRANSLATOR; 917 742 } … … 919 744 return B_OK; 920 745 } 921 746 922 /*! Arguably the most important method in the add-on */ 747 923 748 status_t 924 Translate(BPositionIO *inSource, const translator_info *inInfo, 925 BMessage *ioExtension, uint32 outType, BPositionIO *outDestination) 749 JPEGTranslator::DerivedTranslate(BPositionIO* inSource, 750 const translator_info* inInfo, BMessage* ioExtension, uint32 outType, 751 BPositionIO* outDestination, int32 baseType) 926 752 { 927 753 // If no specific type was requested, convert to the interchange format 928 754 if (outType == 0) … … 961 787 return B_NO_TRANSLATOR; 962 788 } 963 789 790 964 791 /*! The user has requested the same format for input and output, so just copy */ 965 stat ic status_t966 Copy(BPositionIO *in, BPositionIO *out)792 status_t 793 JPEGTranslator::Copy(BPositionIO* in, BPositionIO* out) 967 794 { 968 795 int block_size = 65536; 969 void *buffer = malloc(block_size);796 void* buffer = malloc(block_size); 970 797 char temp[1024]; 971 798 if (buffer == NULL) { 972 799 buffer = temp; … … 996 823 997 824 998 825 /*! Encode into the native format */ 999 static status_t 1000 Compress(BPositionIO *in, BPositionIO *out, const jmp_buf* longJumpBuffer) 826 status_t 827 JPEGTranslator::Compress(BPositionIO* in, BPositionIO* out, 828 const jmp_buf* longJumpBuffer) 1001 829 { 1002 // Load Settings 1003 jpeg_settings settings; 1004 LoadSettings(&settings); 830 using namespace conversion; 1005 831 1006 832 // Read info about bitmap 1007 833 TranslatorBitmap header; … … 1025 851 1026 852 // Function pointer to convert function 1027 853 // It will point to proper function if needed 1028 void (*converter)(uchar *inscanline, uchar *outscanline,854 void (*converter)(uchar* inscanline, uchar* outscanline, 1029 855 int32 inRowBytes) = NULL; 1030 856 1031 857 // Default color info … … 1041 867 break; 1042 868 1043 869 case B_GRAY1: 1044 if ( settings.B_GRAY1_as_B_RGB24) {870 if (fSettings->SetGetBool(JPEG_SET_GRAY1_AS_RGB24, NULL)) { 1045 871 converter = convert_from_gray1_to_24; 1046 872 } else { 1047 873 jpg_input_components = 1; 1048 874 jpg_color_space = JCS_GRAYSCALE; 1049 875 converter = convert_from_gray1_to_gray8; 1050 876 } 1051 padding = in_row_bytes - (width /8);877 padding = in_row_bytes - (width / 8); 1052 878 break; 1053 879 1054 880 case B_GRAY8: … … 1115 941 // Set basic things needed for jpeg writing 1116 942 struct jpeg_compress_struct cinfo; 1117 943 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); 1119 945 jpeg_create_compress(&cinfo); 1120 946 be_jpeg_stdio_dest(&cinfo, out); 1121 947 … … 1131 957 1132 958 // This is needed to prevent some colors loss 1133 959 // 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)) { 1135 961 int index = 0; 1136 962 while (index < cinfo.num_components) { 1137 963 cinfo.comp_info[index].h_samp_factor = 1; … … 1139 965 // This will make file smaller, but with worse quality more or less 1140 966 // like with 93%-94% (but it's subjective opinion) on tested images 1141 967 // but with smaller size (between 92% and 93% on tested images) 1142 if ( settings.SmallerFile)968 if (fSettings->SetGetBool(JPEG_SET_SMALL_FILES)) 1143 969 cinfo.comp_info[index].quant_tbl_no = 1; 1144 970 // This will make bigger file, but also better quality ;] 1145 971 // from my tests it seems like useless - better quality with smaller … … 1151 977 } 1152 978 1153 979 // Set quality 1154 jpeg_set_quality(&cinfo, settings.Quality, true);980 jpeg_set_quality(&cinfo, fSettings->SetGetInt32(JPEG_SET_QUALITY, NULL), true); 1155 981 1156 982 // Set progressive compression if needed 1157 983 // if not, turn on optimizing in libjpeg 1158 if ( settings.Progressive)984 if (fSettings->SetGetBool(JPEG_SET_PROGRESSIVE, NULL)) 1159 985 jpeg_simple_progression(&cinfo); 1160 986 else 1161 987 cinfo.optimize_coding = TRUE; 1162 988 1163 989 // Set smoothing (effect like Blur) 1164 cinfo.smoothing_factor = settings.Smoothing;990 cinfo.smoothing_factor = fSettings->SetGetInt32(JPEG_SET_SMOOTHING, NULL); 1165 991 1166 992 // Initialize compression 1167 993 jpeg_start_compress(&cinfo, TRUE); … … 1169 995 // Declare scanlines 1170 996 JSAMPROW in_scanline = NULL; 1171 997 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) 1173 1000 1174 1001 // Allocate scanline 1175 1002 // Use libjpeg memory allocation functions, so in case of error it will free them itself … … 1209 1036 1210 1037 1211 1038 /*! Decode the native format */ 1212 stat ic status_t1213 Decompress(BPositionIO *in, BPositionIO *out, BMessage* ioExtension,1214 const jmp_buf* longJumpBuffer)1039 status_t 1040 JPEGTranslator::Decompress(BPositionIO* in, BPositionIO* out, 1041 BMessage* ioExtension, const jmp_buf* longJumpBuffer) 1215 1042 { 1216 // Load Settings 1217 jpeg_settings settings; 1218 LoadSettings(&settings); 1043 using namespace conversion; 1219 1044 1220 1045 // Set basic things needed for jpeg reading 1221 1046 struct jpeg_decompress_struct cinfo; 1222 1047 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); 1224 1049 jpeg_create_decompress(&cinfo); 1225 1050 be_jpeg_stdio_src(&cinfo, in); 1226 1051 … … 1240 1065 if (ioExtension != NULL) { 1241 1066 // Strip EXIF header from TIFF data 1242 1067 ioExtension->AddData("exif", B_RAW_TYPE, 1243 (uint8 *)marker->data + 6, marker->data_length - 6);1068 (uint8* )marker->data + 6, marker->data_length - 6); 1244 1069 } 1245 1070 1246 1071 BMemoryIO io(marker->data + 6, marker->data_length - 6); … … 1255 1080 1256 1081 // Function pointer to convert function 1257 1082 // It will point to proper function if needed 1258 void (*converter)(uchar *inScanLine, uchar *outScanLine,1083 void (*converter)(uchar* inScanLine, uchar* outScanLine, 1259 1084 int32 inRowBytes, int32 xStep) = convert_from_24_to_32; 1260 1085 1261 1086 // If color space isn't rgb … … 1266 1091 break; 1267 1092 case JCS_GRAYSCALE: /* monochrome */ 1268 1093 // 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)) { 1270 1095 // Grayscale 1271 1096 outColorSpace = B_GRAY8; 1272 1097 outColorComponents = 1; … … 1288 1113 // Fall through to CMYK since we need the same settings 1289 1114 case JCS_CMYK: /* C/M/Y/K */ 1290 1115 // Use proper converter 1291 if ( settings.PhotoshopCMYK)1116 if (fSettings->SetGetBool(JPEG_SET_PHOTOSHOP_CMYK)) 1292 1117 converter = convert_from_CMYK_to_32_photoshop; 1293 1118 else 1294 1119 converter = convert_from_CMYK_to_32; … … 1412 1237 return B_OK; 1413 1238 } 1414 1239 1240 /*! have the other PopulateInfoFromFormat() check both inputFormats & outputFormats */ 1241 status_t 1242 JPEGTranslator::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 1259 status_t 1260 JPEGTranslator::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 1415 1278 /*! 1416 1279 Frees jpeg alocated memory 1417 1280 Returns given error (B_ERROR by default) 1418 1281 */ 1419 stat ic status_t1420 Error(j_common_ptr cinfo, status_t error)1282 status_t 1283 JPEGTranslator::Error(j_common_ptr cinfo, status_t error) 1421 1284 { 1422 1285 jpeg_destroy(cinfo); 1423 1286 return error; 1424 1287 } 1425 1288 1426 1289 1427 // #pragma mark - 1290 JPEGTranslator::JPEGTranslator() 1291 : 1292 BaseTranslator(gTranslatorName, gTranslatorInfo, gTranslatorVersion, 1293 gInputFormats, gInputFormatCount, gOutputFormats, gOutputFormatCount, 1294 SETTINGS_FILE, gSettings, gSettingsCount, 1295 B_TRANSLATOR_BITMAP, JPEG_FORMAT) 1296 {} 1428 1297 1429 1298 1299 BTranslator* 1300 make_nth_translator(int32 n, image_id you, uint32 flags, ...) 1301 { 1302 if (!n) 1303 return new JPEGTranslator(); 1304 1305 return NULL; 1306 } 1307 1308 1430 1309 int 1431 1310 main(int, char**) 1432 1311 { 1433 1312 BApplication app("application/x-vnd.Haiku-JPEGTranslator"); 1313 JPEGTranslator* translator = new JPEGTranslator(); 1314 if (LaunchTranslatorWindow(translator, gTranslatorName) == B_OK) 1315 app.Run(); 1434 1316 1435 TranslatorWindow *window = new TranslatorWindow();1436 window->Show();1437 1438 app.Run();1439 1317 return 0; 1440 1318 } 1441 1319 -
src/add-ons/translators/jpeg/JPEGTranslator.h
50 50 51 51 #include <jpeglib.h> 52 52 53 #include "BaseTranslator.h" 53 54 54 55 // Settings 55 56 #define SETTINGS_FILE "JPEGTranslator" … … 76 77 #define VIEW_LABEL_PHOTOSHOPCMYK "Use CMYK code with 0 for 100% ink coverage" 77 78 #define VIEW_LABEL_SHOWREADERRORBOX "Show warning messages" 78 79 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" 79 90 80 //! Settings storage structure81 struct jpeg_settings {82 // compression83 uchar Smoothing; // default: 084 uchar Quality; // default: 9585 bool Progressive; // default: true86 bool OptimizeColors; // default: true87 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 rgb2489 // decompression90 bool Always_B_RGB32; // default: true91 bool PhotoshopCMYK; // default: true92 bool ShowReadWarningBox; // default: true93 };94 91 95 92 96 93 /*! … … 99 96 */ 100 97 class SSlider : public BSlider { 101 98 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); 108 104 virtual const char* UpdateText() const; 109 void ResizeToPreferred();110 105 111 106 private: 112 107 mutable char fStatusLabel[12]; 113 108 }; 114 109 115 110 116 class SView : public BView { 117 public: 118 SView(BRect frame, const char *name); 119 virtual void AttachedToWindow(); 111 class 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); 120 139 }; 140 121 141 122 //! Configuration view for reading settings 123 class TranslatorReadView : public SView { 142 class TranslatorReadView : public BView { 124 143 public: 125 TranslatorReadView(BRect frame, const char* name, jpeg_settings* settings); 144 TranslatorReadView(const char* name, TranslatorSettings* settings); 145 virtual ~TranslatorReadView(); 126 146 127 147 virtual void AttachedToWindow(); 128 148 virtual void MessageReceived(BMessage* message); 129 149 130 150 private: 131 jpeg_settings*fSettings;151 TranslatorSettings* fSettings; 132 152 BCheckBox* fAlwaysRGB32; 133 153 BCheckBox* fPhotoshopCMYK; 134 154 BCheckBox* fShowErrorBox; 135 155 }; 136 156 137 157 138 //! Configuration view for writing settings 139 class TranslatorWriteView : public SView { 158 class TranslatorWriteView : public BView { 140 159 public: 141 TranslatorWriteView(BRect frame, const char* name, jpeg_settings* settings); 160 TranslatorWriteView(const char* name, TranslatorSettings* settings); 161 virtual ~TranslatorWriteView(); 142 162 143 163 virtual void AttachedToWindow(); 144 164 virtual void MessageReceived(BMessage* message); 145 165 146 166 private: 147 jpeg_settings*fSettings;167 TranslatorSettings* fSettings; 148 168 SSlider* fQualitySlider; 149 169 SSlider* fSmoothingSlider; 150 170 BCheckBox* fProgress; … … 153 173 BCheckBox* fGrayAsRGB24; 154 174 }; 155 175 156 class TranslatorAboutView : public SView { 176 177 class TranslatorAboutView : public BView { 157 178 public: 158 TranslatorAboutView( BRect frame,const char* name);179 TranslatorAboutView(const char* name); 159 180 }; 160 181 161 //! Configuration view 182 162 183 class TranslatorView : public BTabView { 163 184 public: 164 TranslatorView(BRect frame, const char *name); 165 virtual ~TranslatorView(); 185 TranslatorView(const char* name, TranslatorSettings* settings); 166 186 167 187 private: 168 jpeg_settings fSettings; 188 BView* fAboutView; 189 BView* fReadView; 190 BView* fWriteView; 169 191 }; 170 192 171 //! Window used for configuration172 class TranslatorWindow : public BWindow {173 public:174 TranslatorWindow(bool quitOnClose = true);175 };176 193 177 178 194 //--------------------------------------------------- 179 195 // "Initializers" for jpeglib 180 196 // based on default ones, … … 190 206 // (so user can decide to show dialog-boxes or not) 191 207 //--------------------------------------------------- 192 208 EXTERN(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); 194 210 // implemented in "be_jerror.cpp" 195 211 196 212 #endif // _JPEGTRANSLATOR_H_ -
src/add-ons/translators/jpeg/Jamfile
5 5 SubDirSysHdrs [ FDirName $(SUBDIR) $(DOTDOT) raw ] ; 6 6 # for TIFF.h and ReadHelper.h 7 7 8 SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) shared ] ; 9 #for BaseTranslator.h and friends 10 8 11 UseLibraryHeaders jpeg ; 9 12 10 13 Translator JPEGTranslator : … … 13 16 be_jerror.cpp 14 17 exif_parser.cpp 15 18 JPEGTranslator.cpp 16 17 : be translation libjpeg.so $(TARGET_LIBSTDC++) 19 : be translation libtranslatorsutils.a libjpeg.so $(TARGET_LIBSTDC++) 18 20 : true 19 21 ; 20 22 -
src/add-ons/translators/jpeg/be_jerror.cpp
46 46 #include <jconfig.h> 47 47 #include <jerror.h> 48 48 49 // JPEGTtanslator settings header to get SETTINGS struct49 // JPEGTtanslator settings header to get settings stuff 50 50 #include "JPEGTranslator.h" 51 #include "TranslatorSettings.h" 51 52 52 53 53 54 // Since Translator doesn't use it's own error table, we can use error_mgr's … … 109 110 */ 110 111 111 112 GLOBAL(struct jpeg_error_mgr *) 112 be_jpeg_std_error (struct jpeg_error_mgr * err, jpeg_settings *settings,113 be_jpeg_std_error (struct jpeg_error_mgr * err, TranslatorSettings* settings, 113 114 const jmp_buf* longJumpBuffer) 114 115 { 116 settings->Acquire(); 115 117 jpeg_std_error(err); 116 118 117 119 err->error_exit = be_error_exit; 118 120 err->output_message = be_output_message; 119 121 120 err->ShowReadWarnings = settings->S howReadWarningBox;122 err->ShowReadWarnings = settings->SetGetBool(JPEG_SET_SHOWREADWARNING, NULL); 121 123 memcpy(&(err->long_jump_buffer), longJumpBuffer, sizeof(jmp_buf)); 122 124 125 settings->Release(); 123 126 return err; 124 127 }