[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pecl-cvs
Subject:    [PECL-CVS] =?utf-8?q?svn:_/pecl/framegrab/trunk/_config.m4_framegrab.c_framegrab=5Fimage.c_package.x
From:       Melanie_Rhianna_Lewis <cyberspice () php ! net>
Date:       2010-02-28 15:04:54
Message-ID: svn-cyberspice-1267369494-295581-67931078 () svn ! php ! net
[Download RAW message or body]

cyberspice                               Sun, 28 Feb 2010 15:04:54 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=295581

Log:
Release 0.1.0

- Changed config from --enable-framegrab to --with-framegrab
- Changed FrameGrabImage::writePNG() to FrameGrabImage::writeAsPNG()
- Added FrameGrabImage::toStringAsPNG()

Files modified:
  config.m4, php_framegrab_image.h, framegrab.c, framegrab_image.c,
  package.xml

Changed paths:
    U   pecl/framegrab/trunk/config.m4
    U   pecl/framegrab/trunk/framegrab.c
    U   pecl/framegrab/trunk/framegrab_image.c
    U   pecl/framegrab/trunk/package.xml
    U   pecl/framegrab/trunk/php_framegrab_image.h


["svn-diffs-295581.txt" (text/x-diff)]

Modified: pecl/framegrab/trunk/config.m4
===================================================================
--- pecl/framegrab/trunk/config.m4	2010-02-28 12:28:35 UTC (rev 295580)
+++ pecl/framegrab/trunk/config.m4	2010-02-28 15:04:54 UTC (rev 295581)
@@ -3,7 +3,7 @@
 dnl

 PHP_ARG_ENABLE(framegrab, whether to enable video frame grabber support,
-[  --enable-framegrab=[DIR]           Enable video frame grabber support])
+[  --with-framegrab=[DIR]           Enable video frame grabber support])

 if test "$PHP_FRAMEGRAB" != "no"; then
   SEARCH_PATH="/usr/local /usr"

Modified: pecl/framegrab/trunk/framegrab.c
===================================================================
--- pecl/framegrab/trunk/framegrab.c	2010-02-28 12:28:35 UTC (rev 295580)
+++ pecl/framegrab/trunk/framegrab.c	2010-02-28 15:04:54 UTC (rev 295581)
@@ -104,9 +104,9 @@
 }
 /* }}} */

-/* {{{ proto FrameGrabImage::writePNG(filename)
+/* {{{ proto FrameGrabImage::writeAsPNG(filename)
  * Writes image as PNG to filename. */
-PHP_METHOD(framegrabimage, writePNG) {
+PHP_METHOD(framegrabimage, writeAsPNG) {
 	char *filename = NULL;
 	int filename_len = 0;
 	php_framegrab_image_obj *intern;
@@ -124,6 +124,28 @@
 }
 /* }}} */

+/* {{{ proto FrameGrabImage::toStringAsPNG()
+ * Outputs image data in PNG format as a string. */
+PHP_METHOD(framegrabimage, toStringAsPNG) {
+	php_framegrab_image_obj *intern;
+	char *buffer;
+	int buffer_len;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) {
+		RETURN_FALSE
+	}
+
+	intern = (php_framegrab_image_obj *)zend_object_store_get_object(getThis() \
TSRMLS_CC); +	if (!php_framegrab_image_to_string(&(intern->image), (FG_UINT8 \
**)&buffer, &buffer_len, FRAMEGRAB_IMAGE_OUTPUT_PNG)) { +		RETURN_FALSE
+	}
+
+	ZVAL_STRINGL(return_value, buffer, buffer_len, 1)
+	free(buffer);
+	return;
+}
+/* }}} */
+
 /* {{{ */
 static void framegrab_image_object_free(void *object TSRMLS_DC) {
 	php_framegrab_image_obj *intern = (php_framegrab_image_obj *)object;
@@ -235,7 +257,8 @@
 static zend_function_entry framegrab_image_funcs[] = {
 	PHP_ME(framegrabimage, __construct, NULL, ZEND_ACC_CTOR|ZEND_ACC_PROTECTED)
 	PHP_ME(framegrabimage, __toString, NULL, ZEND_ACC_PUBLIC)
-	PHP_ME(framegrabimage, writePNG, NULL, ZEND_ACC_PUBLIC)
+	PHP_ME(framegrabimage, writeAsPNG, NULL, ZEND_ACC_PUBLIC)
+	PHP_ME(framegrabimage, toStringAsPNG, NULL, ZEND_ACC_PUBLIC)

 	/* End of functions */
 	{NULL, NULL, NULL}

Modified: pecl/framegrab/trunk/framegrab_image.c
===================================================================
--- pecl/framegrab/trunk/framegrab_image.c	2010-02-28 12:28:35 UTC (rev 295580)
+++ pecl/framegrab/trunk/framegrab_image.c	2010-02-28 15:04:54 UTC (rev 295581)
@@ -217,10 +217,56 @@
 	}
 }

+#define FRAMEGRAB_PNG_WRITE_DATA_CHUNK_SIZE 0x4000
+
 /**
- * Writes the image to the specified filename.
+ *
  */
-static int framegrab_image_write_to_png(php_framegrab_image_data *image, char \
*filename) { +typedef struct _php_framegrab_png_write_buffer_data {
+	png_bytep  buf;
+	png_size_t buflen;
+	png_size_t size;
+} php_framegrab_png_write_buffer_data;
+
+/**
+ * libpng 'write' function that outputs to a buffer
+ */
+void framegrab_png_write_data(png_structp png_ptr, png_bytep ptr, png_size_t size) {
+	php_framegrab_png_write_buffer_data *data = (php_framegrab_png_write_buffer_data \
*)png_get_io_ptr(png_ptr); +
+	/* Hopefully we got the buffer information */
+	if (data) {
+		/* Do we need to realloc? If so allocate enough chunks to cover the data being
+		 * written.*/
+		if (data->buflen < (data->size + size)) {
+			data->buflen += FRAMEGRAB_PNG_WRITE_DATA_CHUNK_SIZE *
+					        ((size / FRAMEGRAB_PNG_WRITE_DATA_CHUNK_SIZE) + 1);
+			data->buf = (png_bytep)realloc(data->buf, data->buflen);
+		}
+
+		/* Copy the data */
+		if (data->buf) {
+			/* Calculate the offset in to the buffer each time because the buffer
+			 * may have moved in memory. */
+			memcpy(data->buf + data->size, ptr, size);
+			data->size += size;
+		}
+	}
+}
+
+/**
+ * libpng 'flush' function that outputs to a buffer
+ */
+void framegrab_png_flush_data(png_structp png_ptr) {
+	/* Does nothing */
+}
+
+/**
+ * Writes the image to the specified filename or to memory.  If output to
+ * filename set pbuffer and psize to NULL else set filename to NULL.
+ */
+static int framegrab_image_write_to_png(php_framegrab_image_data *image, char \
*filename, FG_UINT8 **pbuffer, int *psize) { +	php_framegrab_png_write_buffer_data \
buffer_data = { NULL, 0, 0};  FILE *file = NULL;
 	png_structp png_ptr = NULL;
 	png_infop info_ptr = NULL;
@@ -241,10 +287,21 @@
 		row_ptr += image->bytes_per_line;
 	}

-	/* Open the output file */
-	file = fopen(filename, "wb");
-	if (!file) {
-		goto png_write_error;
+	if (filename) {
+		/* Open the output file */
+		file = fopen(filename, "wb");
+		if (!file) {
+			goto png_write_error;
+		}
+	} else {
+		/* Initialise the write buffer */
+		buffer_data.buf = (png_bytep)malloc(FRAMEGRAB_PNG_WRITE_DATA_CHUNK_SIZE);
+		if (!buffer_data.buf) {
+			goto png_write_error;
+		}
+
+		buffer_data.buflen = FRAMEGRAB_PNG_WRITE_DATA_CHUNK_SIZE;
+		buffer_data.size   = 0;
 	}

 	/* Initialise the structures required to write a png */
@@ -263,7 +320,13 @@
 		goto png_write_error;
 	}

-	png_init_io(png_ptr, file);
+	if (file) {
+		/* Output to file */
+		png_init_io(png_ptr, file);
+	} else {
+		/* Output to buffer */
+		png_set_write_fn(png_ptr, &buffer_data, framegrab_png_write_data, \
framegrab_png_flush_data); +	}

 	/* Set the output format */
 	switch (image->format) {
@@ -293,9 +356,19 @@
 	png_write_end(png_ptr, info_ptr);

 	/* Clean up */
+	free(row_ptrs);
 	png_destroy_write_struct(&png_ptr, &info_ptr);
-	fclose(file);
-	free(row_ptrs);
+
+	if (file) {
+		/* Close the file */
+		fclose(file);
+	} else {
+		if (pbuffer && psize) {
+			*pbuffer = (FG_UINT8*)buffer_data.buf;
+			*psize   = (int)buffer_data.size;
+		}
+	}
+
 	return 1;

 png_write_error:
@@ -313,6 +386,10 @@
 		remove(filename);
 	}

+	if (buffer_data.buf) {
+		free(buffer_data.buf);
+	}
+
 	return 0;
 }

@@ -327,7 +404,7 @@
 				case FRAMEGRAB_IMAGE_FORMAT_RGB:
 				case FRAMEGRAB_IMAGE_FORMAT_Y8:
 				case FRAMEGRAB_IMAGE_FORMAT_Y16:
-					return framegrab_image_write_to_png(image, filename);
+					return framegrab_image_write_to_png(image, filename, NULL, NULL);

 				case FRAMEGRAB_IMAGE_FORMAT_YUYV:
 				case FRAMEGRAB_IMAGE_FORMAT_UYVY:
@@ -335,7 +412,7 @@
 					php_framegrab_image_data newimage;

 					if (framegrab_image_data_reformat(image, FRAMEGRAB_IMAGE_FORMAT_RGB, \
                &newimage)) {
-						int retval = framegrab_image_write_to_png(&newimage, filename);
+						int retval = framegrab_image_write_to_png(&newimage, filename, NULL, NULL);
 						php_framegrab_image_data_destroy(&newimage);
 						return retval;
 					}
@@ -353,6 +430,43 @@
 }

 /**
+ * Returns the image in the specified format in a buffer
+ */
+int php_framegrab_image_to_string(php_framegrab_image_data *image, FG_UINT8 \
**pbuffer, int *psize, int format) { +	switch (format) {
+		case FRAMEGRAB_IMAGE_OUTPUT_PNG:
+			/* Some images we have to convert others we can output as is. */
+			switch (image->format) {
+				case FRAMEGRAB_IMAGE_FORMAT_RGB:
+				case FRAMEGRAB_IMAGE_FORMAT_Y8:
+				case FRAMEGRAB_IMAGE_FORMAT_Y16:
+					return framegrab_image_write_to_png(image, NULL, pbuffer, psize);
+
+				case FRAMEGRAB_IMAGE_FORMAT_YUYV:
+				case FRAMEGRAB_IMAGE_FORMAT_UYVY:
+				{
+					php_framegrab_image_data newimage;
+
+					if (framegrab_image_data_reformat(image, FRAMEGRAB_IMAGE_FORMAT_RGB, \
&newimage)) { +						int retval = framegrab_image_write_to_png(&newimage, NULL, \
pbuffer, psize); +						php_framegrab_image_data_destroy(&newimage);
+						return retval;
+					}
+				}
+
+				default:
+					return 0;
+			}
+
+		/* TODO: Other formats */
+
+		default:
+			return 0;
+	}
+}
+
+
+/**
  * Returns a textual description of the image format.
  */
 char *php_framegrab_image_format_to_string(int format) {

Modified: pecl/framegrab/trunk/package.xml
===================================================================
--- pecl/framegrab/trunk/package.xml	2010-02-28 12:28:35 UTC (rev 295580)
+++ pecl/framegrab/trunk/package.xml	2010-02-28 15:04:54 UTC (rev 295581)
@@ -13,19 +13,21 @@
   <email>cyberspice@php.net</email>
   <active>yes</active>
  </lead>
- <date>2010-02-26</date>
+ <date>2010-02-28</date>
  <time>12:10:00</time>
  <version>
-  <release>0.0.1</release>
-  <api>0.0.1</api>
+  <release>0.1.0</release>
+  <api>0.1.0</api>
  </version>
  <stability>
-  <release>alpha</release>
-  <api>alpha</api>
+  <release>beta</release>
+  <api>beta</api>
  </stability>
  <license uri="http://www.php.net/license">PHP</license>
  <notes>
-Initial version
+- Changed the --enable-framegrab option to --with-framegrab since you specify the \
PNG library path on the configure line. +- Changed FrameGrabImage::writePNG() to \
FrameGrabImage::writeAsPNG(). +- Added FrameGrabImage::toStringAsPNG() which returns \
the image as PNG data as a string.  This allows the output to be fed straight in to \
GD without requiring an intermediate file.  </notes>
  <contents>
   <dir name="/">

Modified: pecl/framegrab/trunk/php_framegrab_image.h
===================================================================
--- pecl/framegrab/trunk/php_framegrab_image.h	2010-02-28 12:28:35 UTC (rev 295580)
+++ pecl/framegrab/trunk/php_framegrab_image.h	2010-02-28 15:04:54 UTC (rev 295581)
@@ -109,6 +109,11 @@
 int php_framegrab_image_write(php_framegrab_image_data *image, char *filename, int \
format);

 /**
+ * Returns the image in the specified format in a buffer
+ */
+int php_framegrab_image_to_string(php_framegrab_image_data *image, FG_UINT8 \
**pbuffer, int *psize, int format); +
+/**
  * Returns a textual description of the image format.
  */
 char *php_framegrab_image_format_to_string(int format);



-- 
PECL CVS Mailing List 
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic