1// Package gdkpixbuf was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package gdkpixbuf
3
4import (
5 "structs"
6 "unsafe"
7
8 "github.com/ebitengine/purego"
9
10 "github.com/bnema/puregotk/pkg/core"
11 "github.com/bnema/puregotk/v4/glib"
12 "github.com/bnema/puregotk/v4/gobject"
13 "github.com/bnema/puregotk/v4/gobject/types"
14)
15
16type PixbufLoaderClass struct {
17 _ structs.HostLayout
18
19 ParentClass gobject.ObjectClass
20
21 xSizePrepared uintptr
22
23 xAreaPrepared uintptr
24
25 xAreaUpdated uintptr
26
27 xClosed uintptr
28}
29
30func (x *PixbufLoaderClass) GoPointer() uintptr {
31 return uintptr(unsafe.Pointer(x))
32}
33
34// OverrideSizePrepared sets the "size_prepared" callback function.
35func (x *PixbufLoaderClass) OverrideSizePrepared(cb func(*PixbufLoader, int, int)) {
36 if cb == nil {
37 x.xSizePrepared = 0
38 } else {
39 x.xSizePrepared = purego.NewCallback(func(LoaderVarp uintptr, WidthVarp int, HeightVarp int) {
40 cb(PixbufLoaderNewFromInternalPtr(LoaderVarp), WidthVarp, HeightVarp)
41 })
42 }
43}
44
45// GetSizePrepared gets the "size_prepared" callback function.
46func (x *PixbufLoaderClass) GetSizePrepared() func(*PixbufLoader, int, int) {
47 if x.xSizePrepared == 0 {
48 return nil
49 }
50 var rawCallback func(LoaderVarp uintptr, WidthVarp int, HeightVarp int)
51 purego.RegisterFunc(&rawCallback, x.xSizePrepared)
52 return func(LoaderVar *PixbufLoader, WidthVar int, HeightVar int) {
53 rawCallback(LoaderVar.GoPointer(), WidthVar, HeightVar)
54 }
55}
56
57// OverrideAreaPrepared sets the "area_prepared" callback function.
58func (x *PixbufLoaderClass) OverrideAreaPrepared(cb func(*PixbufLoader)) {
59 if cb == nil {
60 x.xAreaPrepared = 0
61 } else {
62 x.xAreaPrepared = purego.NewCallback(func(LoaderVarp uintptr) {
63 cb(PixbufLoaderNewFromInternalPtr(LoaderVarp))
64 })
65 }
66}
67
68// GetAreaPrepared gets the "area_prepared" callback function.
69func (x *PixbufLoaderClass) GetAreaPrepared() func(*PixbufLoader) {
70 if x.xAreaPrepared == 0 {
71 return nil
72 }
73 var rawCallback func(LoaderVarp uintptr)
74 purego.RegisterFunc(&rawCallback, x.xAreaPrepared)
75 return func(LoaderVar *PixbufLoader) {
76 rawCallback(LoaderVar.GoPointer())
77 }
78}
79
80// OverrideAreaUpdated sets the "area_updated" callback function.
81func (x *PixbufLoaderClass) OverrideAreaUpdated(cb func(*PixbufLoader, int, int, int, int)) {
82 if cb == nil {
83 x.xAreaUpdated = 0
84 } else {
85 x.xAreaUpdated = purego.NewCallback(func(LoaderVarp uintptr, XVarp int, YVarp int, WidthVarp int, HeightVarp int) {
86 cb(PixbufLoaderNewFromInternalPtr(LoaderVarp), XVarp, YVarp, WidthVarp, HeightVarp)
87 })
88 }
89}
90
91// GetAreaUpdated gets the "area_updated" callback function.
92func (x *PixbufLoaderClass) GetAreaUpdated() func(*PixbufLoader, int, int, int, int) {
93 if x.xAreaUpdated == 0 {
94 return nil
95 }
96 var rawCallback func(LoaderVarp uintptr, XVarp int, YVarp int, WidthVarp int, HeightVarp int)
97 purego.RegisterFunc(&rawCallback, x.xAreaUpdated)
98 return func(LoaderVar *PixbufLoader, XVar int, YVar int, WidthVar int, HeightVar int) {
99 rawCallback(LoaderVar.GoPointer(), XVar, YVar, WidthVar, HeightVar)
100 }
101}
102
103// OverrideClosed sets the "closed" callback function.
104func (x *PixbufLoaderClass) OverrideClosed(cb func(*PixbufLoader)) {
105 if cb == nil {
106 x.xClosed = 0
107 } else {
108 x.xClosed = purego.NewCallback(func(LoaderVarp uintptr) {
109 cb(PixbufLoaderNewFromInternalPtr(LoaderVarp))
110 })
111 }
112}
113
114// GetClosed gets the "closed" callback function.
115func (x *PixbufLoaderClass) GetClosed() func(*PixbufLoader) {
116 if x.xClosed == 0 {
117 return nil
118 }
119 var rawCallback func(LoaderVarp uintptr)
120 purego.RegisterFunc(&rawCallback, x.xClosed)
121 return func(LoaderVar *PixbufLoader) {
122 rawCallback(LoaderVar.GoPointer())
123 }
124}
125
126// Incremental image loader.
127//
128// `GdkPixbufLoader` provides a way for applications to drive the
129// process of loading an image, by letting them send the image data
130// directly to the loader instead of having the loader read the data
131// from a file. Applications can use this functionality instead of
132// `gdk_pixbuf_new_from_file()` or `gdk_pixbuf_animation_new_from_file()`
133// when they need to parse image data in small chunks. For example,
134// it should be used when reading an image from a (potentially) slow
135// network connection, or when loading an extremely large file.
136//
137// To use `GdkPixbufLoader` to load an image, create a new instance,
138// and call [method@GdkPixbuf.PixbufLoader.write] to send the data
139// to it. When done, [method@GdkPixbuf.PixbufLoader.close] should be
140// called to end the stream and finalize everything.
141//
142// The loader will emit three important signals throughout the process:
143//
144// - [signal@GdkPixbuf.PixbufLoader::size-prepared] will be emitted as
145// soon as the image has enough information to determine the size of
146// the image to be used. If you want to scale the image while loading
147// it, you can call [method@GdkPixbuf.PixbufLoader.set_size] in
148// response to this signal.
149// - [signal@GdkPixbuf.PixbufLoader::area-prepared] will be emitted as
150// soon as the pixbuf of the desired has been allocated. You can obtain
151// the `GdkPixbuf` instance by calling [method@GdkPixbuf.PixbufLoader.get_pixbuf].
152// If you want to use it, simply acquire a reference to it. You can
153// also call `gdk_pixbuf_loader_get_pixbuf()` later to get the same
154// pixbuf.
155// - [signal@GdkPixbuf.PixbufLoader::area-updated] will be emitted every
156// time a region is updated. This way you can update a partially
157// completed image. Note that you do not know anything about the
158// completeness of an image from the updated area. For example, in an
159// interlaced image you will need to make several passes before the
160// image is done loading.
161//
162// ## Loading an animation
163//
164// Loading an animation is almost as easy as loading an image. Once the
165// first [signal@GdkPixbuf.PixbufLoader::area-prepared] signal has been
166// emitted, you can call [method@GdkPixbuf.PixbufLoader.get_animation] to
167// get the [class@GdkPixbuf.PixbufAnimation] instance, and then call
168// and [method@GdkPixbuf.PixbufAnimation.get_iter] to get a
169// [class@GdkPixbuf.PixbufAnimationIter] to retrieve the pixbuf for the
170// desired time stamp.
171type PixbufLoader struct {
172 gobject.Object
173}
174
175var xPixbufLoaderGLibType func() types.GType
176
177func PixbufLoaderGLibType() types.GType {
178 return xPixbufLoaderGLibType()
179}
180
181func PixbufLoaderNewFromInternalPtr(ptr uintptr) *PixbufLoader {
182 cls := &PixbufLoader{}
183 cls.Ptr = ptr
184 return cls
185}
186
187var xNewPixbufLoader func() uintptr
188
189// Creates a new pixbuf loader object.
190func NewPixbufLoader() *PixbufLoader {
191 var cls *PixbufLoader
192
193 cret := xNewPixbufLoader()
194
195 if cret == 0 {
196 return nil
197 }
198 cls = &PixbufLoader{}
199 cls.Ptr = cret
200 return cls
201}
202
203var xNewPixbufLoaderWithMimeType func(string, **glib.Error) uintptr
204
205// Creates a new pixbuf loader object that always attempts to parse
206// image data as if it were an image of MIME type @mime_type, instead of
207// identifying the type automatically.
208//
209// This function is useful if you want an error if the image isn't the
210// expected MIME type; for loading image formats that can't be reliably
211// identified by looking at the data; or if the user manually forces a
212// specific MIME type.
213//
214// The list of supported mime types depends on what image loaders
215// are installed, but typically "image/png", "image/jpeg", "image/gif",
216// "image/tiff" and "image/x-xpixmap" are among the supported mime types.
217// To obtain the full list of supported mime types, call
218// gdk_pixbuf_format_get_mime_types() on each of the #GdkPixbufFormat
219// structs returned by gdk_pixbuf_get_formats().
220func NewPixbufLoaderWithMimeType(MimeTypeVar string) (*PixbufLoader, error) {
221 var cls *PixbufLoader
222 var cerr *glib.Error
223
224 cret := xNewPixbufLoaderWithMimeType(MimeTypeVar, &cerr)
225
226 if cret == 0 {
227 return nil, cerr
228 }
229 cls = &PixbufLoader{}
230 cls.Ptr = cret
231 if cerr == nil {
232 return cls, nil
233 }
234 return cls, cerr
235
236}
237
238var xNewPixbufLoaderWithType func(string, **glib.Error) uintptr
239
240// Creates a new pixbuf loader object that always attempts to parse
241// image data as if it were an image of type @image_type, instead of
242// identifying the type automatically.
243//
244// This function is useful if you want an error if the image isn't the
245// expected type; for loading image formats that can't be reliably
246// identified by looking at the data; or if the user manually forces
247// a specific type.
248//
249// The list of supported image formats depends on what image loaders
250// are installed, but typically "png", "jpeg", "gif", "tiff" and
251// "xpm" are among the supported formats. To obtain the full list of
252// supported image formats, call gdk_pixbuf_format_get_name() on each
253// of the #GdkPixbufFormat structs returned by gdk_pixbuf_get_formats().
254func NewPixbufLoaderWithType(ImageTypeVar string) (*PixbufLoader, error) {
255 var cls *PixbufLoader
256 var cerr *glib.Error
257
258 cret := xNewPixbufLoaderWithType(ImageTypeVar, &cerr)
259
260 if cret == 0 {
261 return nil, cerr
262 }
263 cls = &PixbufLoader{}
264 cls.Ptr = cret
265 if cerr == nil {
266 return cls, nil
267 }
268 return cls, cerr
269
270}
271
272var xPixbufLoaderClose func(uintptr) bool
273
274// Informs a pixbuf loader that no further writes with
275// gdk_pixbuf_loader_write() will occur, so that it can free its
276// internal loading structures.
277//
278// This function also tries to parse any data that hasn't yet been parsed;
279// if the remaining data is partial or corrupt, an error will be returned.
280//
281// If `FALSE` is returned, `error` will be set to an error from the
282// `GDK_PIXBUF_ERROR` or `G_FILE_ERROR` domains.
283//
284// If you're just cancelling a load rather than expecting it to be finished,
285// passing `NULL` for `error` to ignore it is reasonable.
286//
287// Remember that this function does not release a reference on the loader, so
288// you will need to explicitly release any reference you hold.
289func (x *PixbufLoader) Close() (bool, error) {
290 var cerr *glib.Error
291
292 cret := xPixbufLoaderClose(x.GoPointer())
293 if cerr == nil {
294 return cret, nil
295 }
296 return cret, cerr
297
298}
299
300var xPixbufLoaderGetAnimation func(uintptr) uintptr
301
302// Queries the #GdkPixbufAnimation that a pixbuf loader is currently creating.
303//
304// In general it only makes sense to call this function after the
305// [signal@GdkPixbuf.PixbufLoader::area-prepared] signal has been emitted by
306// the loader.
307//
308// If the loader doesn't have enough bytes yet, and hasn't emitted the `area-prepared`
309// signal, this function will return `NULL`.
310func (x *PixbufLoader) GetAnimation() *PixbufAnimation {
311 var cls *PixbufAnimation
312
313 cret := xPixbufLoaderGetAnimation(x.GoPointer())
314
315 if cret == 0 {
316 return nil
317 }
318 gobject.IncreaseRef(cret)
319 cls = &PixbufAnimation{}
320 cls.Ptr = cret
321 return cls
322}
323
324var xPixbufLoaderGetFormat func(uintptr) *PixbufFormat
325
326// Obtains the available information about the format of the
327// currently loading image file.
328func (x *PixbufLoader) GetFormat() *PixbufFormat {
329
330 cret := xPixbufLoaderGetFormat(x.GoPointer())
331 return cret
332}
333
334var xPixbufLoaderGetPixbuf func(uintptr) uintptr
335
336// Queries the #GdkPixbuf that a pixbuf loader is currently creating.
337//
338// In general it only makes sense to call this function after the
339// [signal@GdkPixbuf.PixbufLoader::area-prepared] signal has been
340// emitted by the loader; this means that enough data has been read
341// to know the size of the image that will be allocated.
342//
343// If the loader has not received enough data via gdk_pixbuf_loader_write(),
344// then this function returns `NULL`.
345//
346// The returned pixbuf will be the same in all future calls to the loader,
347// so if you want to keep using it, you should acquire a reference to it.
348//
349// Additionally, if the loader is an animation, it will return the "static
350// image" of the animation (see gdk_pixbuf_animation_get_static_image()).
351func (x *PixbufLoader) GetPixbuf() *Pixbuf {
352 var cls *Pixbuf
353
354 cret := xPixbufLoaderGetPixbuf(x.GoPointer())
355
356 if cret == 0 {
357 return nil
358 }
359 gobject.IncreaseRef(cret)
360 cls = &Pixbuf{}
361 cls.Ptr = cret
362 return cls
363}
364
365var xPixbufLoaderSetSize func(uintptr, int, int)
366
367// Causes the image to be scaled while it is loaded.
368//
369// The desired image size can be determined relative to the original
370// size of the image by calling gdk_pixbuf_loader_set_size() from a
371// signal handler for the ::size-prepared signal.
372//
373// Attempts to set the desired image size are ignored after the
374// emission of the ::size-prepared signal.
375func (x *PixbufLoader) SetSize(WidthVar int, HeightVar int) {
376
377 xPixbufLoaderSetSize(x.GoPointer(), WidthVar, HeightVar)
378
379}
380
381var xPixbufLoaderWrite func(uintptr, []byte, uint, **glib.Error) bool
382
383// Parses the next `count` bytes in the given image buffer.
384func (x *PixbufLoader) Write(BufVar []byte, CountVar uint) (bool, error) {
385 var cerr *glib.Error
386
387 cret := xPixbufLoaderWrite(x.GoPointer(), BufVar, CountVar, &cerr)
388 if cerr == nil {
389 return cret, nil
390 }
391 return cret, cerr
392
393}
394
395var xPixbufLoaderWriteBytes func(uintptr, *glib.Bytes, **glib.Error) bool
396
397// Parses the next contents of the given image buffer.
398func (x *PixbufLoader) WriteBytes(BufferVar *glib.Bytes) (bool, error) {
399 var cerr *glib.Error
400
401 cret := xPixbufLoaderWriteBytes(x.GoPointer(), BufferVar, &cerr)
402 if cerr == nil {
403 return cret, nil
404 }
405 return cret, cerr
406
407}
408
409func (c *PixbufLoader) GoPointer() uintptr {
410 if c == nil {
411 return 0
412 }
413 return c.Ptr
414}
415
416func (c *PixbufLoader) SetGoPointer(ptr uintptr) {
417 c.Ptr = ptr
418}
419
420// This signal is emitted when the pixbuf loader has allocated the
421// pixbuf in the desired size.
422//
423// After this signal is emitted, applications can call
424// gdk_pixbuf_loader_get_pixbuf() to fetch the partially-loaded
425// pixbuf.
426func (x *PixbufLoader) ConnectAreaPrepared(cb *func(PixbufLoader)) uint {
427 cbPtr := uintptr(unsafe.Pointer(cb))
428 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
429 handlerID := gobject.SignalConnect(x.GoPointer(), "area-prepared", cbRefPtr)
430 glib.SaveHandlerMapping(handlerID, cbPtr)
431 return handlerID
432 }
433
434 fcb := func(clsPtr uintptr) {
435 fa := PixbufLoader{}
436 fa.Ptr = clsPtr
437 cbFn := *cb
438
439 cbFn(fa)
440
441 }
442 cbRefPtr := purego.NewCallback(fcb)
443 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
444 handlerID := gobject.SignalConnect(x.GoPointer(), "area-prepared", cbRefPtr)
445 glib.SaveHandlerMapping(handlerID, cbPtr)
446 return handlerID
447}
448
449// This signal is emitted when a significant area of the image being
450// loaded has been updated.
451//
452// Normally it means that a complete scanline has been read in, but
453// it could be a different area as well.
454//
455// Applications can use this signal to know when to repaint
456// areas of an image that is being loaded.
457func (x *PixbufLoader) ConnectAreaUpdated(cb *func(PixbufLoader, int, int, int, int)) uint {
458 cbPtr := uintptr(unsafe.Pointer(cb))
459 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
460 handlerID := gobject.SignalConnect(x.GoPointer(), "area-updated", cbRefPtr)
461 glib.SaveHandlerMapping(handlerID, cbPtr)
462 return handlerID
463 }
464
465 fcb := func(clsPtr uintptr, XVarp int, YVarp int, WidthVarp int, HeightVarp int) {
466 fa := PixbufLoader{}
467 fa.Ptr = clsPtr
468 cbFn := *cb
469
470 cbFn(fa, XVarp, YVarp, WidthVarp, HeightVarp)
471
472 }
473 cbRefPtr := purego.NewCallback(fcb)
474 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
475 handlerID := gobject.SignalConnect(x.GoPointer(), "area-updated", cbRefPtr)
476 glib.SaveHandlerMapping(handlerID, cbPtr)
477 return handlerID
478}
479
480// This signal is emitted when gdk_pixbuf_loader_close() is called.
481//
482// It can be used by different parts of an application to receive
483// notification when an image loader is closed by the code that
484// drives it.
485func (x *PixbufLoader) ConnectClosed(cb *func(PixbufLoader)) uint {
486 cbPtr := uintptr(unsafe.Pointer(cb))
487 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
488 handlerID := gobject.SignalConnect(x.GoPointer(), "closed", cbRefPtr)
489 glib.SaveHandlerMapping(handlerID, cbPtr)
490 return handlerID
491 }
492
493 fcb := func(clsPtr uintptr) {
494 fa := PixbufLoader{}
495 fa.Ptr = clsPtr
496 cbFn := *cb
497
498 cbFn(fa)
499
500 }
501 cbRefPtr := purego.NewCallback(fcb)
502 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
503 handlerID := gobject.SignalConnect(x.GoPointer(), "closed", cbRefPtr)
504 glib.SaveHandlerMapping(handlerID, cbPtr)
505 return handlerID
506}
507
508// This signal is emitted when the pixbuf loader has been fed the
509// initial amount of data that is required to figure out the size
510// of the image that it will create.
511//
512// Applications can call gdk_pixbuf_loader_set_size() in response
513// to this signal to set the desired size to which the image
514// should be scaled.
515func (x *PixbufLoader) ConnectSizePrepared(cb *func(PixbufLoader, int, int)) uint {
516 cbPtr := uintptr(unsafe.Pointer(cb))
517 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
518 handlerID := gobject.SignalConnect(x.GoPointer(), "size-prepared", cbRefPtr)
519 glib.SaveHandlerMapping(handlerID, cbPtr)
520 return handlerID
521 }
522
523 fcb := func(clsPtr uintptr, WidthVarp int, HeightVarp int) {
524 fa := PixbufLoader{}
525 fa.Ptr = clsPtr
526 cbFn := *cb
527
528 cbFn(fa, WidthVarp, HeightVarp)
529
530 }
531 cbRefPtr := purego.NewCallback(fcb)
532 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
533 handlerID := gobject.SignalConnect(x.GoPointer(), "size-prepared", cbRefPtr)
534 glib.SaveHandlerMapping(handlerID, cbPtr)
535 return handlerID
536}
537
538func init() {
539 core.SetPackageName("GDKPIXBUF", "gdk-pixbuf-2.0")
540 core.SetSharedLibraries("GDKPIXBUF", []string{"libgdk_pixbuf-2.0.so.0"})
541 var libs []uintptr
542 for _, libPath := range core.GetPaths("GDKPIXBUF") {
543 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
544 if err != nil {
545 panic(err)
546 }
547 libs = append(libs, lib)
548 }
549
550 core.PuregoSafeRegister(&xPixbufLoaderGLibType, libs, "gdk_pixbuf_loader_get_type")
551
552 core.PuregoSafeRegister(&xNewPixbufLoader, libs, "gdk_pixbuf_loader_new")
553 core.PuregoSafeRegister(&xNewPixbufLoaderWithMimeType, libs, "gdk_pixbuf_loader_new_with_mime_type")
554 core.PuregoSafeRegister(&xNewPixbufLoaderWithType, libs, "gdk_pixbuf_loader_new_with_type")
555
556 core.PuregoSafeRegister(&xPixbufLoaderClose, libs, "gdk_pixbuf_loader_close")
557 core.PuregoSafeRegister(&xPixbufLoaderGetAnimation, libs, "gdk_pixbuf_loader_get_animation")
558 core.PuregoSafeRegister(&xPixbufLoaderGetFormat, libs, "gdk_pixbuf_loader_get_format")
559 core.PuregoSafeRegister(&xPixbufLoaderGetPixbuf, libs, "gdk_pixbuf_loader_get_pixbuf")
560 core.PuregoSafeRegister(&xPixbufLoaderSetSize, libs, "gdk_pixbuf_loader_set_size")
561 core.PuregoSafeRegister(&xPixbufLoaderWrite, libs, "gdk_pixbuf_loader_write")
562 core.PuregoSafeRegister(&xPixbufLoaderWriteBytes, libs, "gdk_pixbuf_loader_write_bytes")
563
564}