[PHP-CVS] svn: /php/php-src/trunk/ext/gd/libgd/ gd_webp.c

2010-10-05 Thread Ilia Alshanetsky
iliaaTue, 05 Oct 2010 12:27:00 +

Revision: http://svn.php.net/viewvc?view=revisionrevision=304085

Log:
Removed debug code

Changed paths:
U   php/php-src/trunk/ext/gd/libgd/gd_webp.c

Modified: php/php-src/trunk/ext/gd/libgd/gd_webp.c
===
--- php/php-src/trunk/ext/gd/libgd/gd_webp.c2010-10-05 11:43:59 UTC (rev 
304084)
+++ php/php-src/trunk/ext/gd/libgd/gd_webp.c2010-10-05 12:27:00 UTC (rev 
304085)
@@ -71,7 +71,6 @@

do {
n = gdGetBuf(dummy, 1024, infile);
-   printf(%i\n, n);
size += n;
} while (n != EOF);


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

[PHP-CVS] svn: /php/php-src/trunk/ext/gd/libgd/ gd_webp.c

2010-10-04 Thread Pierre Joye
pajoye   Mon, 04 Oct 2010 22:34:02 +

Revision: http://svn.php.net/viewvc?view=revisionrevision=304041

Log:
- missing file for webp

Changed paths:
A   php/php-src/trunk/ext/gd/libgd/gd_webp.c

Added: php/php-src/trunk/ext/gd/libgd/gd_webp.c
===
--- php/php-src/trunk/ext/gd/libgd/gd_webp.c(rev 0)
+++ php/php-src/trunk/ext/gd/libgd/gd_webp.c2010-10-04 22:34:02 UTC (rev 
304041)
@@ -0,0 +1,202 @@
+#include stdio.h
+#include math.h
+#include string.h
+#include stdlib.h
+#include gd.h
+
+
+#ifdef HAVE_LIBVPX
+#include webpimg.h
+#include gdhelpers.h
+
+extern void gd_YUV420toRGBA(uint8* Y,
+  uint8* U,
+  uint8* V,
+  gdImagePtr im);
+
+extern void gd_RGBAToYUV420(gdImagePtr im2,
+  uint8* Y,
+  uint8* U,
+  uint8* V);
+
+const char * gdWebpGetVersionString()
+{
+   return not defined;
+}
+
+gdImagePtr gdImageCreateFromWebp (FILE * inFile)
+{
+   gdImagePtr im;
+   gdIOCtx *in = gdNewFileCtx(inFile);
+   im = gdImageCreateFromWebpCtx(in);
+   in-gd_free(in);
+
+   return im;
+}
+
+gdImagePtr gdImageCreateFromWebpPtr (int size, void *data)
+{
+   intwidth, height, ret;
+   unsigned char   *Y = NULL;
+   unsigned char   *U = NULL;
+   unsigned char   *V = NULL;
+   gdImagePtr im;
+
+   ret = WebPDecode(data, size, Y, U, V, width, height);
+   if (ret != webp_success) {
+   if (Y) free(Y);
+   if (U) free(U);
+   if (V) free(V);
+   php_gd_error(WebP decode: fail to decode input data);
+   return NULL;
+   }
+   im = gdImageCreateTrueColor(width, height);
+   if (!im) {
+   return NULL;
+   }
+   gd_YUV420toRGBA(Y, U, V, im);
+   return im;
+}
+
+gdImagePtr gdImageCreateFromWebpCtx (gdIOCtx * infile)
+{
+   intwidth, height, ret;
+   unsigned char   *filedata;
+   unsigned char   dummy[1024];
+   unsigned char   *Y = NULL;
+   unsigned char   *U = NULL;
+   unsigned char   *V = NULL;
+   size_t size = 0, n;
+   gdImagePtr im;
+
+   do {
+   n = gdGetBuf(dummy, 1024, infile);
+   printf(%i\n, n);
+   size += n;
+   } while (n != EOF);
+
+   filedata = gdMalloc(size);
+   if  (!filedata) {
+   php_gd_error(WebP decode: alloc failed);
+   return NULL;
+   }
+   gdGetBuf(filedata, size, infile);
+   ret = WebPDecode(filedata, size, Y, U, V, width, height);
+   gdFree(filedata);
+   if (ret != webp_success) {
+   if (Y) free(Y);
+   if (U) free(U);
+   if (V) free(V);
+   php_gd_error(WebP decode: fail to decode input data);
+   return NULL;
+   }
+   im = gdImageCreateTrueColor(width, height);
+   gd_YUV420toRGBA(Y, U, V, im);
+   return im;
+}
+
+void gdImageWebpEx (gdImagePtr im, FILE * outFile, int quantization)
+{
+   gdIOCtx *out = gdNewFileCtx(outFile);
+   gdImageWebpCtx(im, out, quantization);
+   out-gd_free(out);
+}
+
+void gdImageWebp (gdImagePtr im, FILE * outFile)
+{
+   gdIOCtx *out = gdNewFileCtx(outFile);
+   gdImageWebpCtx(im, out, -1);
+   out-gd_free(out);
+}
+
+void * gdImageWebpPtr (gdImagePtr im, int *size)
+{
+   void *rv;
+   gdIOCtx *out = gdNewDynamicCtx(2048, NULL);
+   gdImageWebpCtx(im, out, -1);
+   rv = gdDPExtractData(out, size);
+   out-gd_free(out);
+
+   return rv;
+}
+
+void * gdImageWebpPtrEx (gdImagePtr im, int *size, int quantization)
+{
+   void *rv;
+   gdIOCtx *out = gdNewDynamicCtx(2048, NULL);
+   gdImageWebpCtx(im, out, quantization);
+   rv = gdDPExtractData(out, size);
+   out-gd_free(out);
+   return rv;
+}
+
+/*
+ * Maps normalized QP (quality) to VP8 QP
+ */
+int mapQualityToVP8QP(int quality) {
+#define MIN_QUALITY 0
+#define MAX_QUALITY 100
+#define MIN_VP8QP 1
+#define MAX_VP8QP 63
+   const float scale = MAX_VP8QP - MIN_VP8QP;
+   const float vp8qp =
+   scale * (MAX_QUALITY - quality) / (MAX_QUALITY - MIN_QUALITY) + 
MIN_VP8QP;
+   if (quality  MIN_QUALITY || quality  MAX_QUALITY) {
+   php_gd_error(Wrong quality value %d., quality);
+   return -1;
+   }
+
+   return (int)(vp8qp + 0.5);
+}
+
+/* This routine is based in part on code from Dale Lutz (Safe Software Inc.)
+ *  and in part on demo code from Chapter 15 of PNG: The Definitive Guide
+ *  (http://www.cdrom.com/pub/png/pngbook.html).
+ */
+void gdImageWebpCtx (gdImagePtr im, gdIOCtx * outfile, int quantization)
+{
+   int width = im-sx;
+   int height = im-sy;
+   int colors = im-colorsTotal;
+   int *open = im-open;
+
+   int  yuv_width, yuv_height, yuv_nbytes, ret;
+   int