Whitespace fixes.

This commit is contained in:
Ilia Alshanetsky 2003-03-14 16:56:38 +00:00
parent 1afc5a59fe
commit 199ae10f01
5 changed files with 759 additions and 903 deletions

View File

@ -1,4 +1,3 @@
#include <stdio.h>
#include <math.h>
#include <string.h>
@ -20,252 +19,199 @@ extern void gdImageGd (gdImagePtr im, FILE * out);
/* */
/* Shared code to read color tables from gd file. */
/* */
int
_gdGetColors (gdIOCtx * in, gdImagePtr im, int gd2xFlag)
int _gdGetColors (gdIOCtx * in, gdImagePtr im, int gd2xFlag)
{
int i;
if (gd2xFlag)
{
if (!gdGetByte (&im->trueColor, in))
{
goto fail1;
int i;
if (gd2xFlag) {
if (!gdGetByte (&im->trueColor, in)) {
goto fail1;
}
/* This should have been a word all along */
if (!im->trueColor && !gdGetWord(&im->colorsTotal, in)) {
goto fail1;
}
/* Int to accommodate truecolor single-color transparency */
if (!gdGetInt(&im->transparent, in)) {
goto fail1;
}
} else {
if (!gdGetByte(&im->colorsTotal, in)) {
goto fail1;
}
if (!gdGetWord (&im->transparent, in)) {
goto fail1;
}
if (im->transparent == 257) {
im->transparent = (-1);
}
}
/* This should have been a word all along */
if (!im->trueColor)
{
if (!gdGetWord (&im->colorsTotal, in))
{
goto fail1;
}
}
/* Int to accommodate truecolor single-color transparency */
if (!gdGetInt (&im->transparent, in))
{
goto fail1;
}
}
else
{
if (!gdGetByte (&im->colorsTotal, in))
{
goto fail1;
}
if (!gdGetWord (&im->transparent, in))
{
goto fail1;
}
if (im->transparent == 257)
{
im->transparent = (-1);
}
}
GD2_DBG (printf ("Pallette had %d colours (T=%d)\n", im->colorsTotal, im->transparent));
GD2_DBG (php_gd_error("Pallette had %d colours (T=%d)\n", im->colorsTotal, im->transparent));
for (i = 0; (i < gdMaxColors); i++)
{
if (!gdGetByte (&im->red[i], in))
{
goto fail1;
for (i = 0; i < gdMaxColors; i++) {
if (!gdGetByte(&im->red[i], in)) {
goto fail1;
}
if (!gdGetByte(&im->green[i], in)) {
goto fail1;
}
if (!gdGetByte(&im->blue[i], in)) {
goto fail1;
}
if (gd2xFlag && !gdGetByte (&im->alpha[i], in)) {
goto fail1;
}
}
if (!gdGetByte (&im->green[i], in))
{
goto fail1;
}
if (!gdGetByte (&im->blue[i], in))
{
goto fail1;
}
if (gd2xFlag)
{
if (!gdGetByte (&im->alpha[i], in))
{
goto fail1;
}
}
}
for (i = 0; (i < im->colorsTotal); i++)
{
im->open[i] = 0;
};
for (i = 0; (i < im->colorsTotal); i++) {
im->open[i] = 0;
}
return TRUE;
return TRUE;
fail1:
return FALSE;
return FALSE;
}
/* */
/* Use the common basic header info to make the image object. */
/* This is also called from _gd2CreateFromFile */
/* */
static
gdImagePtr
_gdCreateFromFile (gdIOCtx * in, int *sx, int *sy)
static gdImagePtr _gdCreateFromFile (gdIOCtx * in, int *sx, int *sy)
{
gdImagePtr im;
int gd2xFlag = 0;
if (!gdGetWord (sx, in))
{
goto fail1;
}
if (*sx == 65535)
{
/* This is a gd 2.0 .gd file */
gd2xFlag = 1;
if (!gdGetWord (sx, in))
{
goto fail1;
gdImagePtr im;
int gd2xFlag = 0;
if (!gdGetWord(sx, in)) {
goto fail1;
}
if (*sx == 65535) {
/* This is a gd 2.0 .gd file */
gd2xFlag = 1;
if (!gdGetWord(sx, in)) {
goto fail1;
}
}
if (!gdGetWord(sy, in)) {
goto fail1;
}
}
if (!gdGetWord (sy, in))
{
goto fail1;
}
GD2_DBG (printf ("Image is %dx%d\n", *sx, *sy));
GD2_DBG(php_gd_error("Image is %dx%d\n", *sx, *sy));
im = gdImageCreate (*sx, *sy);
im = gdImageCreate (*sx, *sy);
if (!_gdGetColors (in, im, gd2xFlag))
{
goto fail2;
}
if (!_gdGetColors(in, im, gd2xFlag)) {
goto fail2;
}
return im;
return im;
fail2:
gdImageDestroy (im);
gdImageDestroy(im);
fail1:
return 0;
return 0;
}
gdImagePtr
gdImageCreateFromGd (FILE * inFile)
gdImagePtr gdImageCreateFromGd (FILE * inFile)
{
gdImagePtr im;
gdIOCtx *in;
gdImagePtr im;
gdIOCtx *in;
in = gdNewFileCtx (inFile);
im = gdImageCreateFromGdCtx (in);
in = gdNewFileCtx (inFile);
im = gdImageCreateFromGdCtx (in);
in->gd_free (in);
in->gd_free(in);
return im;
return im;
}
gdImagePtr
gdImageCreateFromGdCtx (gdIOCtxPtr in)
gdImagePtr gdImageCreateFromGdCtx (gdIOCtxPtr in)
{
int sx, sy;
int x, y;
gdImagePtr im;
int sx, sy;
int x, y;
gdImagePtr im;
/* Read the header */
im = _gdCreateFromFile (in, &sx, &sy);
if (im == NULL)
{
goto fail1;
};
/* Then the data... */
for (y = 0; (y < sy); y++)
{
for (x = 0; (x < sx); x++)
{
int ch;
ch = gdGetC (in);
if (ch == EOF)
{
goto fail2;
}
/* ROW-MAJOR IN GD 1.3 */
im->pixels[y][x] = ch;
/* Read the header */
if ((im = _gdCreateFromFile (in, &sx, &sy)) == NULL) {
goto fail1;
}
}
return im;
/* Then the data... */
for (y = 0; y < sy; y++) {
for (x = 0; x < sx; x++) {
int ch;
if ((ch = gdGetC(in)) == EOF) {
goto fail2;
}
/* ROW-MAJOR IN GD 1.3 */
im->pixels[y][x] = ch;
}
}
return im;
fail2:
gdImageDestroy (im);
gdImageDestroy (im);
fail1:
return 0;
return 0;
}
void
_gdPutColors (gdImagePtr im, gdIOCtx * out)
void _gdPutColors (gdImagePtr im, gdIOCtx * out)
{
int i;
int i;
gdPutC (im->trueColor, out);
if (!im->trueColor)
{
gdPutWord (im->colorsTotal, out);
}
gdPutInt (im->transparent, out);
if (!im->trueColor)
{
for (i = 0; (i < gdMaxColors); i++)
{
gdPutC ((unsigned char) im->red[i], out);
gdPutC ((unsigned char) im->green[i], out);
gdPutC ((unsigned char) im->blue[i], out);
gdPutC ((unsigned char) im->alpha[i], out);
gdPutC(im->trueColor, out);
if (!im->trueColor) {
gdPutWord (im->colorsTotal, out);
}
}
}
static
void
_gdPutHeader (gdImagePtr im, gdIOCtx * out)
{
/* 65535 indicates this is a gd 2.x .gd file. */
gdPutWord (65535, out);
gdPutWord (im->sx, out);
gdPutWord (im->sy, out);
_gdPutColors (im, out);
}
static void
_gdImageGd (gdImagePtr im, gdIOCtx * out)
{
int x, y;
_gdPutHeader (im, out);
for (y = 0; (y < im->sy); y++)
{
for (x = 0; (x < im->sx); x++)
{
/* ROW-MAJOR IN GD 1.3 */
if (im->trueColor)
{
gdPutInt (im->tpixels[y][x], out);
}
else
{
gdPutC ((unsigned char) im->pixels[y][x], out);
}
gdPutInt (im->transparent, out);
if (!im->trueColor) {
for (i = 0; (i < gdMaxColors); i++) {
gdPutC((unsigned char) im->red[i], out);
gdPutC((unsigned char) im->green[i], out);
gdPutC((unsigned char) im->blue[i], out);
gdPutC((unsigned char) im->alpha[i], out);
}
}
}
}
void
gdImageGd (gdImagePtr im, FILE * outFile)
static void _gdPutHeader (gdImagePtr im, gdIOCtx * out)
{
gdIOCtx *out = gdNewFileCtx (outFile);
_gdImageGd (im, out);
out->gd_free (out);
/* 65535 indicates this is a gd 2.x .gd file. */
gdPutWord(65535, out);
gdPutWord(im->sx, out);
gdPutWord(im->sy, out);
_gdPutColors (im, out);
}
void *
gdImageGdPtr (gdImagePtr im, int *size)
static void _gdImageGd (gdImagePtr im, gdIOCtx * out)
{
void *rv;
gdIOCtx *out = gdNewDynamicCtx (2048, NULL);
_gdImageGd (im, out);
rv = gdDPExtractData (out, size);
out->gd_free (out);
return rv;
int x, y;
_gdPutHeader (im, out);
for (y = 0; y < im->sy; y++) {
for (x = 0; x < im->sx; x++) {
/* ROW-MAJOR IN GD 1.3 */
if (im->trueColor) {
gdPutInt (im->tpixels[y][x], out);
} else {
gdPutC((unsigned char) im->pixels[y][x], out);
}
}
}
}
void gdImageGd (gdImagePtr im, FILE * outFile)
{
gdIOCtx *out = gdNewFileCtx(outFile);
_gdImageGd(im, out);
out->gd_free(out);
}
void * gdImageGdPtr (gdImagePtr im, int *size)
{
void *rv;
gdIOCtx *out = gdNewDynamicCtx(2048, NULL);
_gdImageGd(im, out);
rv = gdDPExtractData(out, size);
out->gd_free(out);
return rv;
}

View File

@ -43,8 +43,7 @@ typedef struct
{
int offset;
int size;
}
t_chunk_info;
} t_chunk_info;
extern int _gdGetColors(gdIOCtx * in, gdImagePtr im, int gd2xFlag);
extern void _gdPutColors(gdImagePtr im, gdIOCtx * out);

File diff suppressed because it is too large Load Diff

View File

@ -17,37 +17,33 @@ extern gdImagePtr gdImageCreateFromPngSource (gdSourcePtr inSource);
#define GD_SS_DBG(s)
#ifdef HAVE_LIBPNG
void
gdImagePngToSink (gdImagePtr im, gdSinkPtr outSink)
void gdImagePngToSink (gdImagePtr im, gdSinkPtr outSink)
{
gdIOCtx *out = gdNewSSCtx (NULL, outSink);
gdImagePngCtx (im, out);
out->gd_free (out);
gdIOCtx *out = gdNewSSCtx(NULL, outSink);
gdImagePngCtx(im, out);
out->gd_free(out);
}
gdImagePtr
gdImageCreateFromPngSource (gdSourcePtr inSource)
gdImagePtr gdImageCreateFromPngSource (gdSourcePtr inSource)
{
gdIOCtx *in = gdNewSSCtx (inSource, NULL);
gdImagePtr im;
gdIOCtx *in = gdNewSSCtx(inSource, NULL);
gdImagePtr im;
im = gdImageCreateFromPngCtx (in);
im = gdImageCreateFromPngCtx(in);
in->gd_free (in);
in->gd_free(in);
return im;
return im;
}
#else /* no HAVE_LIBPNG */
void
gdImagePngToSink (gdImagePtr im, gdSinkPtr outSink)
void gdImagePngToSink (gdImagePtr im, gdSinkPtr outSink)
{
php_gd_error("PNG support is not available\n");
php_gd_error("PNG support is not available\n");
}
gdImagePtr
gdImageCreateFromPngSource (gdSourcePtr inSource)
gdImagePtr gdImageCreateFromPngSource (gdSourcePtr inSource)
{
php_gd_error("PNG support is not available\n");
return NULL;
php_gd_error("PNG support is not available\n");
return NULL;
}
#endif /* HAVE_LIBPNG */

View File

@ -1,5 +1,3 @@
/*
WBMP: Wireless Bitmap Type 0: B/W, Uncompressed Bitmap
Specification of the WBMP format can be found in the file:
@ -67,10 +65,9 @@
** Wrapper around gdPutC for use with writewbmp
**
*/
void
gd_putout (int i, void *out)
void gd_putout (int i, void *out)
{
gdPutC (i, (gdIOCtx *) out);
gdPutC(i, (gdIOCtx *) out);
}
@ -79,10 +76,9 @@ gd_putout (int i, void *out)
** Wrapper around gdGetC for use with readwbmp
**
*/
int
gd_getin (void *in)
int gd_getin (void *in)
{
return (gdGetC ((gdIOCtx *) in));
return (gdGetC((gdIOCtx *) in));
}
@ -95,124 +91,111 @@ gd_getin (void *in)
** considered as background and will not be written
** out: the stream where to write
*/
void
gdImageWBMPCtx (gdImagePtr image, int fg, gdIOCtx * out)
void gdImageWBMPCtx (gdImagePtr image, int fg, gdIOCtx * out)
{
int x, y, pos;
Wbmp *wbmp;
int x, y, pos;
Wbmp *wbmp;
/* create the WBMP */
if ((wbmp = createwbmp (gdImageSX (image), gdImageSY (image), WBMP_WHITE)) == NULL)
php_gd_error("Could not create WBMP\n");
/* fill up the WBMP structure */
pos = 0;
for (y = 0; y < gdImageSY (image); y++)
{
for (x = 0; x < gdImageSX (image); x++)
{
if (gdImageGetPixel (image, x, y) == fg)
{
wbmp->bitmap[pos] = WBMP_BLACK;
}
pos++;
/* create the WBMP */
if ((wbmp = createwbmp (gdImageSX (image), gdImageSY (image), WBMP_WHITE)) == NULL) {
php_gd_error("Could not create WBMP\n");
}
}
/* write the WBMP to a gd file descriptor */
if (writewbmp (wbmp, &gd_putout, out))
php_gd_error("Could not save WBMP\n");
/* des submitted this bugfix: gdFree the memory. */
freewbmp (wbmp);
/* fill up the WBMP structure */
pos = 0;
for (y = 0; y < gdImageSY(image); y++) {
for (x = 0; x < gdImageSX(image); x++) {
if (gdImageGetPixel (image, x, y) == fg) {
wbmp->bitmap[pos] = WBMP_BLACK;
}
pos++;
}
}
/* write the WBMP to a gd file descriptor */
if (writewbmp (wbmp, &gd_putout, out)) {
php_gd_error("Could not save WBMP\n");
}
/* des submitted this bugfix: gdFree the memory. */
freewbmp(wbmp);
}
/* gdImageCreateFromWBMPCtx
** ------------------------
** Create a gdImage from a WBMP file input from an gdIOCtx
*/
gdImagePtr
gdImageCreateFromWBMPCtx (gdIOCtx * infile)
gdImagePtr gdImageCreateFromWBMPCtx (gdIOCtx * infile)
{
/* FILE *wbmp_file; */
Wbmp *wbmp;
gdImagePtr im = NULL;
int black, white;
int col, row, pos;
/* FILE *wbmp_file; */
Wbmp *wbmp;
gdImagePtr im = NULL;
int black, white;
int col, row, pos;
if (readwbmp (&gd_getin, infile, &wbmp))
return (NULL);
if (!(im = gdImageCreate (wbmp->width, wbmp->height)))
{
freewbmp (wbmp);
return (NULL);
}
/* create the background color */
white = gdImageColorAllocate (im, 255, 255, 255);
/* create foreground color */
black = gdImageColorAllocate (im, 0, 0, 0);
/* fill in image (in a wbmp 1 = white/ 0 = black) */
pos = 0;
for (row = 0; row < wbmp->height; row++)
{
for (col = 0; col < wbmp->width; col++)
{
if (wbmp->bitmap[pos++] == WBMP_WHITE)
{
gdImageSetPixel (im, col, row, white);
}
else
{
gdImageSetPixel (im, col, row, black);
}
if (readwbmp (&gd_getin, infile, &wbmp)) {
return NULL;
}
}
freewbmp (wbmp);
if (!(im = gdImageCreate (wbmp->width, wbmp->height))) {
freewbmp (wbmp);
return NULL;
}
return (im);
/* create the background color */
white = gdImageColorAllocate(im, 255, 255, 255);
/* create foreground color */
black = gdImageColorAllocate(im, 0, 0, 0);
/* fill in image (in a wbmp 1 = white/ 0 = black) */
pos = 0;
for (row = 0; row < wbmp->height; row++) {
for (col = 0; col < wbmp->width; col++) {
if (wbmp->bitmap[pos++] == WBMP_WHITE) {
gdImageSetPixel(im, col, row, white);
} else {
gdImageSetPixel(im, col, row, black);
}
}
}
freewbmp(wbmp);
return im;
}
/* gdImageCreateFromWBMP
** ---------------------
*/
gdImagePtr
gdImageCreateFromWBMP (FILE * inFile)
gdImagePtr gdImageCreateFromWBMP (FILE * inFile)
{
gdImagePtr im;
gdIOCtx *in = gdNewFileCtx (inFile);
im = gdImageCreateFromWBMPCtx (in);
in->gd_free (in);
return (im);
gdImagePtr im;
gdIOCtx *in = gdNewFileCtx(inFile);
im = gdImageCreateFromWBMPCtx(in);
in->gd_free(in);
return im;
}
/* gdImageWBMP
** -----------
*/
void
gdImageWBMP (gdImagePtr im, int fg, FILE * outFile)
void gdImageWBMP (gdImagePtr im, int fg, FILE * outFile)
{
gdIOCtx *out = gdNewFileCtx (outFile);
gdImageWBMPCtx (im, fg, out);
out->gd_free (out);
gdIOCtx *out = gdNewFileCtx(outFile);
gdImageWBMPCtx(im, fg, out);
out->gd_free(out);
}
/* gdImageWBMPPtr
** --------------
*/
void *
gdImageWBMPPtr (gdImagePtr im, int *size, int fg)
void * gdImageWBMPPtr (gdImagePtr im, int *size, int fg)
{
void *rv;
gdIOCtx *out = gdNewDynamicCtx (2048, NULL);
gdImageWBMPCtx (im, fg, out);
rv = gdDPExtractData (out, size);
out->gd_free (out);
return rv;
void *rv;
gdIOCtx *out = gdNewDynamicCtx(2048, NULL);
gdImageWBMPCtx(im, fg, out);
rv = gdDPExtractData(out, size);
out->gd_free(out);
return rv;
}