Ticket #2117: jpeg2000.patch
File jpeg2000.patch, 39.2 KB (added by , 14 years ago) |
---|
-
src/add-ons/translators/jpeg2000/JPEG2000Translator.cpp
33 33 #include "JPEG2000Translator.h" 34 34 #include "jp2_cod.h" 35 35 #include "jpc_cs.h" 36 #include "TranslatorWindow.h" 36 37 38 #include <GroupLayoutBuilder.h> 37 39 #include <TabView.h> 40 #include <TextView.h> 38 41 39 42 40 43 // Set these accordingly … … 47 50 #define B_TRANSLATOR_BITMAP_MIME_STRING "image/x-be-bitmap" 48 51 #define B_TRANSLATOR_BITMAP_DESCRIPTION "Be Bitmap Format (JPEG2000Translator)" 49 52 50 // Translation Kit required globals 51 char translatorName[] = "JPEG2000 images"; 52 char translatorInfo[] = "©2002-2003, Shard\n" 53 const char gTranslatorName[] = "JPEG2000 images"; 54 const char gTranslatorInfo[] = "©2002-2003, Shard\n" 53 55 "©2005-2006, Haiku\n" 54 56 "\n" 55 57 "Based on JasPer library:\n" … … 61 63 "ImageMagick's jp2 codec was used as \"tutorial\".\n" 62 64 " http://www.imagemagick.org/\n"; 63 65 64 int32 translatorVersion = 0x100;66 int32 gTranslatorVersion = B_TRANSLATION_MAKE_VERSION(1, 0, 0); 65 67 66 // Define the formats we know how to read 67 translation_format inputFormats[] = { 68 translation_format gInputFormats[] = { 68 69 { JP2_FORMAT, B_TRANSLATOR_BITMAP, 0.5, 0.5, 69 70 JP2_MIME_STRING, JP2_DESCRIPTION }, 70 71 { B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP, 0.5, 0.5, 71 72 B_TRANSLATOR_BITMAP_MIME_STRING, B_TRANSLATOR_BITMAP_DESCRIPTION }, 72 {},73 73 }; 74 const int gInputFormatCount = 75 sizeof(gInputFormats) / sizeof(translation_format); 74 76 75 // Define the formats we know how to write 76 translation_format outputFormats[] = { 77 translation_format gOutputFormats[] = { 77 78 { JP2_FORMAT, B_TRANSLATOR_BITMAP, 0.5, 0.5, 78 79 JP2_MIME_STRING, JP2_DESCRIPTION }, 79 80 { B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP, 0.5, 0.5, 80 81 B_TRANSLATOR_BITMAP_MIME_STRING, B_TRANSLATOR_BITMAP_DESCRIPTION }, 81 {},82 82 }; 83 const int gOutputFormatCount = 84 sizeof(gOutputFormats) / sizeof(translation_format); 83 85 84 86 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 } 87 TranSetting 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 }; 93 const int gSettingsCount = sizeof(gSettings) / sizeof(TranSetting) ; 94 94 95 95 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 96 namespace conversion{ 154 97 //! Make RGB32 scanline from *pixels[3] 155 98 inline void 156 read_rgb24_to_rgb32(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)99 read_rgb24_to_rgb32(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width) 157 100 { 158 101 int32 index = 0; 159 102 int32 x = 0; … … 169 112 170 113 //! Make gray scanline from *pixels[1] 171 114 inline void 172 read_gray_to_rgb32(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)115 read_gray_to_rgb32(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width) 173 116 { 174 117 int32 index = 0; 175 118 int32 x = 0; … … 189 132 (just read data to scanline) 190 133 */ 191 134 inline void 192 read_rgba32(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)135 read_rgba32(jas_matrix_t** pixels, jpr_uchar_t *scanline, int width) 193 136 { 194 137 int32 index = 0; 195 138 int32 x = 0; … … 208 151 (just read data to scanline) 209 152 */ 210 153 inline void 211 read_gray(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)154 read_gray(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width) 212 155 { 213 156 int32 x = 0; 214 157 while (x < width) { … … 220 163 221 164 //! Make *pixels[1] from gray1 scanline 222 165 inline void 223 write_gray1_to_gray(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)166 write_gray1_to_gray(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width) 224 167 { 225 168 int32 x = 0; 226 169 int32 index = 0; … … 238 181 239 182 //! Make *pixels[3] from gray1 scanline 240 183 inline void 241 write_gray1_to_rgb24(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)184 write_gray1_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width) 242 185 { 243 186 int32 x = 0; 244 187 int32 index = 0; 245 while (x < (width /8)) {188 while (x < (width / 8)) { 246 189 unsigned char c = scanline[x++]; 247 190 for (int b = 128; b; b = b >> 1) { 248 191 if (c & b) { … … 262 205 263 206 //! Make *pixels[3] from cmap8 scanline 264 207 inline void 265 write_cmap8_to_rgb24(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)208 write_cmap8_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width) 266 209 { 267 const color_map *map = system_colors();210 const color_map* map = system_colors(); 268 211 int32 x = 0; 269 212 while (x < width) { 270 213 rgb_color color = map->color_list[scanline[x]]; … … 282 225 (just write data to pixels) 283 226 */ 284 227 inline void 285 write_gray(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)228 write_gray(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width) 286 229 { 287 230 int32 x = 0; 288 231 while (x < width) { … … 297 240 (just write data to pixels) 298 241 */ 299 242 inline void 300 write_rgb15_to_rgb24(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)243 write_rgb15_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width) 301 244 { 302 245 int32 x = 0; 303 246 int32 index = 0; … … 306 249 in_pixel = scanline[index] | (scanline[index+1] << 8); 307 250 index += 2; 308 251 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)); 312 258 x++; 313 259 } 314 260 } … … 319 265 (just write data to pixels) 320 266 */ 321 267 inline void 322 write_rgb15b_to_rgb24(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)268 write_rgb15b_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width) 323 269 { 324 270 int32 x = 0; 325 271 int32 index = 0; 326 272 int16 in_pixel; 327 273 while (x < width) { 328 in_pixel = scanline[index +1] | (scanline[index] << 8);274 in_pixel = scanline[index + 1] | (scanline[index] << 8); 329 275 index += 2; 330 276 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)); 334 283 x++; 335 284 } 336 285 } … … 341 290 (just write data to pixels) 342 291 */ 343 292 inline void 344 write_rgb16_to_rgb24(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)293 write_rgb16_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width) 345 294 { 346 295 int32 x = 0; 347 296 int32 index = 0; … … 350 299 in_pixel = scanline[index] | (scanline[index+1] << 8); 351 300 index += 2; 352 301 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)); 356 308 x++; 357 309 } 358 310 } … … 363 315 (just write data to pixels) 364 316 */ 365 317 inline void 366 write_rgb16b_to_rgb24(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)318 write_rgb16b_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width) 367 319 { 368 320 int32 x = 0; 369 321 int32 index = 0; 370 322 int16 in_pixel; 371 323 while (x < width) { 372 in_pixel = scanline[index +1] | (scanline[index] << 8);324 in_pixel = scanline[index + 1] | (scanline[index] << 8); 373 325 index += 2; 374 326 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)); 378 333 x++; 379 334 } 380 335 } … … 385 340 (just write data to pixels) 386 341 */ 387 342 inline void 388 write_rgb24(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)343 write_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width) 389 344 { 390 345 int32 index = 0; 391 346 int32 x = 0; … … 403 358 (just write data to pixels) 404 359 */ 405 360 inline void 406 write_rgb24b(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)361 write_rgb24b(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width) 407 362 { 408 363 int32 index = 0; 409 364 int32 x = 0; … … 421 376 (just write data to pixels) 422 377 */ 423 378 inline void 424 write_rgb32_to_rgb24(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)379 write_rgb32_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width) 425 380 { 426 381 int32 index = 0; 427 382 int32 x = 0; … … 440 395 (just write data to pixels) 441 396 */ 442 397 inline void 443 write_rgb32b_to_rgb24(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)398 write_rgb32b_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width) 444 399 { 445 400 int32 index = 0; 446 401 int32 x = 0; … … 460 415 !!! UNTESTED !!! 461 416 */ 462 417 inline void 463 write_rgba32(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)418 write_rgba32(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width) 464 419 { 465 420 int32 index = 0; 466 421 int32 x = 0; … … 480 435 !!! UNTESTED !!! 481 436 */ 482 437 inline void 483 write_rgba32b(jas_matrix_t **pixels, jpr_uchar_t *scanline, int width)438 write_rgba32b(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width) 484 439 { 485 440 int32 index = 0; 486 441 int32 x = 0; … … 495 450 } 496 451 497 452 453 }// end namespace conversion 454 455 498 456 // #pragma mark - jasper I/O 499 457 500 458 501 459 static int 502 Read(jas_stream_obj_t *object, char *buffer, const int length)460 Read(jas_stream_obj_t* object, char* buffer, const int length) 503 461 { 504 462 return (*(BPositionIO**)object)->Read(buffer, length); 505 463 } 506 464 507 465 508 466 static int 509 Write(jas_stream_obj_t *object, char *buffer, const int length)467 Write(jas_stream_obj_t* object, char* buffer, const int length) 510 468 { 511 469 return (*(BPositionIO**)object)->Write(buffer, length); 512 470 } 513 471 514 472 515 473 static long 516 Seek(jas_stream_obj_t *object, long offset, int origin)474 Seek(jas_stream_obj_t* object, long offset, int origin) 517 475 { 518 476 return (*(BPositionIO**)object)->Seek(offset, origin); 519 477 } 520 478 521 479 522 480 static int 523 Close(jas_stream_obj_t *object)481 Close(jas_stream_obj_t* object) 524 482 { 525 483 return 0; 526 484 } … … 534 492 }; 535 493 536 494 537 static jas_stream_t *495 static jas_stream_t* 538 496 jas_stream_positionIOopen(BPositionIO *positionIO) 539 497 { 540 jas_stream_t *stream;498 jas_stream_t* stream; 541 499 542 500 stream = (jas_stream_t *)malloc(sizeof(jas_stream_t)); 543 501 if (stream == (jas_stream_t *)NULL) … … 564 522 } 565 523 566 524 567 // #pragma mark - SView568 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 void581 SView::AttachedToWindow()582 {583 BView::AttachedToWindow();584 ResizeTo(Parent()->Bounds().Width(), Parent()->Bounds().Height());585 }586 587 588 525 // #pragma mark - 589 526 590 527 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) 528 SSlider::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) 596 534 { 597 535 rgb_color barColor = { 0, 0, 229, 255 }; 598 536 UseFillColor(true, &barColor); … … 608 546 } 609 547 610 548 611 //! BSlider::ResizeToPreferred + Resize width if it's too small to show label612 // and status613 void614 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 626 549 // #pragma mark - 627 550 628 551 629 TranslatorReadView::TranslatorReadView(BRect frame, const char *name, 630 jpeg_settings *settings) 631 : SView(frame, name), 552 TranslatorReadView::TranslatorReadView(const char* name, 553 TranslatorSettings* settings) 554 : 555 BView(name, 0, new BGroupLayout(B_VERTICAL)), 632 556 fSettings(settings) 633 557 { 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); 639 562 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 ); 642 569 } 643 570 644 571 572 TranslatorReadView::~TranslatorReadView() 573 { 574 fSettings->Release(); 575 } 576 577 645 578 void 646 579 TranslatorReadView::AttachedToWindow() 647 580 { 648 SView::AttachedToWindow();649 581 fGrayAsRGB32->SetTarget(this); 650 582 } 651 583 652 584 653 585 void 654 TranslatorReadView::MessageReceived(BMessage *message)586 TranslatorReadView::MessageReceived(BMessage* message) 655 587 { 656 588 switch (message->what) { 657 589 case VIEW_MSG_SET_GRAYASRGB32: 658 590 { 659 591 int32 value; 660 592 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(); 663 596 } 664 597 break; 665 598 } … … 673 606 // #pragma mark - TranslatorWriteView 674 607 675 608 676 TranslatorWriteView::TranslatorWriteView(BRect frame, const char *name, 677 jpeg_settings *settings) 678 : SView(frame, name), 609 TranslatorWriteView::TranslatorWriteView(const char* name, 610 TranslatorSettings* settings) 611 : 612 BView(name, 0, new BGroupLayout(B_VERTICAL)), 679 613 fSettings(settings) 680 614 { 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); 684 617 fQualitySlider->SetHashMarks(B_HASH_MARKS_BOTTOM); 685 618 fQualitySlider->SetHashMarkCount(10); 686 619 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)); 691 621 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, 696 623 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); 700 626 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); 705 631 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 } 711 641 712 AddChild(fCodeStreamOnly); 713 714 fCodeStreamOnly->ResizeToPreferred(); 642 643 TranslatorWriteView::~TranslatorWriteView() 644 { 645 fSettings->Release(); 715 646 } 716 647 717 648 718 649 void 719 650 TranslatorWriteView::AttachedToWindow() 720 651 { 721 SView::AttachedToWindow();722 723 652 fQualitySlider->SetTarget(this); 724 653 fGrayAsRGB24->SetTarget(this); 725 654 fCodeStreamOnly->SetTarget(this); … … 727 656 728 657 729 658 void 730 TranslatorWriteView::MessageReceived(BMessage *message)659 TranslatorWriteView::MessageReceived(BMessage* message) 731 660 { 732 661 switch (message->what) { 733 662 case VIEW_MSG_SET_QUALITY: 734 663 { 735 664 int32 value; 736 665 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(); 739 668 } 740 669 break; 741 670 } … … 743 672 { 744 673 int32 value; 745 674 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(); 748 678 } 749 679 break; 750 680 } … … 752 682 { 753 683 int32 value; 754 684 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(); 757 688 } 758 689 break; 759 690 } … … 767 698 // #pragma mark - 768 699 769 700 770 TranslatorAboutView::TranslatorAboutView(BRect frame, const char *name) 771 : SView(frame, name) 701 TranslatorAboutView::TranslatorAboutView(const char* name) 702 : 703 BView(name, 0, new BGroupLayout(B_VERTICAL)) 772 704 { 773 B StringView *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); 775 707 title->SetFont(be_bold_font); 708 title->SetExplicitAlignment(labelAlignment); 776 709 777 AddChild(title);778 title->ResizeToPreferred();779 780 BRect rect = title->Bounds();781 float space = title->StringWidth(" ");782 783 710 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)); 786 713 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); 794 716 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); 796 721 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 ); 825 732 } 826 733 827 734 828 735 // #pragma mark - 829 736 830 737 831 TranslatorView::TranslatorView(BRect frame, const char *name) 832 : BTabView(frame, name) 738 TranslatorView::TranslatorView(const char* name, TranslatorSettings* settings) 739 : 740 BTabView(name) 833 741 { 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")); 851 745 746 settings->Release(); 852 747 853 TranslatorView::~TranslatorView() 854 { 748 BFont font; 749 GetFont(&font); 750 SetExplicitPreferredSize( 751 BSize((font.Size() * 380) / 12, (font.Size() * 250) / 12)); 855 752 } 856 753 857 754 858 755 // #pragma mark - 859 756 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) 757 BView* 758 JP2Translator::NewConfigView(TranslatorSettings* settings) 864 759 { 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; 875 762 } 876 763 877 764 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)765 JP2Translator::JP2Translator() 766 : 767 BaseTranslator(gTranslatorName, gTranslatorInfo, gTranslatorVersion, 768 gInputFormats, gInputFormatCount, 769 gOutputFormats, gOutputFormatCount, JP2_SETTINGS_FILE, 770 gSettings, gSettingsCount, B_TRANSLATOR_BITMAP, JP2_FORMAT) 884 771 { 885 *outView = new TranslatorView(BRect(0, 0, 300, 250), "TranslatorView");886 *outExtent = (*outView)->Frame();887 return B_OK;888 772 } 889 773 890 774 891 775 //! Determine whether or not we can handle this data 892 776 status_t 893 Identify(BPositionIO *inSource, const translation_format *inFormat, 894 BMessage *ioExtension, translator_info *outInfo, uint32 outType) 777 JP2Translator::DerivedIdentify(BPositionIO* inSource, 778 const translation_format* inFormat, BMessage* ioExtension, 779 translator_info* outInfo, uint32 outType) 895 780 { 896 781 if ((outType != 0) && (outType != B_TRANSLATOR_BITMAP) 897 782 && outType != JP2_FORMAT) … … 908 793 909 794 if (B_BENDIAN_TO_HOST_INT32(((TranslatorBitmap *)header)->magic) 910 795 == 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; 918 798 } else { 919 799 if ((((header[4] << 24) | (header[5] << 16) | (header[6] << 8) 920 800 | header[7]) == JP2_BOX_JP) // JP2 921 801 || (header[0] == (JPC_MS_SOC >> 8) && header[1] 922 802 == (JPC_MS_SOC & 0xff))) // JPC 923 803 { 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; 932 806 } else 933 807 return B_NO_TRANSLATOR; 934 808 } … … 937 811 } 938 812 939 813 940 //! Arguably the most important method in the add-on941 814 status_t 942 Translate(BPositionIO *inSource, const translator_info *inInfo, 943 BMessage *ioExtension, uint32 outType, BPositionIO *outDestination) 815 JP2Translator::DerivedTranslate(BPositionIO* inSource, 816 const translator_info* inInfo, BMessage* ioExtension, uint32 outType, 817 BPositionIO* outDestination, int32 baseType) 944 818 { 945 819 // If no specific type was requested, convert to the interchange format 946 820 if (outType == 0) … … 960 834 961 835 //! The user has requested the same format for input and output, so just copy 962 836 status_t 963 Copy(BPositionIO *in, BPositionIO *out)837 JP2Translator::Copy(BPositionIO* in, BPositionIO* out) 964 838 { 965 839 int block_size = 65536; 966 void *buffer = malloc(block_size);840 void* buffer = malloc(block_size); 967 841 char temp[1024]; 968 842 if (buffer == NULL) { 969 843 buffer = temp; … … 996 870 997 871 //! Encode into the native format 998 872 status_t 999 Compress(BPositionIO *in, BPositionIO *out)873 JP2Translator::Compress(BPositionIO* in, BPositionIO* out) 1000 874 { 1001 // Load settings 1002 jpeg_settings settings; 1003 LoadSettings(&settings); 875 using namespace conversion; 1004 876 1005 877 // Read info about bitmap 1006 878 TranslatorBitmap header; … … 1024 896 1025 897 // Function pointer to write function 1026 898 // 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, 1028 900 int width) = write_rgba32; 1029 901 1030 902 // Default color info … … 1033 905 1034 906 switch ((color_space)B_BENDIAN_TO_HOST_INT32(header.colors)) { 1035 907 case B_GRAY1: 1036 if ( settings.B_GRAY1_as_B_RGB24) {908 if (fSettings->SetGetBool(JP2_SET_GRAY1_AS_B_RGB24)) { 1037 909 converter = write_gray1_to_rgb24; 1038 910 } else { 1039 911 out_color_components = 1; … … 1117 989 return B_ERROR; 1118 990 } 1119 991 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]; 1123 995 jas_image_cmptparm_t component_info[4]; 1124 996 1125 997 if (jas_init()) … … 1157 1029 for (y = 0; y < (long)height; y++) { 1158 1030 err = in->Read(in_scanline, in_row_bytes); 1159 1031 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) 1163 1034 : Error(outs, image, pixels, out_color_components, in_scanline, 1164 1035 B_ERROR); 1165 1036 } … … 1173 1044 } 1174 1045 1175 1046 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); 1180 1055 } 1181 1056 1182 1057 free(in_scanline); … … 1194 1069 1195 1070 //! Decode the native format 1196 1071 status_t 1197 Decompress(BPositionIO *in, BPositionIO *out)1072 JP2Translator::Decompress(BPositionIO* in, BPositionIO* out) 1198 1073 { 1199 jpeg_settings settings; 1200 LoadSettings(&settings); 1074 using namespace conversion; 1201 1075 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]; 1205 1079 1206 1080 if (jas_init()) 1207 1081 return B_ERROR; … … 1219 1093 1220 1094 // Function pointer to read function 1221 1095 // 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, 1223 1097 int width) = NULL; 1224 1098 1225 1099 switch (jas_image_colorspace(image)) { … … 1237 1111 } 1238 1112 break; 1239 1113 case JAS_IMAGE_CS_GRAY: 1240 if ( settings.B_GRAY8_as_B_RGB32) {1114 if (fSettings->SetGetBool(JP2_SET_GRAY8_AS_B_RGB32)) { 1241 1115 out_color_space = B_RGB32; 1242 1116 out_color_components = 4; 1243 1117 converter = read_gray_to_rgb32; … … 1266 1140 // NOTE: things will go wrong if "out_row_bytes" wouldn't fit into 32 bits 1267 1141 1268 1142 // !!! 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); 1270 1144 1145 1271 1146 // Fill out the B_TRANSLATOR_BITMAP's header 1272 1147 TranslatorBitmap header; 1273 1148 header.magic = B_HOST_TO_BENDIAN_INT32(B_TRANSLATOR_BITMAP); … … 1294 1169 for (i = 0; i < (long)in_color_components; i++) { 1295 1170 pixels[i] = jas_matrix_create(1, (unsigned int)width); 1296 1171 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); 1298 1173 } 1299 1174 1300 1175 int32 y = 0; … … 1308 1183 1309 1184 err = out->Write(out_scanline, out_row_bytes); 1310 1185 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) 1314 1188 : Error(ins, image, pixels, in_color_components, out_scanline, 1315 1189 B_ERROR); 1316 1190 } … … 1329 1203 } 1330 1204 1331 1205 1206 /*! searches in both inputFormats & outputFormats */ 1207 status_t 1208 JP2Translator::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 1226 status_t 1227 JP2Translator::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 1332 1246 /*! 1333 1247 Frees jpeg alocated memory 1334 1248 Returns given error (B_ERROR by default) 1335 1249 */ 1336 1250 status_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)1251 Error(jas_stream_t* stream, jas_image_t* image, jas_matrix_t** pixels, 1252 int32 pixels_count, jpr_uchar_t* scanline, status_t error) 1339 1253 { 1340 1254 if (pixels) { 1341 1255 int32 i; … … 1358 1272 1359 1273 // #pragma mark - 1360 1274 1275 BTranslator* 1276 make_nth_translator(int32 n, image_id you, uint32 flags, ...) 1277 { 1278 if (!n) 1279 return new JP2Translator(); 1361 1280 1281 return NULL; 1282 } 1283 1284 1362 1285 int 1363 1286 main() 1364 1287 { 1365 1288 BApplication app("application/x-vnd.Haiku-JPEG2000Translator"); 1289 JP2Translator* translator = new JP2Translator(); 1290 if (LaunchTranslatorWindow(translator, gTranslatorName) == B_OK) 1291 app.Run(); 1366 1292 1367 TranslatorWindow *window = new TranslatorWindow();1368 window->Show();1369 1370 app.Run();1371 1293 return 0; 1372 1294 } 1373 1295 -
src/add-ons/translators/jpeg2000/JPEG2000Translator.h
48 48 #include <stdlib.h> 49 49 #include <string.h> 50 50 51 #include "BaseTranslator.h" 51 52 #include "libjasper/jasper.h" 52 53 53 54 54 55 // Settings 55 #define SETTINGS_FILE "JPEG2000Translator"56 #define JP2_SETTINGS_FILE "JPEG2000Translator" 56 57 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 57 63 // View messages 58 64 #define VIEW_MSG_SET_QUALITY 'JSCQ' 59 65 #define VIEW_MSG_SET_GRAY1ASRGB24 'JSGR' … … 62 68 63 69 // View labels 64 70 #define VIEW_LABEL_QUALITY "Output quality" 71 #define VIEW_LABEL_JPC "Output only codestream (.jpc)" 65 72 #define VIEW_LABEL_GRAY1ASRGB24 "Write black-and-white images as RGB24" 66 #define VIEW_LABEL_JPC "Output only codestream (.jpc)"67 73 #define VIEW_LABEL_GRAYASRGB32 "Read greyscale images as RGB32" 68 74 69 75 70 //! Settings storage structure71 struct jpeg_settings {72 // compression73 jpr_uchar_t Quality; // default: 2574 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 // decompression77 bool B_GRAY8_as_B_RGB32; // default: true78 };79 76 80 81 77 /*! 82 78 Slider used in TranslatorView 83 79 With status showing actual value 84 80 */ 85 81 class 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(); 82 public: 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; 95 89 96 97 90 private: 91 mutable char fStatusLabel[12]; 98 92 }; 99 93 100 //! Basic view class with resizing to needed size101 class SView : public BView {102 public:103 SView(BRect rect, const char* name);104 virtual void AttachedToWindow();105 };106 107 94 //! Configuration view for reading settings 108 class TranslatorReadView : public SView { 109 public: 110 TranslatorReadView(BRect rect, const char* name, jpeg_settings* settings); 95 class TranslatorReadView : public BView { 96 public: 97 TranslatorReadView(const char* name, TranslatorSettings* settings); 98 ~TranslatorReadView(); 111 99 112 113 100 virtual void AttachedToWindow(); 101 virtual void MessageReceived(BMessage* message); 114 102 115 116 jpeg_settings* fSettings;117 103 private: 104 TranslatorSettings* fSettings; 105 BCheckBox* fGrayAsRGB32; 118 106 }; 119 107 120 108 //! Configuration view for writing settings 121 class TranslatorWriteView : public SView { 122 public: 123 TranslatorWriteView(BRect rect, const char* name, jpeg_settings* settings); 109 class TranslatorWriteView : public BView { 110 public: 111 TranslatorWriteView(const char* name, TranslatorSettings* settings); 112 ~TranslatorWriteView(); 124 113 125 126 114 virtual void AttachedToWindow(); 115 virtual void MessageReceived(BMessage* message); 127 116 128 129 jpeg_settings* fSettings;130 131 132 117 private: 118 TranslatorSettings* fSettings; 119 SSlider* fQualitySlider; 120 BCheckBox* fGrayAsRGB24; 121 BCheckBox* fCodeStreamOnly; 133 122 }; 134 123 135 class TranslatorAboutView : public SView {136 137 TranslatorAboutView(BRect rect,const char* name);124 class TranslatorAboutView : public BView { 125 public: 126 TranslatorAboutView(const char* name); 138 127 }; 139 128 140 129 //! Configuration view 141 130 class TranslatorView : public BTabView { 142 public: 143 TranslatorView(BRect rect, const char *name); 144 virtual ~TranslatorView(); 145 146 private: 147 jpeg_settings fSettings; 131 public: 132 TranslatorView(const char* name, TranslatorSettings* settings); 148 133 }; 149 134 150 //! Window used for configuration 151 class TranslatorWindow : public BWindow { 152 public: 153 TranslatorWindow(bool quitOnClose = true); 135 class JP2Translator : public BaseTranslator { 136 public: 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 149 private: 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); 154 159 }; 155 160 161 status_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); 156 163 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 163 164 #endif // _JP2TRANSLATOR_H_ -
src/add-ons/translators/jpeg2000/Jamfile
4 4 5 5 SubDirSysHdrs [ FDirName $(SUBDIR) libjasper ] ; 6 6 7 SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) shared ] ; 8 #for BaseTranslator.h and friends 9 7 10 # Exclude unwanted formats 8 11 CCFLAGS += -DEXCLUDE_MIF_SUPPORT 9 12 -DEXCLUDE_PNM_SUPPORT … … 66 69 67 70 $(jasper_files) 68 71 69 : be translation $(TARGET_LIBSUPC++)72 : be translation libtranslatorsutils.a $(TARGET_LIBSUPC++) 70 73 : true 71 74 ; 72 75