X-Git-Url: http://git.cinelerra-gg.org/git/?p=goodguy%2Fhistory.git;a=blobdiff_plain;f=cinelerra-5.1%2Fcinelerra%2Ffilecr2.C;h=f7db2f01f7b830cef56a0ebfd44af8bc1dcf43bd;hp=fdd5b2c78cda9e0ab9d60a9415c6a7e17db0653f;hb=7e5a0760f40ff787cc3d93cb7768a901ebe52809;hpb=ed1cab1d6cbde6129bbd09b9609f7bba03ab610f diff --git a/cinelerra-5.1/cinelerra/filecr2.C b/cinelerra-5.1/cinelerra/filecr2.C index fdd5b2c7..f7db2f01 100644 --- a/cinelerra-5.1/cinelerra/filecr2.C +++ b/cinelerra-5.1/cinelerra/filecr2.C @@ -30,21 +30,37 @@ #include -extern "C" -{ -extern char dcraw_info[1024]; -extern float **dcraw_data; -extern int dcraw_alpha; -extern float dcraw_matrix[9]; -int dcraw_main (int argc, const char **argv); -} +#define NODEPS +#define NO_JASPER +#define NO_JPEG +#define NO_LCMS +#include "dcraw.h" -static int dcraw_run(int argc, const char **argv) +int FileCR2::dcraw_run(FileCR2 *file, int argc, const char **argv, VFrame *frame) { - static Mutex dcraw_lock; - dcraw_lock.lock("dcraw_run"); - int result = dcraw_main(argc, argv); - dcraw_lock.unlock(); + DCRaw dcraw; + if( frame ) { + dcraw.data = (float**) frame->get_rows(); + dcraw.alpha = frame->get_color_model() == BC_RGBA_FLOAT ? 1 : 0; + } + int result = dcraw.main(argc, argv); + if( file ) + file->format_to_asset(dcraw.info); + if( frame ) { +// This was only used by the bayer interpolate plugin, which itself created +// too much complexity to use effectively. +// It required bypassing the cache any time a plugin parameter changed +// to store the color matrix from dcraw in the frame stack along with the new +// plugin parameters. The cache couldn't know if a parameter in the stack came +// from dcraw or a plugin & replace it. + char string[BCTEXTLEN]; + sprintf(string, "%f %f %f %f %f %f %f %f %f\n", + dcraw.matrix[0], dcraw.matrix[1], dcraw.matrix[2], + dcraw.matrix[3], dcraw.matrix[4], dcraw.matrix[5], + dcraw.matrix[6], dcraw.matrix[7], dcraw.matrix[8]); + frame->get_params()->update("DCRAW_MATRIX", string); +// frame->dump_params(); + } return result; } @@ -73,78 +89,26 @@ int FileCR2::check_sig(Asset *asset) if(ptr) return 0; //printf("FileCR2::check_sig %d\n", __LINE__); FILE *stream = fopen(asset->path, "rb"); - - if(stream) - { + if( stream ) { char test[10]; (void)fread(test, 10, 1, stream); fclose(stream); - - if(test[0] == 'C' && test[1] == 'R' && test[2] == '2' && - test[3] == 'L' && test[4] == 'I' && test[5] == 'S' && test[6] == 'T') - { -//printf("FileCR2::check_sig %d\n", __LINE__); - return 1; - } + if( !strncmp("CR2LIST",test,6) ) return 1; } - -//printf("FileCR2::check_sig %d\n", __LINE__); - - char string[BCTEXTLEN]; - int argc = 3; - strcpy(string, asset->path); - - const char *argv[4] = - { - "dcraw", - "-i", - string, - 0 - }; - - int result = dcraw_run(argc, argv); - + const char *argv[4] = { "dcraw", "-i", string, 0 }; + int argc = 3; + int result = dcraw_run(0, argc, argv); //printf("FileCR2::check_sig %d %d\n", __LINE__, result); - return !result; } -// int FileCR2::open_file(int rd, int wr) -// { -// -// int argc = 3; -// const char *argv[4] = -// { -// "dcraw", -// "-i", -// asset->path, -// 0 -// }; -// -// int result = dcraw_run(argc, argv); -// if(!result) format_to_asset(); -// -// return result; -// } - int FileCR2::read_frame_header(char *path) { int argc = 3; -//printf("FileCR2::read_frame_header %d\n", __LINE__); - const char *argv[4] = - { - "dcraw", - "-i", - path, - 0 - }; - - int result = dcraw_run(argc, argv); - if(!result) format_to_asset(); - -//printf("FileCR2::read_frame_header %d %d\n", __LINE__, result); + const char *argv[4] = { "dcraw", "-i", path, 0 }; + int result = dcraw_run(this, argc, argv); return result; } @@ -156,11 +120,11 @@ int FileCR2::read_frame_header(char *path) // return 0; // } // -void FileCR2::format_to_asset() +void FileCR2::format_to_asset(const char *info) { asset->video_data = 1; asset->layers = 1; - sscanf(dcraw_info, "%d %d", &asset->width, &asset->height); + sscanf(info, "%d %d", &asset->width, &asset->height); } @@ -168,11 +132,6 @@ int FileCR2::read_frame(VFrame *frame, char *path) { //printf("FileCR2::read_frame\n"); - if(frame->get_color_model() == BC_RGBA_FLOAT) - dcraw_alpha = 1; - else - dcraw_alpha = 0; - // Want to disable interpolation if an interpolation plugin is on, but // this is impractical because of the amount of caching. The interpolation // could not respond to a change in the plugin settings and it could not @@ -185,19 +144,13 @@ int FileCR2::read_frame(VFrame *frame, char *path) // printf("FileCR2::read_frame %d\n", interpolate); // frame->dump_stacks(); -// output to stdout - int argc = 0; - char *argv[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - argv[argc++] = (char*)"dcraw"; -// write to stdout - argv[argc++] = (char*)"-c"; -// no rotation - argv[argc++] = (char*)"-j"; + int argc = 0; const char *argv[10]; + argv[argc++] = "dcraw"; + argv[argc++] = "-c"; // output to stdout + argv[argc++] = "-j"; // no rotation // printf("FileCR2::read_frame %d interpolate=%d white_balance=%d\n", -// __LINE__, -// file->interpolate_raw, -// file->white_balance_raw); +// __LINE__, file->interpolate_raw, file->white_balance_raw); // Use camera white balance. // Before 2006, DCraw had no Canon white balance. @@ -205,49 +158,22 @@ int FileCR2::read_frame(VFrame *frame, char *path) // Still no gamma support. // Need to toggle this in preferences because it defeats dark frame subtraction. if(file->white_balance_raw) - argv[argc++] = (char*)"-w"; + argv[argc++] = "-w"; - if(!file->interpolate_raw) - { + if(!file->interpolate_raw) { // Trying to do everything but interpolate doesn't work because convert_to_rgb // doesn't work with bayer patterns. // Use document mode and hack dcraw to apply white balance in the write_ function. - argv[argc++] = (char*)"-d"; + argv[argc++] = "-d"; } //printf("FileCR2::read_frame %d %s\n", __LINE__, path); argv[argc++] = path; - - dcraw_data = (float**)frame->get_rows(); + argv[argc] = 0; //Timer timer; - int result = dcraw_run(argc, (const char**) argv); - -// This was only used by the bayer interpolate plugin, which itself created -// too much complexity to use effectively. -// It required bypassing the cache any time a plugin parameter changed -// to store the color matrix from dcraw in the frame stack along with the new -// plugin parameters. The cache couldn't know if a parameter in the stack came -// from dcraw or a plugin & replace it. - char string[BCTEXTLEN]; - sprintf(string, - "%f %f %f %f %f %f %f %f %f\n", - dcraw_matrix[0], - dcraw_matrix[1], - dcraw_matrix[2], - dcraw_matrix[3], - dcraw_matrix[4], - dcraw_matrix[5], - dcraw_matrix[6], - dcraw_matrix[7], - dcraw_matrix[8]); - - - frame->get_params()->update("DCRAW_MATRIX", string); - -// frame->dump_params(); - + int result = dcraw_run(0, argc, argv, frame); return result; } @@ -270,7 +196,7 @@ int FileCR2::get_best_colormodel(Asset *asset, int driver) // int64_t FileCR2::get_memory_usage() // { // int64_t result = asset->width * asset->height * sizeof(float) * 3; -//printf("FileCR2::get_memory_usage %d " _LD "\n", __LINE__, result); +//printf("FileCR2::get_memory_usage %d %jd\n", __LINE__, result); // return result; // }