4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "bccmodels.h"
39 int FileCR2::dcraw_run(FileCR2 *file, int argc, const char **argv, VFrame *frame)
43 dcraw.data = (float**) frame->get_rows();
44 dcraw.alpha = frame->get_color_model() == BC_RGBA_FLOAT ? 1 : 0;
46 int result = dcraw.main(argc, argv);
48 file->format_to_asset(dcraw.info);
50 // This was only used by the bayer interpolate plugin, which itself created
51 // too much complexity to use effectively.
52 // It required bypassing the cache any time a plugin parameter changed
53 // to store the color matrix from dcraw in the frame stack along with the new
54 // plugin parameters. The cache couldn't know if a parameter in the stack came
55 // from dcraw or a plugin & replace it.
56 char string[BCTEXTLEN];
57 sprintf(string, "%f %f %f %f %f %f %f %f %f\n",
58 dcraw.matrix[0], dcraw.matrix[1], dcraw.matrix[2],
59 dcraw.matrix[3], dcraw.matrix[4], dcraw.matrix[5],
60 dcraw.matrix[6], dcraw.matrix[7], dcraw.matrix[8]);
61 frame->get_params()->update("DCRAW_MATRIX", string);
62 // frame->dump_params();
67 FileCR2::FileCR2(Asset *asset, File *file)
68 : FileList(asset, file, "CR2LIST", ".cr2", FILE_CR2, FILE_CR2_LIST)
71 if(asset->format == FILE_UNKNOWN)
72 asset->format = FILE_CR2;
77 //printf("FileCR2::~FileCR2\n");
86 int FileCR2::check_sig(Asset *asset)
88 char *ptr = strstr(asset->path, ".pcm");
90 //printf("FileCR2::check_sig %d\n", __LINE__);
91 FILE *stream = fopen(asset->path, "rb");
94 (void)fread(test, 10, 1, stream);
96 if( !strncmp("CR2LIST",test,6) ) return 1;
98 char string[BCTEXTLEN];
99 strcpy(string, asset->path);
100 const char *argv[4] = { "dcraw", "-i", string, 0 };
102 int result = dcraw_run(0, argc, argv);
103 //printf("FileCR2::check_sig %d %d\n", __LINE__, result);
107 int FileCR2::read_frame_header(char *path)
110 const char *argv[4] = { "dcraw", "-i", path, 0 };
111 int result = dcraw_run(this, argc, argv);
118 // int FileCR2::close_file()
123 void FileCR2::format_to_asset(const char *info)
125 asset->video_data = 1;
127 sscanf(info, "%d %d", &asset->width, &asset->height);
131 int FileCR2::read_frame(VFrame *frame, char *path)
133 //printf("FileCR2::read_frame\n");
135 // Want to disable interpolation if an interpolation plugin is on, but
136 // this is impractical because of the amount of caching. The interpolation
137 // could not respond to a change in the plugin settings and it could not
138 // reload the frame after the plugin was added. Also, since an 8 bit
139 // PBuffer would be required, it could never have enough resolution.
140 // int interpolate = 0;
141 // if(!strcmp(frame->get_next_effect(), "Interpolate Pixels"))
145 // printf("FileCR2::read_frame %d\n", interpolate);
146 // frame->dump_stacks();
147 int argc = 0; const char *argv[10];
148 argv[argc++] = "dcraw";
149 argv[argc++] = "-c"; // output to stdout
150 argv[argc++] = "-j"; // no rotation
152 // printf("FileCR2::read_frame %d interpolate=%d white_balance=%d\n",
153 // __LINE__, file->interpolate_raw, file->white_balance_raw);
155 // Use camera white balance.
156 // Before 2006, DCraw had no Canon white balance.
157 // In 2006 DCraw seems to support Canon white balance.
158 // Still no gamma support.
159 // Need to toggle this in preferences because it defeats dark frame subtraction.
160 if(file->white_balance_raw)
164 if(!file->interpolate_raw) {
165 // Trying to do everything but interpolate doesn't work because convert_to_rgb
166 // doesn't work with bayer patterns.
167 // Use document mode and hack dcraw to apply white balance in the write_ function.
171 //printf("FileCR2::read_frame %d %s\n", __LINE__, path);
176 int result = dcraw_run(0, argc, argv, frame);
180 int FileCR2::colormodel_supported(int colormodel)
182 if(colormodel == BC_RGB_FLOAT ||
183 colormodel == BC_RGBA_FLOAT)
189 // Be sure to add a line to File::get_best_colormodel
190 int FileCR2::get_best_colormodel(Asset *asset, int driver)
192 //printf("FileCR2::get_best_colormodel %d\n", __LINE__);
196 // int64_t FileCR2::get_memory_usage()
198 // int64_t result = asset->width * asset->height * sizeof(float) * 3;
199 //printf("FileCR2::get_memory_usage %d %jd\n", __LINE__, result);
204 int FileCR2::use_path()