Back to index

php5  5.3.10
Classes | Defines | Functions | Variables
image.c File Reference
#include "php.h"
#include <stdio.h>
#include "fopen_wrappers.h"
#include "ext/standard/fsock.h"
#include "php_image.h"

Go to the source code of this file.

Classes

struct  gfxinfo

Defines

#define M_SOF0   0xC0 /* Start Of Frame N */
#define M_SOF1   0xC1 /* N indicates which compression process */
#define M_SOF2   0xC2 /* Only SOF0-SOF2 are now in common use */
#define M_SOF3   0xC3
#define M_SOF5   0xC5 /* NB: codes C4 and CC are NOT SOF markers */
#define M_SOF6   0xC6
#define M_SOF7   0xC7
#define M_SOF9   0xC9
#define M_SOF10   0xCA
#define M_SOF11   0xCB
#define M_SOF13   0xCD
#define M_SOF14   0xCE
#define M_SOF15   0xCF
#define M_SOI   0xD8
#define M_EOI   0xD9 /* End Of Image (end of datastream) */
#define M_SOS   0xDA /* Start Of Scan (begins compressed data) */
#define M_APP0   0xe0
#define M_APP1   0xe1
#define M_APP2   0xe2
#define M_APP3   0xe3
#define M_APP4   0xe4
#define M_APP5   0xe5
#define M_APP6   0xe6
#define M_APP7   0xe7
#define M_APP8   0xe8
#define M_APP9   0xe9
#define M_APP10   0xea
#define M_APP11   0xeb
#define M_APP12   0xec
#define M_APP13   0xed
#define M_APP14   0xee
#define M_APP15   0xef
#define M_COM   0xFE /* COMment */
#define M_PSEUDO   0xFFD8 /* pseudo marker for start of image(byte 0) */
#define JPEG2000_MARKER_PREFIX   0xFF /* All marker codes start with this */
#define JPEG2000_MARKER_SOC   0x4F /* Start of Codestream */
#define JPEG2000_MARKER_SOT   0x90 /* Start of Tile part */
#define JPEG2000_MARKER_SOD   0x93 /* Start of Data */
#define JPEG2000_MARKER_EOC   0xD9 /* End of Codestream */
#define JPEG2000_MARKER_SIZ   0x51 /* Image and tile size */
#define JPEG2000_MARKER_COD   0x52 /* Coding style default */
#define JPEG2000_MARKER_COC   0x53 /* Coding style component */
#define JPEG2000_MARKER_RGN   0x5E /* Region of interest */
#define JPEG2000_MARKER_QCD   0x5C /* Quantization default */
#define JPEG2000_MARKER_QCC   0x5D /* Quantization component */
#define JPEG2000_MARKER_POC   0x5F /* Progression order change */
#define JPEG2000_MARKER_TLM   0x55 /* Tile-part lengths */
#define JPEG2000_MARKER_PLM   0x57 /* Packet length, main header */
#define JPEG2000_MARKER_PLT   0x58 /* Packet length, tile-part header */
#define JPEG2000_MARKER_PPM   0x60 /* Packed packet headers, main header */
#define JPEG2000_MARKER_PPT   0x61 /* Packed packet headers, tile part header */
#define JPEG2000_MARKER_SOP   0x91 /* Start of packet */
#define JPEG2000_MARKER_EPH   0x92 /* End of packet header */
#define JPEG2000_MARKER_CRG   0x63 /* Component registration */
#define JPEG2000_MARKER_COM   0x64 /* Comment */
#define TAG_IMAGEWIDTH   0x0100
#define TAG_IMAGEHEIGHT   0x0101
#define TAG_COMP_IMAGEWIDTH   0xA002
#define TAG_COMP_IMAGEHEIGHT   0xA003
#define TAG_FMT_BYTE   1
#define TAG_FMT_STRING   2
#define TAG_FMT_USHORT   3
#define TAG_FMT_ULONG   4
#define TAG_FMT_URATIONAL   5
#define TAG_FMT_SBYTE   6
#define TAG_FMT_UNDEFINED   7
#define TAG_FMT_SSHORT   8
#define TAG_FMT_SLONG   9
#define TAG_FMT_SRATIONAL   10
#define TAG_FMT_SINGLE   11
#define TAG_FMT_DOUBLE   12

Functions

 PHP_MINIT_FUNCTION (imagetypes)
static struct gfxinfophp_handle_gif (php_stream *stream TSRMLS_DC)
static struct gfxinfophp_handle_psd (php_stream *stream TSRMLS_DC)
static struct gfxinfophp_handle_bmp (php_stream *stream TSRMLS_DC)
static unsigned long int php_swf_get_bits (unsigned char *buffer, unsigned int pos, unsigned int count)
static struct gfxinfophp_handle_swf (php_stream *stream TSRMLS_DC)
static struct gfxinfophp_handle_png (php_stream *stream TSRMLS_DC)
static unsigned short php_read2 (php_stream *stream TSRMLS_DC)
static unsigned int php_next_marker (php_stream *stream, int last_marker, int comment_correction, int ff_read TSRMLS_DC)
static int php_skip_variable (php_stream *stream TSRMLS_DC)
static int php_read_APP (php_stream *stream, unsigned int marker, zval *info TSRMLS_DC)
static struct gfxinfophp_handle_jpeg (php_stream *stream, zval *info TSRMLS_DC)
static unsigned int php_read4 (php_stream *stream TSRMLS_DC)
static struct gfxinfophp_handle_jpc (php_stream *stream TSRMLS_DC)
static struct gfxinfophp_handle_jp2 (php_stream *stream TSRMLS_DC)
static int php_ifd_get16u (void *Short, int motorola_intel)
static signed short php_ifd_get16s (void *Short, int motorola_intel)
static int php_ifd_get32s (void *Long, int motorola_intel)
static unsigned php_ifd_get32u (void *Long, int motorola_intel)
static struct gfxinfophp_handle_tiff (php_stream *stream, zval *info, int motorola_intel TSRMLS_DC)
static struct gfxinfophp_handle_iff (php_stream *stream TSRMLS_DC)
static int php_get_wbmp (php_stream *stream, struct gfxinfo **result, int check TSRMLS_DC)
static struct gfxinfophp_handle_wbmp (php_stream *stream TSRMLS_DC)
static int php_get_xbm (php_stream *stream, struct gfxinfo **result TSRMLS_DC)
static struct gfxinfophp_handle_xbm (php_stream *stream TSRMLS_DC)
static struct gfxinfophp_handle_ico (php_stream *stream TSRMLS_DC)
PHPAPI char * php_image_type_to_mime_type (int image_type)
 PHP_FUNCTION (image_type_to_mime_type)
 PHP_FUNCTION (image_type_to_extension)
PHPAPI int php_getimagetype (php_stream *stream, char *filetype TSRMLS_DC)
 PHP_FUNCTION (getimagesize)

Variables

PHPAPI const char php_sig_gif [3] = {'G', 'I', 'F'}
PHPAPI const char php_sig_psd [4] = {'8', 'B', 'P', 'S'}
PHPAPI const char php_sig_bmp [2] = {'B', 'M'}
PHPAPI const char php_sig_swf [3] = {'F', 'W', 'S'}
PHPAPI const char php_sig_swc [3] = {'C', 'W', 'S'}
PHPAPI const char php_sig_jpg [3] = {(char) 0xff, (char) 0xd8, (char) 0xff}
PHPAPI const char php_sig_png [8]
PHPAPI const char php_sig_tif_ii [4] = {'I','I', (char)0x2A, (char)0x00}
PHPAPI const char php_sig_tif_mm [4] = {'M','M', (char)0x00, (char)0x2A}
PHPAPI const char php_sig_jpc [3] = {(char)0xff, (char)0x4f, (char)0xff}
PHPAPI const char php_sig_jp2 [12]
PHPAPI const char php_sig_iff [4] = {'F','O','R','M'}
PHPAPI const char php_sig_ico [4] = {(char)0x00, (char)0x00, (char)0x01, (char)0x00}
PHPAPI const int php_tiff_bytes_per_format [] = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8}

Class Documentation

struct gfxinfo

Definition at line 61 of file image.c.

Class Members
unsigned int bits
unsigned int channels
unsigned int height
unsigned int width

Define Documentation

#define JPEG2000_MARKER_COC   0x53 /* Coding style component */

Definition at line 581 of file image.c.

#define JPEG2000_MARKER_COD   0x52 /* Coding style default */

Definition at line 580 of file image.c.

#define JPEG2000_MARKER_COM   0x64 /* Comment */

Definition at line 594 of file image.c.

#define JPEG2000_MARKER_CRG   0x63 /* Component registration */

Definition at line 593 of file image.c.

#define JPEG2000_MARKER_EOC   0xD9 /* End of Codestream */

Definition at line 578 of file image.c.

#define JPEG2000_MARKER_EPH   0x92 /* End of packet header */

Definition at line 592 of file image.c.

#define JPEG2000_MARKER_PLM   0x57 /* Packet length, main header */

Definition at line 587 of file image.c.

#define JPEG2000_MARKER_PLT   0x58 /* Packet length, tile-part header */

Definition at line 588 of file image.c.

#define JPEG2000_MARKER_POC   0x5F /* Progression order change */

Definition at line 585 of file image.c.

#define JPEG2000_MARKER_PPM   0x60 /* Packed packet headers, main header */

Definition at line 589 of file image.c.

#define JPEG2000_MARKER_PPT   0x61 /* Packed packet headers, tile part header */

Definition at line 590 of file image.c.

#define JPEG2000_MARKER_PREFIX   0xFF /* All marker codes start with this */

Definition at line 574 of file image.c.

#define JPEG2000_MARKER_QCC   0x5D /* Quantization component */

Definition at line 584 of file image.c.

#define JPEG2000_MARKER_QCD   0x5C /* Quantization default */

Definition at line 583 of file image.c.

#define JPEG2000_MARKER_RGN   0x5E /* Region of interest */

Definition at line 582 of file image.c.

#define JPEG2000_MARKER_SIZ   0x51 /* Image and tile size */

Definition at line 579 of file image.c.

#define JPEG2000_MARKER_SOC   0x4F /* Start of Codestream */

Definition at line 575 of file image.c.

#define JPEG2000_MARKER_SOD   0x93 /* Start of Data */

Definition at line 577 of file image.c.

#define JPEG2000_MARKER_SOP   0x91 /* Start of packet */

Definition at line 591 of file image.c.

#define JPEG2000_MARKER_SOT   0x90 /* Start of Tile part */

Definition at line 576 of file image.c.

#define JPEG2000_MARKER_TLM   0x55 /* Tile-part lengths */

Definition at line 586 of file image.c.

#define M_APP0   0xe0

Definition at line 338 of file image.c.

#define M_APP1   0xe1

Definition at line 339 of file image.c.

#define M_APP10   0xea

Definition at line 348 of file image.c.

#define M_APP11   0xeb

Definition at line 349 of file image.c.

#define M_APP12   0xec

Definition at line 350 of file image.c.

#define M_APP13   0xed

Definition at line 351 of file image.c.

#define M_APP14   0xee

Definition at line 352 of file image.c.

#define M_APP15   0xef

Definition at line 353 of file image.c.

#define M_APP2   0xe2

Definition at line 340 of file image.c.

#define M_APP3   0xe3

Definition at line 341 of file image.c.

#define M_APP4   0xe4

Definition at line 342 of file image.c.

#define M_APP5   0xe5

Definition at line 343 of file image.c.

#define M_APP6   0xe6

Definition at line 344 of file image.c.

#define M_APP7   0xe7

Definition at line 345 of file image.c.

#define M_APP8   0xe8

Definition at line 346 of file image.c.

#define M_APP9   0xe9

Definition at line 347 of file image.c.

#define M_COM   0xFE /* COMment */

Definition at line 354 of file image.c.

#define M_EOI   0xD9 /* End Of Image (end of datastream) */

Definition at line 336 of file image.c.

#define M_PSEUDO   0xFFD8 /* pseudo marker for start of image(byte 0) */

Definition at line 356 of file image.c.

#define M_SOF0   0xC0 /* Start Of Frame N */

Definition at line 322 of file image.c.

#define M_SOF1   0xC1 /* N indicates which compression process */

Definition at line 323 of file image.c.

#define M_SOF10   0xCA

Definition at line 330 of file image.c.

#define M_SOF11   0xCB

Definition at line 331 of file image.c.

#define M_SOF13   0xCD

Definition at line 332 of file image.c.

#define M_SOF14   0xCE

Definition at line 333 of file image.c.

#define M_SOF15   0xCF

Definition at line 334 of file image.c.

#define M_SOF2   0xC2 /* Only SOF0-SOF2 are now in common use */

Definition at line 324 of file image.c.

#define M_SOF3   0xC3

Definition at line 325 of file image.c.

#define M_SOF5   0xC5 /* NB: codes C4 and CC are NOT SOF markers */

Definition at line 326 of file image.c.

#define M_SOF6   0xC6

Definition at line 327 of file image.c.

#define M_SOF7   0xC7

Definition at line 328 of file image.c.

#define M_SOF9   0xC9

Definition at line 329 of file image.c.

#define M_SOI   0xD8

Definition at line 335 of file image.c.

#define M_SOS   0xDA /* Start Of Scan (begins compressed data) */

Definition at line 337 of file image.c.

#define TAG_COMP_IMAGEHEIGHT   0xA003

Definition at line 738 of file image.c.

#define TAG_COMP_IMAGEWIDTH   0xA002

Definition at line 737 of file image.c.

#define TAG_FMT_BYTE   1

Definition at line 740 of file image.c.

#define TAG_FMT_DOUBLE   12

Definition at line 751 of file image.c.

#define TAG_FMT_SBYTE   6

Definition at line 745 of file image.c.

#define TAG_FMT_SINGLE   11

Definition at line 750 of file image.c.

#define TAG_FMT_SLONG   9

Definition at line 748 of file image.c.

#define TAG_FMT_SRATIONAL   10

Definition at line 749 of file image.c.

#define TAG_FMT_SSHORT   8

Definition at line 747 of file image.c.

#define TAG_FMT_STRING   2

Definition at line 741 of file image.c.

#define TAG_FMT_ULONG   4

Definition at line 743 of file image.c.

#define TAG_FMT_UNDEFINED   7

Definition at line 746 of file image.c.

#define TAG_FMT_URATIONAL   5

Definition at line 744 of file image.c.

#define TAG_FMT_USHORT   3

Definition at line 742 of file image.c.

#define TAG_IMAGEHEIGHT   0x0101

Definition at line 735 of file image.c.

#define TAG_IMAGEWIDTH   0x0100

Definition at line 734 of file image.c.


Function Documentation

PHP_FUNCTION ( image_type_to_mime_type  )

Definition at line 1156 of file image.c.

{
       long p_image_type;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &p_image_type) == FAILURE) {
              return;
       }

       ZVAL_STRING(return_value, (char*)php_image_type_to_mime_type(p_image_type), 1);
}

Here is the call graph for this function:

PHP_FUNCTION ( image_type_to_extension  )

Definition at line 1170 of file image.c.

{
       long image_type;
       zend_bool inc_dot=1;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|b", &image_type, &inc_dot) == FAILURE) {
              RETURN_FALSE;
       }

       switch (image_type) {
              case IMAGE_FILETYPE_GIF:
                     RETURN_STRING(".gif" + !inc_dot, 1);
              case IMAGE_FILETYPE_JPEG:
                     RETURN_STRING(".jpeg" + !inc_dot, 1);
              case IMAGE_FILETYPE_PNG:
                     RETURN_STRING(".png" + !inc_dot, 1);
              case IMAGE_FILETYPE_SWF:
              case IMAGE_FILETYPE_SWC:
                     RETURN_STRING(".swf" + !inc_dot, 1);
              case IMAGE_FILETYPE_PSD:
                     RETURN_STRING(".psd" + !inc_dot, 1);
              case IMAGE_FILETYPE_BMP:
              case IMAGE_FILETYPE_WBMP:
                     RETURN_STRING(".bmp" + !inc_dot, 1);
              case IMAGE_FILETYPE_TIFF_II:
              case IMAGE_FILETYPE_TIFF_MM:
                     RETURN_STRING(".tiff" + !inc_dot, 1);
              case IMAGE_FILETYPE_IFF:
                     RETURN_STRING(".iff" + !inc_dot, 1);
              case IMAGE_FILETYPE_JPC:
                     RETURN_STRING(".jpc" + !inc_dot, 1);
              case IMAGE_FILETYPE_JP2:
                     RETURN_STRING(".jp2" + !inc_dot, 1);
              case IMAGE_FILETYPE_JPX:
                     RETURN_STRING(".jpx" + !inc_dot, 1);
              case IMAGE_FILETYPE_JB2:
                     RETURN_STRING(".jb2" + !inc_dot, 1);
              case IMAGE_FILETYPE_XBM:
                     RETURN_STRING(".xbm" + !inc_dot, 1);
              case IMAGE_FILETYPE_ICO:
                     RETURN_STRING(".ico" + !inc_dot, 1);
       }

       RETURN_FALSE;
}

Here is the call graph for this function:

PHP_FUNCTION ( getimagesize  )

Definition at line 1294 of file image.c.

{
       zval **info = NULL;
       char *arg1, *temp;
       int arg1_len, itype = 0, argc = ZEND_NUM_ARGS();
       struct gfxinfo *result = NULL;
       php_stream * stream = NULL;

       if (zend_parse_parameters(argc TSRMLS_CC, "s|Z", &arg1, &arg1_len, &info) == FAILURE) {
              return;
       }
       
       if (argc == 2) {
              zval_dtor(*info);
              array_init(*info);
       }

       stream = php_stream_open_wrapper(arg1, "rb", STREAM_MUST_SEEK|REPORT_ERRORS|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL);

       if (!stream) {
              RETURN_FALSE;
       }

       itype = php_getimagetype(stream, NULL TSRMLS_CC);
       switch( itype) {
              case IMAGE_FILETYPE_GIF:
                     result = php_handle_gif(stream TSRMLS_CC);
                     break;
              case IMAGE_FILETYPE_JPEG:
                     if (info) {
                            result = php_handle_jpeg(stream, *info TSRMLS_CC);
                     } else {
                            result = php_handle_jpeg(stream, NULL TSRMLS_CC);
                     }
                     break;
              case IMAGE_FILETYPE_PNG:
                     result = php_handle_png(stream TSRMLS_CC);
                     break;
              case IMAGE_FILETYPE_SWF:
                     result = php_handle_swf(stream TSRMLS_CC);
                     break;
              case IMAGE_FILETYPE_SWC:
#if HAVE_ZLIB && !defined(COMPILE_DL_ZLIB)
                     result = php_handle_swc(stream TSRMLS_CC);
#else
                     php_error_docref(NULL TSRMLS_CC, E_NOTICE, "The image is a compressed SWF file, but you do not have a static version of the zlib extension enabled");
#endif
                     break;
              case IMAGE_FILETYPE_PSD:
                     result = php_handle_psd(stream TSRMLS_CC);
                     break;
              case IMAGE_FILETYPE_BMP:
                     result = php_handle_bmp(stream TSRMLS_CC);
                     break;
              case IMAGE_FILETYPE_TIFF_II:
                     result = php_handle_tiff(stream, NULL, 0 TSRMLS_CC);
                     break;
              case IMAGE_FILETYPE_TIFF_MM:
                     result = php_handle_tiff(stream, NULL, 1 TSRMLS_CC);
                     break;
              case IMAGE_FILETYPE_JPC:
                     result = php_handle_jpc(stream TSRMLS_CC);
                     break;
              case IMAGE_FILETYPE_JP2:
                     result = php_handle_jp2(stream TSRMLS_CC);
                     break;
              case IMAGE_FILETYPE_IFF:
                     result = php_handle_iff(stream TSRMLS_CC);
                     break;
              case IMAGE_FILETYPE_WBMP:
                     result = php_handle_wbmp(stream TSRMLS_CC);
                     break;
              case IMAGE_FILETYPE_XBM:
                     result = php_handle_xbm(stream TSRMLS_CC);
                     break;
              case IMAGE_FILETYPE_ICO:
                     result = php_handle_ico(stream TSRMLS_CC);
                     break;
              default:
              case IMAGE_FILETYPE_UNKNOWN:
                     break;
       }

       php_stream_close(stream);

       if (result) {
              array_init(return_value);
              add_index_long(return_value, 0, result->width);
              add_index_long(return_value, 1, result->height);
              add_index_long(return_value, 2, itype);
              spprintf(&temp, 0, "width=\"%d\" height=\"%d\"", result->width, result->height);
              add_index_string(return_value, 3, temp, 0);

              if (result->bits != 0) {
                     add_assoc_long(return_value, "bits", result->bits);
              }
              if (result->channels != 0) {
                     add_assoc_long(return_value, "channels", result->channels);
              }
              add_assoc_string(return_value, "mime", (char*)php_image_type_to_mime_type(itype), 1);
              efree(result);
       } else {
              RETURN_FALSE;
       }
}

Here is the call graph for this function:

static int php_get_wbmp ( php_stream *  stream,
struct gfxinfo **  result,
int check  TSRMLS_DC 
) [static]

Definition at line 940 of file image.c.

{
       int i, width = 0, height = 0;

       if (php_stream_rewind(stream)) {
              return 0;
       }

       /* get type */
       if (php_stream_getc(stream) != 0) {
              return 0;
       }

       /* skip header */
       do {
              i = php_stream_getc(stream);
              if (i < 0) {
                     return 0;
              }
       } while (i & 0x80);

       /* get width */
       do {
              i = php_stream_getc(stream);
              if (i < 0) {
                     return 0;
              }
              width = (width << 7) | (i & 0x7f);
       } while (i & 0x80);
       
       /* get height */
       do {
              i = php_stream_getc(stream);
              if (i < 0) {
                     return 0;
              }
              height = (height << 7) | (i & 0x7f);
       } while (i & 0x80);

       /* maximum valid sizes for wbmp (although 127x127 may be a more accurate one) */
       if (!height || !width || height > 2048 || width > 2048) {
              return 0;
       }
       
       if (!check) {
              (*result)->width = width;
              (*result)->height = height;
       }

       return IMAGE_FILETYPE_WBMP;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int php_get_xbm ( php_stream *  stream,
struct gfxinfo **result  TSRMLS_DC 
) [static]

Definition at line 1010 of file image.c.

{
    char *fline;
    char *iname;
    char *type;
    int value;
    unsigned int width = 0, height = 0;

       if (result) {
              *result = NULL;
       }
       if (php_stream_rewind(stream)) {
              return 0;
       }
       while ((fline=php_stream_gets(stream, NULL, 0)) != NULL) {
              iname = estrdup(fline); /* simple way to get necessary buffer of required size */
              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 (height) {
                                   efree(iname);
                                   break;
                            }
                     }
                     if (!strcmp("height", type)) {
                            height = (unsigned int) value;
                            if (width) {
                                   efree(iname);
                                   break;
                            }
                     }
              }
              efree(fline);
              efree(iname);
       }
       if (fline) {
              efree(fline);
       }

       if (width && height) {
              if (result) {
                     *result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
                     (*result)->width = width;
                     (*result)->height = height;
              }
              return IMAGE_FILETYPE_XBM;
       }

       return 0;
}

Here is the caller graph for this function:

PHPAPI int php_getimagetype ( php_stream *  stream,
char *filetype  TSRMLS_DC 
)

Definition at line 1219 of file image.c.

{
       char tmp[12];

       if ( !filetype) filetype = tmp;
       if((php_stream_read(stream, filetype, 3)) != 3) {
              php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Read error!");
              return IMAGE_FILETYPE_UNKNOWN;
       }

/* BYTES READ: 3 */
       if (!memcmp(filetype, php_sig_gif, 3)) {
              return IMAGE_FILETYPE_GIF;
       } else if (!memcmp(filetype, php_sig_jpg, 3)) {
              return IMAGE_FILETYPE_JPEG;
       } else if (!memcmp(filetype, php_sig_png, 3)) {
              if (php_stream_read(stream, filetype+3, 5) != 5) {
                     php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Read error!");
                     return IMAGE_FILETYPE_UNKNOWN;
              }
              if (!memcmp(filetype, php_sig_png, 8)) {
                     return IMAGE_FILETYPE_PNG;
              } else {
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "PNG file corrupted by ASCII conversion");
                     return IMAGE_FILETYPE_UNKNOWN;
              }
       } else if (!memcmp(filetype, php_sig_swf, 3)) {
              return IMAGE_FILETYPE_SWF;
       } else if (!memcmp(filetype, php_sig_swc, 3)) {
              return IMAGE_FILETYPE_SWC;
       } else if (!memcmp(filetype, php_sig_psd, 3)) {
              return IMAGE_FILETYPE_PSD;
       } else if (!memcmp(filetype, php_sig_bmp, 2)) {
              return IMAGE_FILETYPE_BMP;
       } else if (!memcmp(filetype, php_sig_jpc, 3)) {
              return IMAGE_FILETYPE_JPC;
       }

       if (php_stream_read(stream, filetype+3, 1) != 1) {
              php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Read error!");
              return IMAGE_FILETYPE_UNKNOWN;
       }
/* BYTES READ: 4 */
       if (!memcmp(filetype, php_sig_tif_ii, 4)) {
              return IMAGE_FILETYPE_TIFF_II;
       } else if (!memcmp(filetype, php_sig_tif_mm, 4)) {
              return IMAGE_FILETYPE_TIFF_MM;
       } else if (!memcmp(filetype, php_sig_iff, 4)) {
              return IMAGE_FILETYPE_IFF;
       } else if (!memcmp(filetype, php_sig_ico, 4)) {
              return IMAGE_FILETYPE_ICO;
       }

       if (php_stream_read(stream, filetype+4, 8) != 8) {
              php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Read error!");
              return IMAGE_FILETYPE_UNKNOWN;
       }
/* BYTES READ: 12 */
       if (!memcmp(filetype, php_sig_jp2, 12)) {
              return IMAGE_FILETYPE_JP2;
       }

/* AFTER ALL ABOVE FAILED */
       if (php_get_wbmp(stream, NULL, 1 TSRMLS_CC)) {
              return IMAGE_FILETYPE_WBMP;
       }
       if (php_get_xbm(stream, NULL TSRMLS_CC)) {
              return IMAGE_FILETYPE_XBM;
       }
       return IMAGE_FILETYPE_UNKNOWN;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static struct gfxinfo* php_handle_bmp ( php_stream *stream  TSRMLS_DC) [static, read]

Definition at line 144 of file image.c.

{
       struct gfxinfo *result = NULL;
       unsigned char dim[16];
       int size;

       if (php_stream_seek(stream, 11, SEEK_CUR))
              return NULL;

       if (php_stream_read(stream, dim, sizeof(dim)) != sizeof(dim))
              return NULL;

       size   = (((unsigned int)dim[ 3]) << 24) + (((unsigned int)dim[ 2]) << 16) + (((unsigned int)dim[ 1]) << 8) + ((unsigned int) dim[ 0]);
       if (size == 12) {
              result = (struct gfxinfo *) ecalloc (1, sizeof(struct gfxinfo));
              result->width    =  (((unsigned int)dim[ 5]) << 8) + ((unsigned int) dim[ 4]);
              result->height   =  (((unsigned int)dim[ 7]) << 8) + ((unsigned int) dim[ 6]);
              result->bits     =  ((unsigned int)dim[11]);
       } else if (size > 12 && (size <= 64 || size == 108)) {
              result = (struct gfxinfo *) ecalloc (1, sizeof(struct gfxinfo));
              result->width    =  (((unsigned int)dim[ 7]) << 24) + (((unsigned int)dim[ 6]) << 16) + (((unsigned int)dim[ 5]) << 8) + ((unsigned int) dim[ 4]);
              result->height   =  (((unsigned int)dim[11]) << 24) + (((unsigned int)dim[10]) << 16) + (((unsigned int)dim[ 9]) << 8) + ((unsigned int) dim[ 8]);
              result->bits     =  (((unsigned int)dim[15]) <<  8) +  ((unsigned int)dim[14]);
       } else {
              return NULL;
       }

       return result;
}

Here is the caller graph for this function:

static struct gfxinfo* php_handle_gif ( php_stream *stream  TSRMLS_DC) [static, read]

Definition at line 100 of file image.c.

{
       struct gfxinfo *result = NULL;
       unsigned char dim[5];

       if (php_stream_seek(stream, 3, SEEK_CUR))
              return NULL;

       if (php_stream_read(stream, dim, sizeof(dim)) != sizeof(dim))
              return NULL;

       result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
       result->width    = (unsigned int)dim[0] | (((unsigned int)dim[1])<<8);
       result->height   = (unsigned int)dim[2] | (((unsigned int)dim[3])<<8);
       result->bits     = dim[4]&0x80 ? ((((unsigned int)dim[4])&0x07) + 1) : 0;
       result->channels = 3; /* allways */

       return result;
}

Here is the caller graph for this function:

static struct gfxinfo* php_handle_ico ( php_stream *stream  TSRMLS_DC) [static, read]

Definition at line 1080 of file image.c.

{
       struct gfxinfo *result = NULL;
       unsigned char dim[16];
       int num_icons = 0;

       if (php_stream_read(stream, dim, 2) != 2)
              return NULL;

       num_icons = (((unsigned int)dim[1]) << 8) + ((unsigned int) dim[0]);

       if (num_icons < 1 || num_icons > 255)
              return NULL;

       result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));

       while (num_icons > 0)
       {
              if (php_stream_read(stream, dim, sizeof(dim)) != sizeof(dim))
                     break;

              if ((((unsigned int)dim[7]) <<  8) +  ((unsigned int)dim[6]) >= result->bits)
              {
                     result->width    =  (unsigned int)dim[0];
                     result->height   =  (unsigned int)dim[1];
                     result->bits     =  (((unsigned int)dim[7]) <<  8) +  ((unsigned int)dim[6]);
              }
              num_icons--;
       }

       return result;
}

Here is the caller graph for this function:

static struct gfxinfo* php_handle_iff ( php_stream *stream  TSRMLS_DC) [static, read]

Definition at line 879 of file image.c.

{
       struct gfxinfo * result;
       unsigned char a[10];
       int chunkId;
       int size;
       short width, height, bits;

       if (php_stream_read(stream, a, 8) != 8) {
              return NULL;
       }
       if (strncmp(a+4, "ILBM", 4) && strncmp(a+4, "PBM ", 4)) {
              return NULL;
       }

       /* loop chunks to find BMHD chunk */
       do {
              if (php_stream_read(stream, a, 8) != 8) {
                     return NULL;
              }
              chunkId = php_ifd_get32s(a+0, 1);
              size    = php_ifd_get32s(a+4, 1);
              if (size < 0) {
                     return NULL;
              }
              if ((size & 1) == 1) {
                     size++;
              }
              if (chunkId == 0x424d4844) { /* BMHD chunk */
                     if (size < 9 || php_stream_read(stream, a, 9) != 9) {
                            return NULL;
                     }
                     width  = php_ifd_get16s(a+0, 1);
                     height = php_ifd_get16s(a+2, 1);
                     bits   = a[8] & 0xff;
                     if (width > 0 && height > 0 && bits > 0 && bits < 33) {
                            result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
                            result->width    = width;
                            result->height   = height;
                            result->bits     = bits;
                            result->channels = 0;
                            return result;
                     }
              } else {
                     if (php_stream_seek(stream, size, SEEK_CUR)) {
                            return NULL;
                     }
              }
       } while (1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static struct gfxinfo* php_handle_jp2 ( php_stream *stream  TSRMLS_DC) [static, read]

Definition at line 671 of file image.c.

{
       struct gfxinfo *result = NULL;
       unsigned int box_length;
       unsigned int box_type;
       char jp2c_box_id[] = {(char)0x6a, (char)0x70, (char)0x32, (char)0x63};

       /* JP2 is a wrapper format for JPEG 2000. Data is contained within "boxes".
          Boxes themselves can be contained within "super-boxes". Super-Boxes can
          contain super-boxes which provides us with a hierarchical storage system.

          It is valid for a JP2 file to contain multiple individual codestreams.
          We'll just look for the first codestream at the root of the box structure
          and handle that.
       */

       for (;;)
       {
              box_length = php_read4(stream TSRMLS_CC); /* LBox */
              /* TBox */
              if (php_stream_read(stream, (void *)&box_type, sizeof(box_type)) != sizeof(box_type)) {
                     /* Use this as a general "out of stream" error */
                     break;
              }

              if (box_length == 1) {
                     /* We won't handle XLBoxes */
                     return NULL;
              }

              if (!memcmp(&box_type, jp2c_box_id, 4))
              {
                     /* Skip the first 3 bytes to emulate the file type examination */
                     php_stream_seek(stream, 3, SEEK_CUR);

                     result = php_handle_jpc(stream TSRMLS_CC);
                     break;
              }

              /* Stop if this was the last box */
              if ((int)box_length <= 0) {
                     break;
              }

              /* Skip over LBox (Which includes both TBox and LBox itself */
              if (php_stream_seek(stream, box_length - 8, SEEK_CUR)) {
                     break;
              }
       }

       if (result == NULL) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "JP2 file has no codestreams at root level");
       }

       return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static struct gfxinfo* php_handle_jpc ( php_stream *stream  TSRMLS_DC) [static, read]

Definition at line 599 of file image.c.

{
       struct gfxinfo *result = NULL;
       unsigned short dummy_short;
       int highest_bit_depth, bit_depth;
       unsigned char first_marker_id;
       unsigned int i;

       /* JPEG 2000 components can be vastly different from one another.
          Each component can be sampled at a different resolution, use
          a different colour space, have a seperate colour depth, and
          be compressed totally differently! This makes giving a single
          "bit depth" answer somewhat problematic. For this implementation
          we'll use the highest depth encountered. */

       /* Get the single byte that remains after the file type indentification */
       first_marker_id = php_stream_getc(stream);

       /* Ensure that this marker is SIZ (as is mandated by the standard) */
       if (first_marker_id != JPEG2000_MARKER_SIZ) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "JPEG2000 codestream corrupt(Expected SIZ marker not found after SOC)");
              return NULL;
       }

       result = (struct gfxinfo *)ecalloc(1, sizeof(struct gfxinfo));

       dummy_short = php_read2(stream TSRMLS_CC); /* Lsiz */
       dummy_short = php_read2(stream TSRMLS_CC); /* Rsiz */
       result->width = php_read4(stream TSRMLS_CC); /* Xsiz */
       result->height = php_read4(stream TSRMLS_CC); /* Ysiz */

#if MBO_0
       php_read4(stream TSRMLS_CC); /* XOsiz */
       php_read4(stream TSRMLS_CC); /* YOsiz */
       php_read4(stream TSRMLS_CC); /* XTsiz */
       php_read4(stream TSRMLS_CC); /* YTsiz */
       php_read4(stream TSRMLS_CC); /* XTOsiz */
       php_read4(stream TSRMLS_CC); /* YTOsiz */
#else
       if (php_stream_seek(stream, 24, SEEK_CUR)) {
              efree(result);
              return NULL;
       }
#endif

       result->channels = php_read2(stream TSRMLS_CC); /* Csiz */
       if (result->channels < 0 || result->channels > 256) {
              efree(result);
              return NULL;
       }

       /* Collect bit depth info */
       highest_bit_depth = 0;
       for (i = 0; i < result->channels; i++) {
              bit_depth = php_stream_getc(stream); /* Ssiz[i] */
              bit_depth++;
              if (bit_depth > highest_bit_depth) {
                     highest_bit_depth = bit_depth;
              }

              php_stream_getc(stream); /* XRsiz[i] */
              php_stream_getc(stream); /* YRsiz[i] */
       }

       result->bits = highest_bit_depth;

       return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static struct gfxinfo* php_handle_jpeg ( php_stream *  stream,
zval *info  TSRMLS_DC 
) [static, read]

Definition at line 470 of file image.c.

{
       struct gfxinfo *result = NULL;
       unsigned int marker = M_PSEUDO;
       unsigned short length, ff_read=1;

       for (;;) {
              marker = php_next_marker(stream, marker, 1, ff_read TSRMLS_CC);
              ff_read = 0;
              switch (marker) {
                     case M_SOF0:
                     case M_SOF1:
                     case M_SOF2:
                     case M_SOF3:
                     case M_SOF5:
                     case M_SOF6:
                     case M_SOF7:
                     case M_SOF9:
                     case M_SOF10:
                     case M_SOF11:
                     case M_SOF13:
                     case M_SOF14:
                     case M_SOF15:
                            if (result == NULL) {
                                   /* handle SOFn block */
                                   result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
                                   length = php_read2(stream TSRMLS_CC);
                                   result->bits     = php_stream_getc(stream);
                                   result->height   = php_read2(stream TSRMLS_CC);
                                   result->width    = php_read2(stream TSRMLS_CC);
                                   result->channels = php_stream_getc(stream);
                                   if (!info || length < 8) { /* if we don't want an extanded info -> return */
                                          return result;
                                   }
                                   if (php_stream_seek(stream, length - 8, SEEK_CUR)) { /* file error after info */
                                          return result;
                                   }
                            } else {
                                   if (!php_skip_variable(stream TSRMLS_CC)) {
                                          return result;
                                   }
                            }
                            break;

                     case M_APP0:
                     case M_APP1:
                     case M_APP2:
                     case M_APP3:
                     case M_APP4:
                     case M_APP5:
                     case M_APP6:
                     case M_APP7:
                     case M_APP8:
                     case M_APP9:
                     case M_APP10:
                     case M_APP11:
                     case M_APP12:
                     case M_APP13:
                     case M_APP14:
                     case M_APP15:
                            if (info) {
                                   if (!php_read_APP(stream, marker, info TSRMLS_CC)) { /* read all the app markes... */
                                          return result;
                                   }
                            } else {
                                   if (!php_skip_variable(stream TSRMLS_CC)) {
                                          return result;
                                   }
                            }
                            break;

                     case M_SOS:
                     case M_EOI:
                            return result;       /* we're about to hit image data, or are at EOF. stop processing. */
                     
                     default:
                            if (!php_skip_variable(stream TSRMLS_CC)) { /* anything else isn't interesting */
                                   return result;
                            }
                            break;
              }
       }

       return result; /* perhaps image broken -> no info but size */
}

Here is the call graph for this function:

Here is the caller graph for this function:

static struct gfxinfo* php_handle_png ( php_stream *stream  TSRMLS_DC) [static, read]

Definition at line 292 of file image.c.

{
       struct gfxinfo *result = NULL;
       unsigned char dim[9];
/* Width:              4 bytes
 * Height:             4 bytes
 * Bit depth:          1 byte
 * Color type:         1 byte
 * Compression method: 1 byte
 * Filter method:      1 byte
 * Interlace method:   1 byte
 */

       if (php_stream_seek(stream, 8, SEEK_CUR))
              return NULL;

       if((php_stream_read(stream, dim, sizeof(dim))) < sizeof(dim))
              return NULL;

       result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
       result->width  = (((unsigned int)dim[0]) << 24) + (((unsigned int)dim[1]) << 16) + (((unsigned int)dim[2]) << 8) + ((unsigned int)dim[3]);
       result->height = (((unsigned int)dim[4]) << 24) + (((unsigned int)dim[5]) << 16) + (((unsigned int)dim[6]) << 8) + ((unsigned int)dim[7]);
       result->bits   = (unsigned int)dim[8];
       return result;
}

Here is the caller graph for this function:

static struct gfxinfo* php_handle_psd ( php_stream *stream  TSRMLS_DC) [static, read]

Definition at line 123 of file image.c.

{
       struct gfxinfo *result = NULL;
       unsigned char dim[8];

       if (php_stream_seek(stream, 11, SEEK_CUR))
              return NULL;

       if (php_stream_read(stream, dim, sizeof(dim)) != sizeof(dim))
              return NULL;

       result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
       result->height   =  (((unsigned int)dim[0]) << 24) + (((unsigned int)dim[1]) << 16) + (((unsigned int)dim[2]) << 8) + ((unsigned int)dim[3]);
       result->width    =  (((unsigned int)dim[4]) << 24) + (((unsigned int)dim[5]) << 16) + (((unsigned int)dim[6]) << 8) + ((unsigned int)dim[7]);

       return result;
}

Here is the caller graph for this function:

static struct gfxinfo* php_handle_swf ( php_stream *stream  TSRMLS_DC) [static, read]

Definition at line 266 of file image.c.

{
       struct gfxinfo *result = NULL;
       long bits;
       unsigned char a[32];

       if (php_stream_seek(stream, 5, SEEK_CUR))
              return NULL;

       if (php_stream_read(stream, a, sizeof(a)) != sizeof(a))
              return NULL;

       result = (struct gfxinfo *) ecalloc (1, sizeof (struct gfxinfo));
       bits = php_swf_get_bits (a, 0, 5);
       result->width = (php_swf_get_bits (a, 5 + bits, bits) -
              php_swf_get_bits (a, 5, bits)) / 20;
       result->height = (php_swf_get_bits (a, 5 + (3 * bits), bits) -
              php_swf_get_bits (a, 5 + (2 * bits), bits)) / 20;
       result->bits     = 0;
       result->channels = 0;
       return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static struct gfxinfo* php_handle_tiff ( php_stream *  stream,
zval *  info,
int motorola_intel  TSRMLS_DC 
) [static, read]

Definition at line 798 of file image.c.

{
       struct gfxinfo *result = NULL;
       int i, num_entries;
       unsigned char *dir_entry;
       size_t ifd_size, dir_size, entry_value, width=0, height=0, ifd_addr;
       int entry_tag , entry_type;
       char *ifd_data, ifd_ptr[4];

       if (php_stream_read(stream, ifd_ptr, 4) != 4)
              return NULL;
       ifd_addr = php_ifd_get32u(ifd_ptr, motorola_intel);
       if (php_stream_seek(stream, ifd_addr-8, SEEK_CUR))
              return NULL;
       ifd_size = 2;
       ifd_data = emalloc(ifd_size);
       if (php_stream_read(stream, ifd_data, 2) != 2) {
              efree(ifd_data);
              return NULL;
       }
       num_entries = php_ifd_get16u(ifd_data, motorola_intel);
       dir_size = 2/*num dir entries*/ +12/*length of entry*/*num_entries +4/* offset to next ifd (points to thumbnail or NULL)*/;
       ifd_size = dir_size;
       ifd_data = erealloc(ifd_data,ifd_size);
       if (php_stream_read(stream, ifd_data+2, dir_size-2) != dir_size-2) {
              efree(ifd_data);
              return NULL;
       }
       /* now we have the directory we can look how long it should be */
       ifd_size = dir_size;
       for(i=0;i<num_entries;i++) {
              dir_entry      = ifd_data+2+i*12;
              entry_tag    = php_ifd_get16u(dir_entry+0, motorola_intel);
              entry_type   = php_ifd_get16u(dir_entry+2, motorola_intel);
              switch(entry_type) {
                     case TAG_FMT_BYTE:
                     case TAG_FMT_SBYTE:
                            entry_value  = (size_t)(dir_entry[8]);
                            break;
                     case TAG_FMT_USHORT:
                            entry_value  = php_ifd_get16u(dir_entry+8, motorola_intel);
                            break;
                     case TAG_FMT_SSHORT:
                            entry_value  = php_ifd_get16s(dir_entry+8, motorola_intel);
                            break;
                     case TAG_FMT_ULONG:
                            entry_value  = php_ifd_get32u(dir_entry+8, motorola_intel);
                            break;
                     case TAG_FMT_SLONG:
                            entry_value  = php_ifd_get32s(dir_entry+8, motorola_intel);
                            break;
                     default:
                            continue;
              }
              switch(entry_tag) {
                     case TAG_IMAGEWIDTH:
                     case TAG_COMP_IMAGEWIDTH:
                            width  = entry_value;
                            break;
                     case TAG_IMAGEHEIGHT:
                     case TAG_COMP_IMAGEHEIGHT:
                            height = entry_value;
                            break;
              }
       }
       efree(ifd_data);
       if ( width && height) {
              /* not the same when in for-loop */
              result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
              result->height   = height;
              result->width    = width;
              result->bits     = 0;
              result->channels = 0;
              return result;
       }
       return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static struct gfxinfo* php_handle_wbmp ( php_stream *stream  TSRMLS_DC) [static, read]

Definition at line 995 of file image.c.

{
       struct gfxinfo *result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));

       if (!php_get_wbmp(stream, &result, 0 TSRMLS_CC)) {
              efree(result);
              return NULL;
       }

       return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static struct gfxinfo* php_handle_xbm ( php_stream *stream  TSRMLS_DC) [static, read]

Definition at line 1070 of file image.c.

{
       struct gfxinfo *result;
       php_get_xbm(stream, &result TSRMLS_CC);
       return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static signed short php_ifd_get16s ( void *  Short,
int  motorola_intel 
) [static]

Definition at line 768 of file image.c.

{
       return (signed short)php_ifd_get16u(Short, motorola_intel);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int php_ifd_get16u ( void *  Short,
int  motorola_intel 
) [static]

Definition at line 756 of file image.c.

{
       if (motorola_intel) {
              return (((unsigned char *)Short)[0] << 8) | ((unsigned char *)Short)[1];
       } else {
              return (((unsigned char *)Short)[1] << 8) | ((unsigned char *)Short)[0];
       }
}

Here is the caller graph for this function:

static int php_ifd_get32s ( void *  Long,
int  motorola_intel 
) [static]

Definition at line 776 of file image.c.

{
       if (motorola_intel) {
              return  ((( char *)Long)[0] << 24) | (((unsigned char *)Long)[1] << 16)
                    | (((unsigned char *)Long)[2] << 8 ) | (((unsigned char *)Long)[3] << 0 );
       } else {
              return  ((( char *)Long)[3] << 24) | (((unsigned char *)Long)[2] << 16)
                    | (((unsigned char *)Long)[1] << 8 ) | (((unsigned char *)Long)[0] << 0 );
       }
}

Here is the caller graph for this function:

static unsigned php_ifd_get32u ( void *  Long,
int  motorola_intel 
) [static]

Definition at line 790 of file image.c.

{
       return (unsigned)php_ifd_get32s(Long, motorola_intel) & 0xffffffff;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHPAPI char* php_image_type_to_mime_type ( int  image_type)

Definition at line 1116 of file image.c.

{
       switch( image_type) {
              case IMAGE_FILETYPE_GIF:
                     return "image/gif";
              case IMAGE_FILETYPE_JPEG:
                     return "image/jpeg";
              case IMAGE_FILETYPE_PNG:
                     return "image/png";
              case IMAGE_FILETYPE_SWF:
              case IMAGE_FILETYPE_SWC:
                     return "application/x-shockwave-flash";
              case IMAGE_FILETYPE_PSD:
                     return "image/psd";
              case IMAGE_FILETYPE_BMP:
                     return "image/x-ms-bmp";
              case IMAGE_FILETYPE_TIFF_II:
              case IMAGE_FILETYPE_TIFF_MM:
                     return "image/tiff";
              case IMAGE_FILETYPE_IFF:
                     return "image/iff";
              case IMAGE_FILETYPE_WBMP:
                     return "image/vnd.wap.wbmp";
              case IMAGE_FILETYPE_JPC:
                     return "application/octet-stream";
              case IMAGE_FILETYPE_JP2:
                     return "image/jp2";
              case IMAGE_FILETYPE_XBM:
                     return "image/xbm";
              case IMAGE_FILETYPE_ICO:
                     return "image/vnd.microsoft.icon";
              default:
              case IMAGE_FILETYPE_UNKNOWN:
                     return "application/octet-stream"; /* suppose binary format */
       }
}

Here is the caller graph for this function:

PHP_MINIT_FUNCTION ( imagetypes  )

Definition at line 70 of file image.c.

{
       REGISTER_LONG_CONSTANT("IMAGETYPE_GIF",     IMAGE_FILETYPE_GIF,     CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_JPEG",    IMAGE_FILETYPE_JPEG,    CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_PNG",     IMAGE_FILETYPE_PNG,     CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_SWF",     IMAGE_FILETYPE_SWF,     CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_PSD",     IMAGE_FILETYPE_PSD,     CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_BMP",     IMAGE_FILETYPE_BMP,     CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_TIFF_II", IMAGE_FILETYPE_TIFF_II, CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_TIFF_MM", IMAGE_FILETYPE_TIFF_MM, CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_JPC",     IMAGE_FILETYPE_JPC,     CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_JP2",     IMAGE_FILETYPE_JP2,     CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_JPX",     IMAGE_FILETYPE_JPX,     CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_JB2",     IMAGE_FILETYPE_JB2,     CONST_CS | CONST_PERSISTENT);
#if HAVE_ZLIB && !defined(COMPILE_DL_ZLIB)
       REGISTER_LONG_CONSTANT("IMAGETYPE_SWC",     IMAGE_FILETYPE_SWC,     CONST_CS | CONST_PERSISTENT);
#endif 
       REGISTER_LONG_CONSTANT("IMAGETYPE_IFF",     IMAGE_FILETYPE_IFF,     CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_WBMP",    IMAGE_FILETYPE_WBMP,    CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_JPEG2000",IMAGE_FILETYPE_JPC,     CONST_CS | CONST_PERSISTENT); /* keep alias */
       REGISTER_LONG_CONSTANT("IMAGETYPE_XBM",     IMAGE_FILETYPE_XBM,     CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_ICO",     IMAGE_FILETYPE_ICO,     CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_UNKNOWN", IMAGE_FILETYPE_UNKNOWN, CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_COUNT",   IMAGE_FILETYPE_COUNT,   CONST_CS | CONST_PERSISTENT);
       return SUCCESS;
}
static unsigned int php_next_marker ( php_stream *  stream,
int  last_marker,
int  comment_correction,
int ff_read  TSRMLS_DC 
) [static]

Definition at line 373 of file image.c.

{
       int a=0, marker;

       /* get marker byte, swallowing possible padding                           */
       if (last_marker==M_COM && comment_correction) {
              /* some software does not count the length bytes of COM section           */
              /* one company doing so is very much envolved in JPEG... so we accept too */
              /* by the way: some of those companies changed their code now...          */
              comment_correction = 2;
       } else {
              last_marker = 0;
              comment_correction = 0;
       }
       if (ff_read) {
              a = 1; /* already read 0xff in filetype detection */
       }
       do {
              if ((marker = php_stream_getc(stream)) == EOF)
              {
                     return M_EOI;/* we hit EOF */
              }
              if (last_marker==M_COM && comment_correction>0)
              {
                     if (marker != 0xFF)
                     {
                            marker = 0xff;
                            comment_correction--;
                     } else {
                            last_marker = M_PSEUDO; /* stop skipping non 0xff for M_COM */
                     }
              }
              a++;
       } while (marker == 0xff);
       if (a < 2)
       {
              return M_EOI; /* at least one 0xff is needed before marker code */
       }
       if ( last_marker==M_COM && comment_correction)
       {
              return M_EOI; /* ah illegal: char after COM section not 0xFF */
       }
       return (unsigned int)marker;
}

Here is the caller graph for this function:

static unsigned short php_read2 ( php_stream *stream  TSRMLS_DC) [static]

Definition at line 360 of file image.c.

{
       unsigned char a[2];

       /* just return 0 if we hit the end-of-file */
       if((php_stream_read(stream, a, sizeof(a))) <= 0) return 0;

       return (((unsigned short)a[0]) << 8) + ((unsigned short)a[1]);
}

Here is the caller graph for this function:

static unsigned int php_read4 ( php_stream *stream  TSRMLS_DC) [static]

Definition at line 559 of file image.c.

{
       unsigned char a[4];

       /* just return 0 if we hit the end-of-file */
       if ((php_stream_read(stream, a, sizeof(a))) != sizeof(a)) return 0;

       return (((unsigned int)a[0]) << 24)
            + (((unsigned int)a[1]) << 16)
            + (((unsigned int)a[2]) <<  8)
            + (((unsigned int)a[3]));
}

Here is the caller graph for this function:

static int php_read_APP ( php_stream *  stream,
unsigned int  marker,
zval *info  TSRMLS_DC 
) [static]

Definition at line 436 of file image.c.

{
       unsigned short length;
       unsigned char *buffer;
       unsigned char markername[16];
       zval *tmp;

       length = php_read2(stream TSRMLS_CC);
       if (length < 2)      {
              return 0;
       }
       length -= 2;                       /* length includes itself */

       buffer = emalloc(length);

       if (php_stream_read(stream, buffer, (long) length) <= 0) {
              efree(buffer);
              return 0;
       }

       snprintf(markername, sizeof(markername), "APP%d", marker - M_APP0);

       if (zend_hash_find(Z_ARRVAL_P(info), markername, strlen(markername)+1, (void **) &tmp) == FAILURE) {
              /* XXX we onyl catch the 1st tag of it's kind! */
              add_assoc_stringl(info, markername, buffer, length, 1);
       }

       efree(buffer);
       return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int php_skip_variable ( php_stream *stream  TSRMLS_DC) [static]

Definition at line 421 of file image.c.

{
       off_t length = ((unsigned int)php_read2(stream TSRMLS_CC));

       if (length < 2)      {
              return 0;
       }
       length = length - 2;
       php_stream_seek(stream, (long)length, SEEK_CUR);
       return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static unsigned long int php_swf_get_bits ( unsigned char *  buffer,
unsigned int  pos,
unsigned int  count 
) [static]

Definition at line 177 of file image.c.

{
       unsigned int loop;
       unsigned long int result = 0;

       for (loop = pos; loop < pos + count; loop++)
       {
              result = result +
                     ((((buffer[loop / 8]) >> (7 - (loop % 8))) & 0x01) << (count - (loop - pos) - 1));
       }
       return result;
}

Here is the caller graph for this function:


Variable Documentation

PHPAPI const char php_sig_bmp[2] = {'B', 'M'}

Definition at line 41 of file image.c.

PHPAPI const char php_sig_gif[3] = {'G', 'I', 'F'}

Definition at line 39 of file image.c.

PHPAPI const char php_sig_ico[4] = {(char)0x00, (char)0x00, (char)0x01, (char)0x00}

Definition at line 54 of file image.c.

PHPAPI const char php_sig_iff[4] = {'F','O','R','M'}

Definition at line 53 of file image.c.

PHPAPI const char php_sig_jp2[12]
Initial value:
 {(char)0x00, (char)0x00, (char)0x00, (char)0x0c,
                                     (char)0x6a, (char)0x50, (char)0x20, (char)0x20,
                                     (char)0x0d, (char)0x0a, (char)0x87, (char)0x0a}

Definition at line 50 of file image.c.

PHPAPI const char php_sig_jpc[3] = {(char)0xff, (char)0x4f, (char)0xff}

Definition at line 49 of file image.c.

PHPAPI const char php_sig_jpg[3] = {(char) 0xff, (char) 0xd8, (char) 0xff}

Definition at line 44 of file image.c.

PHPAPI const char php_sig_png[8]
Initial value:
 {(char) 0x89, (char) 0x50, (char) 0x4e, (char) 0x47,
                                    (char) 0x0d, (char) 0x0a, (char) 0x1a, (char) 0x0a}

Definition at line 45 of file image.c.

PHPAPI const char php_sig_psd[4] = {'8', 'B', 'P', 'S'}

Definition at line 40 of file image.c.

PHPAPI const char php_sig_swc[3] = {'C', 'W', 'S'}

Definition at line 43 of file image.c.

PHPAPI const char php_sig_swf[3] = {'F', 'W', 'S'}

Definition at line 42 of file image.c.

PHPAPI const char php_sig_tif_ii[4] = {'I','I', (char)0x2A, (char)0x00}

Definition at line 47 of file image.c.

PHPAPI const char php_sig_tif_mm[4] = {'M','M', (char)0x00, (char)0x2A}

Definition at line 48 of file image.c.

PHPAPI const int php_tiff_bytes_per_format[] = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8}

Definition at line 731 of file image.c.