A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 136 lines 4.1 kB view raw
1/***************************************************************************** 2 * __________ __ ___. 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 * Source | _// __ \_/ ___\| |/ /| __ \ / __ \ \/ / 5 * Jukebox | | ( (__) ) \___| ( | \_\ ( (__) ) ( 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 * \/ \/ \/ \/ \/ 8 * $Id$ 9 * 10 * Copyright (C) 2009 Andrew Mahone 11 * 12 * scaler benchmark 13 * 14 * This program is free software; you can redistribute it and/or 15 * modify it under the terms of the GNU General Public License 16 * as published by the Free Software Foundation; either version 2 17 * of the License, or (at your option) any later version. 18 * 19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 20 * KIND, either express or implied. 21 * 22 ****************************************************************************/ 23 24#include "plugin.h" 25#include "lib/jpeg_mem.h" 26 27 28static unsigned char output; 29static int output_y = 0; 30static int font_h; 31static unsigned char *plugin_buf; 32struct img_part part; 33 34/* a null output plugin to save memory and better isolate scale cost */ 35static unsigned int get_size_null(struct bitmap *bm) 36{ 37 (void) bm; 38 return 1; 39} 40 41static void output_row_null(uint32_t row, void * row_in, 42 struct scaler_context *ctx) 43{ 44 (void) row; 45 uint32_t *in = (uint32_t *)row_in; 46#ifdef HAVE_LCD_COLOR 47 uint32_t *lim = in + ctx->bm->width * 3; 48#else 49 uint32_t *lim = in + ctx->bm->width; 50#endif 51 while (in < lim) 52 output = SC_OUT(*in++, ctx); 53 return; 54} 55 56struct img_part *store_part_null(void *args) 57{ 58 (void) args; 59 part.len = 256; 60 part.buf = (typeof(part.buf))plugin_buf; 61 return &part; 62} 63 64const struct custom_format format_null = { 65 .output_row_8 = NULL, 66#ifdef HAVE_LCD_COLOR 67 .output_row_32 = { 68 output_row_null, 69 output_row_null 70 }, 71#else 72 .output_row_32 = output_row_null, 73#endif 74 .get_size = get_size_null 75}; 76 77#define lcd_printf(...) \ 78do { \ 79 rb->lcd_putsxyf(0, output_y, __VA_ARGS__); \ 80 rb->lcd_update_rect(0, output_y, LCD_WIDTH, font_h); \ 81 output_y += font_h; \ 82} while (0) 83 84/* this is the plugin entry point */ 85enum plugin_status plugin_start(const void* parameter) 86{ 87 size_t plugin_buf_len; 88 plugin_buf = (unsigned char *)rb->plugin_get_buffer(&plugin_buf_len); 89 struct bitmap bm; 90 struct dim in_dim; 91 struct rowset rset = { 92 .rowstep = 1, 93 .rowstart = 0, 94 }; 95 (void)parameter; 96 97 rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); 98 rb->lcd_fillrect(0, 0, LCD_WIDTH, LCD_HEIGHT); 99 rb->lcd_set_drawmode(DRMODE_SOLID); 100 rb->lcd_getstringsize("A", NULL, &font_h); 101 bm.data = plugin_buf; 102 int in, out; 103 for (in = 64; in < 1025; in <<= 2) 104 { 105 for (out = 64; out < 257; out <<= 1) 106 { 107 if (in == out) 108 continue; 109 lcd_printf("timing %dx%d->%dx>%d scale", in, in, out, out); 110 long t1, t2, t_end; 111 int count = 0; 112 t2 = *(rb->current_tick); 113 in_dim.width = in_dim.height = in; 114 bm.width = bm.height = rset.rowstop = out; 115 while (t2 != (t1 = *(rb->current_tick))); 116 t_end = t1 + 10 * HZ; 117 do { 118 resize_on_load(&bm, false, &in_dim, &rset, (unsigned char *)plugin_buf, plugin_buf_len, &format_null, IF_PIX_FMT(0,) store_part_null, NULL); 119 count++; 120 t2 = *(rb->current_tick); 121 } while (TIME_BEFORE(t2, t_end) || count < 10); 122 t2 -= t1; 123 t2 *= 10; 124 t2 += count >> 1; 125 t2 /= count; 126 t1 = t2 / 1000; 127 t2 -= t1 * 1000; 128 lcd_printf("%01d.%03d secs/scale", (int)t1, (int)t2); 129 if (!(bm.width && bm.height)) 130 break; 131 } 132 } 133 134 while (rb->get_action(CONTEXT_STD,1) != ACTION_STD_OK) rb->yield(); 135 return PLUGIN_OK; 136}