X-Git-Url: https://git.cinelerra-gg.org/git/?a=blobdiff_plain;ds=sidebyside;f=cinelerra-5.1%2Fguicast%2Fvframe.C;h=14794aa2b8aea07fb7a6e6eb64612238b3eef3fd;hb=fb661e853152fd63537629a20f493a4cdcd4f019;hp=3eca676452ca8536fa3f78993e68a24bf35fd9a1;hpb=7fd85fb66168f6b518c5f2d73e04036e87faa0e1;p=goodguy%2Fcinelerra.git diff --git a/cinelerra-5.1/guicast/vframe.C b/cinelerra-5.1/guicast/vframe.C index 3eca6764..14794aa2 100644 --- a/cinelerra-5.1/guicast/vframe.C +++ b/cinelerra-5.1/guicast/vframe.C @@ -44,7 +44,7 @@ class PngReadFunction { public: static void png_read_function(png_structp png_ptr, - png_bytep data, png_size_t length) + png_bytep data, png_size_t length) { VFrame *frame = (VFrame*)png_get_io_ptr(png_ptr); if(frame->image_size - frame->image_offset < (long)length) @@ -388,6 +388,16 @@ int VFrame::get_keyframe() return is_keyframe; } +void VFrame::get_temp(VFrame *&vfrm, int w, int h, int color_model) +{ + if( vfrm && ( vfrm->color_model != color_model || + vfrm->get_w() != w || vfrm->get_h() != h ) ) { + delete vfrm; vfrm = 0; + } + if( !vfrm ) vfrm = new VFrame(w, h, color_model, 0); +} + + VFrameScene* VFrame::get_scene() { @@ -819,7 +829,7 @@ int VFramePng::read_png(const unsigned char *data, long sz, double xscale, doubl int ww = w * xscale, hh = h * yscale; if( ww != w || hh != h ) { VFrame vframe(*this); - reallocate(NULL, -1, 0, 0, 0, ww, hh, color_model, -1); + reallocate(NULL, -1, 0, 0, 0, ww, hh, color_model, -1); transfer_from(&vframe); } return 0; @@ -865,6 +875,28 @@ int VFrame::write_png(const char *path) return 0; } +void VFrame::write_ppm(VFrame *vfrm, const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + char fn[BCTEXTLEN]; + vsnprintf(fn, sizeof(fn), fmt, ap); + va_end(ap); + FILE *fp = fopen(fn,"w"); + if( !fp ) { perror("write_ppm"); return; } + VFrame *frm = vfrm; + if( frm->get_color_model() != BC_RGB888 ) { + frm = new VFrame(frm->get_w(), frm->get_h(), BC_RGB888); + frm->transfer_from(vfrm); + } + int w = frm->get_w(), h = frm->get_h(); + fprintf(fp,"P6\n%d %d\n255\n",w,h); + unsigned char **rows = frm->get_rows(); + for( int i=0; itimestamp; copy_params(that); - if( this->get_color_model() == that->get_color_model() && + if( in_x == 0 && in_y == 0 && in_w == that->get_w() && in_h == that->get_h() && + bg_color == 0 && this->get_color_model() == that->get_color_model() && this->get_w() == that->get_w() && this->get_h() == that->get_h() && this->get_bytes_per_line() == that->get_bytes_per_line() ) return this->copy_from(that); @@ -1341,14 +1374,16 @@ int VFrame::get_memory_usage() return get_h() * get_bytes_per_line(); } -void VFrame::set_pixel_color(int rgb) +// rgb component colors (eg. from colors.h) +// a (~alpha) transparency, 0x00==solid .. 0xff==transparent +void VFrame::set_pixel_color(int rgb, int a) { - pixel_rgb = rgb; + pixel_rgb = (rgb&0xffffff) | ~a<<24; int ir = 0xff & (pixel_rgb >> 16); int ig = 0xff & (pixel_rgb >> 8); int ib = 0xff & (pixel_rgb >> 0); YUV::yuv.rgb_to_yuv_8(ir, ig, ib); - pixel_yuv = (ir<<16) | (ig<<8) | (ib<<0); + pixel_yuv = (~a<<24) | (ir<<16) | (ig<<8) | (ib<<0); } void VFrame::set_stiple(int mask) @@ -1360,49 +1395,52 @@ int VFrame::draw_pixel(int x, int y) { if( x < 0 || y < 0 || x >= get_w() || y >= get_h() ) return 1; -#define DRAW_PIXEL(type, r, g, b) { \ +#define DRAW_PIXEL(type, r, g, b, comps, a) { \ type **rows = (type**)get_rows(); \ - rows[y][x * components + 0] = r; \ - rows[y][x * components + 1] = g; \ - rows[y][x * components + 2] = b; \ - if( components == 4 ) \ - rows[y][x * components + 3] = mx; \ -} - int components = BC_CModels::components(color_model); - int bch = BC_CModels::calculate_pixelsize(color_model) / components; - int sz = 8*bch, mx = BC_CModels::is_float(color_model) ? 1 : (1<> 16); float fr = 0; - int ig = 0xff & (pixel_color >> 8); float fg = 0; - int ib = 0xff & (pixel_color >> 0); float fb = 0; + type *rp = rows[y], *bp = rp + x*comps; \ + bp[0] = r; \ + if( comps > 1 ) { bp[1] = g; bp[2] = b; } \ + if( comps == 4 ) bp[3] = a; \ +} + float fr = 0, fg = 0, fb = 0, fa = 0; + int pixel_color = BC_CModels::is_yuv(color_model) ? pixel_yuv : pixel_rgb; + int ir = (0xff & (pixel_color >> 16)); + int ig = (0xff & (pixel_color >> 8)); + int ib = (0xff & (pixel_color >> 0)); + int ia = (0xff & (pixel_color >> 24)) ^ 0xff; // transparency, not opacity if( (x+y) & stipple ) { ir = 255 - ir; ig = 255 - ig; ib = 255 - ib; } + int rr = (ir<<8) | ir, gg = (ig<<8) | ig, bb = (ib<<8) | ib, aa = (ia<<8) | ia; if( BC_CModels::is_float(color_model) ) { - fr = ir / 255.; fg = ig / 255.; fb = ib / 255.; - mx = 1; - } - else if( (sz-=8) > 0 ) { - ir <<= sz; ig <<= sz; ib <<= sz; + fr = rr/65535.f; fg = gg/65535.f; fb = bb/65535.f; fa = aa/65535.f; } switch(get_color_model()) { + case BC_A8: + DRAW_PIXEL(uint8_t, ib, 0, 0, 1, 0); + break; case BC_RGB888: case BC_YUV888: + DRAW_PIXEL(uint8_t, ir, ig, ib, 3, 0); + break; case BC_RGBA8888: case BC_YUVA8888: - DRAW_PIXEL(uint8_t, ir, ig, ib); + DRAW_PIXEL(uint8_t, ir, ig, ib, 4, ia); break; case BC_RGB161616: case BC_YUV161616: + DRAW_PIXEL(uint16_t, rr, gg, bb, 3, 0); + break; case BC_RGBA16161616: case BC_YUVA16161616: - DRAW_PIXEL(uint16_t, ir, ig, ib); + DRAW_PIXEL(uint16_t, rr, gg, bb, 4, aa); break; case BC_RGB_FLOAT: + DRAW_PIXEL(float, fr, fg, fb, 3, 0); + break; case BC_RGBA_FLOAT: - DRAW_PIXEL(float, fr, fg, fb); + DRAW_PIXEL(float, fr, fg, fb, 4, fa); break; } return 0;