1 /* 2 * Copyright 2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include "RAWTranslator.h" 8 #include "RAW.h" 9 #include "TranslatorWindow.h" 10 11 #include <Application.h> 12 13 #define TEST_MODE 0 14 #define SHOW_MODE 1 15 #if SHOW_MODE && TEST_MODE 16 # include <Bitmap.h> 17 # include <BitmapStream.h> 18 # include <String.h> 19 # include <View.h> 20 # include <Window.h> 21 #endif 22 23 #include <stdio.h> 24 #include <string.h> 25 26 27 int 28 main(int argc, char **argv) 29 { 30 BApplication app("application/x-vnd.Haiku-RAWTranslator"); 31 32 #if TEST_MODE 33 if (argc > 1) { 34 for (int i = 1; i < argc; i++) { 35 BFile file; 36 status_t status = file.SetTo(argv[i], B_READ_ONLY); 37 if (status != B_OK) { 38 fprintf(stderr, "Cannot read file %s: %s\n", argv[i], 39 strerror(status)); 40 continue; 41 } 42 43 DCRaw raw(file); 44 45 try { 46 status = raw.Identify(); 47 } catch (status_t error) { 48 status = error; 49 } 50 51 if (status < B_OK) { 52 fprintf(stderr, "Could not identify file %s: %s\n", 53 argv[i], strerror(status)); 54 continue; 55 } 56 57 image_meta_info meta; 58 raw.GetMetaInfo(meta); 59 60 printf("manufacturer: %s\n", meta.manufacturer); 61 printf("model: %s\n", meta.model); 62 printf("software: %s\n", meta.software); 63 printf("flash used: %g\n", meta.flash_used); 64 printf("ISO speed: %g\n", meta.iso_speed); 65 printf("shutter: "); 66 if (meta.shutter >= 1) 67 printf("%g sec\n", meta.shutter); 68 else 69 printf("1/%g sec\n", 1 / meta.shutter); 70 printf("aperture: %g\n", meta.aperture); 71 printf("focal length: %g mm\n", meta.focal_length); 72 printf("pixel aspect: %g\n", meta.pixel_aspect); 73 printf("flip: %d\n", meta.flip); 74 printf("shot order: %ld\n", meta.shot_order); 75 printf("DNG version: %ld\n", meta.dng_version); 76 printf("Camera White Balance:"); 77 for (int32 i = 0; i < 4; i++) { 78 printf(" %g", meta.camera_multipliers[i]); 79 } 80 putchar('\n'); 81 82 for (int32 i = 0; i < (int32)raw.CountImages(); i++) { 83 image_data_info data; 84 raw.ImageAt(i, data); 85 86 printf(" [%ld] %s %lu x %lu (%ld bits per sample, compression %ld)\n", 87 i, data.is_raw ? "RAW " : "JPEG", 88 data.width, data.height, data.bits_per_sample, data.compression); 89 90 # if SHOW_MODE 91 if (!data.is_raw) { 92 // write data to file 93 uint8* buffer; 94 size_t bufferSize; 95 try { 96 status = raw.ReadImageAt(i, buffer, bufferSize); 97 } catch (status_t error) { 98 status = error; 99 } 100 if (status == B_OK) { 101 BString name = "/tmp/output"; 102 name << i << ".jpg"; 103 BFile output(name.String(), 104 B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY); 105 output.Write(buffer, bufferSize); 106 } 107 } else { 108 RAWTranslator translator; 109 BBitmapStream output; 110 BBitmap* bitmap; 111 112 status_t status = translator.DerivedTranslate(&file, NULL, 113 NULL, B_TRANSLATOR_BITMAP, &output, 0); 114 if (status == B_OK) 115 status = output.DetachBitmap(&bitmap); 116 if (status == B_OK) { 117 BWindow* window = new BWindow(BRect(50, 50, 118 bitmap->Bounds().Width() + 50, 119 bitmap->Bounds().Height() + 50), 120 "RAW", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS 121 | B_NOT_RESIZABLE); 122 BView* view = new BView(window->Bounds(), NULL, 123 B_WILL_DRAW, B_FOLLOW_NONE); 124 window->AddChild(view); 125 window->Show(); 126 snooze(300000); 127 window->Lock(); 128 view->DrawBitmap(bitmap, window->Bounds()); 129 view->Sync(); 130 window->Unlock(); 131 delete bitmap; 132 133 wait_for_thread(window->Thread(), &status); 134 } 135 } 136 # endif 137 } 138 } 139 return 0; 140 } 141 #endif 142 143 status_t status = LaunchTranslatorWindow(new RAWTranslator, "RAW Settings", 144 BRect(0, 0, 225, 175)); 145 if (status != B_OK) 146 return 1; 147 148 app.Run(); 149 return 0; 150 } 151 152