A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 167 lines 5.4 kB view raw
1/*************************************************************************** 2 * __________ __ ___. 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 * \/ \/ \/ \/ \/ 8 * $Id$ 9 * 10 * Copyright (C) 2006 by Antoine Cellerier <dionoea -at- videolan -dot- org> 11 * Copyright (C) 2009 by Andrew Mahone 12 * 13 * This program is free software; you can redistribute it and/or 14 * modify it under the terms of the GNU General Public License 15 * as published by the Free Software Foundation; either version 2 16 * of the License, or (at your option) any later version. 17 * 18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 19 * KIND, either express or implied. 20 * 21 ****************************************************************************/ 22 23#include "pluginlib_bmp.h" 24 25#include "lcd.h" 26#include "file.h" 27#include "system.h" 28 29#if defined(HAVE_LCD_COLOR) 30#define LE16(x) (htole16(x))&0xff, ((htole16(x))>>8)&0xff 31#define LE32(x) (htole32(x))&0xff, ((htole32(x))>>8)&0xff, ((htole32(x))>>16)&0xff, ((htole32(x))>>24)&0xff 32/** 33 * Save to 24 bit bitmap. 34 */ 35int save_bmp_file( char* filename, struct bitmap *bm ) 36{ 37 int line_width = (bm->width*3+3) & ~3; 38 int padsize = line_width - bm->width*3; 39 40 const unsigned char header[] = 41 { 42 0x42, 0x4d, /* signature - 'BM' */ 43 LE32( bm->height*line_width + 54 + 4*0 ), /* file size in bytes */ 44 0x00, 0x00, 0x00, 0x00, /* 0, 0 */ 45 LE32( 54 + 4*0 ), /* offset to bitmap */ 46 0x28, 0x00, 0x00, 0x00, /* size of this struct (40) */ 47 LE32( bm->width ), /* bmap width in pixels */ 48 LE32( bm->height ), /* bmap height in pixels */ 49 0x01, 0x00, /* num planes - always 1 */ 50 LE16( 24 ), /* bits per pixel */ 51 LE32( 0 ), /* compression flag */ 52 LE32( bm->height*line_width ), /* image size in bytes */ 53 0xc4, 0x0e, 0x00, 0x00, /* horz resolution */ 54 0xc4, 0x0e, 0x00, 0x00, /* vert resolution */ 55 LE32( 0 ), /* 0 -> color table size */ 56 LE32( 0 ) /* important color count */ 57 }; 58 59 int fh; 60 int x,y; 61 if( bm->format != FORMAT_NATIVE ) return -1; 62 fh = rb->creat( filename , 0666); 63 if( fh < 0 ) return -1; 64 65 rb->write( fh, header, sizeof( header ) ); 66 for( y = bm->height-1; y >= 0; y-- ) 67 { 68 for( x = 0; x < bm->width; x++ ) 69 { 70 fb_data *d = (fb_data*)( bm->data ) + (x+y*bm->width); 71 unsigned char c[] = 72 { 73 FB_UNPACK_BLUE( *d ), 74 FB_UNPACK_GREEN( *d ), 75 FB_UNPACK_RED( *d ) 76 }; 77 rb->write( fh, c, 3 ); 78 } 79 if(padsize != 0) 80 { 81 unsigned int c = 0; /* padsize is at most 3. */ 82 rb->write( fh, &c, padsize ); 83 } 84 } 85 rb->close( fh ); 86 return 1; 87} 88#endif /* HAVE_LCD_COLOR */ 89 90/** 91 Very simple image scale from src to dst (nearest neighbour). 92 Source and destination dimensions are read from the struct bitmap. 93 FIXME: this doesn't work well for LCD_DEPTH<4 94*/ 95void simple_resize_bitmap(struct bitmap *src, struct bitmap *dst) 96{ 97#if LCD_STRIDEFORMAT == VERTICAL_STRIDE 98 const int srcw = src->height; 99 const int srch = src->width; 100 const int dstw = dst->height; 101 const int dsth = dst->width; 102#else 103 const int srcw = src->width; 104 const int srch = src->height; 105 const int dstw = dst->width; 106 const int dsth = dst->height; 107#endif 108 const fb_data *srcd = (fb_data *)(src->data); 109 const fb_data *dstd = (fb_data *)(dst->data); 110 const long xrstep = ((srcw-1) << 8) / (dstw-1); 111 const long yrstep = ((srch-1) << 8) / (dsth-1); 112 fb_data *src_row, *dst_row; 113 long xr, yr = 0; 114 int src_x, src_y, dst_x, dst_y; 115 for (dst_y=0; dst_y < dsth; dst_y++) 116 { 117 src_y = (yr >> 8); 118 src_row = (fb_data *)&srcd[src_y * srcw]; 119 dst_row = (fb_data *)&dstd[dst_y * dstw]; 120 for (xr=0,dst_x=0; dst_x < dstw; dst_x++) 121 { 122 src_x = (xr >> 8); 123 dst_row[dst_x] = src_row[src_x]; 124 xr += xrstep; 125 } 126 yr += yrstep; 127 } 128} 129 130#if (LCD_DEPTH < 4) 131/** 132 Same as simple_resize_bitmap except this is for use with greylib. 133*/ 134void grey_resize_bitmap(struct bitmap *src, struct bitmap *dst) 135{ 136 const int srcw = src->width; 137 const int srch = src->height; 138 const int dstw = dst->width; 139 const int dsth = dst->height; 140 const long xrstep = ((srcw-1) << 8) / (dstw-1); 141 const long yrstep = ((srch-1) << 8) / (dsth-1); 142 unsigned char *srcd = src->data; 143 unsigned char *dstd = dst->data; 144 unsigned char *src_row, *dst_row; 145 long xr, yr = 0; 146 int src_x, src_y, dst_x, dst_y; 147 for (dst_y=0; dst_y < dsth; dst_y++) 148 { 149 src_y = (yr >> 8); 150 src_row = &srcd[src_y * srcw]; 151 dst_row = &dstd[dst_y * dstw]; 152 for (xr=0,dst_x=0; dst_x < dstw; dst_x++) 153 { 154 src_x = (xr >> 8); 155 dst_row[dst_x] = src_row[src_x]; 156 xr += xrstep; 157 } 158 yr += yrstep; 159 } 160} 161#endif 162 163 164#include "wrappers.h" 165 166/* import the core bmp loader */ 167#include "recorder/bmp.c"