A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007 Jonas Hurrelmann
11 *
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.
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 "lib/pluginlib_actions.h"
29#include "lib/pluginlib_bmp.h"
30
31
32
33const struct button_mapping *plugin_contexts[]
34= {pla_main_ctx};
35
36
37/* Key assignement */
38#define SIZE_INCREASE PLA_UP
39#define SIZE_INCREASE_REPEAT PLA_UP_REPEAT
40#define SIZE_DECREASE PLA_DOWN
41#define SIZE_DECREASE_REPEAT PLA_DOWN_REPEAT
42
43#define WIDTH_INCREASE PLA_RIGHT
44#define WIDTH_INCREASE_REPEAT PLA_RIGHT_REPEAT
45#define WIDTH_DECREASE PLA_LEFT
46#define WIDTH_DECREASE_REPEAT PLA_LEFT_REPEAT
47
48#define BUTTON_QUIT PLA_EXIT
49#define CHANGE_MODE PLA_SELECT
50
51#define MAX_OUTPUT_WIDTH LCD_WIDTH
52#define MAX_OUTPUT_HEIGHT LCD_HEIGHT
53
54static fb_data *b;
55
56static struct bitmap input_bmp;
57static struct bitmap output_bmp;
58
59static fb_data input_bmp_data[200*200];
60static fb_data output_bmp_data[MAX_OUTPUT_WIDTH*MAX_OUTPUT_HEIGHT];
61
62
63/* this is the plugin entry point */
64enum plugin_status plugin_start(const void* parameter)
65{
66 (void)parameter;
67 struct viewport *vp_main = rb->lcd_set_viewport(NULL);
68 b = vp_main->buffer->fb_ptr;
69
70 rb->lcd_set_background(LCD_RGBPACK(0,0,0));
71 rb->lcd_clear_display(); // TODO: Optimizes this by e.g. invalidating rects
72
73 input_bmp.data = (char*)input_bmp_data;
74 output_bmp.data = (char*)output_bmp_data;
75
76 int ret = rb->read_bmp_file("/test.bmp", &input_bmp, sizeof(input_bmp_data),
77 FORMAT_NATIVE, NULL);
78
79 if (ret < 0) {
80 rb->splash(HZ, "Could not load /test.bmp");
81 return PLUGIN_ERROR;
82 }
83
84 int button;
85 output_bmp.width = 50;
86 output_bmp.height = 50;
87
88 DEBUGF("input_bmp_data starts at %p\n", input_bmp_data);
89 DEBUGF("output_bmp_data starts at %p\n", output_bmp_data);
90
91 int scale_algorithm = 0;
92
93 while(1) {
94 rb->lcd_clear_display();
95 rb->lcd_bitmap(input_bmp_data, 0, 0, input_bmp.width, input_bmp.height);
96
97 switch ( scale_algorithm ) {
98 case 0:
99 smooth_resize_bitmap(&input_bmp, &output_bmp);
100 rb->lcd_putsxy(0,0,"smooth_resize_bitmap");
101 break;
102 case 1:
103 simple_resize_bitmap(&input_bmp, &output_bmp);
104 rb->lcd_putsxy(0,0,"simple_resize_bitmap");
105 break;
106 }
107
108 rb->lcd_bitmap(output_bmp_data, 0, 100, output_bmp.width,
109 output_bmp.height);
110
111 rb->lcd_update();
112 button = pluginlib_getaction(HZ, plugin_contexts,
113 ARRAYLEN(plugin_contexts));
114 switch (button) {
115 case BUTTON_QUIT:
116 return PLUGIN_OK;
117 case SIZE_INCREASE:
118 case SIZE_INCREASE_REPEAT:
119 if (output_bmp.width < MAX_OUTPUT_WIDTH - 2)
120 output_bmp.width += 2;
121 if (output_bmp.height < MAX_OUTPUT_HEIGHT - 2)
122 output_bmp.height += 2;
123 break;
124
125 case SIZE_DECREASE:
126 case SIZE_DECREASE_REPEAT:
127 if (output_bmp.width > 2) output_bmp.width -= 2;
128 if (output_bmp.height > 2) output_bmp.height -= 2;
129 break;
130
131 case WIDTH_INCREASE:
132 case WIDTH_INCREASE_REPEAT:
133 if (output_bmp.width < MAX_OUTPUT_WIDTH - 2)
134 output_bmp.width += 2;
135 break;
136
137 case WIDTH_DECREASE:
138 case WIDTH_DECREASE_REPEAT:
139 if (output_bmp.width > 2) output_bmp.width -= 2;
140 break;
141
142 case CHANGE_MODE:
143 scale_algorithm = (scale_algorithm+1)%2;
144 break;
145 }
146 }
147 return PLUGIN_OK;
148}