00001 #include "asset.h"
00002 #include "colormodels.h"
00003 #include "filecr2.h"
00004 #include "mutex.h"
00005 #include <string.h>
00006 #include <unistd.h>
00007
00008
00009 static Mutex cr2_mutex;
00010
00011
00012 FileCR2::FileCR2(Asset *asset, File *file)
00013 : FileBase(asset, file)
00014 {
00015 reset();
00016 }
00017
00018 FileCR2::~FileCR2()
00019 {
00020 close_file();
00021 }
00022
00023
00024 void FileCR2::reset()
00025 {
00026 }
00027
00028 int FileCR2::check_sig(Asset *asset)
00029 {
00030 cr2_mutex.lock("FileCR2::check_sig");
00031 char string[BCTEXTLEN];
00032 int argc = 3;
00033
00034 strcpy(string, asset->path);
00035
00036 char *argv[4];
00037 argv[0] = "dcraw";
00038 argv[1] = "-i";
00039 argv[2] = string;
00040 argv[3] = 0;
00041
00042 int result = dcraw_main(argc, argv);
00043
00044 cr2_mutex.unlock();
00045
00046 return !result;
00047 }
00048
00049 int FileCR2::open_file(int rd, int wr)
00050 {
00051 cr2_mutex.lock("FileCR2::check_sig");
00052
00053 int argc = 3;
00054 char *argv[3] =
00055 {
00056 "dcraw",
00057 "-i",
00058 asset->path
00059 };
00060
00061 int result = dcraw_main(argc, argv);
00062 if(!result) format_to_asset();
00063
00064 cr2_mutex.unlock();
00065 return result;
00066 }
00067
00068
00069 int FileCR2::close_file()
00070 {
00071 return 0;
00072 }
00073
00074 void FileCR2::format_to_asset()
00075 {
00076 asset->video_data = 1;
00077 asset->layers = 1;
00078 sscanf(dcraw_info, "%d %d", &asset->width, &asset->height);
00079 if(!asset->frame_rate) asset->frame_rate = 1;
00080 asset->video_length = -1;
00081 }
00082
00083
00084 int FileCR2::read_frame(VFrame *frame)
00085 {
00086 cr2_mutex.lock("FileCR2::check_sig");
00087 if(frame->get_color_model() == BC_RGBA_FLOAT)
00088 dcraw_alpha = 1;
00089 else
00090 dcraw_alpha = 0;
00091
00092
00093
00094 int argc = 3;
00095 char *argv[3] =
00096 {
00097 "dcraw",
00098 "-c",
00099 asset->path
00100 };
00101 dcraw_data = (float**)frame->get_rows();
00102
00103 int result = dcraw_main(argc, argv);
00104
00105 cr2_mutex.unlock();
00106 return 0;
00107 }
00108
00109 int FileCR2::colormodel_supported(int colormodel)
00110 {
00111 if(colormodel == BC_RGB_FLOAT ||
00112 colormodel == BC_RGBA_FLOAT)
00113 return colormodel;
00114 return BC_RGB_FLOAT;
00115 }
00116
00117
00118
00119
00120
00121
00122
00123