4 #include "colormodels.h"
11 // Only allow one instance of the decoder to run simultaneously.
12 static Mutex cr2_mutex("cr2_mutex");
16 extern char dcraw_info[1024];
17 extern float **dcraw_data;
18 extern int dcraw_alpha;
19 extern float dcraw_matrix[9];
20 int dcraw_main (int argc, char **argv);
24 FileCR2::FileCR2(Asset *asset, File *file)
25 : FileBase(asset, file)
28 if(asset->format == FILE_UNKNOWN)
29 asset->format = FILE_CR2;
42 int FileCR2::check_sig(Asset *asset)
44 cr2_mutex.lock("FileCR2::check_sig");
45 char string[BCTEXTLEN];
48 strcpy(string, asset->path);
56 int result = dcraw_main(argc, argv);
63 int FileCR2::open_file(int rd, int wr)
65 cr2_mutex.lock("FileCR2::check_sig");
75 int result = dcraw_main(argc, argv);
76 if(!result) format_to_asset();
83 int FileCR2::close_file()
88 void FileCR2::format_to_asset()
90 asset->video_data = 1;
92 sscanf(dcraw_info, "%d %d", &asset->width, &asset->height);
93 if(!asset->frame_rate) asset->frame_rate = 1;
94 asset->video_length = -1;
98 int FileCR2::read_frame(VFrame *frame)
100 cr2_mutex.lock("FileCR2::read_frame");
101 if(frame->get_color_model() == BC_RGBA_FLOAT)
106 // Want to disable interpolation if an interpolation plugin is on, but
107 // this is impractical because of the amount of caching. The interpolation
108 // could not respond to a change in the plugin settings and it could not
109 // reload the frame after the plugin was added. Also, since an 8 bit
110 // PBuffer would be required, it could never have enough resolution.
111 // int interpolate = 0;
112 // if(!strcmp(frame->get_next_effect(), "Interpolate Pixels"))
116 // printf("FileCR2::read_frame %d\n", interpolate);
117 // frame->dump_stacks();
120 char *argv[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
121 argv[argc++] = "dcraw";
124 // Use camera white balance.
125 // Before 2006, DCraw had no Canon white balance.
126 // In 2006 DCraw seems to support Canon white balance.
127 // Still no gamma support.
128 // Need to toggle this in preferences because it defeats dark frame subtraction.
129 if(file->white_balance_raw)
131 if(!file->interpolate_raw)
133 // Trying to do everything but interpolate doesn't work because convert_to_rgb
134 // doesn't work with bayer patterns.
135 // Use document mode and hack dcraw to apply white balance in the write_ function.
139 argv[argc++] = asset->path;
141 dcraw_data = (float**)frame->get_rows();
144 int result = dcraw_main(argc, argv);
146 char string[BCTEXTLEN];
148 "%f %f %f %f %f %f %f %f %f\n",
160 frame->get_params()->update("DCRAW_MATRIX", string);
162 // printf("FileCR2::read_frame\n");
163 // frame->dump_params();
169 int FileCR2::colormodel_supported(int colormodel)
171 if(colormodel == BC_RGB_FLOAT ||
172 colormodel == BC_RGBA_FLOAT)