IUP

Check-in [f9c7269e5a]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Image loading from blobs / strings for CHICKEN
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f9c7269e5afe21781e42e4714d2ab85ce6d97168
User & Date: murphy 2016-01-01 15:27:21
Context
2016-01-01
15:29
Bumped egg version to 1.8.0 check-in: 80eadca25f user: murphy tags: trunk, v1.8.0
15:27
Image loading from blobs / strings for CHICKEN check-in: f9c7269e5a user: murphy tags: trunk
2015-10-15
05:58
Canvas pointer marshalling for callbacks check-in: fb90ae1afa user: murphy tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to api/base.wiki.

362
363
364
365
366
367
368





369
370
371
372
373
374
375
Creates an image to be shown on a label, button, toggle, or as a cursor from
binary data in RGBA mode.

<h3><a id="image_file"><code><nowiki>(image/file [file path-string?] #:<name> <value> ...) → ihandle?</nowiki></code></a></h3>

Creates an image to be shown on a label, button, toggle, or as a cursor from
data in a file.






<h3><a id="image-save"><code><nowiki>(image-save [handle ihandle?] [file path-string?] [format (or/c symbol? string?)]) → void?</nowiki></code></a></h3>

Saves an image to a file in the given format.

<h2>Focus Functions</h2>








>
>
>
>
>







362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
Creates an image to be shown on a label, button, toggle, or as a cursor from
binary data in RGBA mode.

<h3><a id="image_file"><code><nowiki>(image/file [file path-string?] #:<name> <value> ...) → ihandle?</nowiki></code></a></h3>

Creates an image to be shown on a label, button, toggle, or as a cursor from
data in a file.

<h3><a id="image_blob"><code><nowiki>(image/blob [data bytes?] #:<name> <value> ...) → ihandle?</nowiki></code></a></h3>

Creates an image to be shown on a label, button, toggle, or as a cursor from
data in memory.

<h3><a id="image-save"><code><nowiki>(image-save [handle ihandle?] [file path-string?] [format (or/c symbol? string?)]) → void?</nowiki></code></a></h3>

Saves an image to a file in the given format.

<h2>Focus Functions</h2>

Changes to chicken/iup-base.scm.

1
2
3
4
5
6
7


8
9
10
11
12
13
14
...
628
629
630
631
632
633
634






















635
636
637
638
639
640
641
;; -*- mode: Scheme; tab-width: 2; -*- ;;

;; {{{ Data types

(foreign-declare
	"#include <callback.h>\n"
	"#include <locale.h>\n"


	"#include <iup.h>\n"
	"#include <iupim.h>\n"
	"typedef struct Iclass_ Iclass;\n"
	"struct Ihandle_ { char sig[4]; Iclass *iclass; /* ... */ } ;\n"
	"extern char *iupClassCallbackGetFormat(Iclass *iclass, const char *name);\n")

(define *ihandle-tag* "Ihandle")
................................................................................

(define image/file
	(letrec ([load-image (foreign-lambda ihandle "IupLoadImage" c-string)])
		(make-constructor-procedure
			(lambda (file)
				(or (load-image file) (error 'image/file (attribute #f 'iupim-lasterror)))))))























(define image-save
	(letrec ([save-image (foreign-lambda bool "IupSaveImage" nonnull-ihandle c-string iname/upcase)])
		(lambda (handle file format)
			(unless (save-image handle file format)
				(error 'image-save (attribute #f 'iupim-lasterror))))))

;; }}}







>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
...
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
;; -*- mode: Scheme; tab-width: 2; -*- ;;

;; {{{ Data types

(foreign-declare
	"#include <callback.h>\n"
	"#include <locale.h>\n"
	"#include <im.h>\n"
	"#include <im_binfile.h>\n"
	"#include <iup.h>\n"
	"#include <iupim.h>\n"
	"typedef struct Iclass_ Iclass;\n"
	"struct Ihandle_ { char sig[4]; Iclass *iclass; /* ... */ } ;\n"
	"extern char *iupClassCallbackGetFormat(Iclass *iclass, const char *name);\n")

(define *ihandle-tag* "Ihandle")
................................................................................

(define image/file
	(letrec ([load-image (foreign-lambda ihandle "IupLoadImage" c-string)])
		(make-constructor-procedure
			(lambda (file)
				(or (load-image file) (error 'image/file (attribute #f 'iupim-lasterror)))))))

(define image/blob
	(letrec ([load-image
						(foreign-lambda* ihandle ([scheme-pointer data] [int size])
							"Ihandle *image;"
							"imBinMemoryFileName file;"
							"int oldModule = imBinFileSetCurrentModule(IM_MEMFILE);"
							"file.buffer = data;"
							"file.size = size;"
							"file.reallocate = 0;"
							"image = IupLoadImage((const char *)&file);"
							"imBinFileSetCurrentModule(oldModule);"
							"C_return(image);")])
		(make-constructor-procedure
			(lambda (data)
				(or (load-image
						 data
						 (cond
							[(blob? data) (blob-size data)]
							[(string? data) (string-length data)]
							[else (error 'image/blob "unknown argument type")]))
						(error 'image/blob (attribute #f 'iupim-lasterror)))))))

(define image-save
	(letrec ([save-image (foreign-lambda bool "IupSaveImage" nonnull-ihandle c-string iname/upcase)])
		(lambda (handle file format)
			(unless (save-image handle file format)
				(error 'image-save (attribute #f 'iupim-lasterror))))))

;; }}}

Changes to chicken/iup.scm.

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
	 :children children
	 refresh redraw
	 child-x/y->pos
	 show hide
	 dialog
	 fill gridbox hbox vbox zbox cbox sbox
	 radio normalizer backgroundbox detachbox expandbox scrollbox split
	 image/palette image/rgb image/rgba image/file image-save
	 current-focus focus-next focus-previous
	 menu menu-item menu-separator
	 clipboard timer send-url)
	(import
		scheme chicken foreign
		lolevel data-structures extras srfi-1 srfi-13 srfi-42 srfi-69 irregex
		(only posix setenv))







|







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
	 :children children
	 refresh redraw
	 child-x/y->pos
	 show hide
	 dialog
	 fill gridbox hbox vbox zbox cbox sbox
	 radio normalizer backgroundbox detachbox expandbox scrollbox split
	 image/palette image/rgb image/rgba image/file image/blob image-save
	 current-focus focus-next focus-previous
	 menu menu-item menu-separator
	 clipboard timer send-url)
	(import
		scheme chicken foreign
		lolevel data-structures extras srfi-1 srfi-13 srfi-42 srfi-69 irregex
		(only posix setenv))