File: ex3.c

package info (click to toggle)
allegro4.4 2%3A4.4.2-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 19,920 kB
  • ctags: 39,951
  • sloc: ansic: 164,225; asm: 17,620; cpp: 3,848; objc: 1,687; sh: 1,131; python: 676; pascal: 179; makefile: 48; perl: 29; lisp: 1
file content (55 lines) | stat: -rw-r--r-- 1,102 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
 *	Example program for the JPGalleg library
 *
 *  Version 2.6, by Angelo Mottola, 2000-2006
 *
 *	This example shows how to save a JPG image to disk.
 */

#include <allegro.h>
#include <jpgalleg.h>


int
main(void)
{
	BITMAP *bmp;

	allegro_init();
	install_keyboard();
	
	jpgalleg_init();

	set_color_depth(32);
	if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) {
		set_color_depth(16);
		if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) {
			set_color_depth(15);
			if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) {
				allegro_message("Unable to init truecolor 640x480 gfx mode: %s", allegro_error);
				return -1;
			}
		}
	}
	
	clear(screen);
	bmp = load_bitmap("cat.tga", NULL);
	if (!bmp) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Error loading cat.tga\n");
		return -1;
	}
	blit(bmp, screen, 0, 0, 0, 0, bmp->w, bmp->h);
	
	readkey();
	
	if (save_jpg("savedcat.jpg", bmp, NULL)) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Error saving savedcat.jpg (error code %d)\n", jpgalleg_error);
		return -1;
	}
	destroy_bitmap(bmp);
	
	return 0;
}
END_OF_MAIN();