summaryrefslogtreecommitdiff
path: root/apps/plugins/lib/bmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/lib/bmp.c')
-rw-r--r--apps/plugins/lib/bmp.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/apps/plugins/lib/bmp.c b/apps/plugins/lib/bmp.c
new file mode 100644
index 0000000000..18968af7c1
--- /dev/null
+++ b/apps/plugins/lib/bmp.c
@@ -0,0 +1,84 @@
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 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include "bmp.h"
21
22#include "lcd.h"
23#include "file.h"
24#include "lcd.h"
25#include "system.h"
26
27#define LE16(x) (htole16(x))&0xff, ((htole16(x))>>8)&0xff
28#define LE32(x) (htole32(x))&0xff, ((htole32(x))>>8)&0xff, ((htole32(x))>>16)&0xff, ((htole32(x))>>24)&0xff
29/**
30 * Save to 24 bit bitmap.
31 */
32int save_bmp_file( char* filename, struct bitmap *bm, struct plugin_api* rb )
33{
34 /* I'm not really sure about this one :) */
35 int line_width = bm->width*3+((bm->width*3)%4?4-((bm->width*3)%4):0);
36
37 const unsigned char header[] =
38 {
39 0x42, 0x4d, /* signature - 'BM' */
40 LE32( bm->height*line_width + 54 + 4*0 ), /* file size in bytes */
41 0x00, 0x00, 0x00, 0x00, /* 0, 0 */
42 LE32( 54 + 4*0 ), /* offset to bitmap */
43 0x28, 0x00, 0x00, 0x00, /* size of this struct (40) */
44 LE32( bm->width ), /* bmap width in pixels */
45 LE32( bm->height ), /* bmap height in pixels */
46 0x01, 0x00, /* num planes - always 1 */
47 LE16( 24 ), /* bits per pixel */
48 LE32( 0 ), /* compression flag */
49 LE32( bm->height*line_width ), /* image size in bytes */
50 0xc4, 0x0e, 0x00, 0x00, /* horz resolution */
51 0xc4, 0x0e, 0x00, 0x00, /* vert resolution */
52 LE32( 0 ), /* 0 -> color table size */
53 LE32( 0 ) /* important color count */
54 };
55
56 int fh;
57 int x,y;
58 if( bm->format != FORMAT_NATIVE ) return -1;
59 fh = rb->PREFIX(creat)( filename, O_WRONLY );
60 if( fh < 0 ) return -1;
61
62 rb->write( fh, header, sizeof( header ) );
63 for( y = bm->height-1; y >= 0; y-- )
64 {
65 for( x = 0; x < bm->width; x++ )
66 {
67 fb_data *d = (fb_data*)( bm->data ) + (x+y*bm->width);
68 unsigned char c[] =
69 {
70 RGB_UNPACK_BLUE( *d ),
71 RGB_UNPACK_GREEN( *d ),
72 RGB_UNPACK_RED( *d )
73 };
74 rb->write( fh, c, 3 );
75 }
76 for( x = 0; x < 3*bm->width - line_width; x++ )
77 {
78 unsigned char c = 0;
79 rb->write( fh, &c, 1 );
80 }
81 }
82 rb->close( fh );
83 return 1;
84}