summaryrefslogtreecommitdiffstats
path: root/libhb/fifo.c
diff options
context:
space:
mode:
authorjstebbins <[email protected]>2014-07-29 18:40:38 +0000
committerjstebbins <[email protected]>2014-07-29 18:40:38 +0000
commit6942656aeac26e63e87d8c1772ccec3e64b437e1 (patch)
treee82d337589c6bcfafe17963337f99ad6d41ec890 /libhb/fifo.c
parent56680a9b967772ca6eb9112ac6f2a9e9bbe7244b (diff)
libhb: add new function for retrieving previews
This new function has a couple advantages over the old one (which we should phase out). It does not require hb_job_t as a parameter, instead it uses hb_ui_geometry_t which is a smaller and simpler struct. The entire job struct is overkill as input to this function. It returns an hb_image_t that fully describes the returned image instead of just a uint8_t array. The caller does not have to make assumptions about image size, line stide, or pixel format since hb_image_t specifies these things. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6242 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb/fifo.c')
-rw-r--r--libhb/fifo.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/libhb/fifo.c b/libhb/fifo.c
index 043790e17..0e05ea031 100644
--- a/libhb/fifo.c
+++ b/libhb/fifo.c
@@ -681,6 +681,58 @@ void hb_buffer_move_subs( hb_buffer_t * dst, hb_buffer_t * src )
}
+hb_image_t * hb_buffer_to_image(hb_buffer_t *buf)
+{
+ hb_image_t *image = calloc(1, sizeof(hb_image_t));
+
+#if defined( SYS_DARWIN ) || defined( SYS_FREEBSD ) || defined( SYS_MINGW )
+ image->data = malloc( buf->size );
+#elif defined( SYS_CYGWIN )
+ /* FIXME */
+ image->data = malloc( buf->size + 17 );
+#else
+ image->data = memalign( 16, buf->size );
+#endif
+ if (image->data == NULL)
+ {
+ free(image);
+ return NULL;
+ }
+
+ image->format = buf->f.fmt;
+ image->width = buf->f.width;
+ image->height = buf->f.height;
+ memcpy(image->data, buf->data, buf->size);
+
+ int p;
+ uint8_t *data = image->data;
+ for (p = 0; p < 4; p++)
+ {
+ image->plane[p].data = data;
+ image->plane[p].width = buf->plane[p].width;
+ image->plane[p].height = buf->plane[p].height;
+ image->plane[p].stride = buf->plane[p].stride;
+ image->plane[p].height_stride = buf->plane[p].height_stride;
+ image->plane[p].size = buf->plane[p].size;
+ data += image->plane[p].size;
+ }
+ return image;
+}
+
+void hb_image_close(hb_image_t **_image)
+{
+ if (_image == NULL)
+ return;
+
+ hb_image_t * image = *_image;
+ if (image != NULL)
+ {
+ free(image->data);
+ free(image);
+ *_image = NULL;
+ }
+}
+
hb_fifo_t * hb_fifo_init( int capacity, int thresh )
{
hb_fifo_t * f;