ArdourCanvas::Image allow to set custom data instead of class pre-allocated memory.
This commit is contained in:
parent
9727a23111
commit
8f2a2877b5
|
@ -35,6 +35,13 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace ARDOUR;
|
using namespace ARDOUR;
|
||||||
|
|
||||||
|
static void freedata_cb (uint8_t *d, void *arg) {
|
||||||
|
/* later this can be used with libharvid
|
||||||
|
* the buffer/videocacheline instead of freeing it
|
||||||
|
*/
|
||||||
|
free (d);
|
||||||
|
}
|
||||||
|
|
||||||
VideoImageFrame::VideoImageFrame (PublicEditor& ed, ArdourCanvas::Group& parent, int w, int h, std::string vsurl, std::string vfn)
|
VideoImageFrame::VideoImageFrame (PublicEditor& ed, ArdourCanvas::Group& parent, int w, int h, std::string vsurl, std::string vfn)
|
||||||
: editor (ed)
|
: editor (ed)
|
||||||
, _parent(&parent)
|
, _parent(&parent)
|
||||||
|
@ -117,7 +124,7 @@ VideoImageFrame::draw_line ()
|
||||||
const int rowstride = img->stride;
|
const int rowstride = img->stride;
|
||||||
const int clip_height = img->height;
|
const int clip_height = img->height;
|
||||||
uint8_t *pixels, *p;
|
uint8_t *pixels, *p;
|
||||||
pixels = img->data.get();
|
pixels = img->data;
|
||||||
|
|
||||||
int y;
|
int y;
|
||||||
for (y = 0;y < clip_height; y++) {
|
for (y = 0;y < clip_height; y++) {
|
||||||
|
@ -133,7 +140,7 @@ VideoImageFrame::fill_frame (const uint8_t r, const uint8_t g, const uint8_t b)
|
||||||
const int clip_height = img->height;
|
const int clip_height = img->height;
|
||||||
const int clip_width = img->width;
|
const int clip_width = img->width;
|
||||||
uint8_t *pixels, *p;
|
uint8_t *pixels, *p;
|
||||||
pixels = img->data.get();
|
pixels = img->data;
|
||||||
|
|
||||||
int x,y;
|
int x,y;
|
||||||
for (y = 0; y < clip_height; ++y) {
|
for (y = 0; y < clip_height; ++y) {
|
||||||
|
@ -152,7 +159,7 @@ VideoImageFrame::draw_x ()
|
||||||
const int clip_width = img->width;
|
const int clip_width = img->width;
|
||||||
const int clip_height = img->height;
|
const int clip_height = img->height;
|
||||||
uint8_t *pixels, *p;
|
uint8_t *pixels, *p;
|
||||||
pixels = img->data.get();
|
pixels = img->data;
|
||||||
|
|
||||||
for (x = 0;x < clip_width; x++) {
|
for (x = 0;x < clip_width; x++) {
|
||||||
y = clip_height * x / clip_width;
|
y = clip_height * x / clip_width;
|
||||||
|
@ -173,7 +180,7 @@ VideoImageFrame::cut_rightend ()
|
||||||
const int clip_height = img->height;
|
const int clip_height = img->height;
|
||||||
const int clip_width = img->width;
|
const int clip_width = img->width;
|
||||||
uint8_t *pixels, *p;
|
uint8_t *pixels, *p;
|
||||||
pixels = img->data.get();
|
pixels = img->data;
|
||||||
if (rightend > clip_width) { return; }
|
if (rightend > clip_width) { return; }
|
||||||
|
|
||||||
int x,y;
|
int x,y;
|
||||||
|
@ -233,10 +240,9 @@ VideoImageFrame::http_download_done (char *data){
|
||||||
cut_rightend();
|
cut_rightend();
|
||||||
image->put_image(img);
|
image->put_image(img);
|
||||||
} else {
|
} else {
|
||||||
img = image->get_image();
|
img = image->get_image(false);
|
||||||
/* TODO - have curl write directly to the shared memory region */
|
img->data = (uint8_t*) data;
|
||||||
memcpy((void*) img->data.get(), data, img->stride * img->height);
|
img->destroy_callback = &freedata_cb;
|
||||||
free(data);
|
|
||||||
draw_line();
|
draw_line();
|
||||||
cut_rightend();
|
cut_rightend();
|
||||||
image->put_image(img);
|
image->put_image(img);
|
||||||
|
|
|
@ -25,27 +25,42 @@
|
||||||
|
|
||||||
#include "canvas/item.h"
|
#include "canvas/item.h"
|
||||||
|
|
||||||
|
typedef void (*ImageReleaseCallback)(uint8_t *d, void *arg);
|
||||||
|
|
||||||
namespace ArdourCanvas {
|
namespace ArdourCanvas {
|
||||||
|
|
||||||
|
|
||||||
class Image : public Item
|
class Image : public Item
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Image (Group *, Cairo::Format, int width, int height);
|
Image (Group *, Cairo::Format, int width, int height);
|
||||||
|
|
||||||
struct Data {
|
struct Data {
|
||||||
Data (boost::shared_array<uint8_t> d, int w, int h, int s, Cairo::Format fmt)
|
Data (uint8_t *d, int w, int h, int s, Cairo::Format fmt)
|
||||||
: data (d)
|
: data (d)
|
||||||
, width (w)
|
, width (w)
|
||||||
, height (h)
|
, height (h)
|
||||||
, stride (s)
|
, stride (s)
|
||||||
, format (fmt)
|
, format (fmt)
|
||||||
|
, destroy_callback(NULL)
|
||||||
|
, destroy_arg(NULL)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
boost::shared_array<uint8_t> data;
|
virtual ~Data () {
|
||||||
|
if (destroy_callback) {
|
||||||
|
destroy_callback(data, destroy_arg);
|
||||||
|
} else {
|
||||||
|
free(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t* data;
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
int stride;
|
int stride;
|
||||||
Cairo::Format format;
|
Cairo::Format format;
|
||||||
|
ImageReleaseCallback destroy_callback;
|
||||||
|
void* destroy_arg;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,7 +74,8 @@ public:
|
||||||
* ... to avoid collisions with Image deletion, some synchronization method
|
* ... to avoid collisions with Image deletion, some synchronization method
|
||||||
* may be required or the use of shared_ptr<Image> or similar.
|
* may be required or the use of shared_ptr<Image> or similar.
|
||||||
*/
|
*/
|
||||||
boost::shared_ptr<Data> get_image ();
|
boost::shared_ptr<Data> get_image (bool allocate_data = true);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queues a Data object to be used to redraw this Image item
|
* Queues a Data object to be used to redraw this Image item
|
||||||
|
|
|
@ -36,7 +36,7 @@ void
|
||||||
Image::render (Rect const& area, Cairo::RefPtr<Cairo::Context> context) const
|
Image::render (Rect const& area, Cairo::RefPtr<Cairo::Context> context) const
|
||||||
{
|
{
|
||||||
if (_need_render && _pending) {
|
if (_need_render && _pending) {
|
||||||
_surface = Cairo::ImageSurface::create (_pending->data.get(),
|
_surface = Cairo::ImageSurface::create (_pending->data,
|
||||||
_pending->format,
|
_pending->format,
|
||||||
_pending->width,
|
_pending->width,
|
||||||
_pending->height,
|
_pending->height,
|
||||||
|
@ -59,14 +59,18 @@ Image::compute_bounding_box () const
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::shared_ptr<Image::Data>
|
boost::shared_ptr<Image::Data>
|
||||||
Image::get_image ()
|
Image::get_image (bool allocate_data)
|
||||||
{
|
{
|
||||||
/* can be called by any thread */
|
/* can be called by any thread */
|
||||||
|
|
||||||
int stride = Cairo::ImageSurface::format_stride_for_width (_format, _width);
|
int stride = Cairo::ImageSurface::format_stride_for_width (_format, _width);
|
||||||
boost::shared_ptr<Data> d (new Data (boost::shared_array<uint8_t> (new uint8_t[stride*_height]), _width, _height, stride, _format));
|
if (allocate_data) {
|
||||||
|
boost::shared_ptr<Data> d (new Data (new uint8_t[stride*_height], _width, _height, stride, _format));
|
||||||
return d;
|
return d;
|
||||||
|
} else {
|
||||||
|
boost::shared_ptr<Data> d (new Data (NULL, _width, _height, stride, _format));
|
||||||
|
return d;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in New Issue
Block a user