From: Good Guy Date: Mon, 5 Jun 2017 00:54:52 +0000 (-0600) Subject: dcraw/filecr2 rework, cpozer zoom slider resize fix, rename mpeg3 utils as zmpeg3 X-Git-Url: http://git.cinelerra-gg.org/git/?p=goodguy%2Fhistory.git;a=commitdiff_plain;h=3e86a949f432853fbfa17f6d5d02602447592e87 dcraw/filecr2 rework, cpozer zoom slider resize fix, rename mpeg3 utils as zmpeg3 --- diff --git a/cinelerra-5.1/Makefile.am b/cinelerra-5.1/Makefile.am index 02fe4ce7..067f1b63 100644 --- a/cinelerra-5.1/Makefile.am +++ b/cinelerra-5.1/Makefile.am @@ -44,7 +44,7 @@ buninstall: # with system_build cinstall: cd bin; $(inst_sh) "$(DESTDIR)$(bindir)" "$(WANT_CIN)" \ - cin_db mpeg3{cat,cc2txt,ifochk,show,toc} + cin_db zmpeg3{cat,cc2txt,ifochk,show,toc} cd bin; $(inst_sh) "$(DESTDIR)$(WANT_CINLIB_DIR)" \ bdwrite cutads hveg2enc mpeg2enc mplex mplexlo cd bin; $(inst_sh) "$(DESTDIR)$(datadir)/$(WANT_CIN)" \ @@ -57,7 +57,7 @@ cinstall: cuninstall: rm -f "$(DESTDIR)$(bindir)/$(WANT_CIN)" - rm -f "$(DESTDIR)$(bindir)"/mpeg3{cat,cc2txt,ifochk,show,toc} + rm -f "$(DESTDIR)$(bindir)"/zmpeg3{cat,cc2txt,ifochk,show,toc} rm -f "$(DESTDIR)$(bindir)/cin_db" rm -rf "$(DESTDIR)$(WANT_CINLIB_DIR)" rm -rf "$(DESTDIR)$(datadir)/$(WANT_CIN)" diff --git a/cinelerra-5.1/cinelerra/Makefile b/cinelerra-5.1/cinelerra/Makefile index 93fd8b61..bfb27354 100644 --- a/cinelerra-5.1/cinelerra/Makefile +++ b/cinelerra-5.1/cinelerra/Makefile @@ -446,7 +446,8 @@ $(OBJDIR)/sha1.o: sha1.C sha1.h $(CXX) `cat $(OBJDIR)/c_flags` -O3 -c $< -o $@ $(DCRAW): dcraw.c - $(GCC) `cat $(OBJDIR)/c_flags` -O4 -Wno-misleading-indentation dcraw.c -c -o $*.o + $(GCC) `cat $(OBJDIR)/c_flags` $(if $(findstring -ggdb,$(CFLAGS)),,-O4) -c -o $*.o \ + -Wno-misleading-indentation -Wno-sign-compare -Wno-narrowing dcraw.c $(THEME_DATA): cd $(OBJDIR) && \ diff --git a/cinelerra-5.1/cinelerra/cpanel.C b/cinelerra-5.1/cinelerra/cpanel.C index 19cea490..8788b047 100644 --- a/cinelerra-5.1/cinelerra/cpanel.C +++ b/cinelerra-5.1/cinelerra/cpanel.C @@ -79,14 +79,15 @@ void CPanel::create_objects() y += operation[CWINDOW_TOOL_WINDOW]->get_h(); subwindow->add_subwindow(operation[CWINDOW_TITLESAFE] = new CPanelTitleSafe(mwindow, this, x, y)); y += operation[CWINDOW_TITLESAFE]->get_h(); - x += (w - BC_Slider::get_span(1)) / 2; - subwindow->add_subwindow(cpanel_zoom = new CPanelZoom(mwindow, this, x, y+15, h-y-15)); + x += (w - BC_Slider::get_span(1)) / 2; y += 15; + subwindow->add_subwindow(cpanel_zoom = new CPanelZoom(mwindow, this, x, y, h-y-20)); } -void CPanel::reposition_buttons(int x, int y) +void CPanel::reposition_buttons(int x, int y, int h) { this->x = x; this->y = y; + this->h = h; for(int i = 0; i < CPANEL_OPERATIONS; i++) { @@ -94,7 +95,10 @@ void CPanel::reposition_buttons(int x, int y) y += operation[i]->get_h(); } x += (w - BC_Slider::get_span(1)) / 2; - cpanel_zoom->reposition_window(x, y+15); + y += 15; + h = this->h - this->y; + cpanel_zoom->reposition_window(x, y, w, h-y-20); + cpanel_zoom->set_pointer_motion_range(h); } @@ -365,7 +369,7 @@ int CPanelTitleSafe::handle_event() } CPanelZoom::CPanelZoom(MWindow *mwindow, CPanel *gui, int x, int y, int h) - : BC_FSlider(x, y, 1, h-30, h, -2., 2., 0, 0) + : BC_FSlider(x, y, 1, h, h, -2., 2., 0, 0) { this->mwindow = mwindow; this->gui = gui; diff --git a/cinelerra-5.1/cinelerra/cpanel.h b/cinelerra-5.1/cinelerra/cpanel.h index cbca255a..7836d285 100644 --- a/cinelerra-5.1/cinelerra/cpanel.h +++ b/cinelerra-5.1/cinelerra/cpanel.h @@ -35,7 +35,7 @@ public: ~CPanel(); void create_objects(); - void reposition_buttons(int x, int y); + void reposition_buttons(int x, int y, int h); void set_operation(int value); MWindow *mwindow; diff --git a/cinelerra-5.1/cinelerra/cwindowgui.C b/cinelerra-5.1/cinelerra/cwindowgui.C index 6d431550..e676fc8b 100644 --- a/cinelerra-5.1/cinelerra/cwindowgui.C +++ b/cinelerra-5.1/cinelerra/cwindowgui.C @@ -245,7 +245,7 @@ int CWindowGUI::resize_event(int w, int h) flash(0); composite_panel->reposition_buttons(mwindow->theme->ccomposite_x, - mwindow->theme->ccomposite_y); + mwindow->theme->ccomposite_y, mwindow->theme->ccomposite_h); canvas->reposition_window(mwindow->edl, mwindow->theme->ccanvas_x, diff --git a/cinelerra-5.1/cinelerra/dcraw.c b/cinelerra-5.1/cinelerra/dcraw.c index 98106822..b78bba04 100644 --- a/cinelerra-5.1/cinelerra/dcraw.c +++ b/cinelerra-5.1/cinelerra/dcraw.c @@ -193,7 +193,6 @@ static struct ph1 { #define ULIM(x,y,z) ((y) < (z) ? LIM(x,y,z) : LIM(x,z,y)) #define CLIP(x) LIM((int)(x),0,65535) #define SWAP(a,b) { a=a+b; b=a-b; a=a-b; } - /* In order to inline this calculation, I make the risky assumption that all filter patterns can be described @@ -273,27 +272,114 @@ int CLASS fcol (int row, int col) // CINELERRA static void reset() { - shot_select=0; - multi_out=0; - aber[0]=1; aber[1]=1; aber[2]=1; aber[3]=1; - gamm[0]=0.45; gamm[1]=4.5; gamm[2]=0; gamm[3]=0; gamm[4]=0; gamm[5]=0; - bright=1; - user_mul[0]=0; user_mul[1]=0; user_mul[2]=0; user_mul[3]=0; - threshold=0; - half_size=0; - four_color_rgb=0; - document_mode=0; - highlight=0; - verbose=0; - use_auto_wb=0; - use_camera_wb=0; - use_camera_matrix=1; - output_color=1; - output_bps=8; - output_tiff=0; - med_passes=0; - no_auto_bright=0; - greybox[0]=0; greybox[1]=0; greybox[2]=UINT_MAX; greybox[3]=UINT_MAX; +// uninitialized +#define ZERO(var) memset(&var, 0, sizeof var); + aperture = 0; + ZERO(artist); + black = 0; + ZERO(cam_mul) + canon_ev = 0; + ZERO(cblack); + ZERO(cmatrix); + ZERO(cdesc); + colors = 0; + ZERO(cr2_slice); + ZERO(curve); + data_error = 0; + data_offset = 0; + dng_version = 0; + exif_cfa = 0; + ZERO(failure); + filters = 0; + ZERO(first_decode); + flash_used = 0; + flip = 0; + focal_len = 0; + fuji_layout = 0; + fuji_width = 0; + ZERO(gpsdata); + height = 0; + ZERO(histogram); + ifname = 0; + ifp = 0; + iheight = 0; + is_foveon = 0; + iso_speed = 0; + is_raw = 0; + iwidth = 0; + kodak_cbpp = 0; + left_margin = 0; + load_flags = 0; + load_raw = 0; + maximum = 0; + meta_data = 0; + meta_length = 0; + meta_offset = 0; + mix_green = 0; + ZERO(model); + ZERO(model2); + ofp = 0; + oprof = 0; + order = 0; + ZERO(ph1); + pixel_aspect = 0; + memset(pre_mul, 0, sizeof pre_mul); + profile_length = 0; + profile_offset = 0; + raw_color = 0; + raw_height = 0; + raw_width = 0; + raw_image = 0; + memset(rgb_cam, 0, sizeof rgb_cam); + shot_order = 0; + shrink = 0; + shutter = 0; + strip_offset = 0; + thumb_height = 0; + thumb_length = 0; + thumb_load_raw = 0; + thumb_misc = 0; + thumb_offset = 0; + thumb_width = 0; + tiff_bps = 0; + tiff_compress = 0; + tiff_flip = 0; + tiff_nifds = 0; + tiff_samples = 0; + tile_length = 0; + tile_width = 0; + timestamp = 0; + top_margin = 0; + unique_id = 0; + ZERO(white); + width = 0; + zero_after_ff = 0; + zero_is_bad = 0; + +// initializer data + shot_select = 0; + multi_out = 0; + aber[0] = aber[1] = aber[2] = aber[3] = 1; + gamm[0] = 0.45; gamm[1] = 4.5; gamm[2] = 0; + gamm[3] = 0; gamm[4] = 0; gamm[5] = 0; + bright = 1; + ZERO(user_mul); + threshold = 0; + half_size = 0; + four_color_rgb = 0; + document_mode = 0; + highlight = 0; + verbose = 0; + use_auto_wb = 0; + use_camera_wb = 0; + use_camera_matrix = 1; + output_color = 1; + output_bps = 8; + output_tiff = 0; + med_passes = 0; + no_auto_bright = 0; + greybox[0] = 0; greybox[1] = 0; + greybox[2] = UINT_MAX; greybox[3] = UINT_MAX; } #if 0 @@ -3325,8 +3411,7 @@ int CLASS foveon_fixed (void *ptr, int size, const char *name) { void *dp; unsigned dim[3]; -// CINELERRA - memset (ptr, 0, size*4); + if (!name) return 0; dp = foveon_camf_matrix (dim, name); if (!dp) return 0; @@ -9454,10 +9539,16 @@ notraw: if (flip == UINT_MAX) flip = 0; // CINELERRA - if (flip & 4) - sprintf(dcraw_info, "%d %d", height, width); +{ unsigned flp = flip; + switch ((flp+3600) % 360) { + case 270: flp = 5; break; + case 180: flp = 3; break; + case 90: flp = 6; + } + if( (flp & 4) ) + sprintf(dcraw_info, "%d %d", height, width); else - sprintf(dcraw_info, "%d %d", width, height); + sprintf(dcraw_info, "%d %d", width, height); } } #ifndef NO_LCMS @@ -9905,42 +9996,46 @@ void CLASS write_ppm_tiff() } // CINELERRA -void CLASS write_cinelerra (FILE *ofp) -{ - int row, col; - float *output; - - for (row = 0; row < height; row++) - { - output = dcraw_data[row]; - - if(document_mode) - { - for (col = 0; col < width; col++) - { - ushort *pixel = image[row * width + col]; - - *output++ = (float)pixel[0] / 0xffff; - *output++ = (float)pixel[1] / 0xffff; - *output++ = (float)pixel[2] / 0xffff; - - if(dcraw_alpha) *output++ = 1.0; +void CLASS write_cinelerra() +{ + int c, row, col, soff, cstep, rstep; + float scale = 1. / 0xffff; + iheight = height; iwidth = width; + if( (flip & 4) != 0 ) SWAP(height,width); + soff = flip_index(0, 0); + cstep = flip_index(0, 1) - soff; + rstep = flip_index(1, 0) - flip_index(0, width); + if( document_mode ) { + for( row=0; row 32; ) + if( (total += histogram[c][val]) > perc ) break; + if( white < val ) white = val; + } + } + gamma_curve(gamm[0], gamm[1], 2, (white << 3)/bright); + for( row=0; rowget_rows(); + dcraw_alpha = !frame ? 0 : + frame->get_color_model() == BC_RGBA_FLOAT ? 1 : 0; int result = dcraw_main(argc, argv); + if( !result && file ) + file->format_to_asset(dcraw_info); + if( !result && 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(); + } + dcraw_lock.unlock(); return result; } @@ -73,78 +97,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 +128,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); } @@ -185,19 +157,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 +171,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; } diff --git a/cinelerra-5.1/cinelerra/filecr2.h b/cinelerra-5.1/cinelerra/filecr2.h index 5bcce486..1e3884d7 100644 --- a/cinelerra-5.1/cinelerra/filecr2.h +++ b/cinelerra-5.1/cinelerra/filecr2.h @@ -39,6 +39,9 @@ class FileCR2 : public FileList { + static Mutex dcraw_lock; + static int dcraw_run(FileCR2 *file, int argc, const char **argv, VFrame *frame=0); + void format_to_asset(const char *info); public: FileCR2(Asset *asset, File *file); ~FileCR2(); @@ -58,9 +61,6 @@ public: static int get_best_colormodel(Asset *asset, int driver); // int64_t get_memory_usage(); int read_frame_header(char *path); - -private: - void format_to_asset(); }; diff --git a/cinelerra-5.1/cinelerra/filetiff.C b/cinelerra-5.1/cinelerra/filetiff.C index 7a2f393b..b7891ac7 100644 --- a/cinelerra-5.1/cinelerra/filetiff.C +++ b/cinelerra-5.1/cinelerra/filetiff.C @@ -74,6 +74,10 @@ int FileTIFF::check_sig(Asset *asset) if(test[0] == 'I' && test[1] == 'I') { + // Reject cr2, libtiff fails with it + if( test[4] == 0x10 && !test[5] && !test[6] && !test[7] && + test[8] == 'C' && test[9] == 'R' ) + return 0; return 1; } else diff --git a/cinelerra-5.1/libzmpeg3/Makefile b/cinelerra-5.1/libzmpeg3/Makefile index a1f0ce2c..022f1f42 100644 --- a/cinelerra-5.1/libzmpeg3/Makefile +++ b/cinelerra-5.1/libzmpeg3/Makefile @@ -69,11 +69,11 @@ DIRS := \ $(shell mkdir -p $(DIRS) ) OUTPUT = $(OBJDIR)/libzmpeg3.a -UTILS += $(OBJDIR)/mpeg3toc -UTILS += $(OBJDIR)/mpeg3show -UTILS += $(OBJDIR)/mpeg3cat -UTILS += $(OBJDIR)/mpeg3ifochk -UTILS += $(OBJDIR)/mpeg3cc2txt +UTILS += $(OBJDIR)/zmpeg3toc +UTILS += $(OBJDIR)/zmpeg3show +UTILS += $(OBJDIR)/zmpeg3cat +UTILS += $(OBJDIR)/zmpeg3ifochk +UTILS += $(OBJDIR)/zmpeg3cc2txt LIBS = -lm -lpthread @@ -104,8 +104,8 @@ $(OUTPUT): $(OBJS) $(ASMOBJS) $(NASMOBJS) ar rcs $(OUTPUT) `cat $(OBJDIR)/objs` -mpeg3% $(OBJDIR)/mpeg3%: $(OUTPUT) mpeg3%.C - $(CXX) `cat $(OBJDIR)/c_flags` -o $(OBJDIR)/$(notdir $@) $(notdir $@).C $(OUTPUT) $(LIBS) +zmpeg3% $(OBJDIR)/zmpeg3%: $(OUTPUT) mpeg3%.C + $(CXX) `cat $(OBJDIR)/c_flags` -o $(OBJDIR)/$(notdir $@) mpeg3$*.C $(OUTPUT) $(LIBS) tags: ctags -R . diff --git a/cinelerra-5.1/thirdparty/src/dcraw.c.xz b/cinelerra-5.1/thirdparty/src/dcraw.c.xz new file mode 100644 index 00000000..8d55e998 Binary files /dev/null and b/cinelerra-5.1/thirdparty/src/dcraw.c.xz differ