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_4444argb_resources.h"
6 #include "all_widgets_4444argb_specifications.h"
7 
8 extern VOID memory_free(VOID *mem);
9 
10 GX_PIXELMAP pixelmap_memory[2];
11 GX_PIXELMAP *png_to_4444argb_map = GX_NULL;
12 GX_PIXELMAP *jpeg_to_4444argb_map = GX_NULL;
13 
14 GX_IMAGE_READER  image_reader;
15 GX_UBYTE image_reader_mode = GX_IMAGE_READER_MODE_ALPHA | GX_IMAGE_READER_MODE_COMPRESS | GX_IMAGE_READER_MODE_DITHER;
16 GX_UBYTE output_color_format = GX_COLOR_FORMAT_4444ARGB;
17 
18 /* Convert png/jpeg 4444argb format pixelmap. */
png_jpeg_to_4444argb_convert()19 void png_jpeg_to_4444argb_convert()
20 {
21 GX_PIXELMAP *pixelmap;
22 
23     png_to_4444argb_map = &pixelmap_memory[0];
24     jpeg_to_4444argb_map = &pixelmap_memory[1];
25 
26     gx_widget_pixelmap_get((GX_WIDGET *)&image_convert_screen.image_convert_screen_png_to_4444argb_win,
27         GX_PIXELMAP_ID_RED_APPLE_PNG, &pixelmap);
28 
29     gx_image_reader_create(&image_reader,
30         pixelmap->gx_pixelmap_data,
31         pixelmap->gx_pixelmap_data_size,
32         output_color_format, image_reader_mode);
33 
34     if (gx_image_reader_start(&image_reader, png_to_4444argb_map) != GX_SUCCESS)
35     {
36         png_to_4444argb_map = GX_NULL;
37     }
38 
39     gx_widget_pixelmap_get((GX_WIDGET *)&image_convert_screen.image_convert_screen_jpeg_to_4444argb_win,
40         GX_PIXELMAP_ID_ICON_FOOT_JPEG, &pixelmap);
41 
42     gx_image_reader_create(&image_reader,
43         pixelmap->gx_pixelmap_data,
44         pixelmap->gx_pixelmap_data_size,
45         output_color_format, image_reader_mode);
46 
47     if (gx_image_reader_start(&image_reader, jpeg_to_4444argb_map) != GX_SUCCESS)
48     {
49         jpeg_to_4444argb_map = GX_NULL;
50     }
51 }
52 
53 /* Cleanup converted pixlemap. */
cleanup_output_pixelmaps()54 void cleanup_output_pixelmaps()
55 {
56     if (png_to_4444argb_map)
57     {
58         if (png_to_4444argb_map->gx_pixelmap_data)
59         {
60             memory_free((VOID *)png_to_4444argb_map->gx_pixelmap_data);
61             png_to_4444argb_map->gx_pixelmap_data = GX_NULL;
62         }
63 
64         if (png_to_4444argb_map->gx_pixelmap_aux_data)
65         {
66             memory_free((VOID *)png_to_4444argb_map->gx_pixelmap_aux_data);
67             png_to_4444argb_map->gx_pixelmap_aux_data = GX_NULL;
68         }
69         png_to_4444argb_map = GX_NULL;
70     }
71 
72     if (jpeg_to_4444argb_map)
73     {
74         if (jpeg_to_4444argb_map->gx_pixelmap_data)
75         {
76             memory_free((VOID *)jpeg_to_4444argb_map->gx_pixelmap_data);
77             jpeg_to_4444argb_map->gx_pixelmap_data = GX_NULL;
78         }
79 
80         if (jpeg_to_4444argb_map->gx_pixelmap_aux_data)
81         {
82             memory_free((VOID *)jpeg_to_4444argb_map->gx_pixelmap_aux_data);
83             jpeg_to_4444argb_map->gx_pixelmap_aux_data = GX_NULL;
84         }
85         jpeg_to_4444argb_map = GX_NULL;
86     }
87 }
88 
89 
convert_start()90 void convert_start()
91 {
92     cleanup_output_pixelmaps();
93     png_jpeg_to_4444argb_convert();
94     gx_system_dirty_mark((GX_WIDGET *)&image_convert_screen.image_convert_screen_png_to_4444argb_win);
95     gx_system_dirty_mark((GX_WIDGET *)&image_convert_screen.image_convert_screen_jpeg_to_4444argb_win);
96 }
97 
image_convert_screen_handler(GX_WINDOW * window,GX_EVENT * event_ptr)98 UINT image_convert_screen_handler(GX_WINDOW *window, GX_EVENT *event_ptr)
99 {
100     switch (event_ptr->gx_event_type)
101     {
102     case GX_EVENT_SHOW:
103         gx_window_event_process(window, event_ptr);
104         png_jpeg_to_4444argb_convert();
105         break;
106 
107     case GX_EVENT_HIDE:
108         gx_window_event_process(window, event_ptr);
109         cleanup_output_pixelmaps();
110         break;
111 
112     case GX_SIGNAL(ID_ALPHA, GX_EVENT_TOGGLE_ON):
113         image_reader_mode |= GX_IMAGE_READER_MODE_ALPHA;
114         convert_start();
115         break;
116 
117     case GX_SIGNAL(ID_ALPHA, GX_EVENT_TOGGLE_OFF):
118         image_reader_mode &= ~GX_IMAGE_READER_MODE_ALPHA;
119         convert_start();
120         break;
121 
122     case GX_SIGNAL(ID_COMPRESSED, GX_EVENT_TOGGLE_ON):
123         image_reader_mode |= GX_IMAGE_READER_MODE_COMPRESS;
124         convert_start();
125         break;
126 
127     case GX_SIGNAL(ID_COMPRESSED, GX_EVENT_TOGGLE_OFF):
128         image_reader_mode &= ~GX_IMAGE_READER_MODE_COMPRESS;
129         convert_start();
130         break;
131 
132     case GX_SIGNAL(ID_DITHER, GX_EVENT_TOGGLE_ON):
133         image_reader_mode |= GX_IMAGE_READER_MODE_DITHER;
134         convert_start();
135         break;
136 
137     case GX_SIGNAL(ID_DITHER, GX_EVENT_TOGGLE_OFF):
138         image_reader_mode &= ~GX_IMAGE_READER_MODE_DITHER;
139         convert_start();
140         break;
141 
142     case GX_SIGNAL(ID_ALPHAMAP, GX_EVENT_TOGGLE_ON):
143         output_color_format = GX_COLOR_FORMAT_8BIT_ALPHAMAP;
144         convert_start();
145         break;
146 
147     case GX_SIGNAL(ID_ALPHAMAP, GX_EVENT_TOGGLE_OFF):
148         output_color_format = GX_COLOR_FORMAT_4444ARGB;
149         convert_start();
150         break;
151 
152     default:
153         return next_button_handler(window, event_ptr);
154     }
155     return GX_SUCCESS;
156 }
157 
png_to_4444argb_win_draw(GX_WINDOW * window)158 VOID png_to_4444argb_win_draw(GX_WINDOW *window)
159 {
160     int xpos;
161     int ypos;
162 
163     gx_widget_background_draw(window);
164 
165     if (png_to_4444argb_map)
166     {
167         xpos = window->gx_window_client.gx_rectangle_left + 10;
168         ypos = window->gx_widget_clip.gx_rectangle_top + 10;
169 
170         gx_context_fill_color_set(window->gx_widget_normal_fill_color);
171 
172         gx_canvas_pixelmap_draw(xpos, ypos, png_to_4444argb_map);
173     }
174 }
175 
jpeg_to_4444argb_win_draw(GX_WINDOW * window)176 VOID jpeg_to_4444argb_win_draw(GX_WINDOW *window)
177 {
178     int xpos;
179     int ypos;
180 
181     gx_widget_background_draw(window);
182 
183     if (jpeg_to_4444argb_map)
184     {
185         xpos = window->gx_window_client.gx_rectangle_left + 10;
186         ypos = window->gx_widget_clip.gx_rectangle_top + 10;
187 
188         gx_context_fill_color_set(window->gx_widget_normal_fill_color);
189 
190         gx_canvas_pixelmap_draw(xpos, ypos, jpeg_to_4444argb_map);
191     }
192 }
193