Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Nikita Churaev
gtk
Commits
e5dfd2f5
Commit
e5dfd2f5
authored
Oct 26, 1999
by
Jonathan Blandford
Browse files
more work on the incremental loading
parent
c84756cf
Changes
11
Hide whitespace changes
Inline
Side-by-side
demos/testpixbuf.c
View file @
e5dfd2f5
...
...
@@ -24,6 +24,8 @@
#include
<gtk/gtk.h>
#include
"gdk-pixbuf.h"
#include
"gdk-pixbuf-io.h"
#include
"gdk-pixbuf-loader.h"
#define DEFAULT_WIDTH 24
#define DEFAULT_HEIGHT 24
...
...
@@ -407,6 +409,10 @@ main (int argc, char **argv)
int
found_valid
=
FALSE
;
GdkPixbuf
*
pixbuf
;
GtkObject
*
pixbuf_loader
;
FILE
*
file
;
gint
val
;
guchar
buf
;
gtk_init
(
&
argc
,
&
argv
);
...
...
@@ -448,6 +454,20 @@ main (int argc, char **argv)
}
}
pixbuf_loader
=
gdk_pixbuf_loader_new
();
file
=
fopen
(
"/usr/share/pixmaps/up2date.png"
,
"r"
);
g_assert
(
file
!=
NULL
);
while
(
TRUE
)
{
val
=
fgetc
(
file
);
if
(
val
==
EOF
)
break
;
buf
=
(
guint
)
val
;
if
(
gdk_pixbuf_loader_write
(
GDK_PIXBUF_LOADER
(
pixbuf_loader
),
&
buf
,
1
)
==
FALSE
)
break
;
}
fclose
(
file
);
if
(
found_valid
)
gtk_main
();
...
...
gdk-pixbuf/Makefile.am
View file @
e5dfd2f5
...
...
@@ -29,6 +29,8 @@ libexec_LTLIBRARIES = \
$(TIFF_LIB)
noinst_PROGRAMS
=
testpixbuf
DEPS
=
libgdk_pixbuf.la
INCLUDES
=
$(GLIB_CFLAGS)
$(LIBART_CFLAGS)
$(GTK_CFLAGS)
AM_CPPFLAGS
=
"-DPIXBUF_LIBDIR=
\"
$(libexecdir)
\"
"
...
...
@@ -54,6 +56,9 @@ libgdk_pixbufinclude_HEADERS = \
gdk-pixbuf.h
\
gdk-pixbuf-loader.h
noinst_HEADERS
=
\
gdk-pixbuf-io.h
#
# The PNG plugin.
#
...
...
gdk-pixbuf/gdk-pixbuf-io.c
View file @
e5dfd2f5
...
...
@@ -22,10 +22,8 @@
*/
#include
<config.h>
#include
<stdio.h>
#include
<string.h>
#include
<gmodule.h>
#include
"gdk-pixbuf.h"
#include
"gdk-pixbuf-io.h"
...
...
@@ -105,6 +103,7 @@ pixbuf_check_xpm (guchar *buffer, int size)
return
FALSE
;
}
#if 0
static gboolean
pixbuf_check_bmp (guchar *buffer, int size)
{
...
...
@@ -134,14 +133,9 @@ pixbuf_check_ppm (guchar *buffer, int size)
}
return FALSE;
}
#endif
static
struct
{
char
*
module_name
;
gboolean
(
*
format_check
)
(
guchar
*
buffer
,
int
size
);
GModule
*
module
;
GdkPixbuf
*
(
*
load
)
(
FILE
*
f
);
GdkPixbuf
*
(
*
load_xpm_data
)
(
const
gchar
**
data
);
}
file_formats
[]
=
{
ModuleType
file_formats
[]
=
{
{
"png"
,
pixbuf_check_png
,
NULL
,
NULL
,
NULL
},
{
"jpeg"
,
pixbuf_check_jpeg
,
NULL
,
NULL
,
NULL
},
{
"tiff"
,
pixbuf_check_tiff
,
NULL
,
NULL
,
NULL
},
...
...
@@ -156,16 +150,16 @@ static struct {
};
static
void
image_handler_load
(
int
idx
)
image_handler_load
(
ModuleType
*
image_module
)
{
char
*
module_name
;
char
*
path
;
GModule
*
module
;
void
*
load_sym
;
g_return_if_fail
(
file_formats
[
idx
].
module
==
NULL
);
module_name
=
g_strconcat
(
"pixbuf-"
,
file_formats
[
idx
].
module_name
,
NULL
);
g_return_if_fail
(
image_module
->
module
==
NULL
);
module_name
=
g_strconcat
(
"pixbuf-"
,
image_module
->
module_name
,
NULL
);
path
=
g_module_build_path
(
PIXBUF_LIBDIR
,
module_name
);
g_free
(
module_name
);
...
...
@@ -176,59 +170,72 @@ image_handler_load (int idx)
return
;
}
file_formats
[
idx
].
module
=
module
;
image_module
->
module
=
module
;
if
(
g_module_symbol
(
module
,
"image_load"
,
&
load_sym
))
file_formats
[
idx
].
load
=
load_sym
;
image_module
->
load
=
load_sym
;
if
(
g_module_symbol
(
module
,
"image_load_xpm_data"
,
&
load_sym
))
file_formats
[
idx
].
load_xpm_data
=
load_sym
;
image_module
->
load_xpm_data
=
load_sym
;
}
ModuleType
*
gdk_pixbuf_get_module
(
gchar
*
buffer
,
gint
size
)
{
gint
i
;
for
(
i
=
0
;
file_formats
[
i
].
module_name
;
i
++
)
{
if
((
*
file_formats
[
i
].
format_check
)
(
buffer
,
size
))
return
&
(
file_formats
[
i
]);
}
return
NULL
;
}
GdkPixbuf
*
gdk_pixbuf_new_from_file
(
const
char
*
filename
)
{
GdkPixbuf
*
pixbuf
;
gint
n
,
i
;
gint
size
;
FILE
*
f
;
char
buffer
[
128
];
ModuleType
*
image_module
;
f
=
fopen
(
filename
,
"r"
);
if
(
!
f
)
return
NULL
;
n
=
fread
(
&
buffer
,
1
,
sizeof
(
buffer
),
f
);
size
=
fread
(
&
buffer
,
1
,
sizeof
(
buffer
),
f
);
if
(
n
==
0
)
{
if
(
size
==
0
)
{
fclose
(
f
);
return
NULL
;
}
for
(
i
=
0
;
file_formats
[
i
].
module_name
;
i
++
)
{
if
(
(
*
file_formats
[
i
].
format_check
)
(
buffer
,
n
))
{
if
(
!
file_formats
[
i
].
load
)
image_handler_load
(
i
);
image_module
=
gdk_pixbuf_get_module
(
buffer
,
size
);
if
(
image_module
)
{
if
(
!
image_module
->
load
)
image_handler_load
(
i
mage_module
);
if
(
!
file_formats
[
i
].
load
)
{
fclose
(
f
);
return
NULL
;
}
fseek
(
f
,
0
,
SEEK_SET
);
pixbuf
=
(
*
file_formats
[
i
].
load
)
(
f
);
if
(
!
image_module
->
load
)
{
fclose
(
f
);
return
NULL
;
}
if
(
pixbuf
)
g_assert
(
pixbuf
->
ref_count
!=
0
);
fseek
(
f
,
0
,
SEEK_SET
);
pixbuf
=
(
*
image_module
->
load
)
(
f
);
fclose
(
f
);
return
pixbuf
;
}
if
(
pixbuf
)
g_assert
(
pixbuf
->
ref_count
!=
0
);
return
pixbuf
;
}
else
{
g_warning
(
"Unable to find handler for file: %s"
,
filename
);
}
fclose
(
f
);
g_warning
(
"Unable to find handler for file: %s"
,
filename
);
return
NULL
;
}
...
...
@@ -237,9 +244,9 @@ gdk_pixbuf_new_from_xpm_data (const gchar **data)
{
GdkPixbuf
*
(
*
load_xpm_data
)
(
const
gchar
**
data
);
GdkPixbuf
*
pixbuf
;
if
(
file_formats
[
XPM_FILE_FORMAT_INDEX
].
load_xpm_data
==
NULL
)
{
image_handler_load
(
XPM_FILE_FORMAT_INDEX
);
image_handler_load
(
&
file_formats
[
XPM_FILE_FORMAT_INDEX
]
);
}
if
(
file_formats
[
XPM_FILE_FORMAT_INDEX
].
load_xpm_data
==
NULL
)
{
...
...
@@ -253,4 +260,4 @@ gdk_pixbuf_new_from_xpm_data (const gchar **data)
return
pixbuf
;
}
gdk-pixbuf/gdk-pixbuf-io.h
View file @
e5dfd2f5
/* Nothing here yet */
/* GdkPixbuf library - Io handling
*
* Copyright (C) 1999 The Free Software Foundation
*
* Authors: Mark Crichton <crichton@gimp.org>
* Miguel de Icaza <miguel@gnu.org>
* Federico Mena-Quintero <federico@gimp.org>
* Jonathan Blandford <jrb@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include
<gmodule.h>
#include
"gdk-pixbuf.h"
#include
<stdio.h>
typedef
struct
_ModuleType
ModuleType
;
struct
_ModuleType
{
char
*
module_name
;
gboolean
(
*
format_check
)
(
guchar
*
buffer
,
int
size
);
GModule
*
module
;
GdkPixbuf
*
(
*
load
)
(
FILE
*
f
);
GdkPixbuf
*
(
*
load_xpm_data
)
(
const
gchar
**
data
);
};
ModuleType
*
gdk_pixbuf_get_module
(
gchar
*
buffer
,
gint
size
);
gdk-pixbuf/gdk-pixbuf-loader.c
View file @
e5dfd2f5
...
...
@@ -24,14 +24,15 @@
*/
#include
"gdk-pixbuf-loader.h"
#include
"gdk-pixbuf-io.h"
static
GtkObjectClass
*
parent_class
;
static
GtkObjectClass
*
parent_class
;
static
void
gdk_pixbuf_loader_class_init
(
GdkPixbufLoaderClass
*
klass
);
static
void
gdk_pixbuf_loader_init
(
GdkPixbufLoader
*
loader
);
static
void
gdk_pixbuf_loader_destroy
(
G
dkPixbufLoader
*
loader
);
static
void
gdk_pixbuf_loader_finalize
(
G
dkPixbufLoader
*
loader
);
static
void
gdk_pixbuf_loader_destroy
(
G
tkObject
*
loader
);
static
void
gdk_pixbuf_loader_finalize
(
G
tkObject
*
loader
);
/* Internal data */
typedef
struct
_GdkPixbufLoaderPrivate
GdkPixbufLoaderPrivate
;
...
...
@@ -39,6 +40,9 @@ struct _GdkPixbufLoaderPrivate
{
GdkPixbuf
*
pixbuf
;
gboolean
closed
;
gchar
buf
[
128
];
gint
buf_offset
;
ModuleType
*
image_module
;
};
GtkType
...
...
@@ -76,28 +80,33 @@ gdk_pixbuf_loader_class_init (GdkPixbufLoaderClass *klass)
static
void
gdk_pixbuf_loader_init
(
GdkPixbufLoader
*
loader
)
{
GdkPixbuf
*
pixbuf
;
loader
->
private
=
g_new
(
GdkPixbufLoaderPrivate
,
1
);
GdkPixbufLoaderPrivate
*
priv
;
loader
->
pixbuf
=
NULL
;
loader
->
closed
=
FALSE
;
priv
=
g_new
(
GdkPixbufLoaderPrivate
,
1
);
loader
->
private
=
priv
;
priv
->
pixbuf
=
NULL
;
priv
->
closed
=
FALSE
;
priv
->
buf_offset
=
0
;
}
static
void
gdk_pixbuf_loader_destroy
(
G
dkPixbufLoader
*
loader
)
gdk_pixbuf_loader_destroy
(
G
tkObject
*
loader
)
{
GdkPixbufLoaderPrivate
*
priv
;
GdkPixbufLoaderPrivate
*
priv
=
NULL
;
priv
=
loader
->
private
;
priv
=
GDK_PIXBUF_LOADER
(
loader
)
->
private
;
gdk_pixbuf_unref
(
priv
->
pixbuf
);
}
static
void
gdk_pixbuf_loader_finalize
(
G
dkPixbufLoader
*
loader
)
gdk_pixbuf_loader_finalize
(
G
tkObject
*
loader
)
{
GdkPixbufLoaderPrivate
*
priv
;
GdkPixbufLoader
*
load
;
GdkPixbufLoaderPrivate
*
priv
=
NULL
;
priv
=
loader
->
private
;
load
=
GTK_CHECK_CAST
(
loader
,
GDK_TYPE_PIXBUF_LOADER
,
GdkPixbufLoader
);
priv
=
GDK_PIXBUF_LOADER
(
loader
)
->
private
;
g_free
(
priv
);
}
...
...
@@ -117,41 +126,60 @@ gdk_pixbuf_loader_new (void)
* @loader: A loader.
* @buf: The image data.
* @count: The length of @buf in bytes.
*
*
* This will load the next @size bytes of the image. It will return TRUE if the
* data was loaded successfully, and FALSE if an error occurred. In this case,
* the loader will be closed, and will not accept further writes.
*
*
* Return value: Returns TRUE if the write was successful -- FALSE if the loader
* cannot parse the buf.
**/
gboolean
gdk_pixbuf_loader_write
(
GdkPixbufLoader
*
loader
,
gchar
*
buf
,
size_
t
count
)
gdk_pixbuf_loader_write
(
GdkPixbufLoader
*
loader
,
gchar
*
buf
,
gin
t
count
)
{
GdkPixbufLoaderPrivate
*
priv
;
g_return_val_if_fail
(
loader
!=
NULL
,
FALSE
);
g_return_val_if_fail
(
GDK_IS_PIXBUF_LOADER
(
loader
),
FALSE
);
g_return_val_if_fail
(
buf
!=
NULL
,
FALSE
);
g_return_val_if_fail
(
count
>=
0
,
FALSE
);
priv
=
loader
->
private
;
/* we expect it's not to be closed */
g_return_val_if_fail
(
priv
->
closed
==
FALSE
,
FALSE
);
if
(
priv
->
image_module
==
NULL
)
{
g_print
(
"buf_offset:%d:
\n
"
,
priv
->
buf_offset
);
memcpy
(
priv
->
buf
+
priv
->
buf_offset
,
buf
,
(
priv
->
buf_offset
+
count
)
>
128
?
128
-
priv
->
buf_offset
:
count
);
if
((
priv
->
buf_offset
+
count
)
>=
128
)
{
priv
->
image_module
=
gdk_pixbuf_get_module
(
priv
->
buf
,
128
);
if
(
priv
->
image_module
==
NULL
)
{
g_print
(
"no module loaded. bummer
\n
"
);
return
FALSE
;
}
else
{
g_print
(
"module loaded: name is %s
\n
"
,
priv
->
image_module
->
module_name
);
}
}
else
{
priv
->
buf_offset
+=
count
;
}
}
return
TRUE
;
}
/**
* gdk_pixbuf_loader_get_pixbuf:
* @loader: A loader.
*
*
* Gets the GdkPixbuf that the loader is currently loading. If the loader
* hasn't been enough data via gdk_pixbuf_loader_write, then NULL is returned.
* Any application using this function should check for this value when it is
* used. The pixbuf returned will be the same in all future calls to the
* loader, so simply calling a gdk_pixbuf_ref() should be sufficient to continue
* using it.
*
*
* Return value: The GdkPixbuf that the loader is loading.
**/
GdkPixbuf
*
...
...
@@ -169,7 +197,7 @@ gdk_pixbuf_loader_get_pixbuf (GdkPixbufLoader *loader)
/**
* gdk_pixbuf_loader_close:
* @loader: A loader.
*
*
* Tells the loader to stop accepting writes
*
**/
...
...
gdk-pixbuf/gdk-pixbuf-loader.h
View file @
e5dfd2f5
...
...
@@ -32,16 +32,15 @@
#ifdef __cplusplus
extern
"C"
{
#pragma }
#endif
#define GDK_TYPE_PIXBUF_LOADER (g
t
k_pixbuf_get_type ())
#define GDK_PIXBUF_LOADER
(obj) (GTK_CHECK_CAST ((obj), G
T
K_TYPE_
HBOX, GtkHBox
))
#define GDK_PIXBUF_LOADER_CLASS
(klass) (GTK_CHECK_CLASS_CAST ((klass), G
T
K_TYPE_
HBOX, GtkHBox
Class))
#define GDK_IS_PIXBUF_LOADER
(obj) (GTK_CHECK_TYPE ((obj), G
T
K_TYPE_
HBOX
))
#define GDK_IS_PIXBUF_LOADER_CLASS
(klass) (GTK_CHECK_CLASS_TYPE ((klass), G
T
K_TYPE_
HBOX
))
#define GDK_TYPE_PIXBUF_LOADER (g
d
k_pixbuf_
loader_
get_type ())
#define GDK_PIXBUF_LOADER(obj) (GTK_CHECK_CAST ((obj), G
D
K_TYPE_
PIXBUF_LOADER, GdkPixbufLoader
))
#define GDK_PIXBUF_LOADER_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), G
D
K_TYPE_
PIXBUF_LOADER, GdkPixbufLoader
Class))
#define GDK_IS_PIXBUF_LOADER(obj) (GTK_CHECK_TYPE ((obj), G
D
K_TYPE_
PIXBUF_LOADER
))
#define GDK_IS_PIXBUF_LOADER_CLASS(klass)
(GTK_CHECK_CLASS_TYPE ((klass), G
D
K_TYPE_
PIXBUF_LOADER
))
typedef
struct
_GdkPixbufLoader
GdkPixbufLoader
;
...
...
@@ -50,7 +49,7 @@ struct _GdkPixbufLoader
GtkObject
object
;
/* < Private > */
gpointer
d
at
a
;
gpointer
priv
at
e
;
};
typedef
struct
_GdkPixbufLoaderClass
GdkPixbufLoaderClass
;
...
...
@@ -66,8 +65,9 @@ struct _GdkPixbufLoaderClass {
GtkType
gdk_pixbuf_loader_get_type
(
void
);
GtkObject
*
gdk_pixbuf_loader_new
(
void
);
gboolean
gdk_pixbuf_loader_write
(
GdkPixbufLoader
*
loader
,
gchar
*
buf
,
size_
t
count
);
gboolean
gdk_pixbuf_loader_write
(
GdkPixbufLoader
*
loader
,
gchar
*
buf
,
gin
t
count
);
GdkPixbuf
*
gdk_pixbuf_loader_get_pixbuf
(
GdkPixbufLoader
*
loader
);
void
gdk_pixbuf_loader_close
(
GdkPixbufLoader
*
loader
);
...
...
gdk-pixbuf/io-jpeg.c
View file @
e5dfd2f5
...
...
@@ -62,7 +62,8 @@ GdkPixbuf *
image_load
(
FILE
*
f
)
{
int
w
,
h
,
i
,
j
;
guchar
*
pixels
=
NULL
,
*
dptr
;
guchar
*
pixels
=
NULL
;
guchar
*
dptr
;
guchar
*
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."
*/
...
...
gdk-pixbuf/io-png.c
View file @
e5dfd2f5
...
...
@@ -135,8 +135,8 @@ image_load (FILE *f)
free_buffer
,
NULL
);
}
GdkImage
*
gboolean
image_load_by_data
(
void
*
data
,
size_t
count
)
{
return
NULL
;
return
TRUE
;
}
gdk-pixbuf/io-tiff.c
View file @
e5dfd2f5
...
...
@@ -43,7 +43,8 @@ GdkPixbuf *
image_load
(
FILE
*
f
)
{
TIFF
*
tiff
;
guchar
*
pixels
,
*
tmppix
;
guchar
*
pixels
=
NULL
;
guchar
*
tmppix
;
gint
w
,
h
,
x
,
y
,
num_pixs
,
fd
;
uint32
*
rast
,
*
tmp_rast
;
...
...
gtk/gdk-pixbuf-loader.c
View file @
e5dfd2f5
...
...
@@ -24,14 +24,15 @@
*/
#include
"gdk-pixbuf-loader.h"
#include
"gdk-pixbuf-io.h"
static
GtkObjectClass
*
parent_class
;
static
GtkObjectClass
*
parent_class
;
static
void
gdk_pixbuf_loader_class_init
(
GdkPixbufLoaderClass
*
klass
);
static
void
gdk_pixbuf_loader_init
(
GdkPixbufLoader
*
loader
);
static
void
gdk_pixbuf_loader_destroy
(
G
dkPixbufLoader
*
loader
);
static
void
gdk_pixbuf_loader_finalize
(
G
dkPixbufLoader
*
loader
);
static
void
gdk_pixbuf_loader_destroy
(
G
tkObject
*
loader
);
static
void
gdk_pixbuf_loader_finalize
(
G
tkObject
*
loader
);
/* Internal data */
typedef
struct
_GdkPixbufLoaderPrivate
GdkPixbufLoaderPrivate
;
...
...
@@ -39,6 +40,9 @@ struct _GdkPixbufLoaderPrivate
{
GdkPixbuf
*
pixbuf
;
gboolean
closed
;
gchar
buf
[
128
];
gint
buf_offset
;
ModuleType
*
image_module
;
};
GtkType
...
...
@@ -76,28 +80,33 @@ gdk_pixbuf_loader_class_init (GdkPixbufLoaderClass *klass)
static
void
gdk_pixbuf_loader_init
(
GdkPixbufLoader
*
loader
)
{
GdkPixbuf
*
pixbuf
;
loader
->
private
=
g_new
(
GdkPixbufLoaderPrivate
,
1
);
GdkPixbufLoaderPrivate
*
priv
;
loader
->
pixbuf
=
NULL
;
loader
->
closed
=
FALSE
;
priv
=
g_new
(
GdkPixbufLoaderPrivate
,
1
);
loader
->
private
=
priv
;
priv
->
pixbuf
=
NULL
;
priv
->
closed
=
FALSE
;
priv
->
buf_offset
=
0
;
}
static
void
gdk_pixbuf_loader_destroy
(
G
dkPixbufLoader
*
loader
)
gdk_pixbuf_loader_destroy
(
G
tkObject
*
loader
)
{
GdkPixbufLoaderPrivate
*
priv
;
GdkPixbufLoaderPrivate
*
priv
=
NULL
;
priv
=
loader
->
private
;
priv
=
GDK_PIXBUF_LOADER
(
loader
)
->
private
;
gdk_pixbuf_unref
(
priv
->
pixbuf
);
}
static
void
gdk_pixbuf_loader_finalize
(
G
dkPixbufLoader
*
loader
)
gdk_pixbuf_loader_finalize
(
G
tkObject
*
loader
)
{
GdkPixbufLoaderPrivate
*
priv
;
GdkPixbufLoader
*
load
;
GdkPixbufLoaderPrivate
*
priv
=
NULL
;
priv
=
loader
->
private
;
load
=
GTK_CHECK_CAST
(
loader
,
GDK_TYPE_PIXBUF_LOADER
,
GdkPixbufLoader
);
priv
=
GDK_PIXBUF_LOADER
(
loader
)
->
private
;
g_free
(
priv
);
}
...
...
@@ -117,41 +126,60 @@ gdk_pixbuf_loader_new (void)
* @loader: A loader.
* @buf: The image data.
* @count: The length of @buf in bytes.
*
*
* This will load the next @size bytes of the image. It will return TRUE if the
* data was loaded successfully, and FALSE if an error occurred. In this case,
* the loader will be closed, and will not accept further writes.
*
*
* Return value: Returns TRUE if the write was successful -- FALSE if the loader
* cannot parse the buf.
**/
gboolean
gdk_pixbuf_loader_write
(
GdkPixbufLoader
*
loader
,
gchar
*
buf
,
size_
t
count
)
gdk_pixbuf_loader_write
(
GdkPixbufLoader
*
loader
,
gchar
*
buf
,
gin
t
count
)
{
GdkPixbufLoaderPrivate
*
priv
;
g_return_val_if_fail
(
loader
!=
NULL
,
FALSE
);
g_return_val_if_fail
(
GDK_IS_PIXBUF_LOADER
(
loader
),
FALSE
);
g_return_val_if_fail
(
buf
!=
NULL
,
FALSE
);
g_return_val_if_fail
(
count
>=
0
,
FALSE
);
priv
=
loader
->
private
;
/* we expect it's not to be closed */
g_return_val_if_fail
(
priv
->
closed
==
FALSE
,
FALSE
);
if
(
priv
->
image_module
==
NULL
)
{
g_print
(
"buf_offset:%d:
\n
"
,
priv
->
buf_offset
);
memcpy
(
priv
->
buf
+
priv
->
buf_offset
,
buf
,
(
priv
->
buf_offset
+
count
)
>
128
?
128
-
priv
->
buf_offset
:
count
);
if
((
priv
->
buf_offset
+
count
)
>=
128
)
{
priv
->
image_module
=
gdk_pixbuf_get_module
(
priv
->
buf
,
128
);
if
(
priv
->
image_module
==
NULL
)
{
g_print
(
"no module loaded. bummer
\n
"
);
return
FALSE
;
}
else
{
g_print
(
"module loaded: name is %s
\n
"
,
priv
->
image_module
->
module_name
);
}
}
else
{
priv
->
buf_offset
+=
count
;
}
}
return
TRUE
;
}
/**
* gdk_pixbuf_loader_get_pixbuf:
* @loader: A loader.
*
*
* Gets the GdkPixbuf that the loader is currently loading. If the loader
* hasn't been enough data via gdk_pixbuf_loader_write, then NULL is returned.
* Any application using this function should check for this value when it is
* used. The pixbuf returned will be the same in all future calls to the
* loader, so simply calling a gdk_pixbuf_ref() should be sufficient to continue
* using it.
*
*
* Return value: The GdkPixbuf that the loader is loading.