A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 98 lines 3.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 * In-memory JPEG decode test. 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/grey.h" 26#include "lib/jpeg_mem.h" 27#include "lib/mylcd.h" 28 29 30/* different graphics libraries */ 31#if LCD_DEPTH < 8 32#define USEGSLIB 33GREY_INFO_STRUCT 34#define CFORMAT &format_grey 35#else 36#define CFORMAT &format_native 37#endif 38 39/* this is the plugin entry point */ 40enum plugin_status plugin_start(const void* parameter) 41{ 42 size_t plugin_buf_len; 43 unsigned char * plugin_buf = 44 (unsigned char *)rb->plugin_get_buffer(&plugin_buf_len); 45 static char filename[MAX_PATH]; 46 struct bitmap bm = { 47 .width = LCD_WIDTH, 48 .height = LCD_HEIGHT, 49 }; 50 int ret; 51 52 if(!parameter) return PLUGIN_ERROR; 53 54 rb->strcpy(filename, parameter); 55 56#ifdef USEGSLIB 57 long greysize; 58 if (!grey_init(plugin_buf, plugin_buf_len, GREY_ON_COP, 59 LCD_WIDTH, LCD_HEIGHT, &greysize)) 60 { 61 rb->splash(HZ, "grey buf error"); 62 return PLUGIN_ERROR; 63 } 64 plugin_buf += greysize; 65 plugin_buf_len -= greysize; 66#endif 67 int fd = rb->open(filename, O_RDONLY); 68 if (fd < 0) 69 return PLUGIN_ERROR; 70 unsigned long filesize = rb->filesize(fd); 71 if (filesize > plugin_buf_len) 72 return PLUGIN_ERROR; 73 plugin_buf_len -= filesize; 74 unsigned char *jpeg_buf = plugin_buf; 75 plugin_buf += filesize; 76 rb->read(fd, jpeg_buf, filesize); 77 rb->close(fd); 78 bm.data = plugin_buf; 79 ret = decode_jpeg_mem(jpeg_buf, filesize, &bm, plugin_buf_len, 80 FORMAT_NATIVE|FORMAT_RESIZE|FORMAT_KEEP_ASPECT, 81 CFORMAT); 82 if (ret < 1) 83 return PLUGIN_ERROR; 84#ifdef USEGSLIB 85 grey_show(true); 86 grey_ub_gray_bitmap((const unsigned char *)bm.data, (LCD_WIDTH - bm.width) >> 1, 87 (LCD_HEIGHT - bm.height) >> 1, bm.width, bm.height); 88#else 89 rb->lcd_bitmap((fb_data *)bm.data, (LCD_WIDTH - bm.width) >> 1, 90 (LCD_HEIGHT - bm.height) >> 1, bm.width, bm.height); 91#endif 92 mylcd_ub_update(); 93 while (rb->get_action(CONTEXT_STD,1) != ACTION_STD_OK) rb->yield(); 94#ifdef USEGSLIB 95 grey_release(); 96#endif 97 return PLUGIN_OK; 98}