Skip to content

Instantly share code, notes, and snippets.

View angstyloop's full-sized avatar

Sean Allen angstyloop

View GitHub Profile
@angstyloop
angstyloop / threshold2.c
Last active March 7, 2023 00:37
Threshold an image to create a "binary" or "boolean" black and white image, in C with the VIPS library. Revised version of threshold1.c. Uses vips_image_new to create a dummy object. vips_object_local_array is used to create an array of VipsImage pointers - the array is hung off the dummy VipsObject, so everything gets cleaned up when the dummy …
/** threshold2.c
*
* COMPILE
*
* gcc -Wall -o threshold2 threshold2.c `pkg-config vips --cflags --libs`
*
* EXAMPLE
*
* ./threshold2 128 in.png out.png
*
@angstyloop
angstyloop / scale.c
Created March 6, 2023 23:35
Simple GTK 3 example of how to use GtkScale (which inherits from GtkRange) in C.
/** scale.c
*
* GTK3 example of how to use GtkScale (which inherits from GtkRange).
*
* COMPILE
* gcc -Wall -o scale scale.c `pkg-config --libs --cflags gtk+-3.0`
*
* EXAMPLE
* ./scale
*
@angstyloop
angstyloop / threshold_scale.c
Last active March 7, 2023 01:04
Threshold an image with VIPS and a GTK slider UI.
/** threshold_scale.c
*
* Threshold an image with VIPS and a GTK slider UI.
*
* COMPILE
*
* gcc -Wall -o threshold_scale threshold_scale.c `pkg-config vips gtk+-3.0 --cflags --libs`
*
* EXAMPLE
*
@angstyloop
angstyloop / file_chooser_native.c
Created March 7, 2023 06:21
Open a native file chooser with GTK 3 if one is available.
/** file_chooser_native.c
*
* Open a native file chooser with GTK 3 if one is available.
*
* COMPILE
* gcc -Wall -o file_chooser_native file_chooser_native.c `pkg-config gtk+-3.0 --libs --cflags`
*
* EXAMPLE
* ./file_chooser_native
*/
@angstyloop
angstyloop / file_chooser_dialog.c
Created March 7, 2023 06:22
Open a file chooser with GTK 3.
/** file_chooser_dialog.c
*
* Open a file chooser with GTK 3.
*
* COMPILE
* gcc -Wall -o file_chooser_dialog file_chooser_dialog.c `pkg-config gtk+-3.0 --libs --cflags`
*
* EXAMPLE
* ./file_chooser_dialog
*/
@angstyloop
angstyloop / copy.c
Created March 7, 2023 08:19
Copy a file using copy_file_range
/* copy.c
*
* Compile with:
*
* gcc copy.c -o copy -Wall -g
*
* Defines function copy:
*
* Copy a source file to a destination file. If the destination file already
* exists, this clobbers it. If the destination file does not exist, it is
@angstyloop
angstyloop / import_file.c
Created March 7, 2023 09:41
Select a file using a GTK file chooser, and copy it into /tmp (Unix only) using copy_file_range.
/** import_file.c
*
* Import a file to be used by threshold.c and friends.
*
* COMPILE
* gcc -Wall -o import_file import_file.c `pkg-config gtk+-3.0 --libs --cflags`
*
* EXAMPLE
* ./import_file source.png
*/
/** example-0.c
*
* COMPILE
*
* gcc `pkg-config --cflags gtk4` -o example-0 example-0.c `pkg-config --libs gtk4`
*
* EXAMPLE
*
* ./example-0
*
/** example-1.c
*
* COMPILE
*
* gcc `pkg-config --cflags gtk4` -o example-1 example-1.c `pkg-config --libs gtk4`
*
* EXAMPLE
*
* ./example-1
*
/** example-2.c
*
* COMPILE
*
* gcc `pkg-config --cflags gtk4` -o example-2 example-2.c `pkg-config --libs gtk4`
*
* EXAMPLE
*
* ./example-2
*