summaryrefslogtreecommitdiff
path: root/apps/plugins/test_resize.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/test_resize.c')
-rw-r--r--apps/plugins/test_resize.c127
1 files changed, 127 insertions, 0 deletions
diff --git a/apps/plugins/test_resize.c b/apps/plugins/test_resize.c
new file mode 100644
index 0000000000..8583613d99
--- /dev/null
+++ b/apps/plugins/test_resize.c
@@ -0,0 +1,127 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007 Jonas Hurrelmann
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20/* Resizing test plugin. Loads /test.bmp (max 100x100) and displays a resized
21 * version. Use the scrollwheel or the left/right keys to change the size of
22 * the resizded version.
23 */
24
25#include "plugin.h"
26#include "pluginlib_actions.h"
27#include "bmp.h"
28
29PLUGIN_HEADER
30
31static struct plugin_api* rb;
32
33const struct button_mapping *plugin_contexts[]
34= {generic_actions, generic_directions};
35
36#define NB_ACTION_CONTEXTS sizeof(plugin_contexts)/sizeof(plugin_contexts[0])
37
38/* Key assignement */
39#if (CONFIG_KEYPAD == IPOD_1G2G_PAD) \
40 || (CONFIG_KEYPAD == IPOD_3G_PAD) \
41 || (CONFIG_KEYPAD == IPOD_4G_PAD) \
42 || (CONFIG_KEYPAD == SANSA_E200_PAD)
43#define SIZE_INCREASE PLA_UP
44#define SIZE_INCREASE_REPEAT PLA_UP_REPEAT
45#define SIZE_DECREASE PLA_DOWN
46#define SIZE_DECREASE_REPEAT PLA_DOWN_REPEAT
47#else
48#define SIZE_INCREASE PLA_RIGHT
49#define SIZE_INCREASE_REPEAT PLA_RIGHT_REPEAT
50#define SIZE_DECREASE PLA_LEFT
51#define SIZE_DECREASE_REPEAT PLA_LEFT_REPEAT
52#endif
53#define BUTTON_QUIT PLA_QUIT
54
55#define MAX_OUTPUT_WIDTH 200
56#define MAX_OUTPUT_HEIGHT 200
57
58static fb_data *b;
59
60static struct bitmap input_bmp;
61static struct bitmap output_bmp;
62
63static fb_data input_bmp_data[100*100];
64static fb_data output_bmp_data[MAX_OUTPUT_WIDTH*MAX_OUTPUT_HEIGHT];
65
66
67/* this is the plugin entry point */
68enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
69{
70 (void)parameter;
71
72 rb = api;
73 b = rb->lcd_framebuffer;
74
75 rb->lcd_set_background(LCD_RGBPACK(0,0,0));
76 rb->lcd_clear_display(); // TODO: Optimizes this by e.g. invalidating rects
77
78 input_bmp.data = (char*)input_bmp_data;
79 output_bmp.data = (char*)output_bmp_data;
80
81 int ret = rb->read_bmp_file("/test.bmp", &input_bmp, sizeof(input_bmp_data),
82 FORMAT_NATIVE);
83
84 if (ret < 0) {
85 rb->splash(HZ, "Could not load /test.bmp");
86 return PLUGIN_ERROR;
87 }
88
89 int button;
90 output_bmp.width = 50;
91 output_bmp.height = 50;
92
93 DEBUGF("input_bmp_data starts at %p\n", input_bmp_data);
94 DEBUGF("output_bmp_data starts at %p\n", output_bmp_data);
95
96 while(1) {
97 rb->lcd_clear_display();
98 rb->lcd_bitmap(input_bmp_data, 0, 0, input_bmp.width, input_bmp.height);
99
100 simple_resize_bitmap(&input_bmp, &output_bmp);
101
102 rb->lcd_bitmap(output_bmp_data, 0, 100, output_bmp.width,
103 output_bmp.height);
104
105 rb->lcd_update();
106 button = pluginlib_getaction(rb, HZ,
107 plugin_contexts, NB_ACTION_CONTEXTS);
108 switch (button) {
109 case BUTTON_QUIT:
110 return PLUGIN_OK;
111 case SIZE_INCREASE:
112 case SIZE_INCREASE_REPEAT:
113 if (output_bmp.width < MAX_OUTPUT_WIDTH - 2)
114 output_bmp.width += 2;
115 if (output_bmp.height < MAX_OUTPUT_HEIGHT - 2)
116 output_bmp.height += 2;
117 break;
118
119 case SIZE_DECREASE:
120 case SIZE_DECREASE_REPEAT:
121 if (output_bmp.width >= 2) output_bmp.width -= 2;
122 if (output_bmp.height >= 2) output_bmp.height -= 2;
123 break;
124 }
125 }
126 return PLUGIN_OK;
127}