X-Git-Url: http://git.cinelerra-gg.org/git/?a=blobdiff_plain;f=cinelerra-5.1%2Fguicast%2Fvframe.C;h=2573e56b334af163db07d684965901fbf49c3248;hb=6338f0b010dfd93ae6a823970d853cfdd5279500;hp=25dd05eca6fd90334899ebe46a6024535e8bbe66;hpb=17e433a6e5021cc080101fd88ac3236dacb9f2e8;p=goodguy%2Fhistory.git diff --git a/cinelerra-5.1/guicast/vframe.C b/cinelerra-5.1/guicast/vframe.C index 25dd05ec..2573e56b 100644 --- a/cinelerra-5.1/guicast/vframe.C +++ b/cinelerra-5.1/guicast/vframe.C @@ -304,6 +304,11 @@ int VFrame::clear_objects(int do_opengl) pbuffer = 0; } +#ifdef LEAKER +if( memory_type != VFrame::SHARED ) + printf("==del %p from %p\n", data, __builtin_return_address(0)); +#endif + // Delete data switch(memory_type) { @@ -522,6 +527,9 @@ int VFrame::allocate_data(unsigned char *data, int shmid, if(!this->data) printf("VFrame::allocate_data %dx%d: memory exhausted.\n", this->w, this->h); +#ifdef LEAKER +printf("==new %p from %p sz %d\n", this->data, __builtin_return_address(0), size); +#endif //printf("VFrame::allocate_data %d %p data=%p %d %d\n", __LINE__, this, this->data, this->w, this->h); //if(size > 1000000) printf("VFrame::allocate_data %d\n", size); @@ -930,12 +938,9 @@ int VFrame::clear_frame() void VFrame::rotate90() { // Allocate new frame - int new_w = h, new_h = w, new_bytes_per_line = bytes_per_pixel * new_w; - unsigned char *new_data = new unsigned char[calculate_data_size(new_w, new_h, new_bytes_per_line, color_model)]; - unsigned char **new_rows = new unsigned char*[new_h]; - for(int i = 0; i < new_h; i++) - new_rows[i] = &new_data[new_bytes_per_line * i]; - + int new_w = h, new_h = w; + VFrame new_frame(new_w, new_h, color_model); + unsigned char **new_rows = new_frame.get_rows(); // Copy data for(int in_y = 0, out_x = new_w - 1; in_y < h; in_y++, out_x--) { @@ -950,23 +955,34 @@ void VFrame::rotate90() } // Swap frames - clear_objects(0); +// swap memory + unsigned char *new_data = new_frame.data; + new_frame.data = data; data = new_data; +// swap rows + new_rows = new_frame.rows; + new_frame.rows = rows; rows = new_rows; - bytes_per_line = new_bytes_per_line; - w = new_w; - h = new_h; +// swap shmid + int new_shmid = new_frame.shmid; + new_frame.shmid = shmid; + shmid = new_shmid; +// swap bytes_per_line + int new_bpl = new_frame.bytes_per_line; + new_frame.bytes_per_line = bytes_per_line; + bytes_per_line = new_bpl; + new_frame.clear_objects(0); + + w = new_frame.w; + h = new_frame.h; } void VFrame::rotate270() { // Allocate new frame - int new_w = h, new_h = w, new_bytes_per_line = bytes_per_pixel * new_w; - unsigned char *new_data = new unsigned char[calculate_data_size(new_w, new_h, new_bytes_per_line, color_model)]; - unsigned char **new_rows = new unsigned char*[new_h]; - for(int i = 0; i < new_h; i++) - new_rows[i] = &new_data[new_bytes_per_line * i]; - + int new_w = h, new_h = w; + VFrame new_frame(new_w, new_h, color_model); + unsigned char **new_rows = new_frame.get_rows(); // Copy data for(int in_y = 0, out_x = 0; in_y < h; in_y++, out_x++) { @@ -981,12 +997,26 @@ void VFrame::rotate270() } // Swap frames - clear_objects(0); +// swap memory + unsigned char *new_data = new_frame.data; + new_frame.data = data; data = new_data; +// swap rows + new_rows = new_frame.rows; + new_frame.rows = rows; rows = new_rows; - bytes_per_line = new_bytes_per_line; - w = new_w; - h = new_h; +// swap shmid + int new_shmid = new_frame.shmid; + new_frame.shmid = shmid; + shmid = new_shmid; +// swap bytes_per_line + int new_bpl = new_frame.bytes_per_line; + new_frame.bytes_per_line = bytes_per_line; + bytes_per_line = new_bpl; + new_frame.clear_objects(0); + + w = new_frame.w; + h = new_frame.h; } void VFrame::flip_vert() @@ -1020,6 +1050,18 @@ void VFrame::flip_horiz() int VFrame::copy_from(VFrame *frame) { + if(this->w != frame->get_w() || + this->h != frame->get_h()) + { + printf("VFrame::copy_from %d sizes differ src %dx%d != dst %dx%d\n", + __LINE__, + frame->get_w(), + frame->get_h(), + get_w(), + get_h()); + return 1; + } + int w = MIN(this->w, frame->get_w()); int h = MIN(this->h, frame->get_h()); timestamp = frame->timestamp; @@ -1630,6 +1672,7 @@ void VFrame::smooth_draw(int x1, int y1, int x2, int y2, int x3, int y3) } } + void VFrame::draw_rect(int x1, int y1, int x2, int y2) { draw_line(x1, y1, x2, y1); @@ -1638,6 +1681,52 @@ void VFrame::draw_rect(int x1, int y1, int x2, int y2) draw_line(x1, y2 - 1, x1, y1 + 1); } + +void VFrame::draw_oval(int x1, int y1, int x2, int y2) +{ + int w = x2 - x1; + int h = y2 - y1; + int center_x = (x2 + x1) / 2; + int center_y = (y2 + y1) / 2; + int x_table[h / 2]; + +//printf("VFrame::draw_oval %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2); + + for(int i = 0; i < h / 2; i++) { +// A^2 = -(B^2) + C^2 + x_table[i] = (int)(sqrt(-SQR(h / 2 - i) + SQR(h / 2)) * w / h); +//printf("VFrame::draw_oval %d i=%d x=%d\n", __LINE__, i, x_table[i]); + } + + for(int i = 0; i < h / 2 - 1; i++) { + int x3 = x_table[i]; + int x4 = x_table[i + 1]; + + if(x4 > x3 + 1) { + for(int j = x3; j < x4; j++) { + draw_pixel(center_x + j, y1 + i); + draw_pixel(center_x - j, y1 + i); + draw_pixel(center_x + j, y2 - i - 1); + draw_pixel(center_x - j, y2 - i - 1); + } + } + else { + draw_pixel(center_x + x3, y1 + i); + draw_pixel(center_x - x3, y1 + i); + draw_pixel(center_x + x3, y2 - i - 1); + draw_pixel(center_x - x3, y2 - i - 1); + } + } + + draw_pixel(center_x, y1); + draw_pixel(center_x, y2 - 1); + draw_pixel(x1, center_y); + draw_pixel(x2 - 1, center_y); + draw_pixel(x1, center_y - 1); + draw_pixel(x2 - 1, center_y - 1); +} + + void VFrame::draw_arrow(int x1, int y1, int x2, int y2, int sz) { double angle = atan((float)(y2 - y1) / (float)(x2 - x1));