Nicolas Pennequin | a7d0877 | 2007-12-11 18:54:50 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2007 Jonas Hurrelmann |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 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. |
Nicolas Pennequin | a7d0877 | 2007-12-11 18:54:50 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | |
| 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. |
| 25 | */ |
| 26 | |
| 27 | #include "plugin.h" |
| 28 | #include "pluginlib_actions.h" |
| 29 | #include "bmp.h" |
| 30 | |
| 31 | PLUGIN_HEADER |
| 32 | |
Steve Bavin | 6526577 | 2008-05-13 09:57:56 +0000 | [diff] [blame] | 33 | static const struct plugin_api* rb; |
Nicolas Pennequin | a7d0877 | 2007-12-11 18:54:50 +0000 | [diff] [blame] | 34 | |
| 35 | const struct button_mapping *plugin_contexts[] |
| 36 | = {generic_actions, generic_directions}; |
| 37 | |
| 38 | #define NB_ACTION_CONTEXTS sizeof(plugin_contexts)/sizeof(plugin_contexts[0]) |
| 39 | |
| 40 | /* Key assignement */ |
Nicolas Pennequin | a7d0877 | 2007-12-11 18:54:50 +0000 | [diff] [blame] | 41 | #define SIZE_INCREASE PLA_UP |
| 42 | #define SIZE_INCREASE_REPEAT PLA_UP_REPEAT |
| 43 | #define SIZE_DECREASE PLA_DOWN |
| 44 | #define SIZE_DECREASE_REPEAT PLA_DOWN_REPEAT |
Nicolas Pennequin | a7d0877 | 2007-12-11 18:54:50 +0000 | [diff] [blame] | 45 | |
Nicolas Pennequin | 6aa36c6 | 2008-04-06 22:30:50 +0000 | [diff] [blame] | 46 | #define WIDTH_INCREASE PLA_RIGHT |
| 47 | #define WIDTH_INCREASE_REPEAT PLA_RIGHT_REPEAT |
| 48 | #define WIDTH_DECREASE PLA_LEFT |
| 49 | #define WIDTH_DECREASE_REPEAT PLA_LEFT_REPEAT |
| 50 | |
| 51 | #define BUTTON_QUIT PLA_QUIT |
| 52 | #define CHANGE_MODE PLA_MENU |
| 53 | |
| 54 | #define MAX_OUTPUT_WIDTH LCD_WIDTH |
| 55 | #define MAX_OUTPUT_HEIGHT LCD_HEIGHT |
Nicolas Pennequin | a7d0877 | 2007-12-11 18:54:50 +0000 | [diff] [blame] | 56 | |
| 57 | static fb_data *b; |
| 58 | |
| 59 | static struct bitmap input_bmp; |
| 60 | static struct bitmap output_bmp; |
| 61 | |
Nicolas Pennequin | 6aa36c6 | 2008-04-06 22:30:50 +0000 | [diff] [blame] | 62 | static fb_data input_bmp_data[200*200]; |
Nicolas Pennequin | a7d0877 | 2007-12-11 18:54:50 +0000 | [diff] [blame] | 63 | static fb_data output_bmp_data[MAX_OUTPUT_WIDTH*MAX_OUTPUT_HEIGHT]; |
| 64 | |
| 65 | |
| 66 | /* this is the plugin entry point */ |
Steve Bavin | 6526577 | 2008-05-13 09:57:56 +0000 | [diff] [blame] | 67 | enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter) |
Nicolas Pennequin | a7d0877 | 2007-12-11 18:54:50 +0000 | [diff] [blame] | 68 | { |
| 69 | (void)parameter; |
| 70 | |
| 71 | rb = api; |
| 72 | b = rb->lcd_framebuffer; |
| 73 | |
| 74 | rb->lcd_set_background(LCD_RGBPACK(0,0,0)); |
| 75 | rb->lcd_clear_display(); // TODO: Optimizes this by e.g. invalidating rects |
| 76 | |
| 77 | input_bmp.data = (char*)input_bmp_data; |
| 78 | output_bmp.data = (char*)output_bmp_data; |
| 79 | |
| 80 | int ret = rb->read_bmp_file("/test.bmp", &input_bmp, sizeof(input_bmp_data), |
| 81 | FORMAT_NATIVE); |
| 82 | |
| 83 | if (ret < 0) { |
| 84 | rb->splash(HZ, "Could not load /test.bmp"); |
| 85 | return PLUGIN_ERROR; |
| 86 | } |
| 87 | |
| 88 | int button; |
| 89 | output_bmp.width = 50; |
| 90 | output_bmp.height = 50; |
| 91 | |
| 92 | DEBUGF("input_bmp_data starts at %p\n", input_bmp_data); |
| 93 | DEBUGF("output_bmp_data starts at %p\n", output_bmp_data); |
| 94 | |
Nicolas Pennequin | 6aa36c6 | 2008-04-06 22:30:50 +0000 | [diff] [blame] | 95 | int scale_algorithm = 0; |
| 96 | |
Nicolas Pennequin | a7d0877 | 2007-12-11 18:54:50 +0000 | [diff] [blame] | 97 | while(1) { |
| 98 | rb->lcd_clear_display(); |
| 99 | rb->lcd_bitmap(input_bmp_data, 0, 0, input_bmp.width, input_bmp.height); |
| 100 | |
Nicolas Pennequin | 6aa36c6 | 2008-04-06 22:30:50 +0000 | [diff] [blame] | 101 | switch ( scale_algorithm ) { |
| 102 | case 0: |
| 103 | smooth_resize_bitmap(&input_bmp, &output_bmp); |
| 104 | rb->lcd_putsxy(0,0,"smooth_resize_bitmap"); |
| 105 | break; |
| 106 | case 1: |
| 107 | simple_resize_bitmap(&input_bmp, &output_bmp); |
| 108 | rb->lcd_putsxy(0,0,"simple_resize_bitmap"); |
| 109 | break; |
| 110 | } |
Nicolas Pennequin | a7d0877 | 2007-12-11 18:54:50 +0000 | [diff] [blame] | 111 | |
| 112 | rb->lcd_bitmap(output_bmp_data, 0, 100, output_bmp.width, |
| 113 | output_bmp.height); |
| 114 | |
| 115 | rb->lcd_update(); |
| 116 | button = pluginlib_getaction(rb, HZ, |
| 117 | plugin_contexts, NB_ACTION_CONTEXTS); |
| 118 | switch (button) { |
| 119 | case BUTTON_QUIT: |
| 120 | return PLUGIN_OK; |
| 121 | case SIZE_INCREASE: |
| 122 | case SIZE_INCREASE_REPEAT: |
| 123 | if (output_bmp.width < MAX_OUTPUT_WIDTH - 2) |
| 124 | output_bmp.width += 2; |
| 125 | if (output_bmp.height < MAX_OUTPUT_HEIGHT - 2) |
| 126 | output_bmp.height += 2; |
| 127 | break; |
| 128 | |
| 129 | case SIZE_DECREASE: |
| 130 | case SIZE_DECREASE_REPEAT: |
Nicolas Pennequin | 6aa36c6 | 2008-04-06 22:30:50 +0000 | [diff] [blame] | 131 | if (output_bmp.width > 2) output_bmp.width -= 2; |
| 132 | if (output_bmp.height > 2) output_bmp.height -= 2; |
| 133 | break; |
| 134 | |
| 135 | case WIDTH_INCREASE: |
| 136 | case WIDTH_INCREASE_REPEAT: |
| 137 | if (output_bmp.width < MAX_OUTPUT_WIDTH - 2) |
| 138 | output_bmp.width += 2; |
| 139 | break; |
| 140 | |
| 141 | case WIDTH_DECREASE: |
| 142 | case WIDTH_DECREASE_REPEAT: |
| 143 | if (output_bmp.width > 2) output_bmp.width -= 2; |
| 144 | break; |
| 145 | |
| 146 | case CHANGE_MODE: |
| 147 | scale_algorithm = (scale_algorithm+1)%2; |
Nicolas Pennequin | a7d0877 | 2007-12-11 18:54:50 +0000 | [diff] [blame] | 148 | break; |
| 149 | } |
| 150 | } |
| 151 | return PLUGIN_OK; |
| 152 | } |