00001 #include "asset.h"
00002 #include "bchash.h"
00003 #include "clip.h"
00004 #include "colormodels.h"
00005 #include "file.h"
00006 #include "filecr2.h"
00007 #include "mutex.h"
00008 #include <string.h>
00009 #include <unistd.h>
00010
00011
00012 static Mutex cr2_mutex("cr2_mutex");
00013
00014 extern "C"
00015 {
00016 extern char dcraw_info[1024];
00017 extern float **dcraw_data;
00018 extern int dcraw_alpha;
00019 extern float dcraw_matrix[9];
00020 int dcraw_main (int argc, char **argv);
00021 }
00022
00023
00024 FileCR2::FileCR2(Asset *asset, File *file)
00025 : FileBase(asset, file)
00026 {
00027 reset();
00028 if(asset->format == FILE_UNKNOWN)
00029 asset->format = FILE_CR2;
00030 }
00031
00032 FileCR2::~FileCR2()
00033 {
00034 close_file();
00035 }
00036
00037
00038 void FileCR2::reset()
00039 {
00040 }
00041
00042 int FileCR2::check_sig(Asset *asset)
00043 {
00044 cr2_mutex.lock("FileCR2::check_sig");
00045 char string[BCTEXTLEN];
00046 int argc = 3;
00047
00048 strcpy(string, asset->path);
00049
00050 char *argv[4];
00051 argv[0] = "dcraw";
00052 argv[1] = "-i";
00053 argv[2] = string;
00054 argv[3] = 0;
00055
00056 int result = dcraw_main(argc, argv);
00057
00058 cr2_mutex.unlock();
00059
00060 return !result;
00061 }
00062
00063 int FileCR2::open_file(int rd, int wr)
00064 {
00065 cr2_mutex.lock("FileCR2::check_sig");
00066
00067 int argc = 3;
00068 char *argv[3] =
00069 {
00070 "dcraw",
00071 "-i",
00072 asset->path
00073 };
00074
00075 int result = dcraw_main(argc, argv);
00076 if(!result) format_to_asset();
00077
00078 cr2_mutex.unlock();
00079 return result;
00080 }
00081
00082
00083 int FileCR2::close_file()
00084 {
00085 return 0;
00086 }
00087
00088 void FileCR2::format_to_asset()
00089 {
00090 asset->video_data = 1;
00091 asset->layers = 1;
00092 sscanf(dcraw_info, "%d %d", &asset->width, &asset->height);
00093 if(!asset->frame_rate) asset->frame_rate = 1;
00094 asset->video_length = -1;
00095 }
00096
00097
00098 int FileCR2::read_frame(VFrame *frame)
00099 {
00100 cr2_mutex.lock("FileCR2::read_frame");
00101 if(frame->get_color_model() == BC_RGBA_FLOAT)
00102 dcraw_alpha = 1;
00103 else
00104 dcraw_alpha = 0;
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 int argc = 0;
00120 char *argv[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
00121 argv[argc++] = "dcraw";
00122
00123 argv[argc++] = "-c";
00124
00125
00126
00127
00128
00129 if(file->white_balance_raw)
00130 argv[argc++] = "-w";
00131 if(!file->interpolate_raw)
00132 {
00133
00134
00135
00136 argv[argc++] = "-d";
00137 }
00138
00139 argv[argc++] = asset->path;
00140
00141 dcraw_data = (float**)frame->get_rows();
00142
00143
00144 int result = dcraw_main(argc, argv);
00145
00146 char string[BCTEXTLEN];
00147 sprintf(string,
00148 "%f %f %f %f %f %f %f %f %f\n",
00149 dcraw_matrix[0],
00150 dcraw_matrix[1],
00151 dcraw_matrix[2],
00152 dcraw_matrix[3],
00153 dcraw_matrix[4],
00154 dcraw_matrix[5],
00155 dcraw_matrix[6],
00156 dcraw_matrix[7],
00157 dcraw_matrix[8]);
00158
00159
00160 frame->get_params()->update("DCRAW_MATRIX", string);
00161
00162
00163
00164
00165 cr2_mutex.unlock();
00166 return 0;
00167 }
00168
00169 int FileCR2::colormodel_supported(int colormodel)
00170 {
00171 if(colormodel == BC_RGB_FLOAT ||
00172 colormodel == BC_RGBA_FLOAT)
00173 return colormodel;
00174 return BC_RGB_FLOAT;
00175 }
00176
00177
00178
00179
00180
00181
00182
00183