1 /* This is a demo of the high-performance GUIX graphics framework. */
2
3 #include <stdio.h>
4 #include "gx_api.h"
5 #include "all_widgets_1555xrgb_resources.h"
6 #include "all_widgets_1555xrgb_specifications.h"
7 #include "gx_system.h"
8
9 extern VOID memory_free(VOID *mem);
10
11 GX_PIXELMAP pixelmap_memory[2];
12 GX_PIXELMAP *png_to_1555xrgb_map = GX_NULL;
13 GX_PIXELMAP *jpeg_to_1555xrgb_map = GX_NULL;
14
15 GX_IMAGE_READER image_reader;
16 GX_UBYTE image_reader_mode = GX_IMAGE_READER_MODE_ALPHA | GX_IMAGE_READER_MODE_COMPRESS | GX_IMAGE_READER_MODE_DITHER;
17 GX_UBYTE output_color_format = GX_COLOR_FORMAT_1555XRGB;
18 GX_BOOL do_color_convert = GX_TRUE;
19
20 /* Convert png/jpeg 4444argb format pixelmap. */
png_jpeg_to_1555xrgb_convert()21 void png_jpeg_to_1555xrgb_convert()
22 {
23 GX_PIXELMAP *pixelmap;
24
25 png_to_1555xrgb_map = &pixelmap_memory[0];
26 jpeg_to_1555xrgb_map = &pixelmap_memory[1];
27
28 gx_widget_pixelmap_get((GX_WIDGET *)&image_convert_screen.image_convert_screen_png_to_1555xrgb_win,
29 GX_PIXELMAP_ID_RED_APPLE_PNG, &pixelmap);
30
31 gx_image_reader_create(&image_reader,
32 pixelmap->gx_pixelmap_data,
33 pixelmap->gx_pixelmap_data_size,
34 output_color_format, image_reader_mode);
35
36 if (gx_image_reader_start(&image_reader, png_to_1555xrgb_map) != GX_SUCCESS)
37 {
38 png_to_1555xrgb_map = GX_NULL;
39 }
40
41 gx_widget_pixelmap_get((GX_WIDGET *)&image_convert_screen.image_convert_screen_jpeg_to_1555xrgb_win,
42 GX_PIXELMAP_ID_ICON_FOOT_JPEG, &pixelmap);
43
44 gx_image_reader_create(&image_reader,
45 pixelmap->gx_pixelmap_data,
46 pixelmap->gx_pixelmap_data_size,
47 output_color_format, image_reader_mode);
48
49 if (gx_image_reader_start(&image_reader, jpeg_to_1555xrgb_map) != GX_SUCCESS)
50 {
51 jpeg_to_1555xrgb_map = GX_NULL;
52 }
53 }
54
55 /* Cleanup converted pixlemap. */
cleanup_output_pixelmaps()56 void cleanup_output_pixelmaps()
57 {
58 if (png_to_1555xrgb_map)
59 {
60 if (png_to_1555xrgb_map->gx_pixelmap_data)
61 {
62 memory_free((VOID *)png_to_1555xrgb_map->gx_pixelmap_data);
63 png_to_1555xrgb_map->gx_pixelmap_data = GX_NULL;
64 }
65
66 if (png_to_1555xrgb_map->gx_pixelmap_aux_data)
67 {
68 memory_free((VOID *)png_to_1555xrgb_map->gx_pixelmap_aux_data);
69 png_to_1555xrgb_map->gx_pixelmap_aux_data = GX_NULL;
70 }
71 png_to_1555xrgb_map = GX_NULL;
72 }
73
74 if (jpeg_to_1555xrgb_map)
75 {
76 if (jpeg_to_1555xrgb_map->gx_pixelmap_data)
77 {
78 memory_free((VOID *)jpeg_to_1555xrgb_map->gx_pixelmap_data);
79 jpeg_to_1555xrgb_map->gx_pixelmap_data = GX_NULL;
80 }
81
82 if (jpeg_to_1555xrgb_map->gx_pixelmap_aux_data)
83 {
84 memory_free((VOID *)jpeg_to_1555xrgb_map->gx_pixelmap_aux_data);
85 jpeg_to_1555xrgb_map->gx_pixelmap_aux_data = GX_NULL;
86 }
87 jpeg_to_1555xrgb_map = GX_NULL;
88 }
89 }
90
91
mark_dirty()92 void mark_dirty()
93 {
94 gx_system_dirty_mark((GX_WIDGET *)&image_convert_screen.image_convert_screen_png_to_1555xrgb_win);
95 gx_system_dirty_mark((GX_WIDGET *)&image_convert_screen.image_convert_screen_jpeg_to_1555xrgb_win);
96 }
97
convert_start()98 void convert_start()
99 {
100 cleanup_output_pixelmaps();
101 png_jpeg_to_1555xrgb_convert();
102
103 mark_dirty();
104 }
105
image_convert_screen_handler(GX_WINDOW * window,GX_EVENT * event_ptr)106 UINT image_convert_screen_handler(GX_WINDOW *window, GX_EVENT *event_ptr)
107 {
108 switch (event_ptr->gx_event_type)
109 {
110 case GX_EVENT_SHOW:
111 gx_window_event_process(window, event_ptr);
112 GX_ENTER_CRITICAL
113 png_jpeg_to_1555xrgb_convert();
114 GX_EXIT_CRITICAL
115 break;
116
117 case GX_EVENT_HIDE:
118 gx_window_event_process(window, event_ptr);
119 cleanup_output_pixelmaps();
120 break;
121
122 case GX_SIGNAL(ID_COLOR_CONVERT, GX_EVENT_TOGGLE_ON):
123 do_color_convert = GX_TRUE;
124 mark_dirty();
125 break;
126
127 case GX_SIGNAL(ID_COLOR_CONVERT, GX_EVENT_TOGGLE_OFF):
128 do_color_convert = GX_FALSE;
129 mark_dirty();
130 break;
131
132 case GX_SIGNAL(ID_ALPHA, GX_EVENT_TOGGLE_ON):
133 image_reader_mode |= GX_IMAGE_READER_MODE_ALPHA;
134 convert_start();
135 break;
136
137 case GX_SIGNAL(ID_ALPHA, GX_EVENT_TOGGLE_OFF):
138 image_reader_mode &= ~GX_IMAGE_READER_MODE_ALPHA;
139 convert_start();
140 break;
141
142 case GX_SIGNAL(ID_COMPRESSED, GX_EVENT_TOGGLE_ON):
143 image_reader_mode |= GX_IMAGE_READER_MODE_COMPRESS;
144 convert_start();
145 break;
146
147 case GX_SIGNAL(ID_COMPRESSED, GX_EVENT_TOGGLE_OFF):
148 image_reader_mode &= ~GX_IMAGE_READER_MODE_COMPRESS;
149 convert_start();
150 break;
151
152 case GX_SIGNAL(ID_DITHER, GX_EVENT_TOGGLE_ON):
153 image_reader_mode |= GX_IMAGE_READER_MODE_DITHER;
154 convert_start();
155 break;
156
157 case GX_SIGNAL(ID_DITHER, GX_EVENT_TOGGLE_OFF):
158 image_reader_mode &= ~GX_IMAGE_READER_MODE_DITHER;
159 convert_start();
160 break;
161
162 case GX_SIGNAL(ID_ALPHAMAP, GX_EVENT_TOGGLE_ON):
163 output_color_format = GX_COLOR_FORMAT_8BIT_ALPHAMAP;
164 convert_start();
165 break;
166
167 case GX_SIGNAL(ID_ALPHAMAP, GX_EVENT_TOGGLE_OFF):
168 output_color_format = GX_COLOR_FORMAT_1555XRGB;
169 convert_start();
170 break;
171
172 default:
173 return next_button_handler(window, event_ptr);
174 }
175 return GX_SUCCESS;
176 }
177
png_to_1555xrgb_win_draw(GX_WINDOW * window)178 VOID png_to_1555xrgb_win_draw(GX_WINDOW *window)
179 {
180 int xpos;
181 int ypos;
182
183 if (do_color_convert)
184 {
185 gx_widget_background_draw(window);
186
187 if (png_to_1555xrgb_map)
188 {
189 xpos = window->gx_window_client.gx_rectangle_left + 10;
190 ypos = window->gx_widget_clip.gx_rectangle_top + 10;
191
192 gx_context_fill_color_set(window->gx_widget_normal_fill_color);
193
194 gx_canvas_pixelmap_draw(xpos, ypos, png_to_1555xrgb_map);
195 }
196 }
197 else
198 {
199 gx_window_draw(window);
200 }
201 }
202
jpeg_to_1555xrgb_win_draw(GX_WINDOW * window)203 VOID jpeg_to_1555xrgb_win_draw(GX_WINDOW *window)
204 {
205 int xpos;
206 int ypos;
207
208 if (do_color_convert)
209 {
210 gx_widget_background_draw(window);
211
212 if (jpeg_to_1555xrgb_map)
213 {
214 xpos = window->gx_window_client.gx_rectangle_left + 10;
215 ypos = window->gx_widget_clip.gx_rectangle_top + 10;
216
217 gx_context_fill_color_set(window->gx_widget_normal_fill_color);
218
219 gx_canvas_pixelmap_draw(xpos, ypos, jpeg_to_1555xrgb_map);
220 }
221 }
222 else
223 {
224 gx_window_draw(window);
225 }
226 }
227