Don't force double-buffering for sd devices. They apparently are not faster with...
[kugel-rb.git] / apps / plugins / test_resize.c
bloba6a183a54b17ec030696aa77e4d3d9fdbca775c9
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 Jonas Hurrelmann
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 /* Resizing test plugin. Loads /test.bmp (max 100x100) and displays a resized
23 * version. Use the scrollwheel or the left/right keys to change the size of
24 * the resizded version.
27 #include "plugin.h"
28 #include "lib/pluginlib_actions.h"
29 #include "lib/pluginlib_bmp.h"
31 PLUGIN_HEADER
33 const struct button_mapping *plugin_contexts[]
34 = {generic_actions, generic_directions};
36 #define NB_ACTION_CONTEXTS sizeof(plugin_contexts)/sizeof(plugin_contexts[0])
38 /* Key assignement */
39 #define SIZE_INCREASE PLA_UP
40 #define SIZE_INCREASE_REPEAT PLA_UP_REPEAT
41 #define SIZE_DECREASE PLA_DOWN
42 #define SIZE_DECREASE_REPEAT PLA_DOWN_REPEAT
44 #define WIDTH_INCREASE PLA_RIGHT
45 #define WIDTH_INCREASE_REPEAT PLA_RIGHT_REPEAT
46 #define WIDTH_DECREASE PLA_LEFT
47 #define WIDTH_DECREASE_REPEAT PLA_LEFT_REPEAT
49 #define BUTTON_QUIT PLA_QUIT
50 #define CHANGE_MODE PLA_MENU
52 #define MAX_OUTPUT_WIDTH LCD_WIDTH
53 #define MAX_OUTPUT_HEIGHT LCD_HEIGHT
55 static fb_data *b;
57 static struct bitmap input_bmp;
58 static struct bitmap output_bmp;
60 static fb_data input_bmp_data[200*200];
61 static fb_data output_bmp_data[MAX_OUTPUT_WIDTH*MAX_OUTPUT_HEIGHT];
64 /* this is the plugin entry point */
65 enum plugin_status plugin_start(const void* parameter)
67 (void)parameter;
69 b = rb->lcd_framebuffer;
71 rb->lcd_set_background(LCD_RGBPACK(0,0,0));
72 rb->lcd_clear_display(); // TODO: Optimizes this by e.g. invalidating rects
74 input_bmp.data = (char*)input_bmp_data;
75 output_bmp.data = (char*)output_bmp_data;
77 int ret = rb->read_bmp_file("/test.bmp", &input_bmp, sizeof(input_bmp_data),
78 FORMAT_NATIVE, NULL);
80 if (ret < 0) {
81 rb->splash(HZ, "Could not load /test.bmp");
82 return PLUGIN_ERROR;
85 int button;
86 output_bmp.width = 50;
87 output_bmp.height = 50;
89 DEBUGF("input_bmp_data starts at %p\n", input_bmp_data);
90 DEBUGF("output_bmp_data starts at %p\n", output_bmp_data);
92 int scale_algorithm = 0;
94 while(1) {
95 rb->lcd_clear_display();
96 rb->lcd_bitmap(input_bmp_data, 0, 0, input_bmp.width, input_bmp.height);
98 switch ( scale_algorithm ) {
99 case 0:
100 smooth_resize_bitmap(&input_bmp, &output_bmp);
101 rb->lcd_putsxy(0,0,"smooth_resize_bitmap");
102 break;
103 case 1:
104 simple_resize_bitmap(&input_bmp, &output_bmp);
105 rb->lcd_putsxy(0,0,"simple_resize_bitmap");
106 break;
109 rb->lcd_bitmap(output_bmp_data, 0, 100, output_bmp.width,
110 output_bmp.height);
112 rb->lcd_update();
113 button = pluginlib_getaction(HZ,
114 plugin_contexts, NB_ACTION_CONTEXTS);
115 switch (button) {
116 case BUTTON_QUIT:
117 return PLUGIN_OK;
118 case SIZE_INCREASE:
119 case SIZE_INCREASE_REPEAT:
120 if (output_bmp.width < MAX_OUTPUT_WIDTH - 2)
121 output_bmp.width += 2;
122 if (output_bmp.height < MAX_OUTPUT_HEIGHT - 2)
123 output_bmp.height += 2;
124 break;
126 case SIZE_DECREASE:
127 case SIZE_DECREASE_REPEAT:
128 if (output_bmp.width > 2) output_bmp.width -= 2;
129 if (output_bmp.height > 2) output_bmp.height -= 2;
130 break;
132 case WIDTH_INCREASE:
133 case WIDTH_INCREASE_REPEAT:
134 if (output_bmp.width < MAX_OUTPUT_WIDTH - 2)
135 output_bmp.width += 2;
136 break;
138 case WIDTH_DECREASE:
139 case WIDTH_DECREASE_REPEAT:
140 if (output_bmp.width > 2) output_bmp.width -= 2;
141 break;
143 case CHANGE_MODE:
144 scale_algorithm = (scale_algorithm+1)%2;
145 break;
148 return PLUGIN_OK;