]> granicus.if.org Git - php/commitdiff
- new xbm support
authorMarcus Boerger <helly@php.net>
Sun, 2 Feb 2003 01:34:54 +0000 (01:34 +0000)
committerMarcus Boerger <helly@php.net>
Sun, 2 Feb 2003 01:34:54 +0000 (01:34 +0000)
@Added XBM support for bundled gd library. (marcus)

# It was enabled by the last commit and fixed by this one.

ext/gd/config.m4
ext/gd/libgd/gd.c
ext/gd/libgd/xbm.c [new file with mode: 0644]
ext/gd/tests/conv_test.xbm [new file with mode: 0644]
ext/gd/tests/xbm2png.phpt [new file with mode: 0644]

index cbebee088bbfbf6dfe31a867f023cbe28ed6b248..deba71ee16de19a7f6fd58d30f878ff5dd4ad4c3 100644 (file)
@@ -257,7 +257,8 @@ if test "$PHP_GD" = "yes"; then
                  libgd/gd_io_file.c libgd/gd_ss.c libgd/gd_io_ss.c libgd/gd_png.c libgd/gd_jpeg.c \
                  libgd/gdxpm.c libgd/gdfontt.c libgd/gdfonts.c libgd/gdfontmb.c libgd/gdfontl.c \
                  libgd/gdfontg.c libgd/gdtables.c libgd/gdft.c libgd/gdcache.c libgd/gdkanji.c \
-                 libgd/wbmp.c libgd/gd_wbmp.c libgd/gdhelpers.c libgd/gd_topal.c libgd/gd_gif_in.c"
+                 libgd/wbmp.c libgd/gd_wbmp.c libgd/gdhelpers.c libgd/gd_topal.c libgd/gd_gif_in.c \
+                 libgd/xbm.c"
 
 dnl check for fabsf and floorf which are available since C99
   AC_CHECK_FUNCS(fabsf floorf)
index 7eddeb72403352a78aed4782ba71c90adb6987d8..9867df0e9e257eebfc5048f800bc10869753c574 100644 (file)
@@ -2777,6 +2777,7 @@ gdImagePtr gdImageRotate (gdImagePtr src, double dAngle, int clrBack)
 }
 /* End Rotate function */
 
+#if MBO_0
 gdImagePtr
 gdImageCreateFromXbm (FILE * fd)
 {
@@ -2902,6 +2903,7 @@ fail:
   gdImageDestroy (im);
   return 0;
 }
+#endif /* MBO_0 */
 
 void
 gdImagePolygon (gdImagePtr im, gdPointPtr p, int n, int c)
diff --git a/ext/gd/libgd/xbm.c b/ext/gd/libgd/xbm.c
new file mode 100644 (file)
index 0000000..b873c51
--- /dev/null
@@ -0,0 +1,150 @@
+/*
+   +----------------------------------------------------------------------+
+   | PHP Version 4                                                        |
+   +----------------------------------------------------------------------+
+   | Copyright (c) 1997-2003 The PHP Group                                |
+   +----------------------------------------------------------------------+
+   | This source file is subject to version 2.02 of the PHP license,      |
+   | that is bundled with this package in the file LICENSE, and is        |
+   | available at through the world-wide-web at                           |
+   | http://www.php.net/license/2_02.txt.                                 |
+   | If you did not receive a copy of the PHP license and are unable to   |
+   | obtain it through the world-wide-web, please send a note to          |
+   | license@php.net so we can mail you a copy immediately.               |
+   +----------------------------------------------------------------------+
+   | Author: Marcus Boerger <helly@php.net>                               |
+   +----------------------------------------------------------------------+
+ */
+
+/* $Id$ */
+
+#include <stdio.h>
+#include <math.h>
+#include <string.h>
+#include <stdlib.h>
+#include "gd.h"
+#include "gdhelpers.h"
+
+#include "php.h"
+
+#define MAX_XBM_LINE_SIZE 255
+
+gdImagePtr
+gdImageCreateFromXbm (FILE * fd)
+{
+       char fline[MAX_XBM_LINE_SIZE];
+       char iname[MAX_XBM_LINE_SIZE];
+       char *type;
+       int value;
+       unsigned int width = 0, height = 0;
+       int fail = 0;
+       int max_bit = 0;
+
+       gdImagePtr im;
+       int bytes = 0, i;
+       int bit, x = 0, y = 0;
+       int ch;
+       char h[8];
+       unsigned int b;
+       
+       rewind(fd);
+       while (fgets(fline, MAX_XBM_LINE_SIZE, fd)) {
+               fline[MAX_XBM_LINE_SIZE-1] = '\0';
+               if (strlen(fline) == MAX_XBM_LINE_SIZE-1) {
+                       return 0;
+               }
+               if (sscanf(fline, "#define %s %d", iname, &value) == 2) {
+                       if (!(type = strrchr(iname, '_'))) {
+                               type = iname;
+                       } else {
+                               type++;
+                       }
+       
+                       if (!strcmp("width", type)) {
+                               width = (unsigned int) value;
+                       }
+                       if (!strcmp("height", type)) {
+                               height = (unsigned int) value;
+                       }
+               } else {
+                       if ( sscanf(fline, "static unsigned char %s = {", iname) == 1
+                         || sscanf(fline, "static char %s = {", iname) == 1)
+                       {
+                               max_bit = 128;
+                       } else if (sscanf(fline, "static unsigned short %s = {", iname) == 1
+                                       || sscanf(fline, "static short %s = {", iname) == 1)
+                       {
+                               max_bit = 32768;
+                       }
+                       if (max_bit) {
+                               bytes = (width * height / 8) + 1;
+                               if (!bytes) {
+                                       return 0;
+                               }
+                               if (!(type = strrchr(iname, '_'))) {
+                                       type = iname;
+                               } else {
+                                       type++;
+                               }
+                               if (!strcmp("bits[]", type)) {
+                                       break;
+                               }
+                       }
+               }
+       }
+       if (!bytes || !max_bit) {
+               return 0;
+       }
+
+       im = gdImageCreate(width, height);
+       gdImageColorAllocate(im, 255, 255, 255);
+       gdImageColorAllocate(im, 0, 0, 0);
+       h[2] = '\0';
+       h[4] = '\0';
+       for (i = 0; i < bytes; i++) {
+               while (1) {
+                       ch = getc(fd);
+                       if (ch == EOF)
+                       {
+                               fail = 1;
+                               break;
+                       }
+                       if (ch == 'x')
+                       {
+                               break;
+                       }
+               }
+               if (fail) {
+                       break;
+               }
+               /* Get hex value */
+               if ((ch=getc(fd)) == EOF) break;
+               h[0] = ch;
+               if ((ch=getc(fd)) == EOF) break;
+               h[1] = ch;
+               if (max_bit == 32768) {
+                       if ((ch=getc(fd)) == EOF) break;
+                       h[2] = ch;
+                       if ((ch=getc(fd)) == EOF) break;
+                       h[3] = ch;
+               }
+               sscanf(h, "%x", &b);
+               for (bit = 1; bit <= max_bit; bit = bit << 1) {
+                       gdImageSetPixel (im, x++, y, (b & bit) ? 1 : 0);
+                       if (x == im->sx)
+                       {
+                               x = 0;
+                               y++;
+                               if (y == im->sy)
+                               {
+                                       return im;
+                               }
+                               break;
+                       }
+               }
+       }
+
+       php_gd_error("EOF before image was complete\n");
+       gdImageDestroy(im);
+       return 0;
+}
diff --git a/ext/gd/tests/conv_test.xbm b/ext/gd/tests/conv_test.xbm
new file mode 100644 (file)
index 0000000..85cbe36
--- /dev/null
@@ -0,0 +1,4 @@
+#define conv_test.xbm_width 16\r
+#define conv_test.xbm_height 5\r
+static unsigned char conv_test.xbm_bits[] = {\r
+ 0x4c, 0x0d, 0x54, 0x15, 0xcc, 0x0d, 0x44, 0x05, 0x44, 0x05};
\ No newline at end of file
diff --git a/ext/gd/tests/xbm2png.phpt b/ext/gd/tests/xbm2png.phpt
new file mode 100644 (file)
index 0000000..5c51226
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+xbm --> png conversion test
+--SKIPIF--
+<?php 
+       if (!extension_loaded('gd')) {
+               die("skip gd extension not avaliable.");
+       }
+       if (!function_exists("imagepng")) {
+               die("skip png support unavailable");
+       }
+       if (!function_exists("imagecreatefromxbm")) {
+               die("skip xbm read support unavailable");
+       }
+?>
+--FILE--
+<?php
+       $cwd = dirname(__FILE__);
+
+       echo "XBM to PNG conversion: ";
+       echo imagepng(imagecreatefromxbm($cwd . "/conv_test.xbm"), $cwd . "/test_xbm.png") ? 'ok' : 'failed';
+       echo "\n";
+       
+       @unlink($cwd . "/test_xbm.png");
+?>
+--EXPECT--
+XBM to PNG conversion: ok