New function to create a blank pixbuf.

1999-10-27  Havoc Pennington  <hp@pobox.com>

* src/gdk-pixbuf.c (gdk_pixbuf_new): New function to create a
blank pixbuf.

* src/gdk-pixbuf-loader.c (gdk_pixbuf_loader_write): Check all
three progressive load funcs are non-NULL, rather than checking
begin_load three times. Also, check whether begin_load returns
NULL on failure.
This commit is contained in:
Havoc Pennington 1999-10-27 17:28:44 +00:00 committed by Havoc Pennington
parent e8242a24eb
commit 1a0a5d0399
4 changed files with 80 additions and 6 deletions

View File

@ -240,14 +240,19 @@ gdk_pixbuf_loader_write (GdkPixbufLoader *loader, gchar *buf, gint count)
if (priv->image_module == NULL) {
return FALSE;
} else if ((priv->image_module->begin_load == NULL) ||
(priv->image_module->begin_load == NULL) ||
(priv->image_module->begin_load == NULL) ||
(priv->image_module->begin_load == NULL)) {
(priv->image_module->stop_load == NULL) ||
(priv->image_module->load_increment == NULL)) {
g_warning ("module %s does not support incremental loading.\n", priv->image_module->module_name);
return FALSE;
} else {
g_print ("module loaded: name is %s\n", priv->image_module->module_name);
priv->context = (priv->image_module->begin_load) (gdk_pixbuf_loader_prepare, loader);
if (priv->context == NULL) {
g_warning("Failed to begin progressive load");
return FALSE;
}
retval = (priv->image_module->load_increment) (priv->context, priv->buf, 128);
/* if we had more then 128 bytes total, we want to send the rest of the buffer */

View File

@ -99,3 +99,64 @@ gdk_pixbuf_new_from_art_pixbuf (ArtPixBuf *art_pixbuf)
return pixbuf;
}
/**
* gdk_pixbuf_new:
* @art_pixbuf: A libart pixbuf.
*
* Creates a &GdkPixbuf; magically sets the ArtPixFormat, rowstride, and creates
* the buffer. Use gdk_pixbuf_new_from_data() to do things manually.
*
* Return value: A newly-created &GdkPixbuf structure with a reference count of
* 1. Somewhat oddly, returns NULL if it can't allocate the buffer; this unusual
* behavior is needed because images can be very large.
**/
GdkPixbuf *
gdk_pixbuf_new (gboolean has_alpha, int width, int height)
{
GdkPixbuf *pixbuf;
g_return_val_if_fail (width > 0, NULL);
g_return_val_if_fail (height > 0, NULL);
pixbuf = g_new (GdkPixbuf, 1);
pixbuf->ref_count = 1;
if (has_alpha) {
art_u8* pixels;
int rowstride;
/* FIXME, pick an optimal stride */
rowstride = 4*width;
pixels = art_alloc(rowstride*height);
if (pixels == NULL) {
g_free(pixbuf);
return NULL;
}
pixbuf->art_pixbuf = art_pixbuf_new_rgba(pixels, width, height, rowstride);
} else {
art_u8* pixels;
int rowstride;
/* FIXME, pick an optimal stride */
rowstride = 3*width;
pixels = art_alloc(rowstride*height);
if (pixels == NULL) {
g_free(pixbuf);
return NULL;
}
pixbuf->art_pixbuf = art_pixbuf_new_rgb(pixels, width, height, rowstride);
}
return pixbuf;
}

View File

@ -59,6 +59,9 @@ void gdk_pixbuf_unref (GdkPixbuf *pixbuf);
GdkPixbuf *gdk_pixbuf_new_from_art_pixbuf (ArtPixBuf *art_pixbuf);
/* Create a "blank" pixbuf with an optimal rowstride and a new buffer */
GdkPixbuf *gdk_pixbuf_new (gboolean has_alpha, int width, int height);
/* Simple loading */
GdkPixbuf *gdk_pixbuf_new_from_file (const char *filename);

View File

@ -240,14 +240,19 @@ gdk_pixbuf_loader_write (GdkPixbufLoader *loader, gchar *buf, gint count)
if (priv->image_module == NULL) {
return FALSE;
} else if ((priv->image_module->begin_load == NULL) ||
(priv->image_module->begin_load == NULL) ||
(priv->image_module->begin_load == NULL) ||
(priv->image_module->begin_load == NULL)) {
(priv->image_module->stop_load == NULL) ||
(priv->image_module->load_increment == NULL)) {
g_warning ("module %s does not support incremental loading.\n", priv->image_module->module_name);
return FALSE;
} else {
g_print ("module loaded: name is %s\n", priv->image_module->module_name);
priv->context = (priv->image_module->begin_load) (gdk_pixbuf_loader_prepare, loader);
if (priv->context == NULL) {
g_warning("Failed to begin progressive load");
return FALSE;
}
retval = (priv->image_module->load_increment) (priv->context, priv->buf, 128);
/* if we had more then 128 bytes total, we want to send the rest of the buffer */