diff options
author | Jeremy Simon <jsimon13@yahoo.fr> | 2002-11-22 22:25:03 +0000 |
---|---|---|
committer | Jeremy Simon <jsimon13@yahoo.fr> | 2002-11-22 22:25:03 +0000 |
commit | 486da3557de3aa74feb7c89a4d9f30423efa8240 (patch) | |
tree | 92d53b4ae6a5759e3a8f84a9167cf99bcacd5641 /ext/libpng | |
parent | 6881559d8c6ed94b0cfbac06aea5efb788d1207e (diff) |
should work with avifile too some cleanup ( video/png, ... )
Original commit message from CVS:
should work with avifile too
some cleanup ( video/png, ... )
Diffstat (limited to 'ext/libpng')
-rw-r--r-- | ext/libpng/Makefile.am | 2 | ||||
-rw-r--r-- | ext/libpng/gstpng.c | 115 | ||||
-rw-r--r-- | ext/libpng/gstpngenc.c | 95 | ||||
-rw-r--r-- | ext/libpng/gstpngenc.h | 71 |
4 files changed, 146 insertions, 137 deletions
diff --git a/ext/libpng/Makefile.am b/ext/libpng/Makefile.am index a65008d9..41e8e0f9 100644 --- a/ext/libpng/Makefile.am +++ b/ext/libpng/Makefile.am @@ -7,5 +7,5 @@ libgstpng_la_CFLAGS = $(GST_CFLAGS) libgstpng_la_LIBADD = $(GST_LIBS) $(LIBPNG_LIBS) libgstpng_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) -noinst_HEADERS = gstpng.h +noinst_HEADERS = gstpngenc.h diff --git a/ext/libpng/gstpng.c b/ext/libpng/gstpng.c index 61dfe0b2..5a5da081 100644 --- a/ext/libpng/gstpng.c +++ b/ext/libpng/gstpng.c @@ -18,94 +18,63 @@ #include <string.h> #include <gst/gst.h> -#include "gstpng.h" +#include "gstpngenc.h" -struct _elements_entry { - gchar *name; - GType (*type) (void); - GstElementDetails *details; - gboolean (*factoryinit) (GstElementFactory *factory); -}; - -static struct _elements_entry _elements[] = { - { "pngenc", gst_pngenc_get_type, &gst_pngenc_details, NULL }, - { NULL, 0 }, -}; - +extern GstElementDetails gst_pngenc_details; -GstPadTemplate* -gst_png_src_factory (void) +static GstCaps* +png_caps_factory (void) { - static GstPadTemplate *templ = NULL; - if (!templ) { - templ = GST_PAD_TEMPLATE_NEW ( - "src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_CAPS_NEW ( - "png_src", - "video/raw", - NULL - ) - ); - } - return templ; + return gst_caps_new ( "png_png", "video/png", NULL); } -GstPadTemplate* -gst_png_sink_factory (void) -{ - static GstPadTemplate *templ = NULL; - if (!templ) { - templ = GST_PAD_TEMPLATE_NEW ( - "sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_CAPS_NEW ( - "png_sink", - "video/raw", - "format", GST_PROPS_FOURCC (GST_STR_FOURCC ("RGB ")), - "bpp", GST_PROPS_INT (24), - "red_mask", GST_PROPS_INT (0xff0000), - "green_mask", GST_PROPS_INT (0xff00), - "blue_mask", GST_PROPS_INT (0xff), - "width", GST_PROPS_INT_RANGE (16, 4096), - "height", GST_PROPS_INT_RANGE (16, 4096) - ) - ); - } - return templ; -} +static GstCaps* +raw_caps_factory (void) +{ + return gst_caps_new ( "png_raw", + "video/raw", + gst_props_new ( + "format", GST_PROPS_FOURCC (GST_STR_FOURCC ("RGB ")), + "bpp", GST_PROPS_INT (24), + "red_mask", GST_PROPS_INT (0xff), + "green_mask", GST_PROPS_INT (0xff00), + "blue_mask", GST_PROPS_INT (0xff0000), + "width", GST_PROPS_INT_RANGE (16, 4096), + "height", GST_PROPS_INT_RANGE (16, 4096), + NULL ) + ); +} static gboolean plugin_init (GModule * module, GstPlugin * plugin) { - GstElementFactory *factory; - gint i = 0; + GstElementFactory *png_enc; + GstCaps *raw_caps, *png_caps; - while (_elements[i].name) { - factory = gst_element_factory_new (_elements[i].name, - (_elements[i].type) (), - _elements[i].details); + /* create an elementfactory for the jpegdec element */ + png_enc = gst_element_factory_new("pngenc", GST_TYPE_PNGENC, &gst_pngenc_details); + g_return_val_if_fail(png_enc != NULL, FALSE); - if (!factory) { - g_warning ("gst_png_new failed for `%s'", - _elements[i].name); - continue; - } - - gst_element_factory_add_pad_template (factory, gst_png_src_factory ()); - gst_element_factory_add_pad_template (factory, gst_png_sink_factory ()); + raw_caps = raw_caps_factory (); + png_caps = png_caps_factory (); - gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory)); - if (_elements[i].factoryinit) { - _elements[i].factoryinit (factory); - } - i++; - } + /* register sink pads */ + pngenc_sink_template = gst_pad_template_new ("sink", GST_PAD_SINK, + GST_PAD_ALWAYS, + raw_caps, NULL); + gst_element_factory_add_pad_template (png_enc, pngenc_sink_template); + + /* register src pads */ + pngenc_src_template = gst_pad_template_new ("src", GST_PAD_SRC, + GST_PAD_ALWAYS, + png_caps, NULL); + gst_element_factory_add_pad_template (png_enc, pngenc_src_template); + + gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (png_enc)); + return TRUE; } diff --git a/ext/libpng/gstpngenc.c b/ext/libpng/gstpngenc.c index d967f5ed..912f93fb 100644 --- a/ext/libpng/gstpngenc.c +++ b/ext/libpng/gstpngenc.c @@ -18,45 +18,12 @@ #include <string.h> #include <gst/gst.h> -#include "gstpng.h" - -#define GST_TYPE_PNGENC \ - (gst_pngenc_get_type()) -#define GST_PNGENC(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PNGENC,GstPngEnc)) -#define GST_PNGENC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_ULAW,GstPngEnc)) -#define GST_IS_PNGENC(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PNGENC)) -#define GST_IS_PNGENC_CLASS(obj) \ - (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PNGENC)) +#include "gstpngenc.h" #define MAX_HEIGHT 4096 -typedef struct _GstPngEnc GstPngEnc; -typedef struct _GstPngEncClass GstPngEncClass; gint frame=0; -struct _GstPngEnc -{ - GstElement element; - - GstPad *sinkpad, *srcpad; - GstBuffer *buffer_out; - - png_structp png_struct_ptr; - png_infop png_info_ptr; - - gint width; - gint height; - gint bpp; -}; - -struct _GstPngEncClass -{ - GstElementClass parent_class; -}; - GstElementDetails gst_pngenc_details = { "", "Filter/Video/Effect", @@ -80,7 +47,7 @@ enum ARG_0 }; -static void gst_pngenc_class_init (GstPngEncClass * klass); +static void gst_pngenc_class_init (GstPngEncClass * klass); static void gst_pngenc_init (GstPngEnc * pngenc); static void gst_pngenc_set_property (GObject * object, guint prop_id, @@ -161,51 +128,51 @@ gst_pngenc_sinkconnect (GstPad * pad, GstCaps * caps) static void gst_pngenc_init (GstPngEnc * pngenc) { - pngenc->sinkpad = gst_pad_new_from_template (gst_png_sink_factory (), "sink"); + pngenc->sinkpad = gst_pad_new_from_template (pngenc_sink_template, "sink"); gst_element_add_pad (GST_ELEMENT (pngenc), pngenc->sinkpad); - pngenc->srcpad = gst_pad_new_from_template (gst_png_src_factory (), "src"); + pngenc->srcpad = gst_pad_new("src",GST_PAD_SRC); gst_element_add_pad (GST_ELEMENT (pngenc), pngenc->srcpad); gst_pad_set_chain_function (pngenc->sinkpad, gst_pngenc_chain); gst_pad_set_connect_function (pngenc->sinkpad, gst_pngenc_sinkconnect); - pngenc->png_struct_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL, user_error_fn, user_warning_fn); + pngenc->png_struct_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, (png_voidp)NULL, user_error_fn, user_warning_fn); if ( pngenc->png_struct_ptr == NULL ) - g_warning( "Failed to initialize png structure"); + g_warning ("Failed to initialize png structure"); - pngenc->png_info_ptr = png_create_info_struct( pngenc->png_struct_ptr ); + pngenc->png_info_ptr = png_create_info_struct (pngenc->png_struct_ptr); - if (setjmp( pngenc->png_struct_ptr->jmpbuf)) - png_destroy_write_struct(&pngenc->png_struct_ptr, &pngenc->png_info_ptr); + if (setjmp(pngenc->png_struct_ptr->jmpbuf)) + png_destroy_write_struct (&pngenc->png_struct_ptr, &pngenc->png_info_ptr); } -void user_flush_data(png_structp png_ptr) + +void user_flush_data (png_structp png_ptr) { GstPngEnc *pngenc; - g_print("FLUSH\n"); - - pngenc = (GstPngEnc *) png_get_io_ptr(png_ptr); + pngenc = (GstPngEnc *) png_get_io_ptr (png_ptr); gst_pad_push (pngenc->srcpad, GST_BUFFER (gst_event_new (GST_EVENT_FLUSH))); } -void user_write_data(png_structp png_ptr, png_bytep data, png_uint_32 length) + +void user_write_data (png_structp png_ptr, png_bytep data, png_uint_32 length) { GstBuffer *buffer; GstPngEnc *pngenc; - pngenc = (GstPngEnc *) png_get_io_ptr(png_ptr); + pngenc = (GstPngEnc *) png_get_io_ptr (png_ptr); buffer = gst_buffer_new(); - GST_BUFFER_DATA (buffer) = g_memdup( data, length ); + GST_BUFFER_DATA (buffer) = g_memdup (data, length); GST_BUFFER_SIZE (buffer) = length; - if ( pngenc->buffer_out ) + if (pngenc->buffer_out) { - pngenc->buffer_out = gst_buffer_merge( pngenc->buffer_out, buffer ); + pngenc->buffer_out = gst_buffer_merge (pngenc->buffer_out, buffer); gst_buffer_unref( buffer ); } else @@ -219,7 +186,7 @@ gst_pngenc_chain (GstPad * pad, GstBuffer * buf) gint row_indice; png_byte *row_pointers[ MAX_HEIGHT ]; - if ( frame != 300 ) + if (frame != 300) { frame++; gst_buffer_unref (buf); @@ -230,8 +197,8 @@ gst_pngenc_chain (GstPad * pad, GstBuffer * buf) pngenc->buffer_out = NULL; - png_set_filter( pngenc->png_struct_ptr, 0, PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE ); - png_set_compression_level( pngenc->png_struct_ptr, 9); + png_set_filter (pngenc->png_struct_ptr, 0, PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE); + png_set_compression_level (pngenc->png_struct_ptr, 9); png_set_IHDR( pngenc->png_struct_ptr, @@ -245,20 +212,22 @@ gst_pngenc_chain (GstPad * pad, GstBuffer * buf) PNG_FILTER_TYPE_DEFAULT ); - png_set_write_fn(pngenc->png_struct_ptr, pngenc, (png_rw_ptr)user_write_data, user_flush_data); + png_set_write_fn (pngenc->png_struct_ptr, pngenc, (png_rw_ptr)user_write_data, user_flush_data); - for ( row_indice = 0; row_indice < pngenc->height; row_indice++ ) - row_pointers[row_indice] = GST_BUFFER_DATA(buf) + (pngenc->width * row_indice * pngenc->bpp/8 ); + for (row_indice = 0; row_indice < pngenc->height; row_indice++) + row_pointers[row_indice] = GST_BUFFER_DATA (buf) + (pngenc->width * row_indice * pngenc->bpp/8); - png_write_info( pngenc->png_struct_ptr, pngenc->png_info_ptr ); - png_write_image( pngenc->png_struct_ptr, row_pointers ); - png_write_end( pngenc->png_struct_ptr, NULL ); - png_destroy_info_struct ( pngenc->png_struct_ptr, &pngenc->png_info_ptr ); - png_destroy_write_struct( &pngenc->png_struct_ptr, (png_infopp)NULL ); + png_write_info (pngenc->png_struct_ptr, pngenc->png_info_ptr); + png_write_image (pngenc->png_struct_ptr, row_pointers); + png_write_end (pngenc->png_struct_ptr, NULL); gst_pad_push (pngenc->srcpad, pngenc->buffer_out ); + user_flush_data (pngenc->png_struct_ptr); + + png_destroy_info_struct (pngenc->png_struct_ptr, &pngenc->png_info_ptr); + png_destroy_write_struct (&pngenc->png_struct_ptr, (png_infopp)NULL); - g_print("Frame %d dumped\n", frame ); + g_print ("Frame %d dumped\n", frame); frame++; gst_buffer_unref (buf); diff --git a/ext/libpng/gstpngenc.h b/ext/libpng/gstpngenc.h new file mode 100644 index 00000000..fcda16fb --- /dev/null +++ b/ext/libpng/gstpngenc.h @@ -0,0 +1,71 @@ +/* GStreamer + * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + +#ifndef __GST_PNGENC_H__ +#define __GST_PNGENC_H__ + +#include <gst/gst.h> +#include <png.h> + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +#define GST_TYPE_PNGENC (gst_pngenc_get_type()) +#define GST_PNGENC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PNGENC,GstPngEnc)) +#define GST_PNGENC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PNGENC,GstPngEnc)) +#define GST_IS_PNGENC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PNGENC)) +#define GST_IS_PNGENC_CLASS(obj)(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PNGENC)) + +typedef struct _GstPngEnc GstPngEnc; +typedef struct _GstPngEncClass GstPngEncClass; + +GstPadTemplate *pngenc_src_template, *pngenc_sink_template; + +struct _GstPngEnc +{ + GstElement element; + + GstPad *sinkpad, *srcpad; + GstBuffer *buffer_out; + + png_structp png_struct_ptr; + png_infop png_info_ptr; + + gint width; + gint height; + gint bpp; +}; + +struct _GstPngEncClass +{ + GstElementClass parent_class; +}; + +GType gst_pngenc_get_type(void); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + +#endif /* __GST_PNGENC_H__ */ |