upgrade vpx to 1.8.1, rm meson prereq and add dav1d Makefile, warn/gettid patch
[goodguy/cinelerra.git] / cinelerra-5.1 / guicast / vframe.C
index 6f0dfbb18e754e8afeed54fb846628a4df0e14e6..4c1aa390393a868c9f069396db3f2c7db95a05f4 100644 (file)
@@ -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)
@@ -282,6 +282,8 @@ int VFrame::reset_parameters(int do_opengl)
        pixel_rgb = 0x000000; // BLACK
        pixel_yuv = 0x008080;
        stipple = 0;
+       clear_color = 0x000000;
+       clear_alpha = 0x00;
 
        if(do_opengl)
        {
@@ -390,10 +392,11 @@ int VFrame::get_keyframe()
 
 void VFrame::get_temp(VFrame *&vfrm, int w, int h, int color_model)
 {
-        if( vfrm && ( vfrm->get_w() != w || vfrm->get_h() != h ) ) {
-                delete vfrm;  vfrm = 0;
-        }
-        if( !vfrm ) vfrm = new VFrame(w, h, color_model, 0);
+       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);
 }
 
 
@@ -828,7 +831,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;
@@ -874,6 +877,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; i<h; ++i ) fwrite(rows[i],3,w,fp);
+       fclose(fp);
+       if( frm != vfrm ) delete frm;
+}
+
 
 #define ZERO_YUV(components, type, max) \
 { \
@@ -890,10 +915,10 @@ int VFrame::write_png(const char *path)
        } \
 }
 
-int VFrame::clear_frame()
+void VFrame::black_frame()
 {
        int sz = w * h;
-//printf("VFrame::clear_frame %d\n", __LINE__);
+//printf("VFrame::black_frame %d\n", __LINE__);
        switch(color_model) {
        case BC_COMPRESSED:
                break;
@@ -961,7 +986,24 @@ int VFrame::clear_frame()
                bzero(data, calculate_data_size(w, h, bytes_per_line, color_model));
                break;
        }
-       return 0;
+}
+
+void VFrame::set_clear_color(int color, int alpha)
+{
+       clear_color = color;
+       clear_alpha = alpha;
+}
+int VFrame::get_clear_color() { return clear_color; }
+int VFrame::get_clear_alpha() { return clear_alpha; }
+
+void VFrame::clear_frame()
+{
+       if( clear_color >= 0 &&
+           !BC_CModels::init_color(clear_color, clear_alpha,
+                       get_rows(), get_color_model(), get_y(), get_u(), get_v(),
+                       0,0, get_w(),get_h(), get_bytes_per_line()) )
+               return;
+       black_frame();
 }
 
 void VFrame::rotate90()
@@ -1147,7 +1189,8 @@ int VFrame::transfer_from(VFrame *that, int bg_color, int in_x, int in_y, int in
        timestamp = that->timestamp;
        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);
@@ -1352,15 +1395,14 @@ int VFrame::get_memory_usage()
 
 // rgb component colors (eg. from colors.h)
 // a (~alpha) transparency, 0x00==solid .. 0xff==transparent
-void VFrame::set_pixel_color(int argb)
+void VFrame::set_pixel_color(int rgb, int a)
 {
-       pixel_rgb = argb;
-       int ia = 0xff & (pixel_rgb >> 24);
+       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 =  (ia<<24) | (ir<<16) | (ig<<8) | (ib<<0);
+       pixel_yuv =  (~a<<24) | (ir<<16) | (ig<<8) | (ib<<0);
 }
 
 void VFrame::set_stiple(int mask)
@@ -1397,6 +1439,7 @@ int VFrame::draw_pixel(int x, int y)
        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;