/[projet1]/public/pc/shared_libraries/freeimage/v3.12.0/Examples/Linux/linux-gtk.c
Defence Force logotype

Contents of /public/pc/shared_libraries/freeimage/v3.12.0/Examples/Linux/linux-gtk.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 126 - (show annotations)
Mon Jul 13 12:20:10 2009 UTC (10 years, 7 months ago) by dbug
File MIME type: text/plain
File size: 2135 byte(s)
Added some shared libraries (UnitTest++, and FreeImage) to avoid having every single project brings its own libraries.
Ideally people should add them in a way we can upgrade versions without breaking things:
-> public/pc/shared_libraries/library_name/library_version/actuall_content
1 #include <gtk/gtk.h>
2 #include "FreeImage.h"
3
4 void destroy(GtkWidget * widget, gpointer data) {
5 gtk_main_quit();
6 }
7
8 int main(int argc, char *argv[])
9 {
10 GtkWidget *window, *imagebox;
11 GdkVisual *visual;
12 GdkImage *image;
13 FIBITMAP *dib;
14 int y;
15
16 // initialize the FreeImage library
17 FreeImage_Initialise();
18
19 dib = FreeImage_Load(FIF_PNG, "freeimage.png", PNG_DEFAULT);
20
21 gtk_init(&argc, &argv);
22
23 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
24
25 gtk_signal_connect(GTK_OBJECT(window), "destroy",
26 GTK_SIGNAL_FUNC(destroy), NULL);
27
28 visual = gdk_visual_get_system();
29
30 image = gdk_image_new(GDK_IMAGE_NORMAL,visual,
31 FreeImage_GetWidth(dib),FreeImage_GetHeight(dib));
32
33 g_print("picture: %d bpp\n"
34 "system: %d bpp byteorder: %d\n"
35 " redbits: %d greenbits: %d bluebits: %d\n"
36 "image: %d bpp %d bytes/pixel\n",
37 FreeImage_GetBPP(dib),
38 visual->depth,visual->byte_order,
39 visual->red_prec,visual->green_prec,visual->blue_prec,
40 image->depth,image->bpp );
41
42 if (FreeImage_GetBPP(dib) != (image->bpp << 3)) {
43 FIBITMAP *ptr;
44
45 switch (image->bpp) {
46 case 1:
47 ptr = FreeImage_ConvertTo8Bits(dib);
48 break;
49
50 case 2:
51 if (image->depth == 15) {
52 ptr = FreeImage_ConvertTo16Bits555(dib);
53 } else {
54 ptr = FreeImage_ConvertTo16Bits565(dib);
55 }
56
57 break;
58 case 3:
59 ptr = FreeImage_ConvertTo24Bits(dib);
60 break;
61
62 default:
63 case 4:
64 ptr = FreeImage_ConvertTo32Bits(dib);
65 break;
66 }
67
68 FreeImage_Unload(dib);
69 dib = ptr;
70 }
71
72 //makes it upside down :(
73 // memcpy(image->mem, FreeImage_GetBits(dib), image->bpl * image->height);
74
75 BYTE *ptr = FreeImage_GetBits(dib);
76
77 for (y = 0; y < image->height; y++) {
78 memcpy(image->mem + (y * image->bpl),
79 ptr + ((image->height - y - 1) * image->bpl),
80 image->bpl);
81 }
82
83 FreeImage_Unload(dib);
84
85 imagebox = gtk_image_new(image, NULL);
86 gtk_container_add(GTK_CONTAINER(window), imagebox);
87
88 gtk_widget_show(imagebox);
89 gtk_widget_show(window);
90
91 gtk_main();
92
93 // release the FreeImage library
94 FreeImage_DeInitialise();
95
96 return 0;
97 }

  ViewVC Help
Powered by ViewVC 1.1.26