diff --git a/synfig-core/src/modules/lyr_std/import.h b/synfig-core/src/modules/lyr_std/import.h index e313f5b..084587e 100644 --- a/synfig-core/src/modules/lyr_std/import.h +++ b/synfig-core/src/modules/lyr_std/import.h @@ -33,7 +33,6 @@ #include #include #include -#include /* === M A C R O S ========================================================= */ diff --git a/synfig-core/src/modules/mod_bmp/mptr_bmp.cpp b/synfig-core/src/modules/mod_bmp/mptr_bmp.cpp index a7e3e49..0d60998 100644 --- a/synfig-core/src/modules/mod_bmp/mptr_bmp.cpp +++ b/synfig-core/src/modules/mod_bmp/mptr_bmp.cpp @@ -205,30 +205,18 @@ bmp_mptr::get_frame(synfig::Surface &surface, const synfig::RendDesc &/*renddesc return false; } - int x; - int y; - surface.set_wh(w,h); - for(y=0;ygetc()*(1.0/255.0); -// float g=(float)(unsigned char)stream->getc()*(1.0/255.0); -// float r=(float)(unsigned char)stream->getc()*(1.0/255.0); - float b=gamma().b_U8_to_F32((unsigned char)stream->get()); - float g=gamma().g_U8_to_F32((unsigned char)stream->get()); - float r=gamma().r_U8_to_F32((unsigned char)stream->get()); - - surface[h-y-1][x]=Color( - r, - g, - b, - 1.0 - ); - if(bit_count==32) + surface.set_wh(w, h); + const ColorReal k = 1/255.0; + for(int y = 0; y < surface.get_h(); ++y) + for(int x = 0; x < surface.get_w(); ++x) { + ColorReal b = ((unsigned char)stream->get())*k; + ColorReal g = ((unsigned char)stream->get())*k; + ColorReal r = ((unsigned char)stream->get())*k; + surface[h-y-1][x] = Color(r, g, b); + if (bit_count == 32) stream->get(); } - return true; } diff --git a/synfig-core/src/modules/mod_bmp/trgt_bmp.cpp b/synfig-core/src/modules/mod_bmp/trgt_bmp.cpp index a77c7c3..5c4dff2 100644 --- a/synfig-core/src/modules/mod_bmp/trgt_bmp.cpp +++ b/synfig-core/src/modules/mod_bmp/trgt_bmp.cpp @@ -295,7 +295,7 @@ bmp::end_scanline() if(!file) return false; - color_to_pixelformat(buffer, color_buffer, pf, &gamma(), desc.get_w()); + color_to_pixelformat(buffer, color_buffer, pf, 0, desc.get_w()); if(!fwrite(buffer,1,rowspan,file)) return false; diff --git a/synfig-core/src/modules/mod_dv/trgt_dv.cpp b/synfig-core/src/modules/mod_dv/trgt_dv.cpp index c28445d..3468b02 100644 --- a/synfig-core/src/modules/mod_dv/trgt_dv.cpp +++ b/synfig-core/src/modules/mod_dv/trgt_dv.cpp @@ -282,7 +282,7 @@ dv_trgt::end_scanline() if(!file) return false; - color_to_pixelformat(buffer, color_buffer, PF_RGB, &gamma(), desc.get_w()); + color_to_pixelformat(buffer, color_buffer, PF_RGB, 0, desc.get_w()); if(!fwrite(buffer,1,desc.get_w()*3,file)) return false; diff --git a/synfig-core/src/modules/mod_ffmpeg/mptr_ffmpeg.cpp b/synfig-core/src/modules/mod_ffmpeg/mptr_ffmpeg.cpp index 1d81e21..c1e1718 100644 --- a/synfig-core/src/modules/mod_ffmpeg/mptr_ffmpeg.cpp +++ b/synfig-core/src/modules/mod_ffmpeg/mptr_ffmpeg.cpp @@ -217,30 +217,17 @@ ffmpeg_mptr::grab_frame(void) if(feof(file)) return false; - int x; - int y; - frame.set_wh(w,h); - for(y=0;ygamma_r = gamma; - task_gamma->gamma_g = gamma; - task_gamma->gamma_b = gamma; - task_gamma->gamma_a = gamma; + task_gamma->gamma = Gamma(gamma).get_inverted(); task_gamma->sub_task() = task; task = task_gamma; } diff --git a/synfig-core/src/modules/mod_filter/colorcorrect.h b/synfig-core/src/modules/mod_filter/colorcorrect.h index 3e22b87..a1ef4e2 100644 --- a/synfig-core/src/modules/mod_filter/colorcorrect.h +++ b/synfig-core/src/modules/mod_filter/colorcorrect.h @@ -30,7 +30,7 @@ #include #include -#include +#include #include /* === M A C R O S ========================================================= */ diff --git a/synfig-core/src/modules/mod_gif/trgt_gif.cpp b/synfig-core/src/modules/mod_gif/trgt_gif.cpp index 01603a3..7015d90 100644 --- a/synfig-core/src/modules/mod_gif/trgt_gif.cpp +++ b/synfig-core/src/modules/mod_gif/trgt_gif.cpp @@ -34,6 +34,7 @@ #include #include +#include #include #include "trgt_gif.h" @@ -62,7 +63,6 @@ gif::gif(const char *filename_, const synfig::TargetParam & /* params */): bs(), filename(filename_), file( (filename=="-")?stdout:fopen(filename_,POPEN_BINARY_WRITE_TYPE) ), - i(), codesize(), rootsize(), nextcode(), @@ -146,7 +146,7 @@ gif::init(synfig::ProgressCallback * /* cb */) if(!local_palette) { - curr_palette=Palette::grayscale(256/(1<<(8-rootsize))-1); + curr_palette = Palette::grayscale(256/(1<<(8-rootsize))-1, 1); output_curr_palette(); } @@ -170,20 +170,13 @@ void gif::output_curr_palette() { // Output the color table - for(i=0;i<256/(1<<(8-rootsize));i++) - { - if(i<(signed)curr_palette.size()) - { - Color color(curr_palette[i].color.clamped()); - //fputc(i*(1<<(8-rootsize)),file.get()); - //fputc(i*(1<<(8-rootsize)),file.get()); - //fputc(i*(1<<(8-rootsize)),file.get()); - fputc(gamma().r_F32_to_U8(color.get_r()),file.get()); - fputc(gamma().g_F32_to_U8(color.get_g()),file.get()); - fputc(gamma().b_F32_to_U8(color.get_b()),file.get()); - } - else - { + for(int i = 0; i < 256/(1<<(8-rootsize)); ++i) { + if (i < (int)curr_palette.size()) { + Color color = curr_palette[i].color.clamped(); + fputc((unsigned char)(color.get_r()*255.99), file.get()); + fputc((unsigned char)(color.get_g()*255.99), file.get()); + fputc((unsigned char)(color.get_b()*255.99), file.get()); + } else { fputc(255,file.get()); fputc(0,file.get()); fputc(255,file.get()); @@ -214,10 +207,9 @@ gif::start_frame(synfig::ProgressCallback *callback) void gif::end_frame() { - int w=desc.get_w(),h=desc.get_h(),i; + int w = desc.get_w(), h = desc.get_h(); unsigned int value; - int - delaytime=round_to_int(100.0/desc.get_frame_rate()); + int delaytime = round_to_int(100.0/desc.get_frame_rate()); bool build_off_previous(multi_image); @@ -244,12 +236,12 @@ gif::end_frame() if(local_palette) { - curr_palette=Palette(curr_surface,256/(1<<(8-rootsize))-build_off_previous-1); + curr_palette = Palette(curr_surface, 256/(1<<(8-rootsize)) - build_off_previous - 1, Gamma()); synfig::info("curr_palette.size()=%d",curr_palette.size()); } - int transparent_index(curr_palette.find_closest(Color(1,0,1,0))-curr_palette.begin()); - bool has_transparency(curr_palette[transparent_index].color.get_a()<=0.00001); + int transparent_index = curr_palette.find_closest(Color(1,0,1,0), Gamma()) - curr_palette.begin(); + bool has_transparency = curr_palette[transparent_index].color.get_a()<=0.00001; if(has_transparency) build_off_previous=false; @@ -327,10 +319,10 @@ gif::end_frame() //color_to_pixelformat(curr_frame[cur_scanline], curr_surface[cur_scanline], PF_GRAY, &gamma(), desc.get_w()); // Now we compress it! - for(i=0;idata[0], surface[0], PF_RGB, - gamma, + 0, w, h, frame_rgb->linesize[0], @@ -462,7 +462,7 @@ Target_LibAVCodec::set_rend_desc(RendDesc *given_desc) void Target_LibAVCodec::end_frame() - { internal->encode_frame(surface, &gamma(), curr_frame_ > desc.get_frame_end()); } + { internal->encode_frame(surface, curr_frame_ > desc.get_frame_end()); } bool Target_LibAVCodec::start_frame(synfig::ProgressCallback */*callback*/) diff --git a/synfig-core/src/modules/mod_magickpp/trgt_magickpp.cpp b/synfig-core/src/modules/mod_magickpp/trgt_magickpp.cpp index 2126973..1e8f820 100644 --- a/synfig-core/src/modules/mod_magickpp/trgt_magickpp.cpp +++ b/synfig-core/src/modules/mod_magickpp/trgt_magickpp.cpp @@ -276,7 +276,7 @@ bool magickpp_trgt::end_scanline() { if (previous_buffer_pointer) - color_to_pixelformat(previous_buffer_pointer, color_buffer, PF_RGB|PF_A, &gamma(), width); + color_to_pixelformat(previous_buffer_pointer, color_buffer, PF_RGB|PF_A, 0, width); if (!transparent) for (int i = 0; i < width; i++) diff --git a/synfig-core/src/modules/mod_mng/trgt_mng.cpp b/synfig-core/src/modules/mod_mng/trgt_mng.cpp index 6d708ce..098d859 100644 --- a/synfig-core/src/modules/mod_mng/trgt_mng.cpp +++ b/synfig-core/src/modules/mod_mng/trgt_mng.cpp @@ -206,7 +206,6 @@ mng_trgt::init(synfig::ProgressCallback * /* cb */) sizeof(synfig), synfig) != 0) goto cleanup_on_error; } - if (mng_putchunk_gama(mng, MNG_FALSE, (int)(gamma().get_gamma()*100000)) != 0) goto cleanup_on_error; if (mng_putchunk_phys(mng, MNG_FALSE, round_to_int(desc.get_x_res()),round_to_int(desc.get_y_res()), MNG_UNIT_METER) != 0) goto cleanup_on_error; if (mng_putchunk_time(mng, gmt->tm_year + 1900, gmt->tm_mon + 1, gmt->tm_mday, gmt->tm_hour, gmt->tm_min, gmt->tm_sec) != 0) goto cleanup_on_error; buffer=new unsigned char[(4*w)+1]; @@ -330,7 +329,7 @@ mng_trgt::end_scanline() } *buffer = MNG_FILTER_NONE; - color_to_pixelformat(buffer+1, color_buffer, PF_RGB|PF_A, &gamma(), desc.get_w()); + color_to_pixelformat(buffer+1, color_buffer, PF_RGB|PF_A, 0, desc.get_w()); zstream.next_in = buffer; zstream.avail_in = (4*w)+1; diff --git a/synfig-core/src/modules/mod_openexr/trgt_openexr.cpp b/synfig-core/src/modules/mod_openexr/trgt_openexr.cpp index 343537e..744d119 100644 --- a/synfig-core/src/modules/mod_openexr/trgt_openexr.cpp +++ b/synfig-core/src/modules/mod_openexr/trgt_openexr.cpp @@ -71,8 +71,7 @@ exr_trgt::exr_trgt(const char *Filename, const synfig::TargetParam ¶ms): buffer_color(NULL) { // OpenEXR uses linear gamma - gamma().set_gamma(1.0); - sequence_separator=params.sequence_separator; + sequence_separator = params.sequence_separator; } exr_trgt::~exr_trgt() diff --git a/synfig-core/src/modules/mod_png/mptr_cairo_png.cpp b/synfig-core/src/modules/mod_png/mptr_cairo_png.cpp index 6ae837e..450e45c 100644 --- a/synfig-core/src/modules/mod_png/mptr_cairo_png.cpp +++ b/synfig-core/src/modules/mod_png/mptr_cairo_png.cpp @@ -86,30 +86,6 @@ cairo_png_mptr::cairo_png_mptr(const synfig::FileSystem::Identifier &identifier) csurface_=NULL; return; } - CairoSurface cairo_s; - cairo_s.set_cairo_surface(csurface_); - if(!cairo_s.map_cairo_image()) - return; - int w=cairo_s.get_w(); - int h=cairo_s.get_h(); - for(int y=0; y #include #include +#include #include @@ -193,13 +194,10 @@ png_mptr::get_frame(synfig::Surface &surface, const synfig::RendDesc &/*renddesc if (bit_depth < 8) png_set_packing(png_ptr); - double fgamma; - if (png_get_gAMA(png_ptr, info_ptr, &fgamma)) - { - synfig::info("PNG: Image gamma is %f",fgamma); - png_set_gamma(png_ptr, gamma().get_gamma(), fgamma); - } - + double png_gamma; + if (!png_get_gAMA(png_ptr, info_ptr, &png_gamma)) + png_gamma = 1/2.2; + Gamma gamma(2.2*png_gamma); /* if (setjmp(png_jmpbuf(png_ptr))) @@ -230,50 +228,41 @@ png_mptr::get_frame(synfig::Surface &surface, const synfig::RendDesc &/*renddesc png_read_image(png_ptr, row_pointers); - png_uint_32 x, y; - surface.set_wh(width,height); - + surface.set_wh(width, height); switch(color_type) { case PNG_COLOR_TYPE_RGB: - for(y=0;y 0 && trans_alpha != NULL && row_pointers[y][x] < num_trans) - ac = trans_alpha[row_pointers[y][x]]; - float a=gamma().a_U8_to_F32(ac); - - surface[y][x]=Color(r, g, b, a); + a = k*(unsigned char)trans_alpha[row_pointers[y][x]]; + surface[y][x] = gamma.apply(Color(r, g, b, a)); } break; } @@ -319,5 +306,7 @@ png_mptr::get_frame(synfig::Surface &surface, const synfig::RendDesc &/*renddesc png_read_end(png_ptr, end_info); png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); + //debug::DebugSurface::save_to_file(surface, "pngimport"); + return true; } diff --git a/synfig-core/src/modules/mod_png/trgt_cairo_png.cpp b/synfig-core/src/modules/mod_png/trgt_cairo_png.cpp index 36332d2..da74536 100644 --- a/synfig-core/src/modules/mod_png/trgt_cairo_png.cpp +++ b/synfig-core/src/modules/mod_png/trgt_cairo_png.cpp @@ -114,7 +114,6 @@ cairo_png_trgt::obtain_surface(cairo_surface_t *&surface) bool cairo_png_trgt::put_surface(cairo_surface_t *surface, synfig::ProgressCallback *cb) { - gamma_filter(surface, gamma()); if(cairo_surface_status(surface)) { if(cb) cb->error(_("Cairo Surface bad status")); diff --git a/synfig-core/src/modules/mod_png/trgt_png.cpp b/synfig-core/src/modules/mod_png/trgt_png.cpp index de349b8..534e809 100644 --- a/synfig-core/src/modules/mod_png/trgt_png.cpp +++ b/synfig-core/src/modules/mod_png/trgt_png.cpp @@ -201,12 +201,11 @@ png_trgt::start_frame(synfig::ProgressCallback *callback) else png_set_IHDR(png_ptr,info_ptr,w,h,8,PNG_COLOR_TYPE_RGB,PNG_INTERLACE_NONE,PNG_COMPRESSION_TYPE_DEFAULT,PNG_FILTER_TYPE_DEFAULT); - // Write the gamma - //png_set_gAMA(png_ptr, info_ptr,1.0/gamma().get_gamma()); - png_set_gAMA(png_ptr, info_ptr,gamma().get_gamma()); - // Write the physical size png_set_pHYs(png_ptr,info_ptr,round_to_int(desc.get_x_res()),round_to_int(desc.get_y_res()),PNG_RESOLUTION_METER); + + // Explicit set gamma value to 2.2 (it's a default value) + png_set_gAMA(png_ptr,info_ptr,1/2.2); char title [] = "Title"; char description[] = "Description"; @@ -253,7 +252,7 @@ png_trgt::end_scanline() return false; PixelFormat pf = get_alpha_mode()==TARGET_ALPHA_MODE_KEEP ? PF_RGB|PF_A : PF_RGB; - color_to_pixelformat(buffer, color_buffer, pf, &gamma(), desc.get_w()); + color_to_pixelformat(buffer, color_buffer, pf, 0, desc.get_w()); setjmp(png_jmpbuf(png_ptr)); png_write_row(png_ptr,buffer); diff --git a/synfig-core/src/modules/mod_png/trgt_png_spritesheet.cpp b/synfig-core/src/modules/mod_png/trgt_png_spritesheet.cpp index 78032b5..00716a1 100644 --- a/synfig-core/src/modules/mod_png/trgt_png_spritesheet.cpp +++ b/synfig-core/src/modules/mod_png/trgt_png_spritesheet.cpp @@ -352,22 +352,18 @@ png_trgt_spritesheet::read_png_file() cout << "colors checked" << endl; - //Gamma correction for PNG. I took 2.2 value from - //http://www.libpng.org/pub/png/spec/1.2/PNG-GammaAppendix.html - //Also see gamma.h and gamma.cpp - Gamma gamma_png(2.2); - //From png bytes to synfig::Color conversion + const ColorReal k = 1/255.0; for (unsigned int y = 0; y < in_image.height; y++) { png_byte* row = row_pointers[y]; for (unsigned int x = 0; x < in_image.width; x++) { png_byte* ptr = &(row[x*4]); - color_data[y][x].set_r(gamma_png.r_U8_to_F32(ptr[0])); - color_data[y][x].set_g(gamma_png.g_U8_to_F32(ptr[1])); - color_data[y][x].set_b(gamma_png.b_U8_to_F32(ptr[2])); - color_data[y][x].set_a(gamma_png.a_U8_to_F32(ptr[3])); + color_data[y][x].set_r(ptr[0]*k); + color_data[y][x].set_g(ptr[1]*k); + color_data[y][x].set_b(ptr[2]*k); + color_data[y][x].set_a(ptr[3]*k); } } @@ -439,9 +435,6 @@ png_trgt_spritesheet::write_png_file() PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); - // Write the gamma - //png_set_gAMA(png_ptr, info_ptr,1.0/gamma().get_gamma()); - png_set_gAMA(png_ptr, info_ptr,gamma().get_gamma()); // Write the physical size png_set_pHYs(png_ptr,info_ptr,round_to_int(desc.get_x_res()),round_to_int(desc.get_y_res()),PNG_RESOLUTION_METER); @@ -483,7 +476,7 @@ png_trgt_spritesheet::write_png_file() color_data[cur_out_image_row], //PF_RGB|(get_alpha_mode()==TARGET_ALPHA_MODE_KEEP)?PF_A:PF_RGB, //Note: PF_RGB == 0 (get_alpha_mode() == TARGET_ALPHA_MODE_KEEP) ? PF_RGB | PF_A : PF_RGB, //Note: PF_RGB == 0 - &gamma(), + 0, sheet_width ); setjmp(png_jmpbuf(png_ptr)); png_write_row(png_ptr,buffer); diff --git a/synfig-core/src/modules/mod_ppm/mptr_ppm.cpp b/synfig-core/src/modules/mod_ppm/mptr_ppm.cpp index 31c180c..2a19983 100644 --- a/synfig-core/src/modules/mod_ppm/mptr_ppm.cpp +++ b/synfig-core/src/modules/mod_ppm/mptr_ppm.cpp @@ -85,29 +85,14 @@ ppm_mptr::get_frame(synfig::Surface &surface, const synfig::RendDesc &/*renddesc fscanf(file.get(),"%f",&divisor); fgetc(file.get()); - int x; - int y; - surface.set_wh(w,h); - for(y=0;ypos=pos; return _stop; } + Color Svg_parser::adjustGamma(float r,float g,float b,float a){ - Color ret(r,g,b,a); - if(gamma.get_gamma_r()!=1.0){ - if(ret.get_r() < 0) - ret.set_r(-gamma.r_F32_to_F32(-ret.get_r())); - else - ret.set_r(gamma.r_F32_to_F32(ret.get_r())); - } - if(gamma.get_gamma_g()!=1.0){ - if(ret.get_g() < 0) - ret.set_g(-gamma.g_F32_to_F32(-ret.get_g())); - else - ret.set_g(gamma.g_F32_to_F32(ret.get_g())); - } - if(gamma.get_gamma_b()!=1.0){ - if(ret.get_b() < 0) - ret.set_b(-gamma.b_F32_to_F32(-ret.get_b())); - else - ret.set_b(gamma.b_F32_to_F32(ret.get_b())); - } - if(gamma.get_gamma_a()!=1.0){ - if(ret.get_a() < 0) - ret.set_a(-gamma.a_F32_to_F32(-ret.get_a())); - else - ret.set_a(gamma.a_F32_to_F32(ret.get_a())); - } - return ret; + return gamma.apply(Color(r,g,b,a)); } LinearGradient* diff --git a/synfig-core/src/modules/mod_svg/svg_parser.h b/synfig-core/src/modules/mod_svg/svg_parser.h index b9dcb7b..411a53c 100644 --- a/synfig-core/src/modules/mod_svg/svg_parser.h +++ b/synfig-core/src/modules/mod_svg/svg_parser.h @@ -44,7 +44,6 @@ #include #include #include -#include #include /* === M A C R O S ========================================================= */ @@ -122,7 +121,7 @@ private: std::list rg; public: - Svg_parser(); + explicit Svg_parser(const Gamma &gamma = Gamma()); Canvas::Handle load_svg_canvas(std::string _filepath,String &errors, String &warnings); //String get_id(); //void set_id(String source); diff --git a/synfig-core/src/modules/mod_yuv420p/trgt_yuv.cpp b/synfig-core/src/modules/mod_yuv420p/trgt_yuv.cpp index e3fc9dc..01a0669 100644 --- a/synfig-core/src/modules/mod_yuv420p/trgt_yuv.cpp +++ b/synfig-core/src/modules/mod_yuv420p/trgt_yuv.cpp @@ -137,9 +137,6 @@ yuv::end_frame() { Color& c(surface[y][x]); c=c.clamped(); - c.set_r(gamma().r_F32_to_F32(c.get_r())); - c.set_g(gamma().g_F32_to_F32(c.get_g())); - c.set_b(gamma().b_F32_to_F32(c.get_b())); float f(c.get_y()); int i(max(min(round_to_int(c.get_y()*Y_RANGE),Y_RANGE),0)+Y_FLOOR); diff --git a/synfig-core/src/synfig/CMakeLists.txt b/synfig-core/src/synfig/CMakeLists.txt index e668047..617c212 100644 --- a/synfig-core/src/synfig/CMakeLists.txt +++ b/synfig-core/src/synfig/CMakeLists.txt @@ -35,7 +35,6 @@ target_sources(synfig "${CMAKE_CURRENT_LIST_DIR}/curveset.cpp" "${CMAKE_CURRENT_LIST_DIR}/distance.cpp" "${CMAKE_CURRENT_LIST_DIR}/exception.cpp" - "${CMAKE_CURRENT_LIST_DIR}/gamma.cpp" "${CMAKE_CURRENT_LIST_DIR}/guid.cpp" "${CMAKE_CURRENT_LIST_DIR}/importer.cpp" "${CMAKE_CURRENT_LIST_DIR}/cairoimporter.cpp" diff --git a/synfig-core/src/synfig/Makefile.am b/synfig-core/src/synfig/Makefile.am index 3f4b2fb..74298a6 100644 --- a/synfig-core/src/synfig/Makefile.am +++ b/synfig-core/src/synfig/Makefile.am @@ -100,7 +100,6 @@ SYNFIGHEADERS = \ curveset.h \ distance.h \ exception.h \ - gamma.h \ guid.h \ importer.h \ cairoimporter.h \ @@ -117,7 +116,6 @@ SYNFIGHEADERS = \ rect.h \ renddesc.h \ render.h \ - rendermethod.h \ savecanvas.h \ surface.h \ target.h \ @@ -157,7 +155,6 @@ SYNFIGSOURCES = \ curveset.cpp \ distance.cpp \ exception.cpp \ - gamma.cpp \ guid.cpp \ importer.cpp \ cairoimporter.cpp \ diff --git a/synfig-core/src/synfig/cairoimporter.cpp b/synfig-core/src/synfig/cairoimporter.cpp index b49fa6f..ffc8a0c 100644 --- a/synfig-core/src/synfig/cairoimporter.cpp +++ b/synfig-core/src/synfig/cairoimporter.cpp @@ -135,7 +135,6 @@ CairoImporter::open(const FileSystem::Identifier &identifier) } CairoImporter::CairoImporter(const FileSystem::Identifier &identifier): - gamma_(2.2), identifier(identifier) { } diff --git a/synfig-core/src/synfig/cairoimporter.h b/synfig-core/src/synfig/cairoimporter.h index 8767082..41ceb90 100644 --- a/synfig-core/src/synfig/cairoimporter.h +++ b/synfig-core/src/synfig/cairoimporter.h @@ -37,7 +37,7 @@ #include "cairo.h" #include "filesystem.h" -#include "gamma.h" +#include "color.h" #include "progresscallback.h" #include "renddesc.h" #include "string.h" @@ -147,20 +147,12 @@ public: typedef etl::loose_handle LooseHandle; typedef etl::handle ConstHandle; -private: - //! Gamma of the importer. - //! \todo Do not hardcode the gamma to 2.2 - Gamma gamma_; - protected: CairoImporter(const FileSystem::Identifier &identifier); public: const FileSystem::Identifier identifier; - Gamma& gamma() { return gamma_; } - const Gamma& gamma()const { return gamma_; } - virtual ~CairoImporter(); //! Gets a frame and puts it into \a cairo_surface_t diff --git a/synfig-core/src/synfig/canvas.cpp b/synfig-core/src/synfig/canvas.cpp index 0e292b7..3b61d9b 100644 --- a/synfig-core/src/synfig/canvas.cpp +++ b/synfig-core/src/synfig/canvas.cpp @@ -53,6 +53,7 @@ #include "layers/layer_pastecanvas.h" #include "valuenodes/valuenode_const.h" #include "valuenodes/valuenode_scale.h" +#include "rendering/common/task/taskpixelprocessor.h" #endif @@ -300,6 +301,23 @@ Canvas::get_context_sorted(const ContextParams ¶ms, CanvasBase &out_queue) c return Context(out_queue.begin(), params); } +rendering::Task::Handle +Canvas::build_rendering_task(const ContextParams &context_params) const +{ + CanvasBase sub_queue; + Context context = get_context_sorted(context_params, sub_queue); + rendering::Task::Handle task = context.build_rendering_task(); + + rendering::TaskPixelGamma::Handle task_gamma(new rendering::TaskPixelGamma()); + task_gamma->gamma = get_root()->rend_desc().get_gamma().get_inverted(); + task_gamma->sub_task() = task; + if (!task_gamma->is_transparent()) + task = task_gamma; + + return task; +} + + const ValueNodeList & Canvas::value_node_list()const { diff --git a/synfig-core/src/synfig/canvas.h b/synfig-core/src/synfig/canvas.h index e16963d..c55b54d 100644 --- a/synfig-core/src/synfig/canvas.h +++ b/synfig-core/src/synfig/canvas.h @@ -43,6 +43,7 @@ #include "node.h" #include "guid.h" #include "filesystem.h" +#include "rendering/task.h" /* === M A C R O S ========================================================= */ @@ -110,15 +111,20 @@ * * 0.9: git 6922776b8129fdae6cb42953b2715decc810786c * - * Added "split_radius" and "split_angle" to BLinePoint Composite - * Value Node + * Added "split_radius" and "split_angle" to BLinePoint Composite + * Value Node * * 1.0 git * * Added a canvas component called + * + * 1.1 + * + * Added gamma into a canvas rend_desc + * */ -#define CURRENT_CANVAS_VERSION "1.0" +#define CURRENT_CANVAS_VERSION "1.1" /* === T Y P E D E F S ===================================================== */ @@ -592,6 +598,9 @@ public: //! Retireves sorted double queue of Layers and Context of the first layer with rendering parameters Context get_context_sorted(const ContextParams ¶ms, CanvasBase &out_queue) const; + //! Creates sorted context and builds task for rendering based on it with applied gamma + rendering::Task::Handle build_rendering_task(const ContextParams &context_params) const; + int indexof(const const_iterator &iter) const; iterator byindex(int index); const_iterator byindex(int index) const; diff --git a/synfig-core/src/synfig/color.h b/synfig-core/src/synfig/color.h index cc8a79e..474c6e4 100644 --- a/synfig-core/src/synfig/color.h +++ b/synfig-core/src/synfig/color.h @@ -32,6 +32,7 @@ #include #include #include +#include namespace synfig { diff --git a/synfig-core/src/synfig/color/Makefile_insert b/synfig-core/src/synfig/color/Makefile_insert index b8bf4bc..2719b4f 100644 --- a/synfig-core/src/synfig/color/Makefile_insert +++ b/synfig-core/src/synfig/color/Makefile_insert @@ -6,7 +6,8 @@ COLOR_HH = \ color/cairocolor.h \ color/cairocoloraccumulator.h \ color/pixelformat.h \ - color/common.h + color/common.h \ + color/gamma.h COLOR_CC = \ color/color.cpp \ diff --git a/synfig-core/src/synfig/color/color.hpp b/synfig-core/src/synfig/color/color.hpp index e210197..877ffb6 100644 --- a/synfig-core/src/synfig/color/color.hpp +++ b/synfig-core/src/synfig/color/color.hpp @@ -30,7 +30,6 @@ #include #include -#include #include #include diff --git a/synfig-core/src/synfig/color/common.h b/synfig-core/src/synfig/color/common.h index 1b39fac..4f22e77 100644 --- a/synfig-core/src/synfig/color/common.h +++ b/synfig-core/src/synfig/color/common.h @@ -32,17 +32,11 @@ #include #include -#include #include #include /* === M A C R O S ========================================================= */ -#define use_colorspace_gamma() App::use_colorspace_gamma -#define colorspace_gamma() (2.2f) -#define gamma_in(x) ((x>=0) ? pow((float)x,1.0f/colorspace_gamma()) : -pow((float)-x,1.0f/colorspace_gamma())) -#define gamma_out(x) ((x>=0) ? pow((float)x, colorspace_gamma()) : -pow((float)-x, colorspace_gamma())) - namespace synfig { typedef float ColorReal; diff --git a/synfig-core/src/synfig/color/gamma.h b/synfig-core/src/synfig/color/gamma.h new file mode 100644 index 0000000..8cc1f43 --- /dev/null +++ b/synfig-core/src/synfig/color/gamma.h @@ -0,0 +1,121 @@ +/* === S Y N F I G ========================================================= */ +/*! \file gamma.h +** \brief Template Header +** +** $Id$ +** +** \legal +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === S T A R T =========================================================== */ + +#ifndef __SYNFIG_COLOR_GAMMA_H +#define __SYNFIG_COLOR_GAMMA_H + +/* === H E A D E R S ======================================================= */ + +#include "color.h" + +/* === M A C R O S ========================================================= */ + +/* === T Y P E D E F S ===================================================== */ + +/* === C L A S S E S & S T R U C T S ======================================= */ + +namespace synfig { + +/*! \class Gamma +** \brief This class performs color correction on Color classes. +** \stub +*/ +class Gamma +{ +private: + ColorReal gamma[3]; + +public: + static ColorReal calculate(ColorReal f, ColorReal gamma) + { return f < 0 ? -powf(-f, gamma) : powf(f, gamma); } + + explicit Gamma(ColorReal x = ColorReal(1)): + Gamma(x, x, x) { } + Gamma(ColorReal r, ColorReal g, ColorReal b) + { set(r, g, b); } + + bool operator==(const Gamma &other) const + { return get_r() == other.get_r() && get_g() == other.get_g() && get_b() == other.get_b(); } + bool operator!=(const Gamma &other) const + { return !(*this == other); } + bool operator<(const Gamma &other) const { + return get_r() < other.get_r() ? true + : other.get_r() < get_r() ? false + : get_g() < other.get_g() ? true + : other.get_g() < get_g() ? false + : get_b() < other.get_b(); + } + + Gamma operator* (const Gamma &other) const + { return Gamma(get_r()*other.get_r(), get_g()*other.get_g(), get_b()*other.get_b()); } + Gamma operator/ (const Gamma &other) const + { return *this * other.get_inverted(); } + + Gamma operator* (const ColorReal &x) const + { return *this * Gamma(x); } + Gamma operator/ (const ColorReal &x) const + { return *this * Gamma(1/x); } + + Gamma& operator*= (const Gamma &other) + { return *this = *this * other; } + Gamma& operator/= (const Gamma &other) + { return *this = *this / other; } + + Gamma& operator*= (const ColorReal &x) + { return *this = *this * x; } + Gamma& operator/= (const ColorReal &x) + { return *this = *this / x; } + + void set(int channel, ColorReal x) { gamma[channel] = x; } + void set_r(ColorReal x) { set(0, x); } + void set_g(ColorReal x) { set(1, x); } + void set_b(ColorReal x) { set(2, x); } + void set(ColorReal x) { set(x, x, x); } + void set(ColorReal r, ColorReal g, ColorReal b) + { set_r(r); set_g(g); set_b(b); } + + ColorReal get(int channel) const { return gamma[channel]; } + ColorReal get_r() const { return get(0); } + ColorReal get_g() const { return get(1); } + ColorReal get_b() const { return get(2); } + ColorReal get() const + { return (get_r() + get_g() + get_b())*(1/ColorReal(3)); } + + ColorReal apply(int channel, ColorReal x) const { return calculate(x, get(channel)); } + ColorReal apply_r(ColorReal x) const { return apply(0, x); } + ColorReal apply_g(ColorReal x) const { return apply(1, x); } + ColorReal apply_b(ColorReal x) const { return apply(2, x); } + Color apply(const Color &x) const + { return Color(apply_r(x.get_r()), apply_g(x.get_g()), apply_b(x.get_b()), x.get_a()); } + + void invert() { *this = get_inverted(); } + Gamma get_inverted() const + { return Gamma(1/get_r(), 1/get_g(), 1/get_b()); } +}; // END of class Gamma + +}; // END of namespace synfig + +/* === E N D =============================================================== */ + +#endif diff --git a/synfig-core/src/synfig/color/pixelformat.cpp b/synfig-core/src/synfig/color/pixelformat.cpp index e44f1e3..0b063fd 100644 --- a/synfig-core/src/synfig/color/pixelformat.cpp +++ b/synfig-core/src/synfig/color/pixelformat.cpp @@ -124,21 +124,15 @@ namespace { const Color &src, const Gamma *gamma ) { + const Color src_gm = with_gamma ? gamma->apply(src) : src; + // get color values int ri, gi, bi, ac; - if (with_gamma) { - ri = gamma->r_F32_to_U16(clamp(src.get_r())); - gi = gamma->g_F32_to_U16(clamp(src.get_g())); - bi = gamma->b_F32_to_U16(clamp(src.get_b())); - if (alpha) - ac = gamma->a_F32_to_U8(clamp(src.get_a())); - } else { - ri = (int)(clamp(src.get_r()*65535.9f)); - gi = (int)(clamp(src.get_g()*65535.9f)); - bi = (int)(clamp(src.get_b()*65535.9f)); - if (alpha) - ac = (int)(clamp(src.get_a())*ColorReal(255.9)); - } + ri = (int)(clamp(src_gm.get_r())*ColorReal(65535.99)); + gi = (int)(clamp(src_gm.get_g())*ColorReal(65535.99)); + bi = (int)(clamp(src_gm.get_b())*ColorReal(65535.99)); + if (alpha) + ac = (int)(clamp(src_gm.get_a())*ColorReal(255.99)); // put alpha before color channels if need if (alpha && alpha_start) diff --git a/synfig-core/src/synfig/color/pixelformat.h b/synfig-core/src/synfig/color/pixelformat.h index fbf087e..1e25fba 100644 --- a/synfig-core/src/synfig/color/pixelformat.h +++ b/synfig-core/src/synfig/color/pixelformat.h @@ -28,6 +28,7 @@ #define __SYNFIG_COLOR_PIXELFORMAT_H #include "color.h" +#include "gamma.h" #define FLAGS(x,y) (((x)&(y))==(y)) diff --git a/synfig-core/src/synfig/context.cpp b/synfig-core/src/synfig/context.cpp index b7b211e..697c618 100644 --- a/synfig-core/src/synfig/context.cpp +++ b/synfig-core/src/synfig/context.cpp @@ -256,16 +256,6 @@ Context::get_full_bounding_rect()const */ -void -Context::set_render_method(RenderMethod x) -{ - Context context(*this); - - if((context)->empty()) return; - - (*context)->set_render_method(context.get_next(), x); -} - etl::handle Context::hit_check(const Point &pos)const { diff --git a/synfig-core/src/synfig/context.h b/synfig-core/src/synfig/context.h index 3301f56..6227a4e 100644 --- a/synfig-core/src/synfig/context.h +++ b/synfig-core/src/synfig/context.h @@ -170,9 +170,6 @@ public: //! Returns the first context's layer's handle that intesects the given \point */ etl::handle hit_check(const Point &point)const; - // Set Render Method. Passes the information of the render method to use to the layers - void set_render_method(RenderMethod x); - //! Returns \c true if layer is active with this context_params static inline bool active(const ContextParams &context_params, const Layer &layer) { return layer.active() diff --git a/synfig-core/src/synfig/gamma.cpp b/synfig-core/src/synfig/gamma.cpp deleted file mode 100644 index 4da7b9c..0000000 --- a/synfig-core/src/synfig/gamma.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/* === S Y N F I G ========================================================= */ -/*! \file gamma.cpp -** \brief Template File -** -** $Id$ -** -** \legal -** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley -** -** This package is free software; you can redistribute it and/or -** modify it under the terms of the GNU General Public License as -** published by the Free Software Foundation; either version 2 of -** the License, or (at your option) any later version. -** -** This package is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** General Public License for more details. -** \endlegal -*/ -/* ========================================================================= */ - -/* === H E A D E R S ======================================================= */ - -#ifdef USING_PCH -# include "pch.h" -#else -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include - -#include - -#include "real.h" -#include "gamma.h" - -#endif - -/* === U S I N G =========================================================== */ - -using namespace synfig; - -/* === M A C R O S ========================================================= */ - -/* === G L O B A L S ======================================================= */ - -/* === P R O C E D U R E S ================================================= */ - -const Gamma Gamma::no_gamma; - -static void -build_table(float *table_U16_to_F32, unsigned short *table_U16_to_U16, float gamma) -{ - const float k = 1.f/65535.f; - for(int i = 0; i < 65536; ++i) { - float f = Gamma::calculate(k*float(i), gamma); - table_U16_to_F32[i] = f; - table_U16_to_U16[i] = (unsigned short)(f*65535.9f); - } -} - -/* === M E T H O D S ======================================================= */ - -Gamma::Gamma(float x): - Gamma(x, x, x, x) { } - -Gamma::Gamma(float r, float g, float b, float a) { - gamma[0] = gamma[1] = gamma[2] = gamma[3] = -1.f; - memset(table_U16_to_F32, 0, sizeof(table_U16_to_F32)); - memset(table_U16_to_U16, 0, sizeof(table_U16_to_U16)); - set_all(r, g, b, a); -} - -void -Gamma::set_gamma(int channel, float x) -{ - if (gamma[channel] == x) return; - - assert(x > 0.f); - gamma[channel] = x; - for(int i = 0; i < 4; ++i) - if (i != channel && gamma[i] == gamma[channel]) { - memcpy(table_U16_to_F32[channel], table_U16_to_F32[i], sizeof(table_U16_to_F32[channel])); - memcpy(table_U16_to_U16[channel], table_U16_to_U16[i], sizeof(table_U16_to_U16[channel])); - return; - } - build_table(table_U16_to_F32[channel], table_U16_to_U16[channel], gamma[channel]); -} - diff --git a/synfig-core/src/synfig/gamma.h b/synfig-core/src/synfig/gamma.h deleted file mode 100644 index 95eeecc..0000000 --- a/synfig-core/src/synfig/gamma.h +++ /dev/null @@ -1,146 +0,0 @@ -/* === S Y N F I G ========================================================= */ -/*! \file gamma.h -** \brief Template Header -** -** $Id$ -** -** \legal -** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley -** -** This package is free software; you can redistribute it and/or -** modify it under the terms of the GNU General Public License as -** published by the Free Software Foundation; either version 2 of -** the License, or (at your option) any later version. -** -** This package is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** General Public License for more details. -** \endlegal -*/ -/* ========================================================================= */ - -/* === S T A R T =========================================================== */ - -#ifndef __SYNFIG_GAMMA_H -#define __SYNFIG_GAMMA_H - -/* === H E A D E R S ======================================================= */ - -#include - -/* === M A C R O S ========================================================= */ - -/* === T Y P E D E F S ===================================================== */ - -/* === C L A S S E S & S T R U C T S ======================================= */ - -namespace synfig { - -/*! \class Gamma -** \brief This class performs color correction on Color classes. -** \stub -*/ -class Gamma -{ -private: - float gamma[4]; - float table_U16_to_F32[4][65536]; - unsigned short table_U16_to_U16[4][65536]; - -public: - static const Gamma no_gamma; - - static float calculate(float f, float gamma) { return powf(f, gamma); } - - explicit Gamma(float x = 1.f); - Gamma(float r, float g, float b, float a); - - void set_gamma(int channel, float x); - inline void set_gamma_r(float x) { set_gamma(0, x); } - inline void set_gamma_g(float x) { set_gamma(1, x); } - inline void set_gamma_b(float x) { set_gamma(2, x); } - inline void set_gamma_a(float x) { set_gamma(3, x); } - inline void set_gamma(float x) - { set_all(x, x, x, x); } - inline void set_all(float r, float g, float b, float a) - { set_gamma_r(r); set_gamma_g(g); set_gamma_b(b); set_gamma_a(a); } - - inline float get_gamma(int channel) const - { return gamma[channel]; } - inline float get_gamma_r() const { return get_gamma(0); } - inline float get_gamma_g() const { return get_gamma(1); } - inline float get_gamma_b() const { return get_gamma(2); } - inline float get_gamma_a() const { return get_gamma(3); } - inline float get_gamma() const - { return (get_gamma_r() + get_gamma_g() + get_gamma_r() + get_gamma_a())*0.25f; } - - - // conversions from U16 - - inline float U16_to_F32(int channel, unsigned short i) const { return table_U16_to_F32[channel][i]; } - inline float r_U16_to_F32(unsigned short i) const { return U16_to_F32(0, i); } - inline float g_U16_to_F32(unsigned short i) const { return U16_to_F32(1, i); } - inline float b_U16_to_F32(unsigned short i) const { return U16_to_F32(2, i); } - inline float a_U16_to_F32(unsigned short i) const { return U16_to_F32(3, i); } - - inline unsigned short U16_to_U16(int channel, unsigned short i) const { return table_U16_to_U16[channel][i]; } - inline unsigned short r_U16_to_U16(unsigned short i) const { return U16_to_U16(0, i); } - inline unsigned short g_U16_to_U16(unsigned short i) const { return U16_to_U16(1, i); } - inline unsigned short b_U16_to_U16(unsigned short i) const { return U16_to_U16(2, i); } - inline unsigned short a_U16_to_U16(unsigned short i) const { return U16_to_U16(3, i); } - - inline unsigned char U16_to_U8(int channel, unsigned short i) const { return (unsigned char)(U16_to_U16(channel, i) >> 8); } - inline unsigned char r_U16_to_U8(unsigned short i) const { return U16_to_U8(0, i); } - inline unsigned char g_U16_to_U8(unsigned short i) const { return U16_to_U8(1, i); } - inline unsigned char b_U16_to_U8(unsigned short i) const { return U16_to_U8(2, i); } - inline unsigned char a_U16_to_U8(unsigned short i) const { return U16_to_U8(3, i); } - - - // conversions from U8 - - inline float U8_to_F32(int channel, unsigned char i) const { return U16_to_F32(channel, ((unsigned short)i) << 8); } - inline float r_U8_to_F32(unsigned char i) const { return U8_to_F32(0, i); } - inline float g_U8_to_F32(unsigned char i) const { return U8_to_F32(1, i); } - inline float b_U8_to_F32(unsigned char i) const { return U8_to_F32(2, i); } - inline float a_U8_to_F32(unsigned char i) const { return U8_to_F32(3, i); } - - inline unsigned short U8_to_U16(int channel, unsigned char i) const { return U16_to_U16(channel, ((unsigned short)i) << 8); } - inline unsigned short r_U8_to_U16(unsigned char i) const { return U8_to_U16(0, i); } - inline unsigned short g_U8_to_U16(unsigned char i) const { return U8_to_U16(1, i); } - inline unsigned short b_U8_to_U16(unsigned char i) const { return U8_to_U16(2, i); } - inline unsigned short a_U8_to_U16(unsigned char i) const { return U8_to_U16(3, i); } - - inline unsigned char U8_to_U8(int channel, unsigned char i) const { return U16_to_U8(channel, ((unsigned short)i) << 8); } - inline unsigned char r_U8_to_U8(unsigned short i) const { return U8_to_U8(0, i); } - inline unsigned char g_U8_to_U8(unsigned short i) const { return U8_to_U8(1, i); } - inline unsigned char b_U8_to_U8(unsigned short i) const { return U8_to_U8(2, i); } - inline unsigned char a_U8_to_U8(unsigned short i) const { return U8_to_U8(3, i); } - - - // conversions from F32 - - inline float F32_to_F32(int channel, float f) const { return calculate(f, get_gamma(channel)); } - inline float r_F32_to_F32(float f) const { return F32_to_F32(0, f); } - inline float g_F32_to_F32(float f) const { return F32_to_F32(1, f); } - inline float b_F32_to_F32(float f) const { return F32_to_F32(2, f); } - inline float a_F32_to_F32(float f) const { return F32_to_F32(3, f); } - - inline unsigned short F32_to_U16(int channel, float f) const { return U16_to_U16(channel, (unsigned short)(f*65535.9f)); } - inline unsigned short r_F32_to_U16(float f) const { return F32_to_U16(0, f); } - inline unsigned short g_F32_to_U16(float f) const { return F32_to_U16(1, f); } - inline unsigned short b_F32_to_U16(float f) const { return F32_to_U16(2, f); } - inline unsigned short a_F32_to_U16(float f) const { return F32_to_U16(3, f); } - - inline unsigned char F32_to_U8(int channel, float f) const { return U16_to_U8(channel, (unsigned short)(f*65535.9f)); } - inline unsigned char r_F32_to_U8(float f) const { return F32_to_U8(0, f); } - inline unsigned char g_F32_to_U8(float f) const { return F32_to_U8(1, f); } - inline unsigned char b_F32_to_U8(float f) const { return F32_to_U8(2, f); } - inline unsigned char a_F32_to_U8(float f) const { return F32_to_U8(3, f); } -}; // END of class Gamma - -}; // END of namespace synfig - -/* === E N D =============================================================== */ - -#endif diff --git a/synfig-core/src/synfig/importer.cpp b/synfig-core/src/synfig/importer.cpp index 12a87fc..d4668e2 100644 --- a/synfig-core/src/synfig/importer.cpp +++ b/synfig-core/src/synfig/importer.cpp @@ -145,7 +145,6 @@ void Importer::forget(const FileSystem::Identifier &identifier) } Importer::Importer(const FileSystem::Identifier &identifier): - gamma_(2.2), identifier(identifier) { } diff --git a/synfig-core/src/synfig/importer.h b/synfig-core/src/synfig/importer.h index 9a466fb..932bd82 100644 --- a/synfig-core/src/synfig/importer.h +++ b/synfig-core/src/synfig/importer.h @@ -34,7 +34,6 @@ #include #include "filesystem.h" -#include "gamma.h" #include "progresscallback.h" #include "renddesc.h" #include "string.h" @@ -147,9 +146,6 @@ public: typedef etl::handle ConstHandle; private: - //! Gamma of the importer. - //! \todo Do not hardcode the gamma to 2.2 - Gamma gamma_; rendering::Surface::Handle last_surface_; protected: @@ -159,9 +155,6 @@ protected: public: const FileSystem::Identifier identifier; - Gamma& gamma() { return gamma_; } - const Gamma& gamma()const { return gamma_; } - virtual ~Importer(); //! Gets a frame and puts it into \a surface diff --git a/synfig-core/src/synfig/layer.cpp b/synfig-core/src/synfig/layer.cpp index 6133b96..bd36d49 100644 --- a/synfig-core/src/synfig/layer.cpp +++ b/synfig-core/src/synfig/layer.cpp @@ -646,12 +646,6 @@ Layer::set_outline_grow_vfunc(IndependentContext context, Real outline_grow)cons context.set_outline_grow(outline_grow); } -void -Layer::set_render_method(Context context, RenderMethod x) -{ - context.set_render_method(x); -} - Color Layer::get_color(Context context, const Point &pos)const { diff --git a/synfig-core/src/synfig/layer.h b/synfig-core/src/synfig/layer.h index 47d55bf..eae13d3 100644 --- a/synfig-core/src/synfig/layer.h +++ b/synfig-core/src/synfig/layer.h @@ -43,7 +43,6 @@ #include "paramdesc.h" #include "progresscallback.h" #include "real.h" -#include "rendermethod.h" #include "rendering/task.h" #include "string.h" #include "time.h" @@ -593,9 +592,6 @@ public: virtual Color get_color(Context context, const Point &pos)const; virtual CairoColor get_cairocolor(Context context, const Point &pos)const; - //! Sets the render method to the layer. Not all layers uses this virtual member - virtual void set_render_method(Context context, RenderMethod x); - // Temporary function to render transformed layer for leyers which yet not suppurt transformed rendering static bool render_transformed(const Layer *layer, Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb, const char *file, int line); diff --git a/synfig-core/src/synfig/layers/layer_bitmap.cpp b/synfig-core/src/synfig/layers/layer_bitmap.cpp index d1bb164..e90f46b 100644 --- a/synfig-core/src/synfig/layers/layer_bitmap.cpp +++ b/synfig-core/src/synfig/layers/layer_bitmap.cpp @@ -70,7 +70,6 @@ using namespace etl; synfig::Layer_Bitmap::Layer_Bitmap(): Layer_Composite (1.0,Color::BLEND_COMPOSITE), - method (SOFTWARE), surface_modification_id (0), param_tl (Point(-0.5,0.5)), param_br (Point(0.5,-0.5)), @@ -205,13 +204,6 @@ Layer_Bitmap::hit_check(synfig::Context context, const synfig::Point &pos)const return context.hit_check(pos); } -void -synfig::Layer_Bitmap::set_render_method(Context context, RenderMethod x) -{ - set_method(x); - context.set_render_method(x); -} - inline const Color& synfig::Layer_Bitmap::filter(Color& x)const @@ -665,14 +657,10 @@ Layer_Bitmap::build_composite_task_vfunc(ContextParams /* context_params */) con task = task_transform; rendering::TaskPixelGamma::Handle task_gamma = new rendering::TaskPixelGamma(); - if (!approximate_equal_lp(gamma, 1.f)) { - task_gamma->gamma[0] = gamma; - task_gamma->gamma[1] = gamma; - task_gamma->gamma[2] = gamma; - task_gamma->gamma[3] = gamma; - task_gamma->sub_task() = task; + task_gamma->gamma = get_canvas()->get_root()->rend_desc().get_gamma() / gamma; + task_gamma->sub_task() = task; + if (!task_gamma->is_transparent()) task = task_gamma; - } return task; } diff --git a/synfig-core/src/synfig/layers/layer_bitmap.h b/synfig-core/src/synfig/layers/layer_bitmap.h index 9ddda39..6e78820 100644 --- a/synfig-core/src/synfig/layers/layer_bitmap.h +++ b/synfig-core/src/synfig/layers/layer_bitmap.h @@ -31,7 +31,6 @@ #include "layer_composite.h" #include #include -#include // for RenderMethod #include #include @@ -51,7 +50,6 @@ class Layer_Bitmap : public Layer_Composite, public Layer_NoDeform { const Color& filter(Color& c)const; const CairoColor& filter(CairoColor& c)const; - RenderMethod method; GUID surface_modification_id; public: @@ -96,10 +94,6 @@ public: virtual synfig::Layer::Handle hit_check(synfig::Context context, const synfig::Point &point)const; - virtual void set_render_method(Context context, RenderMethod x); - void set_method(RenderMethod x) { method=x;} - RenderMethod get_method()const { return method;} - protected: virtual rendering::Task::Handle build_composite_task_vfunc(ContextParams context_params)const; }; // END of class Layer_Bitmap diff --git a/synfig-core/src/synfig/layers/layer_pastecanvas.cpp b/synfig-core/src/synfig/layers/layer_pastecanvas.cpp index c0a3db7..c9def27 100644 --- a/synfig-core/src/synfig/layers/layer_pastecanvas.cpp +++ b/synfig-core/src/synfig/layers/layer_pastecanvas.cpp @@ -50,6 +50,7 @@ #include #include +#include #include #endif @@ -705,17 +706,6 @@ void Layer_PasteCanvas::get_times_vfunc(Node::time_set &set) const Layer::get_times_vfunc(set); } - -void -Layer_PasteCanvas::set_render_method(Context context, RenderMethod x) -{ - // if there is a sub_canvas pass down to it - if (sub_canvas) - sub_canvas->get_context(context.get_params()).set_render_method(x); - // in any case pass it down - context.set_render_method(x); -} - void Layer_PasteCanvas::fill_sound_processor(SoundProcessor &soundProcessor) const { @@ -735,6 +725,15 @@ Layer_PasteCanvas::build_rendering_task_vfunc(Context context)const task_transformation->transformation->matrix = get_summary_transformation().get_matrix(); task_transformation->sub_task() = sub_context.build_rendering_task(); sub_task = task_transformation; + + if (sub_canvas->get_root() != get_canvas()->get_root()) { + rendering::TaskPixelGamma::Handle task_gamma(new rendering::TaskPixelGamma()); + task_gamma->gamma = get_canvas()->get_root()->rend_desc().get_gamma() + / sub_canvas->get_root()->rend_desc().get_gamma(); + task_gamma->sub_task() = sub_task; + if (!task_gamma->is_transparent()) + sub_task = task_gamma; + } } rendering::TaskBlend::Handle task_blend(new rendering::TaskBlend()); diff --git a/synfig-core/src/synfig/layers/layer_pastecanvas.h b/synfig-core/src/synfig/layers/layer_pastecanvas.h index a23f7c6..1a5c4f2 100644 --- a/synfig-core/src/synfig/layers/layer_pastecanvas.h +++ b/synfig-core/src/synfig/layers/layer_pastecanvas.h @@ -185,7 +185,6 @@ public: virtual Vocab get_param_vocab()const; //! Checks to see if a part of the Paste Canvas Layer is directly under \a point virtual synfig::Layer::Handle hit_check(synfig::Context context, const synfig::Point &point)const; - virtual void set_render_method(Context context, RenderMethod x); virtual void fill_sound_processor(SoundProcessor &soundProcessor) const; diff --git a/synfig-core/src/synfig/loadcanvas.cpp b/synfig-core/src/synfig/loadcanvas.cpp index ae92854..fcf20ef 100644 --- a/synfig-core/src/synfig/loadcanvas.cpp +++ b/synfig-core/src/synfig/loadcanvas.cpp @@ -3210,6 +3210,28 @@ CanvasParser::parse_canvas(xmlpp::Element *element,Canvas::Handle parent,bool in if(element->get_attribute("yres")) canvas->rend_desc().set_y_res(atof(element->get_attribute("yres")->get_value().c_str())); + Gamma gamma = canvas->rend_desc().get_gamma(); + String version = canvas->get_version(); + if ( version == "0.1" + || version == "0.2" + || version == "0.3" + || version == "0.4" + || version == "0.5" + || version == "0.6" + || version == "0.7" + || version == "0.8" + || version == "0.9" + || version == "1.0" ) + { + gamma.set(2.2); + } + if(element->get_attribute("gamma-r")) + gamma.set_r(atof(element->get_attribute("gamma-r")->get_value().c_str())); + if(element->get_attribute("gamma-g")) + gamma.set_g(atof(element->get_attribute("gamma-g")->get_value().c_str())); + if(element->get_attribute("gamma-b")) + gamma.set_b(atof(element->get_attribute("gamma-b")->get_value().c_str())); + canvas->rend_desc().set_gamma(gamma); if(element->get_attribute("fps")) canvas->rend_desc().set_frame_rate(atof(element->get_attribute("fps")->get_value().c_str())); diff --git a/synfig-core/src/synfig/palette.cpp b/synfig-core/src/synfig/palette.cpp index 8cf9d92..9eb1d56 100644 --- a/synfig-core/src/synfig/palette.cpp +++ b/synfig-core/src/synfig/palette.cpp @@ -35,7 +35,6 @@ #include "surface.h" #include "general.h" #include -#include "gamma.h" #include #include #include @@ -93,7 +92,7 @@ PaletteItem::add(const Color& x,int xweight) weight+=xweight; } -Palette::Palette(const Surface& surface, int max_colors): +Palette::Palette(const Surface& surface, int max_colors, const Gamma &gamma): name_(_("Surface Palette")) { max_colors-=2; @@ -118,7 +117,7 @@ Palette::Palette(const Surface& surface, int max_colors): continue; } - iterator iter(find_closest(color,&dist)); + iterator iter(find_closest(color, gamma, &dist)); if(sqrt(dist)<0.005) { iter->add(color); @@ -130,7 +129,7 @@ Palette::Palette(const Surface& surface, int max_colors): iterator iterlight(find_light()); PaletteItem light(*iterlight); erase(iterlight); - find_closest(light.color)->add(light.color,light.weight); + find_closest(light.color, gamma)->add(light.color,light.weight); } */ @@ -161,7 +160,7 @@ Palette::Palette(const Surface& surface, int max_colors): continue; } - iterator iter(find_closest(color,&dist)); + iterator iter(find_closest(color, gamma, &dist)); if(sqrt(dist)<0.005) { iter->add(color); @@ -181,7 +180,7 @@ Palette::Palette(const Surface& surface, int max_colors): { PaletteItem item(back()); pop_back(); - find_closest(item.color)->add(item.color,item.weight); + find_closest(item.color, gamma)->add(item.color,item.weight); } */ push_back(Color::black()); @@ -191,33 +190,35 @@ Palette::Palette(const Surface& surface, int max_colors): } Palette::const_iterator -Palette::find_closest(const Color& color, float* dist)const +Palette::find_closest(const Color& color, const Gamma &gamma, float* dist)const { // For the sake of avoiding cut-and-paste // bugs, we'll just use the non-const // find_closest()... It doesn't change anything // anyway. - return const_cast(this)->find_closest(color,dist); + return const_cast(this)->find_closest(color, gamma, dist); } Palette::iterator -Palette::find_closest(const Color& color, float* dist) +Palette::find_closest(const Color& color, const Gamma &gamma, float* dist) { iterator iter; iterator best_match(begin()); float best_dist(1000000); - const float prep_y(powf(color.get_y(),2.2f)*color.get_a()); - const float prep_u(color.get_u()); - const float prep_v(color.get_v()); + const Color prep = gamma.apply(color); + const float prep_y(prep.get_y()*prep.get_a()); + const float prep_u(prep.get_u()); + const float prep_v(prep.get_v()); for(iter=begin();iter!=end();++iter) { - const float diff_y(prep_y-powf(iter->color.get_y(),2.2f)*iter->color.get_a()); - const float diff_u(prep_u-iter->color.get_u()); - const float diff_v(prep_v-iter->color.get_v()); - const float diff_a(color.get_a()-iter->color.get_a()); + const Color ic = gamma.apply(iter->color); + const float diff_y(prep_y - ic.get_y()*ic.get_a()); + const float diff_u(prep_u - ic.get_u()); + const float diff_v(prep_v - ic.get_v()); + const float diff_a(prep.get_a() - ic.get_a()); const float dist( @@ -229,8 +230,8 @@ Palette::find_closest(const Color& color, float* dist) // cross product /*abs( - prep_u*iter->color.get_u()- - prep_v*iter->color.get_v() + prep_u*ic.get_u()- + prep_v*ic.get_v() )*/ ); if(dist> r >> g >> b; getline(ss, item.name); - item.color.set_r(gamma.r_F32_to_F32(r/255)); - item.color.set_g(gamma.g_F32_to_F32(g/255)); - item.color.set_b(gamma.b_F32_to_F32(b/255)); + item.color.set_r(r/255); + item.color.set_g(g/255); + item.color.set_b(b/255); // Alpha is 1 by default item.color.set_a(1); diff --git a/synfig-core/src/synfig/palette.h b/synfig-core/src/synfig/palette.h index 32ed214..6269436 100644 --- a/synfig-core/src/synfig/palette.h +++ b/synfig-core/src/synfig/palette.h @@ -71,16 +71,16 @@ public: /*! Generates a palette for the given ** surface */ - Palette(const Surface& surface, int size=256); + Palette(const Surface& surface, int size, const Gamma &gamma); - iterator find_closest(const Color& color, float* dist=0); - const_iterator find_closest(const Color& color, float* dist=0)const; + iterator find_closest(const Color& color, const Gamma &gamma, float* dist = 0); + const_iterator find_closest(const Color& color, const Gamma &gamma, float* dist = 0)const; iterator find_heavy(); iterator find_light(); - static Palette grayscale(int steps=16); + static Palette grayscale(int steps, ColorReal gamma); void save_to_file(const synfig::String& filename)const; diff --git a/synfig-core/src/synfig/renddesc.h b/synfig-core/src/synfig/renddesc.h index 2faa961..1efd5c3 100644 --- a/synfig-core/src/synfig/renddesc.h +++ b/synfig-core/src/synfig/renddesc.h @@ -115,6 +115,8 @@ private: Matrix transformation_matrix; //! Root outline grow value Real outline_grow; + //! Gamma value + Gamma gamma; public: //! Default Constructor @@ -139,7 +141,8 @@ public: frame_rate (24), time_begin (0), time_end (0), - outline_grow (0) + outline_grow (0), + gamma () { } static RendDesc zero() @@ -363,6 +366,8 @@ public: Real get_outline_grow() const { return outline_grow; } void set_outline_grow(Real x) { outline_grow = x; } + const Gamma& get_gamma() const { return gamma; } + void set_gamma(const Gamma &x) { gamma = x; } }; // END of class RendDesc }; /* end namespace synfig */ diff --git a/synfig-core/src/synfig/rendering/common/task/taskpixelprocessor.h b/synfig-core/src/synfig/rendering/common/task/taskpixelprocessor.h index 8d5a008..b709e68 100644 --- a/synfig-core/src/synfig/rendering/common/task/taskpixelprocessor.h +++ b/synfig-core/src/synfig/rendering/common/task/taskpixelprocessor.h @@ -92,18 +92,14 @@ public: static Token token; virtual Token::Handle get_token() const { return token.handle(); } - union { - ColorReal gamma[4]; - struct { ColorReal gamma_r, gamma_g, gamma_b, gamma_a; }; - }; - TaskPixelGamma(): gamma_r(1.0), gamma_g(1.0), gamma_b(1.0), gamma_a(1.0) { } + Gamma gamma; + TaskPixelGamma() { } virtual bool is_transparent() const { - return approximate_equal_lp(gamma_r, ColorReal(1.0)) - && approximate_equal_lp(gamma_g, ColorReal(1.0)) - && approximate_equal_lp(gamma_b, ColorReal(1.0)) - && approximate_equal_lp(gamma_a, ColorReal(1.0)); + return approximate_equal_lp(gamma.get_r(), ColorReal(1.0)) + && approximate_equal_lp(gamma.get_g(), ColorReal(1.0)) + && approximate_equal_lp(gamma.get_b(), ColorReal(1.0)); } }; diff --git a/synfig-core/src/synfig/rendering/software/task/taskpixelgammasw.cpp b/synfig-core/src/synfig/rendering/software/task/taskpixelgammasw.cpp index b007d92..993fcb8 100644 --- a/synfig-core/src/synfig/rendering/software/task/taskpixelgammasw.cpp +++ b/synfig-core/src/synfig/rendering/software/task/taskpixelgammasw.cpp @@ -70,9 +70,9 @@ private: int height; union { - ColorReal gamma[4]; + ColorReal gamma[3]; struct { - ColorReal gamma_r, gamma_g, gamma_b, gamma_a; + ColorReal gamma_r, gamma_g, gamma_b; }; }; @@ -80,7 +80,7 @@ private: dst(), dst_stride(), src(), src_stride(), width(), height(), - gamma_r(1.0), gamma_g(1.0), gamma_b(1.0), gamma_a(1.0) + gamma_r(1.0), gamma_g(1.0), gamma_b(1.0) { } Params( @@ -92,13 +92,12 @@ private: int height, ColorReal gamma_r, ColorReal gamma_g, - ColorReal gamma_b, - ColorReal gamma_a + ColorReal gamma_b ): dst((ColorReal*)dst), dst_stride(dst_stride), src((const ColorReal*)src), src_stride(src_stride), width(width), height(height), - gamma_r(gamma_r), gamma_g(gamma_g), gamma_b(gamma_b), gamma_a(gamma_a) + gamma_r(gamma_r), gamma_g(gamma_g), gamma_b(gamma_b) { } }; @@ -108,16 +107,10 @@ private: return std::max(-max, std::min(max, x)); } - static inline ColorReal non_zero(const ColorReal &x) + static inline ColorReal clamp_positive(const ColorReal &x) { - const ColorReal min = real_low_precision(); - return x > ColorReal(0.0) ? std::max(min, x) : std::min(-min, x); - } - - static inline ColorReal positive(const ColorReal &x) - { - const ColorReal min = real_low_precision(); - return std::max(min, x); + const ColorReal max = ColorReal(1.0)/real_low_precision(); + return std::max(real_low_precision(), std::min(max, x)); } static inline void func_none(ColorReal&, const ColorReal&, const ColorReal&) { } @@ -125,21 +118,12 @@ private: { dst = src; } static inline void func_one(ColorReal &dst, const ColorReal &, const ColorReal &) { dst = ColorReal(1.0); } - static inline void func_div(ColorReal &dst, const ColorReal &src, const ColorReal&) - { dst = clamp(ColorReal(1.0)/non_zero(src)); } - static inline void func_pow_positive(ColorReal &dst, const ColorReal &src, const ColorReal &gamma) - { dst = clamp(pow(positive(src), gamma)); } - static inline void func_pow_negative(ColorReal &dst, const ColorReal &src, const ColorReal &gamma) - { dst = clamp(pow(positive(src), gamma)); } - - template - static void process_rgba(const Params &p) { - bool set_one = approximate_equal_lp(p.gamma_r, ColorReal(0.0)) - && approximate_equal_lp(p.gamma_g, ColorReal(0.0)) - && approximate_equal_lp(p.gamma_b, ColorReal(0.0)) - && approximate_equal_lp(p.gamma_a, ColorReal(0.0)); - - if (set_one || p.src == p.dst) + static inline void func_pow(ColorReal &dst, const ColorReal &src, const ColorReal &gamma) + { dst = clamp(src < 0 ? -pow(-src, gamma) : pow(src, gamma)); } + + template + static void process_rgb(const Params &p) { + if (p.src == p.dst) { assert(p.src_stride == p.dst_stride); @@ -153,7 +137,6 @@ private: fr(dst[0], dst[0], p.gamma_r); fg(dst[1], dst[1], p.gamma_g); fb(dst[2], dst[2], p.gamma_b); - fa(dst[3], dst[3], p.gamma_a); } } } @@ -173,57 +156,33 @@ private: fr(dst[0], src[0], p.gamma_r); fg(dst[1], src[1], p.gamma_g); fb(dst[2], src[2], p.gamma_b); - fa(dst[3], src[3], p.gamma_a); + dst[3] = src[3]; } } } } - template - static void process_rgb(const Params &p) { - if (approximate_equal_lp(p.gamma_a, ColorReal( 0.0))) process_rgba(p); else - if (approximate_equal_lp(p.gamma_a, ColorReal(-1.0))) process_rgba(p); else - if (approximate_equal_lp(p.gamma_a, ColorReal( 1.0))) { - if (p.src == p.dst) process_rgba(p); else - process_rgba(p); - } else - if (p.gamma_a > ColorReal(0.0)) process_rgba(p); else - process_rgba(p); - } - template static void process_rg(const Params &p) { - if (approximate_equal_lp(p.gamma_b, ColorReal( 0.0))) process_rgb(p); else - if (approximate_equal_lp(p.gamma_b, ColorReal(-1.0))) process_rgb(p); else - if (approximate_equal_lp(p.gamma_b, ColorReal( 1.0))) { - if (p.src == p.dst) process_rgb(p); else + if ( approximate_equal_lp(p.gamma_b, ColorReal(0.0))) process_rgb(p); else + if (!approximate_equal_lp(p.gamma_b, ColorReal(1.0))) process_rgb(p); else + if (p.src == p.dst) process_rgb(p); else process_rgb(p); - } else - if (p.gamma_b > ColorReal(0.0)) process_rgb(p); else - process_rgb(p); } template static void process_r(const Params &p) { - if (approximate_equal_lp(p.gamma_g, ColorReal( 0.0))) process_rg(p); else - if (approximate_equal_lp(p.gamma_g, ColorReal(-1.0))) process_rg(p); else - if (approximate_equal_lp(p.gamma_g, ColorReal( 1.0))) { - if (p.src == p.dst) process_rg(p); else + if ( approximate_equal_lp(p.gamma_g, ColorReal(0.0))) process_rg(p); else + if (!approximate_equal_lp(p.gamma_g, ColorReal(1.0))) process_rg(p); else + if (p.src == p.dst) process_rg(p); else process_rg(p); - } else - if (p.gamma_g > ColorReal(0.0)) process_rg(p); else - process_rg(p); } static void process(const Params &p) { - if (approximate_equal_lp(p.gamma_r, ColorReal( 0.0))) process_r(p); else - if (approximate_equal_lp(p.gamma_r, ColorReal(-1.0))) process_r(p); else - if (approximate_equal_lp(p.gamma_r, ColorReal( 1.0))) { - if (p.src == p.dst) process_r(p); else + if ( approximate_equal_lp(p.gamma_r, ColorReal(0.0))) process_r(p); else + if (!approximate_equal_lp(p.gamma_r, ColorReal(1.0))) process_r(p); else + if (p.src == p.dst) process_r(p); else process_r(p); - } else - if (p.gamma_r > ColorReal(0.0)) process_r(p); else - process_r(p); } public: @@ -252,10 +211,9 @@ public: src.get_pitch()/sizeof(Color), rs.get_width(), rs.get_height(), - clamp(1.0/non_zero(gamma_r)), - clamp(1.0/non_zero(gamma_g)), - clamp(1.0/non_zero(gamma_b)), - clamp(1.0/non_zero(gamma_a)) )); + clamp_positive(gamma.get_r()), + clamp_positive(gamma.get_g()), + clamp_positive(gamma.get_b()) )); } return true; diff --git a/synfig-core/src/synfig/rendermethod.h b/synfig-core/src/synfig/rendermethod.h deleted file mode 100644 index 4846701..0000000 --- a/synfig-core/src/synfig/rendermethod.h +++ /dev/null @@ -1,46 +0,0 @@ -/* === S Y N F I G ========================================================= */ -/*! \file rendermethod.h - ** \brief Enumeration to define the render method used - ** - ** $Id$ - ** - ** \legal - ** Copyright (c) 2012 Nikita Kitaev - ** - ** This package is free software; you can redistribute it and/or - ** modify it under the terms of the GNU General Public License as - ** published by the Free Software Foundation; either version 2 of - ** the License, or (at your option) any later version. - ** - ** This package is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - ** General Public License for more details. - ** \endlegal - */ -/* ========================================================================= */ - -/* === S T A R T =========================================================== */ - -#ifndef __SYNFIG_RENDERMETHOD_H -#define __SYNFIG_RENDERMETHOD_H - -/* === H E A D E R S ======================================================= */ - -/* === M A C R O S ========================================================= */ - -/* === T Y P E D E F S ===================================================== */ - -/* === C L A S S E S & S T R U C T S ======================================= */ -namespace synfig -{ -//! Available rendering methods -enum RenderMethod { - SOFTWARE = 0x100, //!< Software rendering - OPENGL, //!< OpenGL rendering (not supported) - CAIRO //!< Cairo rendering -}; -}; // end namespace synfig -/* === E N D =============================================================== */ - -#endif diff --git a/synfig-core/src/synfig/savecanvas.cpp b/synfig-core/src/synfig/savecanvas.cpp index 370a389..21a3612 100644 --- a/synfig-core/src/synfig/savecanvas.cpp +++ b/synfig-core/src/synfig/savecanvas.cpp @@ -937,18 +937,24 @@ xmlpp::Element* encode_canvas(xmlpp::Element* root,Canvas::ConstHandle canvas) if(!canvas->get_id().empty() && !canvas->is_root() && !canvas->is_inline()) root->set_attribute("id",canvas->get_id()); - if(!canvas->parent() || canvas->parent()->rend_desc().get_w()!=canvas->rend_desc().get_w()) + if(!canvas->parent() || canvas->parent()->rend_desc().get_w()!=rend_desc.get_w()) root->set_attribute("width",strprintf("%d",rend_desc.get_w())); - if(!canvas->parent() || canvas->parent()->rend_desc().get_h()!=canvas->rend_desc().get_h()) + if(!canvas->parent() || canvas->parent()->rend_desc().get_h()!=rend_desc.get_h()) root->set_attribute("height",strprintf("%d",rend_desc.get_h())); - if(!canvas->parent() || canvas->parent()->rend_desc().get_x_res()!=canvas->rend_desc().get_x_res()) + if(!canvas->parent() || canvas->parent()->rend_desc().get_x_res()!=rend_desc.get_x_res()) root->set_attribute("xres",strprintf("%f",rend_desc.get_x_res())); - if(!canvas->parent() || canvas->parent()->rend_desc().get_y_res()!=canvas->rend_desc().get_y_res()) + if(!canvas->parent() || canvas->parent()->rend_desc().get_y_res()!=rend_desc.get_y_res()) root->set_attribute("yres",strprintf("%f",rend_desc.get_y_res())); + if(!canvas->parent() || canvas->parent()->rend_desc().get_gamma()!=rend_desc.get_gamma()) + { + root->set_attribute("gamma-r",strprintf("%f",rend_desc.get_gamma().get_r())); + root->set_attribute("gamma-g",strprintf("%f",rend_desc.get_gamma().get_g())); + root->set_attribute("gamma-b",strprintf("%f",rend_desc.get_gamma().get_b())); + } if(!canvas->parent() || canvas->parent()->rend_desc().get_tl()!=canvas->rend_desc().get_tl() || @@ -972,6 +978,9 @@ xmlpp::Element* encode_canvas(xmlpp::Element* root,Canvas::ConstHandle canvas) if(!canvas->parent() || canvas->parent()->rend_desc().get_time_end()!=canvas->rend_desc().get_time_end()) root->set_attribute("end-time",rend_desc.get_time_end().get_string(rend_desc.get_frame_rate())); + if(!canvas->parent() || canvas->parent()->rend_desc().get_gamma()!=canvas->rend_desc().get_gamma()) + root->set_attribute("end-time",rend_desc.get_time_end().get_string(rend_desc.get_frame_rate())); + if(!canvas->is_inline()) { root->set_attribute("bgcolor",strprintf(VIEW_BOX_FORMAT, diff --git a/synfig-core/src/synfig/target.cpp b/synfig-core/src/synfig/target.cpp index 358850f..f602d24 100644 --- a/synfig-core/src/synfig/target.cpp +++ b/synfig-core/src/synfig/target.cpp @@ -41,8 +41,6 @@ using namespace std; synfig::Target::Book* synfig::Target::book_; synfig::Target::ExtBook* synfig::Target::ext_book_; -static synfig::Gamma* default_gamma_; - /* === P R O C E D U R E S ================================================= */ bool @@ -50,8 +48,6 @@ Target::subsys_init() { book_=new synfig::Target::Book(); ext_book_=new synfig::Target::ExtBook(); -//! \todo Do not hard core gamma to 2.2 - default_gamma_=new synfig::Gamma(1.0/2.2); // At least one target must be available. book()["null"].factory = @@ -74,7 +70,6 @@ Target::subsys_stop() { delete book_; delete ext_book_; - delete default_gamma_; return true; } @@ -95,7 +90,6 @@ Target::ext_book() Target::Target(): quality_(4), - gamma_(*default_gamma_), alpha_mode(TARGET_ALPHA_MODE_KEEP), avoid_time_sync_(false), curr_frame_(0) diff --git a/synfig-core/src/synfig/target.h b/synfig-core/src/synfig/target.h index 52b201c..36e881c 100644 --- a/synfig-core/src/synfig/target.h +++ b/synfig-core/src/synfig/target.h @@ -175,8 +175,6 @@ public: //! Render quality used for the render process of the target. int quality_; - //! Gamma value used for the render process of the target - Gamma gamma_; //! Tells how to handle alpha. Used by non alpha supported targets to decide if the background must be filled or not TargetAlphaMode alpha_mode; @@ -208,9 +206,6 @@ public: TargetAlphaMode get_alpha_mode()const { return alpha_mode; } //! Sets how to handle alpha void set_alpha_mode(TargetAlphaMode x=TARGET_ALPHA_MODE_KEEP) { alpha_mode=x; } - Gamma &gamma() { return gamma_; } - //! Sets the target gamma - const Gamma &gamma()const { return gamma_; } //! Sets the target canvas. Must be defined by derived targets virtual void set_canvas(etl::handle c); //! Gets the target canvas. diff --git a/synfig-core/src/synfig/target_cairo.cpp b/synfig-core/src/synfig/target_cairo.cpp index 515c261..fd3731a 100644 --- a/synfig-core/src/synfig/target_cairo.cpp +++ b/synfig-core/src/synfig/target_cairo.cpp @@ -38,7 +38,6 @@ #include "canvas.h" #include "context.h" #include "render.h" -#include "rendermethod.h" #include "string.h" #include "surface.h" @@ -122,7 +121,6 @@ synfig::Target_Cairo::render(ProgressCallback *cb) Context context; // pass the Render Method to the context context=canvas->get_context(context_params); - context.set_render_method(CAIRO); // Set the time that we wish to render if(!get_avoid_time_sync() || canvas->get_time()!=t) { @@ -225,15 +223,10 @@ Target_Cairo::gamma_filter(cairo_surface_t *surface, const synfig::Gamma &gamma) { CairoColor c=cairo_s[y][x]; if (c.get_alpha()) { - float a=c.get_alpha(); - c.set_a(gamma.b_U8_to_U8(c.get_alpha())); - float aa=c.get_alpha(); - unsigned char r=(unsigned char)(aa*gamma.r_F32_to_F32(c.get_r()/a)); - unsigned char g=(unsigned char)(aa*gamma.g_F32_to_F32(c.get_g()/a)); - unsigned char b=(unsigned char)(aa*gamma.b_F32_to_F32(c.get_b()/a)); - c.set_r(r); - c.set_g(g); - c.set_b(b); + float a = c.get_alpha(); + c.set_r( (unsigned char)(a*gamma.apply_r(c.get_r()/a)) ); + c.set_r( (unsigned char)(a*gamma.apply_g(c.get_g()/a)) ); + c.set_r( (unsigned char)(a*gamma.apply_b(c.get_b()/a)) ); } cairo_s[y][x]=c; } diff --git a/synfig-core/src/synfig/target_cairo.h b/synfig-core/src/synfig/target_cairo.h index f7db486..81df407 100644 --- a/synfig-core/src/synfig/target_cairo.h +++ b/synfig-core/src/synfig/target_cairo.h @@ -72,7 +72,7 @@ public: //! Puts the rendered surface onto the target. virtual bool put_surface(cairo_surface_t *surface, ProgressCallback *cb=NULL); - //! Filters the cairo surface based on gamma (hardcored for the moment to 2.2) + //! Filters the cairo surface based on gamma static void gamma_filter(cairo_surface_t* surface, const synfig::Gamma &gamma); private: diff --git a/synfig-core/src/synfig/target_cairo_tile.cpp b/synfig-core/src/synfig/target_cairo_tile.cpp index 89df030..54a53f3 100644 --- a/synfig-core/src/synfig/target_cairo_tile.cpp +++ b/synfig-core/src/synfig/target_cairo_tile.cpp @@ -229,7 +229,6 @@ synfig::Target_Cairo_Tile::render(ProgressCallback *cb) Context context; // pass the Render Method to the context context=canvas->get_context(context_params); - context.set_render_method(CAIRO); // Set the time that we wish to render if(!get_avoid_time_sync() || canvas->get_time()!=t) { @@ -291,15 +290,10 @@ Target_Cairo_Tile::gamma_filter(cairo_surface_t *surface, const synfig::Gamma &g { CairoColor c=cairo_s[y][x]; if (c.get_alpha()) { - float a=c.get_alpha(); - c.set_a(gamma.b_U8_to_U8(c.get_alpha())); - float aa=c.get_alpha(); - unsigned char r=(unsigned char)(aa*gamma.r_F32_to_F32(c.get_r()/a)); - unsigned char g=(unsigned char)(aa*gamma.g_F32_to_F32(c.get_g()/a)); - unsigned char b=(unsigned char)(aa*gamma.b_F32_to_F32(c.get_b()/a)); - c.set_r(r); - c.set_g(g); - c.set_b(b); + float a = c.get_alpha(); + c.set_r( (unsigned char)(a*gamma.apply_r(c.get_r()/a)) ); + c.set_r( (unsigned char)(a*gamma.apply_g(c.get_g()/a)) ); + c.set_r( (unsigned char)(a*gamma.apply_b(c.get_b()/a)) ); } cairo_s[y][x]=c; } diff --git a/synfig-core/src/synfig/target_cairo_tile.h b/synfig-core/src/synfig/target_cairo_tile.h index dbafa6d..fa22e8a 100644 --- a/synfig-core/src/synfig/target_cairo_tile.h +++ b/synfig-core/src/synfig/target_cairo_tile.h @@ -123,7 +123,7 @@ public: /*! \see start_frame() */ virtual void end_frame()=0; - //! Filters the cairo surface based on gamma (hardcored for the moment to 2.2) + //! Filters the cairo surface based on gamma static void gamma_filter(cairo_surface_t* surface, const synfig::Gamma &gamma); private: diff --git a/synfig-core/src/synfig/target_scanline.cpp b/synfig-core/src/synfig/target_scanline.cpp index 91fa317..1d298ff 100644 --- a/synfig-core/src/synfig/target_scanline.cpp +++ b/synfig-core/src/synfig/target_scanline.cpp @@ -82,23 +82,14 @@ Target_Scanline::next_frame(Time& time) } bool -synfig::Target_Scanline::call_renderer(Context &context, const etl::handle &surface, int /* quality */, const RendDesc &renddesc, ProgressCallback * /* cb */) +synfig::Target_Scanline::call_renderer( + const etl::handle &surface, + Canvas &canvas, + const ContextParams &context_params, + const RendDesc &renddesc ) { - rendering::Task::Handle task; surface->create(renddesc.get_w(), renddesc.get_h()); - { - // TODO: quick hack - // we need to pass already sorted context to renderer - // when old renderer will finally removed - CanvasBase sub_queue; - Context sub_context; - if (*context && (*context)->get_canvas()) - sub_context = (*context)->get_canvas()->get_context_sorted(context.get_params(), sub_queue); - else - sub_context = context; - - task = sub_context.build_rendering_task(); - } + rendering::Task::Handle task = canvas.build_rendering_task(context_params); if (task) { @@ -136,7 +127,6 @@ synfig::Target_Scanline::render(ProgressCallback *cb) int frames=0, total_frames, - quality=get_quality(), frame_start, frame_end; Time @@ -174,11 +164,6 @@ synfig::Target_Scanline::render(ProgressCallback *cb) if(cb && !cb->amount_complete(total_frames-frames,total_frames)) return false; - Context context; - // pass the Render Method to the context - context = canvas->get_context(context_params); - context.set_render_method(SOFTWARE); - // Set the time that we wish to render if(!get_avoid_time_sync() || canvas->get_time()!=t) { canvas->set_time(t); @@ -229,7 +214,7 @@ synfig::Target_Scanline::render(ProgressCallback *cb) //synfig::info( " -- block %d/%d left, top, width, height: %d, %d, %d, %d", // i+1, rows, 0, i*rowheight, blockrd.get_w(), blockrd.get_h() ); - if(!call_renderer(context,surface,quality,blockrd,0)) + if (!call_renderer(surface, *canvas, context_params, blockrd)) { if(cb)cb->error(_("Accelerated Renderer Failure")); return false; @@ -296,7 +281,7 @@ synfig::Target_Scanline::render(ProgressCallback *cb) #endif SurfaceResource::Handle surface = new SurfaceResource(); - if(!call_renderer(context,surface,quality,desc,0)) + if (!call_renderer(surface, *canvas, context_params, desc)) { // For some reason, the accelerated renderer failed. if(cb)cb->error(_("Accelerated Renderer Failure")); @@ -331,7 +316,6 @@ synfig::Target_Scanline::render(ProgressCallback *cb) canvas->load_resources(t); } canvas->set_outline_grow(desc.get_outline_grow()); - Context context = canvas->get_context(context_params); // If quality is set otherwise, then we use the accelerated renderer { @@ -377,9 +361,7 @@ synfig::Target_Scanline::render(ProgressCallback *cb) //synfig::info( " -- block %d/%d left, top, width, height: %d, %d, %d, %d", // i+1, rows, 0, i*rowheight, blockrd.get_w(), blockrd.get_h() ); - SuperCallback sc(cb, i*rowheight, (i+1)*rowheight, totalheight); - - if(!call_renderer(context,surface,quality,blockrd,&sc)) + if (!call_renderer(surface, *canvas, context_params, blockrd)) { if(cb)cb->error(_("Accelerated Renderer Failure")); return false; @@ -440,7 +422,7 @@ synfig::Target_Scanline::render(ProgressCallback *cb) } //I'm done with this part - sc.amount_complete(100,100); + if (cb) cb->amount_complete((i+1)*rowheight, totalheight); } surface->reset(); @@ -451,7 +433,7 @@ synfig::Target_Scanline::render(ProgressCallback *cb) #endif SurfaceResource::Handle surface = new SurfaceResource(); - if(!call_renderer(context,surface,quality,desc,cb)) + if (!call_renderer(surface, *canvas, context_params, desc)) { if(cb)cb->error(_("Accelerated Renderer Failure")); return false; diff --git a/synfig-core/src/synfig/target_scanline.h b/synfig-core/src/synfig/target_scanline.h index b88feb0..6d52d50 100644 --- a/synfig-core/src/synfig/target_scanline.h +++ b/synfig-core/src/synfig/target_scanline.h @@ -51,7 +51,11 @@ class Target_Scanline : public Target String engine_; - bool call_renderer(Context &context, const etl::handle &surface, int quality, const RendDesc &renddesc, ProgressCallback *cb); + bool call_renderer( + const etl::handle &surface, + Canvas &canvas, + const ContextParams &context_params, + const RendDesc &renddesc ); public: typedef etl::handle Handle; diff --git a/synfig-core/src/synfig/target_tile.cpp b/synfig-core/src/synfig/target_tile.cpp index 8c1b1a1..9060461 100644 --- a/synfig-core/src/synfig/target_tile.cpp +++ b/synfig-core/src/synfig/target_tile.cpp @@ -83,8 +83,7 @@ Target_Tile::Target_Tile(): tile_w_(DEF_TILE_WIDTH), tile_h_(DEF_TILE_HEIGHT), curr_tile_(0), - clipping_(true), - allow_multithreading_(false) + clipping_(true) { curr_frame_=0; if (const char *s = getenv("SYNFIG_TARGET_DEFAULT_ENGINE")) @@ -118,7 +117,11 @@ Target_Tile::next_tile(RectInt& rect) } bool -synfig::Target_Tile::call_renderer(Context &context, const etl::handle &surface, int /* quality */, const RendDesc &renddesc, ProgressCallback * /* cb */) +synfig::Target_Tile::call_renderer( + const etl::handle &surface, + Canvas &canvas, + const ContextParams &context_params, + const RendDesc &renddesc ) { #ifdef DEBUG_MEASURE debug::Measure t("Target_Tile::call_renderer"); @@ -130,17 +133,7 @@ synfig::Target_Tile::call_renderer(Context &context, const etl::handleget_canvas()) - sub_context = (*context)->get_canvas()->get_context_sorted(context.get_params(), sub_queue); - else - sub_context = context; - task = sub_context.build_rendering_task(); + task = canvas.build_rendering_task(context_params); } if (task) @@ -179,119 +172,47 @@ synfig::Target_Tile::call_renderer(Context &context, const etl::handleerror(_("Parametric Renderer Failure")); - return false; - } - else - { - if(!surface) - { - if(cb)cb->error(_("Bad surface")); - return false; - } - switch(get_alpha_mode()) - { - case TARGET_ALPHA_MODE_FILL: - for(int i=0;ierror(_("add_tile():Unable to put surface on target")); - return false; - } - } - tile_timer.reset(); - } - SuperCallback super(cb,i,10000,10000); + // Gather tiles + std::vector tiles; + RectInt rect; + while(next_tile(rect)) { + if (clipping_) + if (rect.minx >= rend_desc.get_w() || rect.miny >= rend_desc.get_h()) + continue; + tiles.push_back(rect); } - else // If quality is set otherwise, then we use the accelerated renderer + + // Render tiles + for(std::vector::iterator i = tiles.begin(); i != tiles.end(); ++i) { - etl::clock tile_timer; + // Progress callback + int index = i - tiles.begin(); + int count = (int)tiles.size(); + SuperCallback super(cb, (count-index)*1000, (count-index+1)*1000, count*1000); + if(!super.amount_complete(0,1000)) + return false; + + // Render tile tile_timer.reset(); - // Gather tiles - std::vector tiles; - RectInt rect; - while(next_tile(rect)) { - if (clipping_) - if (rect.minx >= rend_desc.get_w() || rect.miny >= rend_desc.get_h()) - continue; - tiles.push_back(rect); - } - - // Render tiles - for(std::vector::iterator i = tiles.begin(); i != tiles.end(); ++i) - { - // Progress callback - int index = i - tiles.begin(); - int count = (int)tiles.size(); - SuperCallback super(cb, (count-index)*1000, (count-index+1)*1000, count*1000); - if(!super.amount_complete(0,1000)) - return false; + rect = *i; + if (clipping_) + etl::set_intersect(rect, rect, RectInt(0, 0, rend_desc.get_w(), rend_desc.get_h())); - // Render tile - tile_timer.reset(); + if (!rect.valid()) + continue; - rect = *i; - if (clipping_) - etl::set_intersect(rect, rect, RectInt(0, 0, rend_desc.get_w(), rend_desc.get_h())); - - if (!rect.valid()) - continue; + RendDesc tile_desc=rend_desc; + tile_desc.set_subwindow(rect.minx, rect.miny, rect.maxx - rect.minx, rect.maxy - rect.miny); - RendDesc tile_desc=rend_desc; - tile_desc.set_subwindow(rect.minx, rect.miny, rect.maxx - rect.minx, rect.maxy - rect.miny); - - async_render_tile(rect, context, tile_desc, &super); - } + async_render_tile(canvas, context_params, rect, tile_desc, &super); } if (!wait_render_tiles(cb)) @@ -304,11 +225,16 @@ synfig::Target_Tile::render_frame_(Context context,ProgressCallback *cb) } bool -synfig::Target_Tile::async_render_tile(RectInt rect, Context context, RendDesc tile_desc, ProgressCallback *cb) +synfig::Target_Tile::async_render_tile( + etl::handle canvas, + ContextParams context_params, + RectInt rect, + RendDesc tile_desc, + ProgressCallback *cb) { SurfaceResource::Handle surface = new rendering::SurfaceResource(); - if (!call_renderer(context, surface, get_quality(), tile_desc, cb)) + if (!call_renderer(surface, *canvas, context_params, tile_desc)) { // For some reason, the accelerated renderer failed. if(cb)cb->error(_("Accelerated Renderer Failure")); @@ -412,21 +338,12 @@ synfig::Target_Tile::render(ProgressCallback *cb) if(!start_frame(cb)) return false; - Context context; - // pass the Render Method to the context - context=canvas->get_context(context_params); - context.set_render_method(SOFTWARE); // Set the time that we wish to render - //if(!get_avoid_time_sync() || canvas->get_time()!=t) - // Why the above line was commented here and not in TargetScaline? - canvas->set_time(t); + canvas->set_time(t); canvas->load_resources(t); canvas->set_outline_grow(desc.get_outline_grow()); - - context=canvas->get_context(context_params); - - if(!render_frame_(context,0)) + if(!render_frame_(canvas, context_params, 0)) return false; end_frame(); }while(frames); @@ -440,15 +357,12 @@ synfig::Target_Tile::render(ProgressCallback *cb) return false; // Set the time that we wish to render - //if(!get_avoid_time_sync() || canvas->get_time()!=t) - canvas->set_time(t); + canvas->set_time(t); canvas->load_resources(t); canvas->set_outline_grow(desc.get_outline_grow()); //synfig::info("2time_set_to %s",t.get_string().c_str()); - - Context context = canvas->get_context(context_params); - if(!render_frame_(context, cb)) + if(!render_frame_(canvas, context_params, cb)) return false; end_frame(); } diff --git a/synfig-core/src/synfig/target_tile.h b/synfig-core/src/synfig/target_tile.h index 06e6ff0..9b73473 100644 --- a/synfig-core/src/synfig/target_tile.h +++ b/synfig-core/src/synfig/target_tile.h @@ -61,13 +61,15 @@ class Target_Tile : public Target //! or not bool clipping_; - bool allow_multithreading_; - String engine_; struct TileGroup; - bool call_renderer(Context &context, const etl::handle &surface, int quality, const RendDesc &renddesc, ProgressCallback *cb); + bool call_renderer( + const etl::handle &surface, + Canvas &canvas, + const ContextParams &context_params, + const RendDesc &renddesc ); public: typedef etl::handle Handle; @@ -79,7 +81,12 @@ public: //! Renders the canvas to the target virtual bool render(ProgressCallback *cb=NULL); - virtual bool async_render_tile(RectInt rect, Context context, RendDesc tile_desc, ProgressCallback *cb=NULL); + virtual bool async_render_tile( + etl::handle canvas, + ContextParams context_params, + RectInt rect, + RendDesc tile_desc, + ProgressCallback *cb); virtual bool wait_render_tiles(ProgressCallback *cb=NULL); //! Determines which tile needs to be rendered next. @@ -123,10 +130,6 @@ public: bool get_clipping()const { return clipping_; } //! Sets clipping void set_clipping(bool x) { clipping_=x; } - //! Gets clipping - bool get_allow_multithreading()const { return allow_multithreading_; } - //! Sets clipping - void set_allow_multithreading(bool x) { allow_multithreading_=x; } //! Gets engine const String& get_engine()const { return engine_; } //! Sets engine @@ -134,7 +137,7 @@ public: private: //! Renders the context to the surface - bool render_frame_(Context context,ProgressCallback *cb=0); + bool render_frame_(etl::handle canvas, ContextParams context_params, ProgressCallback *cb); }; // END of class Target_Tile diff --git a/synfig-core/src/tool/main.cpp b/synfig-core/src/tool/main.cpp index 2e1e276..8421933 100644 --- a/synfig-core/src/tool/main.cpp +++ b/synfig-core/src/tool/main.cpp @@ -126,7 +126,6 @@ int main(int argc, char* argv[]) named_type* span_arg_desc = new named_type("NUM"); named_type* antialias_arg_desc = new named_type("1..30"); named_type* quality_arg_desc = new named_type("0..10"); - named_type* gamma_arg_desc = new named_type("NUM (=2.2)"); named_type* threads_arg_desc = new named_type("NUM"); named_type* verbosity_arg_desc = new named_type("NUM"); named_type* canvas_arg_desc = new named_type("canvas-id"); diff --git a/synfig-core/src/tool/optionsprocessor.cpp b/synfig-core/src/tool/optionsprocessor.cpp index c5a6dde..0e57d5d 100644 --- a/synfig-core/src/tool/optionsprocessor.cpp +++ b/synfig-core/src/tool/optionsprocessor.cpp @@ -99,7 +99,6 @@ SynfigCommandLineParser::SynfigCommandLineParser() : set_span(), set_antialias(), set_quality(), - set_gamma(), set_num_threads(), set_input_file(), set_output_file(), @@ -140,12 +139,14 @@ SynfigCommandLineParser::SynfigCommandLineParser() : show_targets(), show_codecs(), show_value_nodes(), - // Debug group + show_version() + #ifdef _DEBUG + , + // Debug group debug_guid(), - debug_signal(), + debug_signal() #endif - show_version() { Glib::init(); @@ -156,7 +157,6 @@ SynfigCommandLineParser::SynfigCommandLineParser() : add_option(og_set, "span", 's', set_span, _("Set the diagonal size of image window (Span)"), "NUM"); add_option(og_set, "antialias", 'a', set_antialias, _("Set antialias amount for parametric renderer."), "1..30"); //og_set.add_option("quality", 'Q', quality_arg_desc, etl::strprintf(_("Specify image quality for accelerated renderer (Default: %d)"), DEFAULT_QUALITY).c_str(), "NUM"); - add_option(og_set, "gamma", 'g', set_gamma, _("Gamma"), "2.2"); add_option(og_set, "threads", 'T', set_num_threads, _("Enable multithreaded renderer using the specified number of threads"), "NUM"); add_option(og_set, "input-file", 'i', set_input_file, _("Specify input filename"), "filename"); add_option(og_set, "output-file", 'o', set_output_file, _("Specify output filename"), "filename"); @@ -602,13 +602,6 @@ RendDesc SynfigCommandLineParser::extract_renddesc(const RendDesc& renddesc) << desc.get_time_start().get_string(desc.get_frame_rate()) << endl; } - if (set_gamma > 0) - { - synfig::warning(_("Gamma argument is currently ignored")); - //int gamma; - //gamma = _vm["gamma"].as(); - //desc.set_gamma(Gamma(gamma)); - } if (w || h) { diff --git a/synfig-core/src/tool/optionsprocessor.h b/synfig-core/src/tool/optionsprocessor.h index 71d31e4..92997fb 100644 --- a/synfig-core/src/tool/optionsprocessor.h +++ b/synfig-core/src/tool/optionsprocessor.h @@ -154,7 +154,6 @@ private: int set_antialias; int set_quality; // (",Q", quality_arg_desc->default_value(DEFAULT_QUALITY), ) - double set_gamma; int set_num_threads; Glib::ustring set_input_file; Glib::ustring set_output_file; diff --git a/synfig-studio/src/gui/app.cpp b/synfig-studio/src/gui/app.cpp index 335fd85..23e965b 100644 --- a/synfig-studio/src/gui/app.cpp +++ b/synfig-studio/src/gui/app.cpp @@ -253,8 +253,6 @@ App::get_workspaces() int App::Busy::count; bool App::shutdown_in_progress; -synfig::Gamma App::gamma; - Glib::RefPtr App::ui_manager_; int App::jack_locks_ = 0; @@ -304,14 +302,6 @@ studio::Dock_Curves *dock_curves; std::list< etl::handle< studio::Module > > module_list_; -bool studio::App::use_colorspace_gamma=true; -#ifdef SINGLE_THREADED - //#ifdef WIN32 - bool studio::App::single_threaded=true; - //#else - //bool studio::App::single_threaded=false; - //#endif // WIN32 -#endif // SINGLE THREADED bool studio::App::restrict_radius_ducks = true; bool studio::App::resize_imported_images = false; bool studio::App::enable_experimental_features = false; @@ -531,16 +521,6 @@ public: try { synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); - if(key=="gamma") - { - value=strprintf("%f %f %f %f", - App::gamma.get_gamma_r(), - App::gamma.get_gamma_g(), - App::gamma.get_gamma_b(), - App::gamma.get_gamma_a() - ); - return true; - } if(key=="time_format") { value=strprintf("%i",App::get_time_format()); @@ -551,23 +531,11 @@ public: value=strprintf("%i",App::get_max_recent_files()); return true; } - if(key=="use_colorspace_gamma") - { - value=strprintf("%i",(int)App::use_colorspace_gamma); - return true; - } if(key=="distance_system") { value=strprintf("%s",Distance::system_name(App::distance_system).c_str()); return true; } -#ifdef SINGLE_THREADED - if(key=="use_single_threaded") - { - value=strprintf("%i",(int)App::single_threaded); - return true; - } -#endif if(key=="autosave_backup") { value=strprintf("%i",App::auto_recover->get_enabled()); @@ -720,17 +688,6 @@ public: try { synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); - if(key=="gamma") - { - float r,g,b,a = -1; - - strscanf(value,"%f %f %f %f", &r, &g, &b, &a); - - if (a <= 0) a = r; - App::gamma.set_all(r,g,b,a); - - return true; - } if(key=="time_format") { int i(atoi(value.c_str())); @@ -755,25 +712,11 @@ public: App::set_max_recent_files(i); return true; } - if(key=="use_colorspace_gamma") - { - int i(atoi(value.c_str())); - App::use_colorspace_gamma=i; - return true; - } if(key=="distance_system") { App::distance_system=Distance::ident_system(value);; return true; } -#ifdef SINGLE_THREADED - if(key=="use_single_threaded") - { - int i(atoi(value.c_str())); - App::single_threaded=i; - return true; - } -#endif if(key=="restrict_radius_ducks") { int i(atoi(value.c_str())); @@ -917,14 +860,9 @@ public: virtual KeyList get_key_list()const { KeyList ret(synfigapp::Settings::get_key_list()); - ret.push_back("gamma"); ret.push_back("time_format"); ret.push_back("distance_system"); ret.push_back("file_history.size"); - ret.push_back("use_colorspace_gamma"); -#ifdef SINGLE_THREADED - ret.push_back("use_single_threaded"); -#endif ret.push_back("autosave_backup"); ret.push_back("autosave_backup_interval"); ret.push_back("restrict_radius_ducks"); @@ -1714,10 +1652,7 @@ App::App(const synfig::String& basepath, int *argc, char ***argv): studio_init_cb.task(_("Loading Settings...")); load_accel_map(); if (!load_settings()) - { - gamma.set_gamma(1.0/2.2); set_workspace_default(); - } if (!load_settings("workspace.layout")) set_workspace_default(); load_file_window_size(); @@ -2348,10 +2283,6 @@ void App::restore_default_settings() { synfigapp::Main::settings().set_value("pref.distance_system", "pt"); - synfigapp::Main::settings().set_value("pref.use_colorspace_gamma", "1"); -#ifdef SINGLE_THREADED - synfigapp::Main::settings().set_value("pref.use_single_threaded", "1"); -#endif synfigapp::Main::settings().set_value("pref.restrict_radius_ducks", "1"); synfigapp::Main::settings().set_value("pref.resize_imported_images", "0"); synfigapp::Main::settings().set_value("pref.enable_experimental_features", "0"); @@ -2378,7 +2309,6 @@ App::restore_default_settings() synfigapp::Main::settings().set_value("pref.autosave_backup", "1"); synfigapp::Main::settings().set_value("pref.autosave_backup_interval", "15000"); synfigapp::Main::settings().set_value("pref.image_editor_path", ""); - } void @@ -4197,6 +4127,14 @@ App::get_instance(etl::handle canvas) return 0; } +Gamma +App::get_selected_canvas_gamma() +{ + if (etl::loose_handle canvas_view = App::get_selected_canvas_view()) + return canvas_view->get_canvas()->rend_desc().get_gamma(); + return Gamma(); +} + void App::dialog_about() { diff --git a/synfig-studio/src/gui/app.h b/synfig-studio/src/gui/app.h index bbd6afa..dec1304 100644 --- a/synfig-studio/src/gui/app.h +++ b/synfig-studio/src/gui/app.h @@ -58,11 +58,6 @@ #define SKETCH_DIR_PREFERENCE "sketch_dir" #define RENDER_DIR_PREFERENCE "render_dir" -// uncomment define SINGLE_THREADED to use a single thread, and hopefully get more stability (dooglus) - changed to be default if using windows (Nov 2009 pixelgeek) -#ifdef _WIN32 -#define SINGLE_THREADED -#endif - /* === T Y P E D E F S ===================================================== */ /* === C L A S S E S & S T R U C T S ======================================= */ @@ -208,8 +203,6 @@ public: static VectorizerSettings *vectorizerpopup; static synfig::Distance::System distance_system; - static synfig::Gamma gamma; - static About *about; static MainWindow *main_window; static Dock_Toolbox *dock_toolbox; @@ -218,12 +211,6 @@ public: static bool shutdown_in_progress; - static bool use_colorspace_gamma; - -#ifdef SINGLE_THREADED - static bool single_threaded; -#endif - static bool restrict_radius_ducks; static bool resize_imported_images; static bool enable_experimental_features; @@ -368,6 +355,7 @@ public: static etl::loose_handle get_selected_instance() { return selected_instance; } static etl::loose_handle get_selected_canvas_view() { return selected_canvas_view; } + static synfig::Gamma get_selected_canvas_gamma(); static std::string get_temporary_directory(); diff --git a/synfig-studio/src/gui/asyncrenderer.cpp b/synfig-studio/src/gui/asyncrenderer.cpp index e1f0d95..f13c38c 100644 --- a/synfig-studio/src/gui/asyncrenderer.cpp +++ b/synfig-studio/src/gui/asyncrenderer.cpp @@ -101,7 +101,6 @@ public: set_alpha_mode(warm_target->get_alpha_mode()); set_threads(warm_target->get_threads()); set_clipping(warm_target->get_clipping()); - set_allow_multithreading(warm_target->get_allow_multithreading()); set_rend_desc(&warm_target->rend_desc()); set_engine(warm_target->get_engine()); alive_flag=true; @@ -120,24 +119,21 @@ public: alive_flag=false; } - virtual bool async_render_tile(synfig::RectInt rect, synfig::Context context, synfig::RendDesc tile_desc, synfig::ProgressCallback *cb=NULL) + virtual bool async_render_tile( + etl::handle canvas, + ContextParams context_params, + RectInt rect, + RendDesc tile_desc, + ProgressCallback *cb ) { if(!alive_flag) return false; -#ifdef SINGLE_THREADED - if (App::single_threaded) - return sync_render_tile(rect, context, tile_desc, cb); -#endif - - if (!get_allow_multithreading()) - return sync_render_tile(rect, context, tile_desc, cb); - Glib::Thread *thread = Glib::Thread::create( sigc::hide_return( sigc::bind( sigc::mem_fun(*this, &AsyncTarget_Tile::sync_render_tile), - rect, context, tile_desc, (synfig::ProgressCallback*)NULL )), + canvas, context_params, rect, tile_desc, (synfig::ProgressCallback*)NULL )), true ); assert(thread); @@ -150,11 +146,16 @@ public: return true; } - bool sync_render_tile(synfig::RectInt rect, synfig::Context context, synfig::RendDesc tile_desc, synfig::ProgressCallback *cb) + bool sync_render_tile( + etl::handle canvas, + ContextParams context_params, + RectInt rect, + RendDesc tile_desc, + ProgressCallback *cb ) { if(!alive_flag) return false; - bool r = warm_target->async_render_tile(rect, context, tile_desc, cb); + bool r = warm_target->async_render_tile(canvas, context_params, rect, tile_desc, cb); if (!r) { Glib::Mutex::Lock lock(mutex); err = true; } return r; } @@ -258,29 +259,22 @@ public: virtual void end_frame() { -#ifdef SINGLE_THREADED - if (!App::single_threaded) + while(alive_flag) { -#endif - while(alive_flag) - { - Glib::Mutex::Lock lock(mutex); - Glib::TimeVal end_time; + Glib::Mutex::Lock lock(mutex); + Glib::TimeVal end_time; - end_time.assign_current_time(); - end_time.add_microseconds(BOREDOM_TIMEOUT); + end_time.assign_current_time(); + end_time.add_microseconds(BOREDOM_TIMEOUT); - if(!tile_queue.empty() && alive_flag) - { - if(cond_tile_queue_empty.timed_wait(mutex,end_time)) - break; - } - else + if(!tile_queue.empty() && alive_flag) + { + if(cond_tile_queue_empty.timed_wait(mutex,end_time)) break; } -#ifdef SINGLE_THREADED + else + break; } -#endif Glib::Mutex::Lock lock(mutex); if(!alive_flag) return; @@ -439,29 +433,22 @@ public: virtual void end_frame() { -#ifdef SINGLE_THREADED - if (!App::single_threaded) + while(alive_flag) { -#endif - while(alive_flag) + Glib::Mutex::Lock lock(mutex); + Glib::TimeVal end_time; + + end_time.assign_current_time(); + end_time.add_microseconds(BOREDOM_TIMEOUT); + + if(!tile_queue.empty() && alive_flag) { - Glib::Mutex::Lock lock(mutex); - Glib::TimeVal end_time; - - end_time.assign_current_time(); - end_time.add_microseconds(BOREDOM_TIMEOUT); - - if(!tile_queue.empty() && alive_flag) - { - if(cond_tile_queue_empty.timed_wait(mutex,end_time)) - break; - } - else + if(cond_tile_queue_empty.timed_wait(mutex,end_time)) break; } -#ifdef SINGLE_THREADED + else + break; } -#endif Glib::Mutex::Lock lock(mutex); if(!alive_flag) return; @@ -556,24 +543,16 @@ public: #endif } -#ifdef SINGLE_THREADED - if (App::single_threaded) - signal_progress()(); - else -#endif - { + Glib::TimeVal end_time; - Glib::TimeVal end_time; + end_time.assign_current_time(); + end_time.add_microseconds(BOREDOM_TIMEOUT); - end_time.assign_current_time(); - end_time.add_microseconds(BOREDOM_TIMEOUT); - - while(alive_flag && !ready_next) - { - Glib::Mutex::Lock lock(mutex); - if(cond_frame_queue_empty.timed_wait(mutex, end_time)) - break; - } + while(alive_flag && !ready_next) + { + Glib::Mutex::Lock lock(mutex); + if(cond_frame_queue_empty.timed_wait(mutex, end_time)) + break; } } @@ -595,10 +574,7 @@ public: Glib::Mutex::Lock lock(mutex); if(alive_flag) alive_flag=warm_target->add_frame(&surface); -#ifdef SINGLE_THREADED - if (!App::single_threaded) -#endif - cond_frame_queue_empty.signal(); + cond_frame_queue_empty.signal(); ready_next=true; int n_total_frames_to_render = warm_target->desc.get_frame_end() //120 @@ -690,24 +666,16 @@ public: #endif } -#ifdef SINGLE_THREADED - if (App::single_threaded) - signal_progress()(); - else -#endif + Glib::TimeVal end_time; + + end_time.assign_current_time(); + end_time.add_microseconds(BOREDOM_TIMEOUT); + + while(alive_flag && !ready_next) { - - Glib::TimeVal end_time; - - end_time.assign_current_time(); - end_time.add_microseconds(BOREDOM_TIMEOUT); - - while(alive_flag && !ready_next) - { - Glib::Mutex::Lock lock(mutex); - if(cond_frame_queue_empty.timed_wait(mutex, end_time)) - break; - } + Glib::Mutex::Lock lock(mutex); + if(cond_frame_queue_empty.timed_wait(mutex, end_time)) + break; } return true; } @@ -717,10 +685,7 @@ public: Glib::Mutex::Lock lock(mutex); if(alive_flag) alive_flag=warm_target->put_surface(surface, callback); -#ifdef SINGLE_THREADED - if (!App::single_threaded) -#endif - cond_frame_queue_empty.signal(); + cond_frame_queue_empty.signal(); ready_next=true; int n_total_frames_to_render = warm_target->desc.get_frame_end() //120 @@ -753,9 +718,6 @@ AsyncRenderer::AsyncRenderer(etl::handle target_,synfig::Progres error(false), success(false), cb(cb), -#ifdef SINGLE_THREADED - updating(false), -#endif start_clock(0), finish_clock(0), start_time(0, 0), @@ -828,10 +790,7 @@ AsyncRenderer::stop() signal_stop_(); #if REJOIN_ON_STOP -#ifdef SINGLE_THREADED - if (!App::single_threaded) -#endif - render_thread->join(); + render_thread->join(); #endif finish_time.assign_current_time(); finish_clock = ::clock(); @@ -880,16 +839,6 @@ AsyncRenderer::start() ); } -#ifdef SINGLE_THREADED -void -AsyncRenderer::rendering_progress() -{ - updating = true; - App::process_all_events(); - updating = false; -} -#endif - void AsyncRenderer::start_() { @@ -899,28 +848,15 @@ AsyncRenderer::start_() #ifndef GLIB_DISPATCHER_BROKEN done_connection=signal_done_.connect(mem_fun(*this,&AsyncRenderer::stop)); #endif - -#ifdef SINGLE_THREADED - if (App::single_threaded) - { - //synfig::info("%s:%d rendering in the same thread", __FILE__, __LINE__); - target->signal_progress().connect(sigc::mem_fun(this,&AsyncRenderer::rendering_progress)); - render_thread = (Glib::Thread*)1; - render_target(); - } - else -#endif - { - render_thread=Glib::Thread::create( - sigc::mem_fun(*this,&AsyncRenderer::render_target), + render_thread=Glib::Thread::create( + sigc::mem_fun(*this,&AsyncRenderer::render_target), #if REJOIN_ON_STOP - true + true #else - false + false #endif - ); - assert(render_thread); - } + ); + assert(render_thread); } else { diff --git a/synfig-studio/src/gui/asyncrenderer.h b/synfig-studio/src/gui/asyncrenderer.h index 2ffc32e..401df5e 100644 --- a/synfig-studio/src/gui/asyncrenderer.h +++ b/synfig-studio/src/gui/asyncrenderer.h @@ -95,10 +95,6 @@ public: void stop(); void pause(); void resume(); -#ifdef SINGLE_THREADED - void rendering_progress(); - bool updating; -#endif bool has_error()const { return error; } bool has_success()const { return success; } diff --git a/synfig-studio/src/gui/dialogs/canvasproperties.h b/synfig-studio/src/gui/dialogs/canvasproperties.h index 4869416..e678ced 100644 --- a/synfig-studio/src/gui/dialogs/canvasproperties.h +++ b/synfig-studio/src/gui/dialogs/canvasproperties.h @@ -47,6 +47,7 @@ namespace synfigapp { class CanvasInterface; }; namespace studio { + class CanvasProperties : public Gtk::Dialog { etl::handle canvas_interface_; diff --git a/synfig-studio/src/gui/dialogs/dialog_color.h b/synfig-studio/src/gui/dialogs/dialog_color.h index e2ae8d5..726da25 100644 --- a/synfig-studio/src/gui/dialogs/dialog_color.h +++ b/synfig-studio/src/gui/dialogs/dialog_color.h @@ -42,8 +42,6 @@ namespace studio { -class Widget_Color; - class Dialog_Color : public Gtk::Dialog { DialogSettings dialog_settings; diff --git a/synfig-studio/src/gui/dialogs/dialog_gradient.h b/synfig-studio/src/gui/dialogs/dialog_gradient.h index d42f4b8..44b38cf 100644 --- a/synfig-studio/src/gui/dialogs/dialog_gradient.h +++ b/synfig-studio/src/gui/dialogs/dialog_gradient.h @@ -35,7 +35,7 @@ #include #include -#include +#include #include #include "widgets/widget_gradient.h" diff --git a/synfig-studio/src/gui/dialogs/dialog_setup.cpp b/synfig-studio/src/gui/dialogs/dialog_setup.cpp index 3648426..346e7ba 100644 --- a/synfig-studio/src/gui/dialogs/dialog_setup.cpp +++ b/synfig-studio/src/gui/dialogs/dialog_setup.cpp @@ -73,10 +73,6 @@ using namespace studio; Dialog_Setup::Dialog_Setup(Gtk::Window& parent): Dialog_Template(parent,_("Synfig Studio Preferences")), input_settings(synfigapp::Main::get_selected_input_device()->settings()), - adj_gamma_r(Gtk::Adjustment::create(2.2,0.1,3.0,0.025,0.025,0.025)), - adj_gamma_g(Gtk::Adjustment::create(2.2,0.1,3.0,0.025,0.025,0.025)), - adj_gamma_b(Gtk::Adjustment::create(2.2,0.1,3.0,0.025,0.025,0.025)), - adj_gamma_a(Gtk::Adjustment::create(2.2,0.1,3.0,0.025,0.025,0.025)), adj_recent_files(Gtk::Adjustment::create(15,1,50,1,1,0)), adj_undo_depth(Gtk::Adjustment::create(100,10,5000,1,1,1)), time_format(Time::FORMAT_NORMAL), @@ -87,12 +83,12 @@ Dialog_Setup::Dialog_Setup(Gtk::Window& parent): pref_modification_flag(false), refreshing(false) { - synfig::String interface_str(_("Interface")), - document_str(_("Document")), - editing_str(_("Editing")), - render_str(_("Render")), - system_str(_("System")), - gamma_str(_("Gamma")); + synfig::String + interface_str(_("Interface")), + document_str(_("Document")), + editing_str(_("Editing")), + render_str(_("Render")), + system_str(_("System")); // WARNING FIXED ORDER : the page added to notebook same has treeview // Interface create_interface_page(add_page(interface_str)); @@ -103,10 +99,7 @@ Dialog_Setup::Dialog_Setup(Gtk::Window& parent): // Render create_render_page(add_page(render_str)); // System - PageInfo pi = add_page(system_str); - create_system_page(pi); - // Gamma - create_gamma_page(add_child_page(gamma_str, pi.row)); + create_system_page(add_page(system_str)); show_all_children(); } @@ -116,53 +109,6 @@ Dialog_Setup::~Dialog_Setup() } void -Dialog_Setup::create_gamma_page(PageInfo pi) -{ - /*---------Gamma------------------*\ - * - * *****°°°°°°°##### - * *****°°°°°°°##### - * *****°°°°°°°##### - * *****°°°°°°°##### - * *****°°°°°°°##### - * red ---------x-------------- - * green ---------x-------------- - * blue ---------x-------------- - * alpha ---------x-------------- - * - */ - - int row(1); -#ifndef __APPLE__ - pi.grid->attach(gamma_pattern, 0, row, 2, 1); - gamma_pattern.set_halign(Gtk::ALIGN_CENTER); -#endif - Gtk::Scale* scale_gamma_r(manage(new Gtk::Scale(adj_gamma_r))); - attach_label(pi.grid, _("Red"), ++row); - pi.grid->attach(*scale_gamma_r, 1, row, 1, 1); - scale_gamma_r->set_hexpand_set(true); - adj_gamma_r->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Setup::on_gamma_r_change)); - - Gtk::Scale* scale_gamma_g(manage(new Gtk::Scale(adj_gamma_g))); - attach_label(pi.grid, _("Green"), ++row); - pi.grid->attach(*scale_gamma_g, 1, row, 1, 1); - scale_gamma_g->set_hexpand(true); - adj_gamma_g->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Setup::on_gamma_g_change)); - - Gtk::Scale* scale_gamma_b(manage(new Gtk::Scale(adj_gamma_b))); - attach_label(pi.grid, _("Blue"), ++row); - pi.grid->attach(*scale_gamma_b, 1, row, 1, 1); - scale_gamma_b->set_hexpand(true); - adj_gamma_b->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Setup::on_gamma_b_change)); - - Gtk::Scale* scale_gamma_a(manage(new Gtk::Scale(adj_gamma_a))); - attach_label(pi.grid, _("Alpha"), ++row); - pi.grid->attach(*scale_gamma_a, 1, row, 1, 1); - scale_gamma_a->set_hexpand(true); - adj_gamma_a->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Setup::on_gamma_a_change)); -} - -void Dialog_Setup::create_system_page(PageInfo pi) { /*---------System--------------------*\ @@ -275,14 +221,6 @@ Dialog_Setup::create_system_page(PageInfo pi) toggle_enable_experimental_features.set_halign(Gtk::ALIGN_START); toggle_enable_experimental_features.set_hexpand(false); -#ifdef SINGLE_THREADED - // System - 12 single_threaded - attach_label_section(pi.grid, _("Single thread only (CPUs)"), ++row); - pi.grid->attach(toggle_single_threaded, 1, row, 1, 1); - toggle_single_threaded.set_hexpand(false); - toggle_single_threaded.set_halign(Gtk::ALIGN_START); -#endif - // signal for change resume auto_backup_interval.signal_changed().connect( sigc::bind(sigc::mem_fun(*this, &Dialog_Setup::on_value_change), CHANGE_AUTOBACKUP)); @@ -479,16 +417,6 @@ Dialog_Setup::create_editing_page(PageInfo pi) // Editing Other section attach_label_section(pi.grid, _("Other"), ++row); - // Editing - Visually Linear Color Selection - attach_label(pi.grid,_("Visually linear color selection"), ++row); - pi.grid->attach(toggle_use_colorspace_gamma, 1, row, 1, 1); - toggle_use_colorspace_gamma.set_halign(Gtk::ALIGN_START); - toggle_use_colorspace_gamma.set_hexpand(false); - toggle_use_colorspace_gamma.set_tooltip_text(_("Color output is non-linear, if 0 \ -is black and 100 is white, then 50 is only about 22 percent of the brightness \ -of white, rather than 50% as you might expect. \ -Option (ON by default) to make sure that if you ask for 50, you get 50% of the brightness of white.")); - // Editing - Restrict Real-value Handles to Top Right Quadrant attach_label(pi.grid,_("Restrict real value handles to top right quadrant"), ++row); pi.grid->attach(toggle_restrict_radius_ducks, 1, row, 1, 1); @@ -725,25 +653,11 @@ Dialog_Setup::on_restore_pressed() void Dialog_Setup::on_apply_pressed() { - App::gamma.set_all( - 1.0/adj_gamma_r->get_value(), - 1.0/adj_gamma_g->get_value(), - 1.0/adj_gamma_b->get_value(), - 1.0/adj_gamma_a->get_value() ); - App::set_max_recent_files((int)adj_recent_files->get_value()); // Set the time format App::set_time_format(get_time_format()); - // Set the use_colorspace_gamma flag - App::use_colorspace_gamma = toggle_use_colorspace_gamma.get_active(); - -#ifdef SINGLE_THREADED - // Set the single_threaded flag - App::single_threaded=toggle_single_threaded.get_active(); -#endif - //if(pref_modification_flag&CHANGE_AUTOBACKUP) // TODO catch change event on auto_backup_interval before use CHANGE_AUTOBACKUP { @@ -860,38 +774,6 @@ Dialog_Setup::on_apply_pressed() } void -Dialog_Setup::on_gamma_r_change() -{ - gamma_pattern.set_gamma_r(1.0/adj_gamma_r->get_value()); - gamma_pattern.refresh(); - gamma_pattern.queue_draw(); -} - -void -Dialog_Setup::on_gamma_g_change() -{ - gamma_pattern.set_gamma_g(1.0/adj_gamma_g->get_value()); - gamma_pattern.refresh(); - gamma_pattern.queue_draw(); -} - -void -Dialog_Setup::on_gamma_b_change() -{ - gamma_pattern.set_gamma_b(1.0/adj_gamma_b->get_value()); - gamma_pattern.refresh(); - gamma_pattern.queue_draw(); -} - -void -Dialog_Setup::on_gamma_a_change() -{ - gamma_pattern.set_gamma_a(1.0/adj_gamma_a->get_value()); - gamma_pattern.refresh(); - gamma_pattern.queue_draw(); -} - -void Dialog_Setup::on_size_template_combo_change() { String selection(size_template_combo->get_active_text()); @@ -1009,20 +891,7 @@ Dialog_Setup::refresh() { refreshing = true; pref_modification_flag = CHANGE_NONE; - // Refresh the temporary gamma; do this before adjusting the sliders, - // or variables will be used before their initialization. - gamma_pattern.set_gamma_r(App::gamma.get_gamma_r()); - gamma_pattern.set_gamma_g(App::gamma.get_gamma_g()); - gamma_pattern.set_gamma_b(App::gamma.get_gamma_b()); - gamma_pattern.set_gamma_a(App::gamma.get_gamma_a()); - - adj_gamma_r->set_value(1.0/App::gamma.get_gamma_r()); - adj_gamma_g->set_value(1.0/App::gamma.get_gamma_g()); - adj_gamma_b->set_value(1.0/App::gamma.get_gamma_b()); - adj_gamma_a->set_value(1.0/App::gamma.get_gamma_a()); - - gamma_pattern.refresh(); - + adj_recent_files->set_value(App::get_max_recent_files()); // Refresh the time format @@ -1030,13 +899,6 @@ Dialog_Setup::refresh() widget_enum->set_value(App::distance_system); - // Refresh the status of the use_colorspace_gamma flag - toggle_use_colorspace_gamma.set_active(App::use_colorspace_gamma); - -#ifdef SINGLE_THREADED - // Refresh the status of the single_threaded flag - toggle_single_threaded.set_active(App::single_threaded); -#endif toggle_autobackup.set_active(App::auto_recover->get_enabled()); // Refresh the value of the auto backup interval auto_backup_interval.set_value(App::auto_recover->get_timeout_ms() / 1000); @@ -1146,124 +1008,6 @@ Dialog_Setup::refresh() refreshing = false; } -GammaPattern::GammaPattern(): - gamma_r(), - gamma_g(), - gamma_b(), - gamma_a(), - tile_w(80), - tile_h(80) -{ - set_size_request(tile_w*4,tile_h*3); -} - -GammaPattern::~GammaPattern() -{ -} - -void -GammaPattern::refresh() -{ - black[0].set_rgb_p( - r_F32_to_F32(0.0), - g_F32_to_F32(0.0), - b_F32_to_F32(0.0) - ); - white[0].set_rgb_p( - r_F32_to_F32(1.0), - g_F32_to_F32(1.0), - b_F32_to_F32(1.0) - ); - gray50[0].set_rgb_p( - r_F32_to_F32(0.5), - g_F32_to_F32(0.5), - b_F32_to_F32(0.5) - ); - gray25[0].set_rgb_p( - r_F32_to_F32(0.25), - g_F32_to_F32(0.25), - b_F32_to_F32(0.25) - ); - - // Reds - black[1].set_rgb(black[0].get_red(),0,0); - gray25[1].set_rgb(gray25[0].get_red(),0,0); - gray50[1].set_rgb(gray50[0].get_red(),0,0); - white[1].set_rgb(white[0].get_red(),0,0); - - // Greens - black[2].set_rgb(0,black[0].get_green(),0); - gray25[2].set_rgb(0,gray25[0].get_green(),0); - gray50[2].set_rgb(0,gray50[0].get_green(),0); - white[2].set_rgb(0,white[0].get_green(),0); - - // blues - black[3].set_rgb(0,0,black[0].get_blue()); - gray25[3].set_rgb(0,0,gray25[0].get_blue()); - gray50[3].set_rgb(0,0,gray50[0].get_blue()); - white[3].set_rgb(0,0,white[0].get_blue()); -} - -bool -GammaPattern::on_draw(const Cairo::RefPtr &cr) -{ - int i; - Gdk::Color trueblack("#000000"); - - int stride = Cairo::ImageSurface::format_stride_for_width(Cairo::FORMAT_A1, 2); - std::vector hlines(2*stride, 0); - hlines[0] = 3; - Cairo::RefPtr stipple_mask_img = Cairo::ImageSurface::create(&hlines.front(), Cairo::FORMAT_A1, 2, 2, stride); - - // 50% Pattern - for(i=0;i<4;i++) - { - cr->set_source_rgb(black[i].get_red_p(), black[i].get_green_p(), black[i].get_blue_p()); - cr->rectangle(i*tile_w, 0, tile_w, tile_h); - cr->fill(); - - cr->set_source_rgb(white[i].get_red_p(), white[i].get_green_p(), white[i].get_blue_p()); - cr->mask(stipple_mask_img, 0, 0); - cr->rectangle(i*tile_w, 0, tile_w, tile_h); - cr->fill(); - - cr->set_source_rgb(gray50[i].get_red_p(), gray50[i].get_green_p(), gray50[i].get_blue_p()); - cr->rectangle(i*tile_w+tile_w/4, tile_h/4, tile_w-tile_w/2, tile_h-tile_h/2); - cr->fill(); - } - - // 25% Pattern - for(i=0;i<4;i++) - { - cr->set_source_rgb(black[i].get_red_p(), black[i].get_green_p(), black[i].get_blue_p()); - cr->rectangle(i*tile_w, tile_h, tile_w, tile_h); - cr->fill(); - - cr->set_source_rgb(gray50[i].get_red_p(), gray50[i].get_green_p(), gray50[i].get_blue_p()); - cr->mask(stipple_mask_img, 0, 0); - cr->rectangle(i*tile_w, tile_h, tile_w, tile_h); - cr->fill(); - - cr->set_source_rgb(gray25[i].get_red_p(), gray25[i].get_green_p(), gray25[i].get_blue_p()); - cr->rectangle(i*tile_w+tile_w/4, tile_h+tile_h/4, tile_w-tile_w/2, tile_h-tile_h/2); - cr->fill(); - } - - // Black-level Pattern - cr->set_source_rgb(trueblack.get_red_p(), trueblack.get_green_p(), trueblack.get_blue_p()); - cr->rectangle(0, tile_h*2, tile_w*4, tile_h); - cr->fill(); - - for(i=0;i<4;i++) - { - cr->set_source_rgb(black[i].get_red_p(), black[i].get_green_p(), black[i].get_blue_p()); - cr->rectangle(i*tile_w+tile_w/4, tile_h*2+tile_h/4, tile_w-tile_w/2, tile_h-tile_h/2); - cr->fill(); - } - - return true; -} - void Dialog_Setup::set_time_format(synfig::Time::Format x) { diff --git a/synfig-studio/src/gui/dialogs/dialog_setup.h b/synfig-studio/src/gui/dialogs/dialog_setup.h index a1502f5..8d9987f 100644 --- a/synfig-studio/src/gui/dialogs/dialog_setup.h +++ b/synfig-studio/src/gui/dialogs/dialog_setup.h @@ -50,7 +50,7 @@ #include -#include +#include #include #include @@ -74,41 +74,6 @@ namespace Gtk { class Menu; }; namespace studio { -class GammaPattern : public Gtk::DrawingArea -{ - float gamma_r; - float gamma_g; - float gamma_b; - float gamma_a; - - int tile_w, tile_h; - - Gdk::Color black[4],white[4],gray50[4],gray25[4]; - - float r_F32_to_F32(float x) const { return std::max(0.f, std::min(1.f, synfig::Gamma::calculate(x, gamma_r))); } - float g_F32_to_F32(float x) const { return std::max(0.f, std::min(1.f, synfig::Gamma::calculate(x, gamma_g))); } - float b_F32_to_F32(float x) const { return std::max(0.f, std::min(1.f, synfig::Gamma::calculate(x, gamma_b))); } - float a_F32_to_F32(float x) const { return std::max(0.f, std::min(1.f, synfig::Gamma::calculate(x, gamma_a))); } - -public: - GammaPattern(); - ~GammaPattern(); - - void refresh(); - - void set_gamma_r(float x) { gamma_r=x; } - void set_gamma_g(float x) { gamma_g=x; }; - void set_gamma_b(float x) { gamma_b=x; }; - void set_gamma_a(float x) { gamma_a=x; }; - - float get_gamma_r()const { return gamma_r; } - float get_gamma_g()const { return gamma_g; } - float get_gamma_b()const { return gamma_b; } - float get_gamma_a()const { return gamma_a; } - - virtual bool on_draw(const Cairo::RefPtr &cr); -}; // END of class GammaPattern - class Widget_Enum; class Dialog_Setup : public Dialog_Template @@ -137,10 +102,6 @@ class Dialog_Setup : public Dialog_Template // TODO on change class void on_value_change(int valueflag); //Signal handlers pages - void on_gamma_r_change(); - void on_gamma_g_change(); - void on_gamma_b_change(); - void on_gamma_a_change(); void on_size_template_combo_change(); void on_fps_template_combo_change(); void on_ui_language_combo_change(); @@ -157,7 +118,6 @@ class Dialog_Setup : public Dialog_Template void on_choose_editor_pressed(); bool select_path_dialog(const std::string &title, std::string &filename); - void create_gamma_page(PageInfo pi); void create_system_page(PageInfo pi); void create_document_page(PageInfo pi); void create_render_page(PageInfo pi); @@ -167,23 +127,12 @@ class Dialog_Setup : public Dialog_Template synfigapp::Settings &input_settings; // Widget for pages - GammaPattern gamma_pattern; Gtk::ComboBoxText timestamp_comboboxtext; std::map time_formats; - Glib::RefPtr adj_gamma_r; - Glib::RefPtr adj_gamma_g; - Glib::RefPtr adj_gamma_b; - Glib::RefPtr adj_gamma_a; - Glib::RefPtr adj_recent_files; Glib::RefPtr adj_undo_depth; - Gtk::Switch toggle_use_colorspace_gamma; -#ifdef SINGLE_THREADED - Gtk::Switch toggle_single_threaded; -#endif - synfig::Time::Format time_format; Widget_Enum *widget_enum; diff --git a/synfig-studio/src/gui/docks/dock_info.cpp b/synfig-studio/src/gui/docks/dock_info.cpp index b4962a9..cc9901a 100644 --- a/synfig-studio/src/gui/docks/dock_info.cpp +++ b/synfig-studio/src/gui/docks/dock_info.cpp @@ -82,22 +82,23 @@ void studio::Dock_Info::on_mouse_move() x.set_text(xv.get_string(3)); y.set_text(yv.get_string(3)); - float cr=0.f,cg=0.f,cb=0.f,ca=0.f; Color c = canvas_view->get_canvas()->get_context( canvas_view->get_context_params() ).get_color(pos); - cr = c.get_r(); cg = c.get_g(); cb = c.get_b(); ca = c.get_a(); + Gamma gamma = canvas_view->get_canvas()->rend_desc().get_gamma(); - if(use_colorspace_gamma()) + if ( approximate_equal_lp(gamma.get_r(), ColorRela(1)) + && approximate_equal_lp(gamma.get_g(), ColorRela(1)) + && approximate_equal_lp(gamma.get_b(), ColorRela(1)) ) { - cr = gamma_in(cr); - cg = gamma_in(cg); - cb = gamma_in(cb); - ca = gamma_in(ca); + r.set_text(strprintf("%.1f%%", c.get_r()*100)); + g.set_text(strprintf("%.1f%%", c.get_g()*100)); + b.set_text(strprintf("%.1f%%", c.get_b()*100)); + } else { + Color cg = gamma.apply(c); + r.set_text(strprintf("%.1f%% (%.1f%%)", c.get_r()*100, cg.get_r()*100)); + r.set_text(strprintf("%.1f%% (%.1f%%)", c.get_g()*100, cg.get_g()*100)); + r.set_text(strprintf("%.1f%% (%.1f%%)", c.get_b()*100, cg.get_b()*100)); } - - r.set_text(strprintf("%.1f%%",cr*100)); - g.set_text(strprintf("%.1f%%",cg*100)); - b.set_text(strprintf("%.1f%%",cb*100)); - a.set_text(strprintf("%.1f%%",ca*100)); + a.set_text(strprintf("%.1f%%", c.get_a()*100)); } studio::Dock_Info::Dock_Info() diff --git a/synfig-studio/src/gui/modules/mod_palette/dock_paledit.h b/synfig-studio/src/gui/modules/mod_palette/dock_paledit.h index d1943d5..71237cb 100644 --- a/synfig-studio/src/gui/modules/mod_palette/dock_paledit.h +++ b/synfig-studio/src/gui/modules/mod_palette/dock_paledit.h @@ -35,7 +35,7 @@ #include #include -#include +#include #include #include "../../widgets/widget_coloredit.h" @@ -61,7 +61,6 @@ class CanvasInterface; namespace studio { -class Widget_Color; class PaletteSettings; class Dock_PalEdit : public Dockable @@ -94,6 +93,7 @@ private: void select_outline_color(int i); synfig::Color get_color(int i)const; void edit_color(int i); + public: void set_palette(const synfig::Palette& x); const synfig::Palette& get_palette()const { return palette_; } diff --git a/synfig-studio/src/gui/preview.cpp b/synfig-studio/src/gui/preview.cpp index 79b8dcd..2dbdd02 100644 --- a/synfig-studio/src/gui/preview.cpp +++ b/synfig-studio/src/gui/preview.cpp @@ -299,7 +299,7 @@ void studio::Preview::frame_finish(const Preview_Target *targ) //convert all the pixels to the pixbuf... buffer... thing... //synfig::warning("Converting..."); - color_to_pixelformat(buffer, surf[0], pf, &App::gamma, surf.get_w(), surf.get_h()); + color_to_pixelformat(buffer, surf[0], pf, 0, surf.get_w(), surf.get_h()); //load time fe.t = time; @@ -1076,13 +1076,7 @@ void studio::Widget_Preview::stoprender() // don't crash if the render has already been stopped if (!preview->renderer) return; - -#ifdef SINGLE_THREADED - if (preview->renderer->updating) - preview->renderer->pause(); - else -#endif - preview->renderer.detach(); + preview->renderer.detach(); } } diff --git a/synfig-studio/src/gui/renddesc.cpp b/synfig-studio/src/gui/renddesc.cpp index 0134b7c..7ccea1a 100644 --- a/synfig-studio/src/gui/renddesc.cpp +++ b/synfig-studio/src/gui/renddesc.cpp @@ -31,16 +31,19 @@ # include #endif -#include -#include "renddesc.h" #include #include #include #include #include +#include + #include -//#include + +#include + +#include "renddesc.h" #include @@ -77,33 +80,158 @@ using namespace studio; /* === P R O C E D U R E S ================================================= */ + +class GammaPattern : public Gtk::DrawingArea +{ +private: + Gamma gamma; + int tile_w, tile_h, gradient_h; + Cairo::RefPtr pattern; + +public: + GammaPattern(): + tile_w(80), + tile_h(80), + gradient_h(20) + { + set_size_request(tile_w*4, tile_h*2 + gradient_h*2); + + // make pattern + Cairo::RefPtr surface = + Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, 2, 2); + Cairo::RefPtr context = Cairo::Context::create(surface); + context->set_operator(Cairo::OPERATOR_SOURCE); + context->set_source_rgba(0, 0, 0, 0); + context->rectangle(0, 0, 1, 1); + context->fill(); + context->set_source_rgba(0, 0, 0, 1); + context->rectangle(0, 0, 1, 1); + context->rectangle(1, 1, 1, 1); + context->fill(); + surface->flush(); + + pattern = Cairo::SurfacePattern::create(surface); + pattern->set_filter(Cairo::FILTER_NEAREST); + pattern->set_extend(Cairo::EXTEND_REPEAT); + } + + const Gamma& get_gamma() const { return gamma; } + + void set_gamma(const Gamma &x) { + if (gamma == x) return; + gamma = x; + queue_draw(); + } + + virtual bool on_draw(const Cairo::RefPtr &cr) + { + cr->save(); + + // prepare colors + ColorReal values[3] = {0.25, 0.5, 1}; + Color colors[3][4]; + for(int i = 0; i < 4; ++i) { + ColorReal v = values[i]; + Color *c = colors[i]; + c[0] = Color(v, v, v); + c[1] = Color(v, 0, 0); + c[2] = Color(0, v, 0); + c[3] = Color(0, 0, v); + for(int j = 0; j < 4; ++j) + c[j] = gamma.apply(c[j]); + } + Color *gray25 = colors[0]; + Color *gray50 = colors[1]; + Color *white = colors[2]; + + // 50% pattern + for(int i = 0; i < 4; ++i) + { + cr->set_source_rgb(white[i].get_r(), white[i].get_g(), white[i].get_b()); + cr->rectangle(i*tile_w, 0, tile_w, tile_h); + cr->fill(); + + cr->set_source(pattern); + cr->rectangle(i*tile_w, 0, tile_w, tile_h); + cr->fill(); + + cr->set_source_rgb(gray50[i].get_r(), gray50[i].get_g(), gray50[i].get_b()); + cr->rectangle(i*tile_w+tile_w/4, tile_h/4, tile_w-tile_w/2, tile_h-tile_h/2); + cr->fill(); + } + + // 25% pattern + for(int i = 0; i < 4; ++i) + { + cr->set_source_rgb(gray50[i].get_r(), gray50[i].get_g(), gray50[i].get_b()); + cr->rectangle(i*tile_w, tile_h, tile_w, tile_h); + cr->fill(); + + cr->set_source(pattern); + cr->rectangle(i*tile_w, tile_h, tile_w, tile_h); + cr->fill(); + + cr->set_source_rgb(gray25[i].get_r(), gray25[i].get_g(), gray25[i].get_b()); + cr->rectangle(i*tile_w+tile_w/4, tile_h+tile_h/4, tile_w-tile_w/2, tile_h-tile_h/2); + cr->fill(); + } + + // black and white level pattern + cr->set_source_rgb(0, 0, 0); + cr->rectangle(0, tile_h*2, tile_w*4, gradient_h); + cr->fill(); + cr->set_source_rgb(1, 1, 1); + cr->rectangle(0, tile_h*2 + gradient_h, tile_w*4, gradient_h); + cr->fill(); + ColorReal level = 1; + for(int i = 0; i < 8; ++i) + { + level *= 0.5; + Color black = gamma.apply(Color(level, level, level)); + Color white = gamma.apply(Color(1-level, 1-level, 1-level)); + double x = tile_w*4*(i/8.0 + 1/16.0); + double yb = tile_h*2 + gradient_h/2.0; + double yw = yb + gradient_h; + double r = gradient_h/4.0; + + cr->set_source_rgb(black.get_r(), black.get_g(), black.get_b()); + cr->arc(x, yb, r, 0, 2*M_PI); + cr->fill(); + + cr->set_source_rgb(white.get_r(), white.get_g(), white.get_b()); + cr->arc(x, yw, r, 0, 2*M_PI); + cr->fill(); + } + cr->restore(); + return true; + } +}; // END of class GammaPattern + + /* === M E T H O D S ======================================================= */ + Widget_RendDesc::Widget_RendDesc(): Gtk::Notebook(), - adjustment_width(Gtk::Adjustment::create(1,1,SYNFIG_MAX_PIXEL_WIDTH)), - adjustment_height(Gtk::Adjustment::create(1,1,SYNFIG_MAX_PIXEL_HEIGHT)), - adjustment_xres(Gtk::Adjustment::create(0,0.0000000001,10000000)), - adjustment_yres(Gtk::Adjustment::create(0,0.0000000001,10000000)), - adjustment_phy_width(Gtk::Adjustment::create(0,0.0000000001,10000000)), - adjustment_phy_height(Gtk::Adjustment::create(0,0.0000000001,10000000)), - adjustment_fps(Gtk::Adjustment::create(0,0.0000000001,10000000)), - adjustment_span(Gtk::Adjustment::create(0,0.0000000001,10000000)) + adjustment_width (Gtk::Adjustment::create(1, 1, SYNFIG_MAX_PIXEL_WIDTH)), + adjustment_height (Gtk::Adjustment::create(1, 1, SYNFIG_MAX_PIXEL_HEIGHT)), + adjustment_xres (Gtk::Adjustment::create(0, 1e-10, 1e7)), + adjustment_yres (Gtk::Adjustment::create(0, 1e-10, 1e7)), + adjustment_phy_width (Gtk::Adjustment::create(0, 1e-10, 1e7)), + adjustment_phy_height(Gtk::Adjustment::create(0, 1e-10, 1e7)), + adjustment_fps (Gtk::Adjustment::create(0, 1e-10, 1e7)), + adjustment_span (Gtk::Adjustment::create(0, 1e-10, 1e7)), + adjustment_gamma_r (Gtk::Adjustment::create(1, 0.1, 3.0, 0.025, 0.025)), + adjustment_gamma_g (Gtk::Adjustment::create(1, 0.1, 3.0, 0.025, 0.025)), + adjustment_gamma_b (Gtk::Adjustment::create(1, 0.1, 3.0, 0.025, 0.025)) { update_lock=0; - create_widgets(); connect_signals(); - - Gtk::Label *image_tab_label = manage(new Gtk::Label(_("Image"))); - Gtk::Label *time_tab_label = manage(new Gtk::Label(_("Time"))); - Gtk::Label *other_tab_label = manage(new Gtk::Label(_("Other"))); - Gtk::Widget *imageTab = create_image_tab(); - Gtk::Widget *timeTab = create_time_tab(); - Gtk::Widget *otherTab = create_other_tab(); - append_page(*imageTab, *image_tab_label); - append_page(*timeTab, *time_tab_label); - append_page(*otherTab, *other_tab_label); + append_page(*create_image_tab(), Glib::ustring(_("Image"))); + append_page(*create_time_tab(), Glib::ustring(_("Time"))); + append_page(*create_gamma_tab(), Glib::ustring(_("Gamma correction"))); + append_page(*create_other_tab(), Glib::ustring(_("Other"))); } Widget_RendDesc::~Widget_RendDesc() @@ -113,7 +241,6 @@ Widget_RendDesc::~Widget_RendDesc() void Widget_RendDesc::set_rend_desc(const synfig::RendDesc &rend_desc) { if(update_lock)return; - rend_desc_=rend_desc; refresh(); } @@ -122,7 +249,8 @@ void Widget_RendDesc::refresh() { UpdateLock lock(update_lock); - //Image Tab + + // image tab adjustment_width->set_value(rend_desc_.get_w()); adjustment_height->set_value(rend_desc_.get_h()); adjustment_phy_width->set_value(METERS2INCHES(rend_desc_.get_physical_w())); @@ -142,17 +270,22 @@ Widget_RendDesc::refresh() entry_br->set_value(rend_desc_.get_br()); adjustment_span->set_value(rend_desc_.get_span()); - //Time Tab + // time tab entry_start_time->set_fps(rend_desc_.get_frame_rate()); entry_start_time->set_value(rend_desc_.get_time_start()); entry_end_time->set_fps(rend_desc_.get_frame_rate()); entry_end_time->set_value(rend_desc_.get_time_end()); entry_duration->set_fps(rend_desc_.get_frame_rate()); entry_duration->set_value(rend_desc_.get_duration()); - adjustment_fps->set_value(rend_desc_.get_frame_rate()); - //Other Tab + // gamma tab + adjustment_gamma_r->set_value(rend_desc_.get_gamma().get_r()); + adjustment_gamma_g->set_value(rend_desc_.get_gamma().get_g()); + adjustment_gamma_b->set_value(rend_desc_.get_gamma().get_b()); + dynamic_cast(gamma_pattern)->set_gamma(rend_desc_.get_gamma().get_inverted()); + + // other tab toggle_px_aspect->set_active((bool)(rend_desc_.get_flags()&RendDesc::PX_ASPECT)); toggle_px_width->set_active((bool)(rend_desc_.get_flags()&RendDesc::PX_W)); toggle_px_height->set_active((bool)(rend_desc_.get_flags()&RendDesc::PX_H)); @@ -342,6 +475,19 @@ Widget_RendDesc::on_span_changed() } void +Widget_RendDesc::on_gamma_changed() +{ + if(update_lock)return; + UpdateLock lock(update_lock); + rend_desc_.set_gamma(Gamma( + adjustment_gamma_r->get_value(), + adjustment_gamma_g->get_value(), + adjustment_gamma_b->get_value() )); + refresh(); + signal_changed()(); +} + +void Widget_RendDesc::disable_time_section() { time_frame->set_sensitive(false); @@ -354,6 +500,18 @@ Widget_RendDesc::enable_time_section() } void +Widget_RendDesc::disable_gamma_section() +{ + gamma_frame->set_sensitive(false); +} + +void +Widget_RendDesc::enable_gamma_section() +{ + gamma_frame->set_sensitive(true); +} + +void Widget_RendDesc::on_ratio_wh_toggled() { if(update_lock)return; @@ -415,6 +573,12 @@ Widget_RendDesc::create_widgets() entry_end_time=manage(new Widget_Time()); entry_duration=manage(new Widget_Time()); entry_focus=manage(new Widget_Vector()); + entry_gamma_r=manage(new Gtk::SpinButton(adjustment_gamma_r,0.01,2)); + entry_gamma_g=manage(new Gtk::SpinButton(adjustment_gamma_g,0.01,2)); + entry_gamma_b=manage(new Gtk::SpinButton(adjustment_gamma_b,0.01,2)); + scale_gamma_r=manage(new Gtk::Scale(adjustment_gamma_r)); + scale_gamma_g=manage(new Gtk::Scale(adjustment_gamma_g)); + scale_gamma_b=manage(new Gtk::Scale(adjustment_gamma_b)); toggle_px_aspect=manage(new Gtk::CheckButton(_("_Pixel Aspect"), true)); toggle_px_aspect->set_alignment(0, 0.5); toggle_px_width=manage(new Gtk::CheckButton(_("Pi_xel Width"), true)); @@ -439,29 +603,32 @@ Widget_RendDesc::create_widgets() void Widget_RendDesc::connect_signals() { - entry_width->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_RendDesc::on_width_changed)); - entry_height->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_RendDesc::on_height_changed)); - entry_xres->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_RendDesc::on_xres_changed)); - entry_yres->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_RendDesc::on_yres_changed)); - entry_phy_width->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_RendDesc::on_phy_width_changed)); - entry_phy_height->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_RendDesc::on_phy_height_changed)); - entry_span->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_RendDesc::on_span_changed)); - entry_tl->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_RendDesc::on_tl_changed)); - entry_br->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_RendDesc::on_br_changed)); - entry_fps->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_RendDesc::on_fps_changed)); - entry_start_time->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_RendDesc::on_start_time_changed)); - entry_end_time->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_RendDesc::on_end_time_changed)); - entry_duration->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_RendDesc::on_duration_changed)); - entry_focus->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_RendDesc::on_focus_changed)); + entry_width ->signal_value_changed().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_width_changed)); + entry_height ->signal_value_changed().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_height_changed)); + entry_xres ->signal_value_changed().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_xres_changed)); + entry_yres ->signal_value_changed().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_yres_changed)); + entry_phy_width ->signal_value_changed().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_phy_width_changed)); + entry_phy_height->signal_value_changed().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_phy_height_changed)); + entry_span ->signal_value_changed().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_span_changed)); + entry_tl ->signal_value_changed().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_tl_changed)); + entry_br ->signal_value_changed().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_br_changed)); + entry_fps ->signal_value_changed().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_fps_changed)); + entry_start_time->signal_value_changed().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_start_time_changed)); + entry_end_time ->signal_value_changed().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_end_time_changed)); + entry_duration ->signal_value_changed().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_duration_changed)); + entry_focus ->signal_value_changed().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_focus_changed)); + entry_gamma_r ->signal_value_changed().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_gamma_changed)); + entry_gamma_g ->signal_value_changed().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_gamma_changed)); + entry_gamma_b ->signal_value_changed().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_gamma_changed)); + toggle_px_aspect->signal_toggled().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_lock_changed)); - toggle_px_width->signal_toggled().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_lock_changed)); + toggle_px_width ->signal_toggled().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_lock_changed)); toggle_px_height->signal_toggled().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_lock_changed)); toggle_im_aspect->signal_toggled().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_lock_changed)); - toggle_im_width->signal_toggled().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_lock_changed)); + toggle_im_width ->signal_toggled().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_lock_changed)); toggle_im_height->signal_toggled().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_lock_changed)); - toggle_im_span->signal_toggled().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_lock_changed)); - - toggle_wh_ratio->signal_toggled().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_ratio_wh_toggled)); + toggle_im_span ->signal_toggled().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_lock_changed)); + toggle_wh_ratio ->signal_toggled().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_ratio_wh_toggled)); toggle_res_ratio->signal_toggled().connect(sigc::mem_fun(*this, &studio::Widget_RendDesc::on_ratio_res_toggled)); } @@ -581,46 +748,124 @@ Widget_RendDesc::create_time_tab() { Gtk::Alignment *paddedPanel = manage(new Gtk::Alignment(0, 0, 1, 1)); paddedPanel->set_padding(12, 12, 12, 12); - + Gtk::Box *panelBox = manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL, 12)); // for future widgets panelBox->set_homogeneous(false); paddedPanel->add(*panelBox); + + { + Gtk::Frame *frame = manage(new Gtk::Frame(_("Time Settings"))); + frame->set_shadow_type(Gtk::SHADOW_NONE); + ((Gtk::Label*)frame->get_label_widget())->set_markup(_("Time Settings")); + panelBox->pack_start(*frame, Gtk::PACK_SHRINK); + time_frame = frame; + + Gtk::Alignment *framePadding = manage(new Gtk::Alignment(0, 0, 1, 1)); + framePadding->set_padding(6, 0, 24, 0); + frame->add(*framePadding); + + Gtk::Grid *frameGrid = manage(new Gtk::Grid()); + framePadding->add(*frameGrid); + frameGrid->set_row_spacing(6); + frameGrid->set_column_spacing(250); + int row = 0; + + { + Gtk::Label *label = manage(new Gtk::Label(_("_Frames per second"), 0, 0.5, true)); + label->set_mnemonic_widget(*entry_fps); + frameGrid->attach(*label, 0, row, 1, 1); + entry_fps->set_hexpand(true); + frameGrid->attach(*entry_fps, 1, row++, 1, 1); + } + + { + Gtk::Label *label = manage(new Gtk::Label(_("_Start Time"), 0, 0.5, true)); + label->set_mnemonic_widget(*entry_start_time); + frameGrid->attach(*label, 0, row, 1, 1); + frameGrid->attach(*entry_start_time, 1, row++, 1, 1); + } + + { + Gtk::Label *label = manage(new Gtk::Label(_("_End Time"), 0, 0.5, true)); + label->set_mnemonic_widget(*entry_end_time); + frameGrid->attach(*label, 0, row, 1, 1); + frameGrid->attach(*entry_end_time, 1, row++, 1, 1); + } + + { + Gtk::Label *label = manage(new Gtk::Label(_("_Duration"), 0, 0.5, true)); + label->set_mnemonic_widget(*entry_duration); + frameGrid->attach(*label, 0, row, 1, 1); + frameGrid->attach(*entry_duration, 1, row++, 1, 1); + } + } + + paddedPanel->show_all(); + return paddedPanel; +} - time_frame = manage(new Gtk::Frame(_("Time Settings"))); - time_frame->set_shadow_type(Gtk::SHADOW_NONE); - ((Gtk::Label *) time_frame->get_label_widget())->set_markup(_("Time Settings")); - panelBox->pack_start(*time_frame, Gtk::PACK_SHRINK); - - Gtk::Alignment *timeFramePadding = manage(new Gtk::Alignment(0, 0, 1, 1)); - timeFramePadding->set_padding(6, 0, 24, 0); - time_frame->add(*timeFramePadding); - - Gtk::Grid *timeFrameGrid = manage(new Gtk::Grid()); - timeFramePadding->add(*timeFrameGrid); - timeFrameGrid->set_row_spacing(6); - timeFrameGrid->set_column_spacing(250); - - Gtk::Label *timeFPSLabel = manage(new Gtk::Label(_("_Frames per second"), 0, 0.5, true)); - timeFPSLabel->set_mnemonic_widget(*entry_fps); - timeFrameGrid->attach(*timeFPSLabel, 0, 0, 1, 1); - entry_fps->set_hexpand(true); - timeFrameGrid->attach(*entry_fps, 1, 0, 1, 1); - - Gtk::Label *timeStartLabel = manage(new Gtk::Label(_("_Start Time"), 0, 0.5, true)); - timeStartLabel->set_mnemonic_widget(*entry_start_time); - timeFrameGrid->attach(*timeStartLabel, 0, 1, 1, 1); - timeFrameGrid->attach(*entry_start_time, 1, 1, 1, 1); - - Gtk::Label *timeEndLabel = manage(new Gtk::Label(_("_End Time"), 0, 0.5, true)); - timeEndLabel->set_mnemonic_widget(*entry_end_time); - timeFrameGrid->attach(*timeEndLabel, 0, 2, 1, 1); - timeFrameGrid->attach(*entry_end_time, 1, 2, 1, 1); - - Gtk::Label *timeDurationLabel = manage(new Gtk::Label(_("_Duration"), 0, 0.5, true)); - timeDurationLabel->set_mnemonic_widget(*entry_duration); - timeFrameGrid->attach(*timeDurationLabel, 0, 3, 1, 1); - timeFrameGrid->attach(*entry_duration, 1, 3, 1, 1); +Gtk::Widget * +Widget_RendDesc::create_gamma_tab() +{ + Gtk::Alignment *paddedPanel = manage(new Gtk::Alignment(0, 0, 1, 1)); + paddedPanel->set_padding(12, 12, 12, 12); + Gtk::Box *panelBox = manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL, 12)); + panelBox->set_homogeneous(false); + paddedPanel->add(*panelBox); + + { + Gtk::Frame *frame = manage(new Gtk::Frame(_("Gamma Correction Settings"))); + frame->set_shadow_type(Gtk::SHADOW_NONE); + ((Gtk::Label*)frame->get_label_widget())->set_markup(_("Gamma Correction Settings")); + panelBox->pack_start(*frame, Gtk::PACK_SHRINK); + + Gtk::Alignment *framePadding = manage(new Gtk::Alignment(0, 0, 1, 1)); + framePadding->set_padding(6, 0, 24, 0); + frame->add(*framePadding); + gamma_frame = frame; + + Gtk::Grid *frameGrid = manage(new Gtk::Grid()); + framePadding->add(*frameGrid); + frameGrid->set_row_spacing(6); + frameGrid->set_column_spacing(250); + int row = 0; + + gamma_pattern = manage(new GammaPattern()); + gamma_pattern->set_halign(Gtk::ALIGN_CENTER); + frameGrid->attach(*gamma_pattern, 0, row++, 2, 1); + + { + Gtk::Label *label = manage(new Gtk::Label(_("_Red"), 0, 0.5, true)); + label->set_mnemonic_widget(*entry_gamma_r); + frameGrid->attach(*label, 0, row, 1, 2); + entry_gamma_r->set_hexpand(true); + frameGrid->attach(*entry_gamma_r, 1, row++, 1, 1); + scale_gamma_r->set_hexpand(true); + frameGrid->attach(*scale_gamma_r, 1, row++, 1, 1); + } + + { + Gtk::Label *label = manage(new Gtk::Label(_("_Green"), 0, 0.5, true)); + label->set_mnemonic_widget(*entry_gamma_g); + frameGrid->attach(*label, 0, row, 1, 2); + entry_gamma_g->set_hexpand(true); + frameGrid->attach(*entry_gamma_g, 1, row++, 1, 1); + scale_gamma_g->set_hexpand(true); + frameGrid->attach(*scale_gamma_g, 1, row++, 1, 1); + } + + { + Gtk::Label *label = manage(new Gtk::Label(_("_Blue"), 0, 0.5, true)); + label->set_mnemonic_widget(*entry_gamma_b); + frameGrid->attach(*label, 0, row, 1, 2); + entry_gamma_b->set_hexpand(true); + frameGrid->attach(*entry_gamma_b, 1, row++, 1, 1); + scale_gamma_b->set_hexpand(true); + frameGrid->attach(*scale_gamma_b, 1, row++, 1, 1); + } + } + paddedPanel->show_all(); return paddedPanel; } diff --git a/synfig-studio/src/gui/renddesc.h b/synfig-studio/src/gui/renddesc.h index 20a135e..d677157 100644 --- a/synfig-studio/src/gui/renddesc.h +++ b/synfig-studio/src/gui/renddesc.h @@ -31,11 +31,14 @@ #include #include -#include +#include #include #include #include #include + +#include + #include "widgets/widget_vector.h" #include "widgets/widget_time.h" #include "widgets/widget_link.h" @@ -61,6 +64,9 @@ class Widget_RendDesc : public Gtk::Notebook Glib::RefPtr adjustment_phy_height; Glib::RefPtr adjustment_fps; Glib::RefPtr adjustment_span; + Glib::RefPtr adjustment_gamma_r; + Glib::RefPtr adjustment_gamma_g; + Glib::RefPtr adjustment_gamma_b; Gtk::SpinButton *entry_width; Gtk::SpinButton *entry_height; @@ -70,6 +76,13 @@ class Widget_RendDesc : public Gtk::Notebook Gtk::SpinButton *entry_phy_height; Gtk::SpinButton *entry_fps; Gtk::SpinButton *entry_span; + Gtk::SpinButton *entry_gamma_r; + Gtk::SpinButton *entry_gamma_g; + Gtk::SpinButton *entry_gamma_b; + + Gtk::Scale* scale_gamma_r; + Gtk::Scale* scale_gamma_g; + Gtk::Scale* scale_gamma_b; Widget_Link *toggle_wh_ratio; Widget_Link *toggle_res_ratio; @@ -86,6 +99,8 @@ class Widget_RendDesc : public Gtk::Notebook Gtk::CheckButton *toggle_im_span; Gtk::Frame *time_frame; + Gtk::Frame *gamma_frame; + Gtk::Widget *gamma_pattern; Widget_Vector *entry_tl; Widget_Vector *entry_br; @@ -122,9 +137,11 @@ public: const synfig::RendDesc &get_rend_desc(); void disable_time_section(); - void enable_time_section(); + void disable_gamma_section(); + void enable_gamma_section(); + void refresh(); private: @@ -144,6 +161,7 @@ private: void on_lock_changed(); void on_focus_changed(); void on_span_changed(); + void on_gamma_changed(); void on_ratio_wh_toggled(); void on_ratio_res_toggled(); @@ -152,6 +170,7 @@ private: void connect_signals(); Gtk::Widget *create_image_tab(); Gtk::Widget *create_time_tab(); + Gtk::Widget *create_gamma_tab(); Gtk::Widget *create_other_tab(); }; diff --git a/synfig-studio/src/gui/widgets/widget_color.cpp b/synfig-studio/src/gui/widgets/widget_color.cpp index 9cd7274..255b18c 100644 --- a/synfig-studio/src/gui/widgets/widget_color.cpp +++ b/synfig-studio/src/gui/widgets/widget_color.cpp @@ -29,13 +29,17 @@ # include #endif -#include - -#include "widgets/widget_color.h" #include -#include "app.h" + #include +#include + +#include +#include + +#include "widget_color.h" + #include #endif @@ -53,17 +57,6 @@ using namespace studio; /* === P R O C E D U R E S ================================================= */ -synfig::Color -studio::colorconv_apply_gamma(const synfig::Color &c_) -{ - const synfig::Color c(c_.clamped()); - return synfig::Color( - App::gamma.r_F32_to_F32(c.get_r()), - App::gamma.g_F32_to_F32(c.get_g()), - App::gamma.b_F32_to_F32(c.get_b()), - App::gamma.b_F32_to_F32(c.get_a()) ); -} - void studio::render_color_to_window(const Cairo::RefPtr &cr, const Gdk::Rectangle &ca, const synfig::Color &color) { @@ -72,16 +65,16 @@ studio::render_color_to_window(const Cairo::RefPtr &cr, const Gd const int square_size(height/2); + Gamma gamma = App::get_selected_canvas_gamma().get_inverted(); + if(color.get_alpha()!=1.0) { // In this case we need to render the alpha squares - const Color bg1( - colorconv_apply_gamma( - Color::blend(color,Color(0.75, 0.75, 0.75),1.0).clamped() )); - const Color bg2( - colorconv_apply_gamma( - Color::blend(color,Color(0.5, 0.5, 0.5),1.0).clamped() )); + const Color bg1 = gamma.apply( + Color::blend(color,Color(0.75, 0.75, 0.75),1.0).clamped() ); + const Color bg2 = gamma.apply( + Color::blend(color,Color(0.5, 0.5, 0.5),1.0).clamped() ); bool toggle(false); for(int i=0;i &cr, const Gd } else { - synfig::Color c = colorconv_apply_gamma(color); + synfig::Color c = gamma.apply(color.clamped()); cr->set_source_rgb(c.get_r(), c.get_g(), c.get_b()); cr->rectangle(ca.get_x(), ca.get_y(), width-1, height-1); cr->fill(); @@ -139,7 +132,8 @@ Widget_Color::Widget_Color() color=Color(0,0,0,0); set_size_request(-1,16); add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK); - + App::signal_canvas_view_focus().connect( + sigc::hide(sigc::mem_fun(*this,&studio::Widget_Color::queue_draw)) ); } Widget_Color::~Widget_Color() @@ -147,15 +141,15 @@ Widget_Color::~Widget_Color() } void -Widget_Color::set_value(const synfig::Color &data) +Widget_Color::set_value(const synfig::Color &x) { - assert(data.is_valid()); - color=data; + assert(x.is_valid()); + color=x; queue_draw(); } const synfig::Color & -Widget_Color::get_value() +Widget_Color::get_value() const { assert(color.is_valid()); return color; diff --git a/synfig-studio/src/gui/widgets/widget_color.h b/synfig-studio/src/gui/widgets/widget_color.h index 1bac2d0..cf3b6ea 100644 --- a/synfig-studio/src/gui/widgets/widget_color.h +++ b/synfig-studio/src/gui/widgets/widget_color.h @@ -43,34 +43,32 @@ namespace studio { -synfig::Color colorconv_apply_gamma(const synfig::Color &c); - void render_color_to_window(const Cairo::RefPtr &cr, const Gdk::Rectangle &ca, const synfig::Color &color); class Widget_Color : public Gtk::DrawingArea { +private: synfig::Color color; - + synfig::Gamma gamma; sigc::signal signal_activate_; sigc::signal signal_middle_click_; sigc::signal signal_right_click_; -protected: - public: sigc::signal& signal_activate() { return signal_activate_; } sigc::signal& signal_clicked() { return signal_activate_; } sigc::signal& signal_middle_click() { return signal_middle_click_; } sigc::signal& signal_right_click() { return signal_right_click_; } - void set_value(const synfig::Color &data); - const synfig::Color &get_value(); + const synfig::Color& get_value() const; + void set_value(const synfig::Color &x); + Widget_Color(); ~Widget_Color(); -private: + +protected: bool on_draw(const Cairo::RefPtr &cr); bool on_event(GdkEvent *event); - }; // END of class Widget_Color }; // END of namespace studio diff --git a/synfig-studio/src/gui/widgets/widget_coloredit.cpp b/synfig-studio/src/gui/widgets/widget_coloredit.cpp index 4407d63..2452008 100644 --- a/synfig-studio/src/gui/widgets/widget_coloredit.cpp +++ b/synfig-studio/src/gui/widgets/widget_coloredit.cpp @@ -68,8 +68,6 @@ using namespace studio; #define ARROW_NEGATIVE_THRESHOLD 0.4 /* === G L O B A L S ======================================================= */ -synfig::Gamma Widget_ColorEdit::hvs_gamma = synfig::Gamma(1.0/2.2); -synfig::Gamma Widget_ColorEdit::hvs_gamma_in = synfig::Gamma(2.2); /* === P R O C E D U R E S ================================================= */ @@ -177,7 +175,7 @@ ColorSlider::draw_arrow( bool ColorSlider::on_draw(const Cairo::RefPtr &cr) { - Color color(color_); + Color color = color_; static const slider_color_func jump_table[int(TYPE_END)] = { @@ -192,8 +190,10 @@ ColorSlider::on_draw(const Cairo::RefPtr &cr) slider_color_TYPE_A, }; - slider_color_func color_func(jump_table[int(type)]); + slider_color_func color_func = jump_table[int(type)]; + Gamma gamma = App::get_selected_canvas_gamma().get_inverted(); + float amount; switch(type) { @@ -208,9 +208,7 @@ ColorSlider::on_draw(const Cairo::RefPtr &cr) case TYPE_A: amount=color.get_a(); break; default: amount=0; break; } - if(use_colorspace_gamma() && (type &cr) const Color bg1(0.75, 0.75, 0.75); const Color bg2(0.5, 0.5, 0.5); - int i; - for(i=width-1;i>=0;i--) + for(int i = width-1; i >= 0; --i) { - color_func(color, - (use_colorspace_gamma() && typescroll.direction){ case GDK_SCROLL_UP: @@ -311,13 +303,8 @@ ColorSlider::on_event(GdkEvent *event) } float pos(x/width); - if(pos<0 || x<=0)pos=0; - if(pos>1)pos=1; - - if(use_colorspace_gamma() && (typebutton.x<=0)pos=0; - if(pos>1)pos=1; + if (pos > 1) pos = 1; + if (pos < 0 || x <= 0 || event->button.x <= 0) pos=0; switch(event->type) { @@ -498,13 +485,9 @@ bool are_close_colors(Gdk::Color const& a, Gdk::Color const& b) { void Widget_ColorEdit::setHVSColor(synfig::Color color) { + Color c = App::get_selected_canvas_gamma().get_inverted().apply(color).clamped(); Gdk::Color gtkColor; - float r = hvs_gamma.r_F32_to_F32(CLIP_VALUE(color.get_r(),0.0,1.0)); - float g = hvs_gamma.g_F32_to_F32(CLIP_VALUE(color.get_g(),0.0,1.0)); - float b = hvs_gamma.b_F32_to_F32(CLIP_VALUE(color.get_b(),0.0,1.0)); - gtkColor.set_red((unsigned short)(r * USHRT_MAX)); - gtkColor.set_green((unsigned short)(g * USHRT_MAX)); - gtkColor.set_blue((unsigned short)(b * USHRT_MAX)); + gtkColor.set_rgb_p(c.get_r(), c.get_g(), c.get_b()); if (!are_close_colors(hvsColorWidget->get_current_color(), gtkColor)) { colorHVSChanged = true; hvsColorWidget->set_current_color(gtkColor); @@ -521,10 +504,11 @@ Widget_ColorEdit::on_color_changed() if (!colorHVSChanged) { Gdk::Color newColor = hvsColorWidget->get_current_color(); - float r = hvs_gamma_in.r_F32_to_F32((float)newColor.get_red() / USHRT_MAX); - float g = hvs_gamma_in.g_F32_to_F32((float)newColor.get_green() / USHRT_MAX); - float b = hvs_gamma_in.b_F32_to_F32((float)newColor.get_blue() / USHRT_MAX); - const synfig::Color synfigColor(r, g, b); + Color synfigColor( + newColor.get_red_p(), + newColor.get_green_p(), + newColor.get_blue_p() ); + synfigColor = App::get_selected_canvas_gamma().apply(synfigColor); set_value(synfigColor); colorHVSChanged = true; //I reset the flag in setHVSColor(..) on_value_changed(); @@ -633,20 +617,10 @@ Widget_ColorEdit::set_value(const synfig::Color &data) color=data; - if(use_colorspace_gamma()) - { - R_adjustment->set_value(gamma_in(color.get_r())*100); - G_adjustment->set_value(gamma_in(color.get_g())*100); - B_adjustment->set_value(gamma_in(color.get_b())*100); - A_adjustment->set_value(gamma_in(color.get_a())*100); - } - else - { - R_adjustment->set_value(color.get_r()*100); - G_adjustment->set_value(color.get_g()*100); - B_adjustment->set_value(color.get_b()*100); - A_adjustment->set_value(color.get_a()*100); - } + R_adjustment->set_value(color.get_r()*100); + G_adjustment->set_value(color.get_g()*100); + B_adjustment->set_value(color.get_b()*100); + A_adjustment->set_value(color.get_a()*100); slider_R->set_color(color); slider_G->set_color(color); @@ -668,20 +642,10 @@ synfig::Color Widget_ColorEdit::get_value_raw() { Color color; - if(use_colorspace_gamma()) - { - color.set_r(gamma_out(R_adjustment->get_value()/100.0f)); - color.set_g(gamma_out(G_adjustment->get_value()/100.0f)); - color.set_b(gamma_out(B_adjustment->get_value()/100.0f)); - color.set_a(gamma_out(A_adjustment->get_value()/100.0f)); - } - else - { - color.set_r(R_adjustment->get_value()/100); - color.set_g(G_adjustment->get_value()/100); - color.set_b(B_adjustment->get_value()/100); - color.set_a(A_adjustment->get_value()/100); - } + color.set_r(R_adjustment->get_value()/100); + color.set_g(G_adjustment->get_value()/100); + color.set_b(B_adjustment->get_value()/100); + color.set_a(A_adjustment->get_value()/100); assert(color.is_valid()); return color; @@ -690,20 +654,9 @@ Widget_ColorEdit::get_value_raw() const synfig::Color & Widget_ColorEdit::get_value() { - if(use_colorspace_gamma()) - { - color.set_r(gamma_out(R_adjustment->get_value()/100.0f)); - color.set_g(gamma_out(G_adjustment->get_value()/100.0f)); - color.set_b(gamma_out(B_adjustment->get_value()/100.0f)); - assert(color.is_valid()); - } - else - { - color.set_r(R_adjustment->get_value()/100); - color.set_g(G_adjustment->get_value()/100); - color.set_b(B_adjustment->get_value()/100); - assert(color.is_valid()); - } + color.set_r(R_adjustment->get_value()/100); + color.set_g(G_adjustment->get_value()/100); + color.set_b(B_adjustment->get_value()/100); color.set_a(A_adjustment->get_value()/100); assert(color.is_valid()); diff --git a/synfig-studio/src/gui/widgets/widget_coloredit.h b/synfig-studio/src/gui/widgets/widget_coloredit.h index e093085..604b17e 100644 --- a/synfig-studio/src/gui/widgets/widget_coloredit.h +++ b/synfig-studio/src/gui/widgets/widget_coloredit.h @@ -34,7 +34,6 @@ #include #include #include -#include #include "widgets/widget_color.h" /* === M A C R O S ========================================================= */ diff --git a/synfig-studio/src/gui/widgets/widget_defaults.cpp b/synfig-studio/src/gui/widgets/widget_defaults.cpp index 5af823c..4ed838a 100644 --- a/synfig-studio/src/gui/widgets/widget_defaults.cpp +++ b/synfig-studio/src/gui/widgets/widget_defaults.cpp @@ -103,7 +103,9 @@ public: render_color_to_window(cr,Gdk::Rectangle(0,0,w,h),synfigapp::Main::get_fill_color()); // Draw in the circle - Color brush = colorconv_apply_gamma( synfigapp::Main::get_outline_color() ); + + Color brush = App::get_selected_canvas_gamma().get_inverted().apply( + synfigapp::Main::get_outline_color() ); cr->set_source_rgba(brush.get_r(), brush.get_g(), brush.get_b(), brush.get_a()); cr->arc(w/2.0, h/2.0, pixelsize, 0.0, 360*M_PI/180.0); cr->fill(); diff --git a/synfig-studio/src/gui/widgets/widget_value.h b/synfig-studio/src/gui/widgets/widget_value.h index 12cc62c..4471f80 100644 --- a/synfig-studio/src/gui/widgets/widget_value.h +++ b/synfig-studio/src/gui/widgets/widget_value.h @@ -65,7 +65,6 @@ namespace studio { class Widget_BoneChooser; -class Widget_Color; class Widget_ColorEdit; class Widget_CanvasChooser; class Widget_Enum; diff --git a/synfig-studio/src/gui/widgets/widget_vector.cpp b/synfig-studio/src/gui/widgets/widget_vector.cpp index 65ec2a7..7f9651e 100644 --- a/synfig-studio/src/gui/widgets/widget_vector.cpp +++ b/synfig-studio/src/gui/widgets/widget_vector.cpp @@ -57,8 +57,6 @@ using namespace studio; /* === M E T H O D S ======================================================= */ -static void init(); - Widget_Vector::Widget_Vector(): Glib::ObjectBase("widget_vector") { diff --git a/synfig-studio/src/gui/workarearenderer/renderer_canvas.cpp b/synfig-studio/src/gui/workarearenderer/renderer_canvas.cpp index 0b3098f..ad18d74 100644 --- a/synfig-studio/src/gui/workarearenderer/renderer_canvas.cpp +++ b/synfig-studio/src/gui/workarearenderer/renderer_canvas.cpp @@ -182,7 +182,7 @@ Renderer_Canvas::convert( cairo_surface->get_data(), pixels, pixel_format, - &App::gamma, + 0, cairo_surface->get_width(), cairo_surface->get_height(), cairo_surface->get_stride() ); @@ -458,10 +458,7 @@ Renderer_Canvas::enqueue_render_frame( canvas->set_time(id.time); canvas->load_resources(id.time); canvas->set_outline_grow(rend_desc.get_outline_grow()); - CanvasBase sub_queue; - Context context = canvas->get_context_sorted(context_params, sub_queue); - rendering::Task::Handle task = context.build_rendering_task(); - sub_queue.clear(); + rendering::Task::Handle task = canvas->build_rendering_task(context_params); // add transformation task to flip result if needed if (task && transform) { diff --git a/synfig-studio/src/gui/workarearenderer/renderer_ducks.cpp b/synfig-studio/src/gui/workarearenderer/renderer_ducks.cpp index 73417a1..f4347b5 100644 --- a/synfig-studio/src/gui/workarearenderer/renderer_ducks.cpp +++ b/synfig-studio/src/gui/workarearenderer/renderer_ducks.cpp @@ -119,6 +119,7 @@ Renderer_Ducks::render_vfunc( cr->set_line_join(Cairo::LINE_JOIN_MITER); // Render the strokes + Gamma gamma = App::get_selected_canvas_gamma().get_inverted(); for(std::list >::const_iterator iter=stroke_list.begin();iter!=stroke_list.end();++iter) { cr->save(); @@ -131,7 +132,7 @@ Renderer_Ducks::render_vfunc( ((*iter2)[1]-window_start[1])/ph ); cr->set_line_width(1.0); - synfig::Color c = colorconv_apply_gamma((*iter)->color); + synfig::Color c = gamma.apply((*iter)->color); cr->set_source_rgb(c.get_r(), c.get_g(), c.get_b()); cr->stroke(); diff --git a/synfig-studio/src/synfigapp/actions/vectorization.cpp b/synfig-studio/src/synfigapp/actions/vectorization.cpp index bd48216..04f0a39 100644 --- a/synfig-studio/src/synfigapp/actions/vectorization.cpp +++ b/synfig-studio/src/synfigapp/actions/vectorization.cpp @@ -237,12 +237,15 @@ Action::Vectorization::perform() studio::VectorizerCore vCore; synfig::Layer_Bitmap::Handle image_layer = synfig::Layer_Bitmap::Handle::cast_dynamic(layer); - // result of vectorization (vector of outline layers) - std::vector< etl::handle > Result = vCore.vectorize(image_layer, configuration); + Gamma gamma = layer->get_canvas()->get_root()->rend_desc().get_gamma(); + gamma.invert(); + + // result of vectorization (vector of outline layers) + std::vector< etl::handle > Result = vCore.vectorize(image_layer, configuration, gamma); synfig::Canvas::Handle child_canvas; child_canvas=synfig::Canvas::create_inline(layer->get_canvas()); - + new_layer->set_description("Vectorized "+layer->get_description()); new_layer->set_param("canvas",child_canvas); int move_depth = 0; diff --git a/synfig-studio/src/synfigapp/vectorizer/centerlinecolors.cpp b/synfig-studio/src/synfigapp/vectorizer/centerlinecolors.cpp index a6f482c..7456578 100644 --- a/synfig-studio/src/synfigapp/vectorizer/centerlinecolors.cpp +++ b/synfig-studio/src/synfigapp/vectorizer/centerlinecolors.cpp @@ -43,28 +43,30 @@ using namespace synfig; /* === P R O C E D U R E S ================================================= */ -synfig::Color pixelToColor(const Surface &rsurface, int x, int y) +synfig::Color pixelToColor(const Surface &rsurface, int x, int y, const Gamma &gamma) { - const int Y = rsurface.get_h() - y -1; - const Color *row = rsurface[Y]; - return row[x]; + const int Y = rsurface.get_h() - y - 1; + return gamma.apply(rsurface[Y][x]); } -bool checkPixelThreshold(const Surface &rsurface, int x, int y,int threshold) +bool checkPixelThreshold(const Surface &rsurface, int x, int y, int threshold) { - const int Y = rsurface.get_h() - y -1; - const Color *row = rsurface[Y]; - int r = 255.0*pow(row[x].get_r(),1/2.2); - int g = 255.0*pow(row[x].get_g(),1/2.2); - int b = 255.0*pow(row[x].get_b(),1/2.2); - int a = 255.0*pow(row[x].get_a(),1/2.2); - return std::max(r,std::max(g,b)) < threshold * (a / 255.0); - + const int Y = rsurface.get_h() - y -1; + const Color color = rsurface[Y][x]; + int r = 255.99*color.get_r(); + int g = 255.99*color.get_g(); + int b = 255.99*color.get_b(); + int a = 255.99*color.get_a(); + return std::max(r,std::max(g,b)) < threshold * (a / 255.0); } //------------------------------------------------------------------------ -static synfig::Point3 firstInkChangePosition(const Surface &ras, - const synfig::Point3 &start, const synfig::Point3 &end, int threshold) +static synfig::Point3 firstInkChangePosition( + const Surface &ras, + const synfig::Point3 &start, + const synfig::Point3 &end, + int threshold, + const Gamma &gamma ) { double dist = (end - start).mag(); @@ -81,7 +83,7 @@ static synfig::Point3 firstInkChangePosition(const Surface &ras, // const TPixelCM32 &pix = pixel(*ras, p.x, p.y); if (checkPixelThreshold(ras,p[0],p[1], threshold)) { - color = pixelToColor(ras,p[0],p[1]); + color = pixelToColor(ras, p[0], p[1], gamma); break; } } @@ -92,7 +94,7 @@ static synfig::Point3 firstInkChangePosition(const Surface &ras, synfig::Point3 p = start *(1 - s/sampleMaxD) + end * (s/sampleMaxD); // const TPixelCM32 &pix = pixel(*ras, p.x, p.y); - if (checkPixelThreshold(ras,p[0],p[1],threshold) && pixelToColor(ras,p[0],p[1]) != color) + if (checkPixelThreshold(ras,p[0],p[1],threshold) && pixelToColor(ras, p[0], p[1], gamma) != color) break; } @@ -132,8 +134,13 @@ static synfig::Point3 firstInkChangePosition(const Surface &ras, // NOTE: The J-S 'upper' graph structure is not altered in here. // Eventualm. to do outside. -static void sampleColor(const etl::handle &ras, int threshold, Sequence &seq, - Sequence &seqOpposite, SequenceList &singleSequences) +static void sampleColor( + const etl::handle &ras, + int threshold, + Sequence &seq, + Sequence &seqOpposite, + SequenceList &singleSequences, + const Gamma &gamma ) { SkeletonGraph *currGraph = seq.m_graphHolder; @@ -183,8 +190,11 @@ static void sampleColor(const etl::handle &ras, int thresh // Exclude 0-length sequences if (params.back() < 0.01) { - seq.m_color = pixelToColor(rsurface, currGraph->getNode(seq.m_head)->operator[](0), - currGraph->getNode(seq.m_head)->operator[](1)); + seq.m_color = pixelToColor( + rsurface, + currGraph->getNode(seq.m_head)->operator[](0), + currGraph->getNode(seq.m_head)->operator[](1), + gamma ); return; } @@ -242,15 +252,15 @@ static void sampleColor(const etl::handle &ras, int thresh // Give s the first sampled ink color found // Initialize with a last-resort reasonable color - not just 0 - seq.m_color = seqOpposite.m_color = pixelToColor(rsurface,samplePoints[0][0],samplePoints[0][1]); + seq.m_color = seqOpposite.m_color = pixelToColor(rsurface, samplePoints[0][0], samplePoints[0][1], gamma); int l; for (l = i - 1; l >= 0; --l) { - if (checkPixelThreshold(rsurface,samplePoints[l][0],samplePoints[l][1], threshold)) + if (checkPixelThreshold(rsurface, samplePoints[l][0], samplePoints[l][1], threshold)) { - seq.m_color = seqOpposite.m_color = pixelToColor(rsurface,samplePoints[l][0],samplePoints[l][1]); + seq.m_color = seqOpposite.m_color = pixelToColor(rsurface, samplePoints[l][0], samplePoints[l][1], gamma); break; } } @@ -260,8 +270,7 @@ static void sampleColor(const etl::handle &ras, int thresh { if (checkPixelThreshold(rsurface,samplePoints[l][0],samplePoints[l][1], threshold)) { - seq.m_color = seqOpposite.m_color = pixelToColor(rsurface, samplePoints[l][0], samplePoints[l][1]); - + seq.m_color = seqOpposite.m_color = pixelToColor(rsurface, samplePoints[l][0], samplePoints[l][1], gamma); break; } } @@ -278,15 +287,15 @@ static void sampleColor(const etl::handle &ras, int thresh // &nextSample = ras->pixels(x1)[y1], // &nextSample2 = ras->pixels(x2)[y2]; // l < k < sampleMax - so +2 is ok - if (checkPixelThreshold(rsurface,x1,y1,threshold) && - pixelToColor(rsurface,x1,y1) != seq.m_color && - checkPixelThreshold(rsurface,x2,y2,threshold) && - pixelToColor(rsurface,x2,y2) == pixelToColor(rsurface,x1,y1)) // Ignore single-sample color changes + if (checkPixelThreshold(rsurface, x1, y1, threshold) && + pixelToColor(rsurface, x1, y1, gamma) != seq.m_color && + checkPixelThreshold(rsurface, x2, y2, threshold) && + pixelToColor(rsurface, x2, y2, gamma) == pixelToColor(rsurface, x1, y1, gamma)) // Ignore single-sample color changes { // Found a color change - apply splitting procedure // NOTE: The function RETURNS BEFORE THE FOR IS CONTINUED! - synfig::Color nextColor = pixelToColor(rsurface,x1,y1); + synfig::Color nextColor = pixelToColor(rsurface, x1, y1, gamma); // Identify split segment int u; @@ -295,7 +304,7 @@ static void sampleColor(const etl::handle &ras, int thresh { const int x = currGraph->getNode(nodes[u + 1])->operator[](0), y = currGraph->getNode(nodes[u + 1])->operator[](1); - if (checkPixelThreshold(rsurface,x,y,threshold) && pixelToColor(rsurface,x,y) != seq.m_color) + if (checkPixelThreshold(rsurface, x, y, threshold) && pixelToColor(rsurface, x, y, gamma) != seq.m_color) break; } @@ -304,7 +313,7 @@ static void sampleColor(const etl::handle &ras, int thresh const synfig::Point3 &nodeStartPos = *currGraph->getNode(nodes[u]), &nodeEndPos = *currGraph->getNode(nodes[u + 1]); - synfig::Point3 splitPoint = firstInkChangePosition(rsurface, nodeStartPos, nodeEndPos, threshold); + synfig::Point3 splitPoint = firstInkChangePosition(rsurface, nodeStartPos, nodeEndPos, threshold, gamma); if (splitPoint == synfig::Point3::nan()) splitPoint = (nodeStartPos + nodeEndPos) * 0.5; @@ -333,7 +342,7 @@ static void sampleColor(const etl::handle &ras, int thresh // Circular case: we update s to splitNode and relaunch this very // procedure on it. seq.m_head = seq.m_tail = splitNode; - sampleColor(ras, threshold, seq, seqOpposite, singleSequences); + sampleColor(ras, threshold, seq, seqOpposite, singleSequences, gamma); } else { @@ -359,7 +368,7 @@ static void sampleColor(const etl::handle &ras, int thresh currGraph->getNode(seq.m_head).hasAttribute(SAMPLECOLOR_SIGN)) singleSequences.push_back(seq); - sampleColor(ras, threshold, newSeq, seqOpposite, singleSequences); + sampleColor(ras, threshold, newSeq, seqOpposite, singleSequences, gamma); } return; @@ -384,7 +393,7 @@ _getOut: /* === E N T R Y P O I N T ================================================= */ -void studio::calculateSequenceColors(const etl::handle &ras, VectorizerCoreGlobals &g) +void studio::calculateSequenceColors(const etl::handle &ras, VectorizerCoreGlobals &g, const Gamma &gamma) { int threshold = g.currConfig->m_threshold; SequenceList &singleSequences = g.singleSequences; @@ -401,7 +410,7 @@ void studio::calculateSequenceColors(const etl::handle &ra for (l = singleSequences.size() - 1; l >= 0; --l) { Sequence rear; - sampleColor(ras, threshold, singleSequences[l], rear, singleSequences); + sampleColor(ras, threshold, singleSequences[l], rear, singleSequences, gamma); // If rear is built, a split occurred and the rear of this // single sequence has to be pushed back. if (rear.m_graphHolder) singleSequences.push_back(rear); @@ -421,7 +430,7 @@ void studio::calculateSequenceColors(const etl::handle &ra unsigned int next = organizedGraphs[i].node(j).link(k).getNext(); unsigned int nextLink = organizedGraphs[i].tailLinkOf(j, k); Sequence &sOpposite = *organizedGraphs[i].node(next).link(nextLink); - sampleColor(ras, threshold, s, sOpposite, singleSequences); + sampleColor(ras, threshold, s, sOpposite, singleSequences, gamma); } } } diff --git a/synfig-studio/src/synfigapp/vectorizer/centerlinepolygonizer.cpp b/synfig-studio/src/synfigapp/vectorizer/centerlinepolygonizer.cpp index c7a1a9c..83ed6d4 100644 --- a/synfig-studio/src/synfigapp/vectorizer/centerlinepolygonizer.cpp +++ b/synfig-studio/src/synfigapp/vectorizer/centerlinepolygonizer.cpp @@ -114,29 +114,27 @@ enum { inner = 0, outer = 1, none = 2, invalid = 3 }; //-------------------------------------------------------------------------- class PixelEvaluator { - Handle m_ras; + const Surface &m_surface; int m_threshold; public: - PixelEvaluator(const Handle &ras, int threshold) - : m_ras(ras), m_threshold(threshold) {} + PixelEvaluator(const Surface &surface, int threshold) + : m_surface(surface), m_threshold(threshold) {} inline unsigned char getBlackOrWhite(int x, int y); }; // //-------------------------------------------------------------------------- -inline unsigned char PixelEvaluator::getBlackOrWhite(int x, int y) +inline unsigned char PixelEvaluator::getBlackOrWhite(int x, int y) { - synfig::rendering::SurfaceResource::LockRead lock( m_ras->rendering_surface ); - const Surface &surface = lock->get_surface(); - const int Y = surface.get_h() - y -1; - const Color *row = surface[Y]; - int r = 255.0*pow(row[x].get_r(),1/2.2); - int g = 255.0*pow(row[x].get_g(),1/2.2); - int b = 255.0*pow(row[x].get_b(),1/2.2); - int a = 255.0*pow(row[x].get_a(),1/2.2); - return std::max(r,std::max(g,b)) < m_threshold * (a / 255.0); + const int Y = m_surface.get_h() - y -1; + const Color &color = m_surface[Y][x]; + int r = 255.99*color.get_r(); + int g = 255.99*color.get_g(); + int b = 255.99*color.get_b(); + int a = 255.99*color.get_a(); + return std::max(r,std::max(g,b)) < m_threshold * (a / 255.0); } //-------------------------------------------------------------------------- @@ -186,37 +184,34 @@ public: //-------------------------------------------------------------------------- -Signaturemap::Signaturemap(const Handle &ras, int threshold) +Signaturemap::Signaturemap(const Handle &ras, int threshold) { - // read the raster data - unsigned char *currByte; - int x, y; + // read the raster data + unsigned char *currByte; + int x, y; - PixelEvaluator evaluator(ras, threshold);//evaluator object with ras, threshold as constructor args - rendering::SurfaceResource::LockRead lock( ras->rendering_surface ); + rendering::SurfaceResource::LockRead lock( ras->rendering_surface ); const Surface &surface = lock->get_surface(); + PixelEvaluator evaluator(surface, threshold);//evaluator object with surface, threshold as constructor args m_rowSize = surface.get_w() + 2; - m_colSize = surface.get_h() + 2; - m_array.reset(new unsigned char[m_rowSize * m_colSize]); + m_colSize = surface.get_h() + 2; + m_array.reset(new unsigned char[m_rowSize * m_colSize]); - memset(m_array.get(), none << 1, m_rowSize); + memset(m_array.get(), none << 1, m_rowSize); - currByte = m_array.get() + m_rowSize; - for (y = 0; y &ras, Contours &polygons, VectorizerCoreGlobals &g) +void studio::polygonize(const etl::handle &ras, Contours &polygons, VectorizerCoreGlobals &g) { - std::cout<<"Welcome to polygonize\n"; - - BorderList *borders; - - borders = extractBorders(ras, g.currConfig->m_threshold, g.currConfig->m_despeckling); - - reduceBorders(*borders, polygons, g.currConfig->m_maxThickness > 0.0); + std::cout<<"Welcome to polygonize\n"; + + BorderList *borders; + + borders = extractBorders(ras, g.currConfig->m_threshold, g.currConfig->m_despeckling); + + reduceBorders(*borders, polygons, g.currConfig->m_maxThickness > 0.0); } diff --git a/synfig-studio/src/synfigapp/vectorizer/centerlinevectorizer.cpp b/synfig-studio/src/synfigapp/vectorizer/centerlinevectorizer.cpp index 930f962..e0c7882 100644 --- a/synfig-studio/src/synfigapp/vectorizer/centerlinevectorizer.cpp +++ b/synfig-studio/src/synfigapp/vectorizer/centerlinevectorizer.cpp @@ -38,6 +38,7 @@ using namespace std; using namespace etl; +using namespace synfig; using namespace studio; /* === M A C R O S ========================================================= */ @@ -63,7 +64,7 @@ inline void deleteSkeletonList(SkeletonList *skeleton) { //************************ // takes two arguments ( image layer handle, config ) -std::vector< etl::handle > VectorizerCore::centerlineVectorize(etl::handle &image, const CenterlineConfiguration &configuration) +std::vector< etl::handle > VectorizerCore::centerlineVectorize(etl::handle &image, const CenterlineConfiguration &configuration, const Gamma &gamma) { std::cout<<"Inside CenterlineVectorize\n"; VectorizerCoreGlobals globals; @@ -143,7 +144,8 @@ std::vector< etl::handle > VectorizerCore::centerlineVectorize(et deleteSkeletonList(skeletons); return sortibleResult; } -std::vector< etl::handle > VectorizerCore::vectorize(const etl::handle &img, const VectorizerConfiguration &c) + +std::vector< etl::handle > VectorizerCore::vectorize(const etl::handle &img, const VectorizerConfiguration &c, const Gamma &gamma) { std::vector< etl::handle > result; @@ -156,7 +158,7 @@ std::vector< etl::handle > VectorizerCore::vectorize(const etl::h else { Handle img2(img); - result = centerlineVectorize(img2, static_cast(c)); + result = centerlineVectorize(img2, static_cast(c), gamma); std::cout<<"After centerlineVectorize result.size(): "< > vectorize(const etl::handle &image, const VectorizerConfiguration &c); + std::vector< etl::handle > vectorize(const etl::handle &image, const VectorizerConfiguration &c, const synfig::Gamma &gamma); private: - std::vector< etl::handle > centerlineVectorize(Handle &image, const CenterlineConfiguration &configuration); + std::vector< etl::handle > centerlineVectorize(Handle &image, const CenterlineConfiguration &configuration, const synfig::Gamma &gamma); }; @@ -80,4 +80,4 @@ private: /* === E N D =============================================================== */ -#endif \ No newline at end of file +#endif diff --git a/synfig-studio/src/synfigapp/vectorizer/polygonizerclasses.h b/synfig-studio/src/synfigapp/vectorizer/polygonizerclasses.h index 5c5afe4..95dc384 100644 --- a/synfig-studio/src/synfigapp/vectorizer/polygonizerclasses.h +++ b/synfig-studio/src/synfigapp/vectorizer/polygonizerclasses.h @@ -443,7 +443,7 @@ void organizeGraphs(SkeletonList *skeleton, VectorizerCoreGlobals &g); void conversionToStrokes(std::vector< etl::handle > &strokes, VectorizerCoreGlobals &g, const etl::handle &image) ; - void calculateSequenceColors(const etl::handle &ras, VectorizerCoreGlobals &g); + void calculateSequenceColors(const etl::handle &ras, VectorizerCoreGlobals &g, const synfig::Gamma &gamma); // void applyStrokeColors(std::vector &strokes, const TRasterP &ras, // TPalette *palette, VectorizerCoreGlobals &g);