Fixed compiler warnings. Fixed write to unallocated memory (row_ptr), and

1999-08-09  Federico Mena Quintero  <federico@nuclecu.unam.mx>

	* src/io-png.c (image_save): Fixed compiler warnings.  Fixed write
	to unallocated memory (row_ptr), and fixed its type as well.  Take
	into account the ArtPixbuf's rowstride when assigning the row
	pointers.

	* src/gdk-pixbuf.c: Fixup includes.

	* src/gdk-pixbuf-io.c: Likewise.
This commit is contained in:
Federico Mena Quintero 1999-08-09 06:09:24 +00:00 committed by Arturo Espinosa
parent ecef1e1f2f
commit 49ca2615f8
7 changed files with 63 additions and 54 deletions

View File

@ -1,3 +1,14 @@
1999-08-09 Federico Mena Quintero <federico@nuclecu.unam.mx>
* src/io-png.c (image_save): Fixed compiler warnings. Fixed write
to unallocated memory (row_ptr), and fixed its type as well. Take
into account the ArtPixbuf's rowstride when assigning the row
pointers.
* src/gdk-pixbuf.c: Fixup includes.
* src/gdk-pixbuf-io.c: Likewise.
Sat Jul 31 19:19:47 CEST 1999
* src/gdk-pixbuf-io.c:

View File

@ -4,8 +4,10 @@
* Author:
* Miguel de Icaza (miguel@gnu.org)
*/
#include <config.h>
#include <stdio.h>
#include <string.h>
#include <glib.h>
#include <gmodule.h>
#include "gdk-pixbuf.h"
@ -37,7 +39,7 @@ pixbuf_check_jpeg (unsigned char *buffer, int size)
if (buffer [0] != 0xff || buffer [1] != 0xd8)
return FALSE;
return TRUE;
}
@ -47,18 +49,18 @@ pixbuf_check_tiff (unsigned char *buffer, int size)
if (size < 10)
return FALSE;
if (buffer [0] == 'M' &&
buffer [1] == 'M' &&
buffer [2] == 0 &&
if (buffer [0] == 'M' &&
buffer [1] == 'M' &&
buffer [2] == 0 &&
buffer [3] == 0x2a)
return TRUE;
if (buffer [0] == 'I' &&
buffer [1] == 'I' &&
buffer [2] == 0x2a &&
if (buffer [0] == 'I' &&
buffer [1] == 'I' &&
buffer [2] == 0x2a &&
buffer [3] == 0)
return TRUE;
return FALSE;
}
@ -67,10 +69,10 @@ pixbuf_check_gif (unsigned char *buffer, int size)
{
if (size < 20)
return FALSE;
if (strncmp (buffer, "GIF8", 4) == 0)
return TRUE;
return FALSE;
}
@ -79,10 +81,10 @@ pixbuf_check_xpm (unsigned char *buffer, int size)
{
if (size < 20)
return FALSE;
if (strncmp (buffer, "/* XPM */", 9) == 0)
return TRUE;
return FALSE;
}
@ -91,10 +93,10 @@ pixbuf_check_bmp (unsigned char *buffer, int size)
{
if (size < 20)
return FALSE;
if (buffer [0] != 'B' || buffer [1] != 'M')
return FALSE;
return TRUE;
}
@ -133,15 +135,6 @@ static struct {
{ NULL, NULL, NULL, NULL, NULL }
};
static int
image_file_format (const char *file)
{
FILE *f = fopen (file, "r");
if (!f)
return -1;
}
static void
image_handler_load (int idx)
{
@ -149,8 +142,8 @@ image_handler_load (int idx)
char *path;
GModule *module;
void *load_sym, *save_sym;
module_name = g_strconcat ("pixbuf-",
module_name = g_strconcat ("pixbuf-",
file_formats [idx].module_name, NULL);
path = g_module_build_path (PIXBUF_LIBDIR, module_name);
g_free (module_name);
@ -184,7 +177,7 @@ gdk_pixbuf_load_image (const char *file)
n = fread (&buffer, 1, sizeof (buffer), f);
if (n == 0){
fclose (f);
fclose (f);
return NULL;
}

View File

@ -5,11 +5,14 @@
* Miguel de Icaza (miguel@gnu.org)
* Mark Crichton (crichton@gimp.org)
*/
#include <config.h>
#include <glib.h>
#include <math.h>
#include <libart_lgpl/art_misc.h>
#include <libart_lgpl/art_rgb_affine.h>
#include <libart_lgpl/art_affine.h>
#include <libart_lgpl/art_pixbuf.h>
#include <libart_lgpl/art_rgb_pixbuf_affine.h>
#include <libart_lgpl/art_alphagamma.h>
#include "gdk-pixbuf.h"
@ -25,7 +28,7 @@ void
gdk_pixbuf_ref (GdkPixBuf *pixbuf)
{
g_return_if_fail (pixbuf != NULL);
pixbuf->ref_count++;
}
@ -34,7 +37,7 @@ gdk_pixbuf_unref (GdkPixBuf *pixbuf)
{
g_return_if_fail (pixbuf != NULL);
g_return_if_fail (pixbuf->ref_count == 0);
pixbuf->ref_count--;
if (pixbuf->ref_count)
gdk_pixbuf_destroy (pixbuf);
@ -43,7 +46,6 @@ gdk_pixbuf_unref (GdkPixBuf *pixbuf)
GdkPixBuf *
gdk_pixbuf_scale (GdkPixBuf *pixbuf, gint w, gint h)
{
GdkPixBuf *spb;
art_u8 *pixels;
gint rowstride;
double affine[6];
@ -53,8 +55,8 @@ gdk_pixbuf_scale (GdkPixBuf *pixbuf, gint w, gint h)
alphagamma = NULL;
affine[1] = affine[2] = affine[4] = affine[5] = 0;
affine[0] = w / (double)(pixbuf->art_pixbuf->width);
affine[3] = h / (double)(pixbuf->art_pixbuf->height);
@ -62,15 +64,15 @@ gdk_pixbuf_scale (GdkPixBuf *pixbuf, gint w, gint h)
rowstride = w * 3;
pixels = art_alloc (h * rowstride);
art_rgb_pixbuf_affine( pixels, 0, 0, w, h, rowstride,
art_rgb_pixbuf_affine (pixels, 0, 0, w, h, rowstride,
pixbuf->art_pixbuf,
affine, ART_FILTER_NEAREST, alphagamma);
if (pixbuf->art_pixbuf->has_alpha)
/* should be rgba */
art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
else
art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
else
art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
art_pixbuf_free (pixbuf->art_pixbuf);
pixbuf->art_pixbuf = art_pixbuf;
@ -81,7 +83,6 @@ gdk_pixbuf_scale (GdkPixBuf *pixbuf, gint w, gint h)
GdkPixBuf *
gdk_pixbuf_rotate (GdkPixBuf *pixbuf, gdouble angle)
{
GdkPixBuf *rotate;
art_u8 *pixels;
gint rowstride, w, h;
gdouble rad;
@ -126,9 +127,9 @@ gdk_pixbuf_rotate (GdkPixBuf *pixbuf, gdouble angle)
affine, ART_FILTER_NEAREST, alphagamma);
if (pixbuf->art_pixbuf->has_alpha)
/* should be rgba */
art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
else
art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
else
art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
art_pixbuf_free (pixbuf->art_pixbuf);
pixbuf->art_pixbuf = art_pixbuf;

View File

@ -181,5 +181,3 @@ GdkPixBuf *image_load(FILE * f)
}
image_save() {}

View File

@ -42,7 +42,7 @@ g_JPEGFatalErrorHandler(j_common_ptr cinfo)
GdkPixBuf *image_load(FILE *f)
{
int w,h,i,j;
art_u8 *pixels=NULL, *dptr, *fptr, *pptr;
art_u8 *pixels=NULL, *dptr;
unsigned char *lines[4], /* Used to expand rows, via rec_outbuf_height, from
the header file:
"* Usually rec_outbuf_height will be 1 or 2, at most 4." */
@ -123,7 +123,7 @@ GdkPixBuf *image_load(FILE *f)
}
pixbuf->ref_count = 0;
pixbuf->unref_func = NULL;
return pixbuf;
}

View File

@ -170,12 +170,12 @@ int image_save(GdkPixBuf *pixbuf, FILE *file)
png_infop info_ptr;
art_u8 *data;
gint y, h, w;
png_bytep row_ptr;
png_bytepp row_ptr;
png_color_8 sig_bit;
gint type;
g_return_val_if_fail(file != NULL, NULL);
g_return_val_if_fail(pixbuf != NULL, NULL);
g_return_val_if_fail(file != NULL, FALSE);
g_return_val_if_fail(pixbuf != NULL, FALSE);
h = pixbuf->art_pixbuf->height;
w = pixbuf->art_pixbuf->width;
@ -184,20 +184,20 @@ int image_save(GdkPixBuf *pixbuf, FILE *file)
NULL, NULL, NULL);
if (png_ptr == NULL) {
fclose(file);
return NULL;
return FALSE;
}
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) {
fclose(file);
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
return NULL;
return FALSE;
}
if (setjmp(png_ptr->jmpbuf)) {
fclose(file);
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
return NULL;
return FALSE;
}
png_init_io(png_ptr, file);
@ -218,18 +218,24 @@ int image_save(GdkPixBuf *pixbuf, FILE *file)
png_set_packing(png_ptr);
data = pixbuf->art_pixbuf->pixels;
row_ptr = g_new(png_byte *, h);
for (y = 0; y < h; y++) {
for (y = 0; y < h; y++)
row_ptr[y] = data + y * pixbuf->art_pixbuf->rowstride;
#if 0
{
if (pixbuf->art_pixbuf->has_alpha)
row_ptr[y] = data + (w * y * 4);
else
row_ptr[y] = data + (w * y * 3);
}
#endif
png_write_image(png_ptr, row_ptr);
g_free (row_ptr);
png_write_end(png_ptr, info_ptr);
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
return TRUE;
}

View File

@ -342,7 +342,7 @@ static GdkPixBuf *
color->transparent = FALSE;
color_name = xpm_extract_color(buffer);
if ((color_name == NULL) || (g_strcasecmp(color_name, "None") == 0)
|| (gdk_color_parse(color_name, &color->color) == FALSE)) {
color->transparent = TRUE;