mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-15 11:07:38 -04:00
Lib to save a bitmap struct to a bmp file. Only works/tested with color bitmaps.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10254 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
5e306b4c19
commit
2da8f69c95
3 changed files with 117 additions and 0 deletions
|
@ -21,4 +21,7 @@ profile_plugin.c
|
|||
xlcd_core.c
|
||||
xlcd_draw.c
|
||||
xlcd_scroll.c
|
||||
#ifdef HAVE_LCD_COLOR
|
||||
bmp.c
|
||||
#endif
|
||||
#endif
|
||||
|
|
84
apps/plugins/lib/bmp.c
Normal file
84
apps/plugins/lib/bmp.c
Normal file
|
@ -0,0 +1,84 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2006 by Antoine Cellerier <dionoea -at- videolan -dot- org>
|
||||
*
|
||||
* All files in this archive are subject to the GNU General Public License.
|
||||
* See the file COPYING in the source tree root for full license agreement.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "bmp.h"
|
||||
|
||||
#include "lcd.h"
|
||||
#include "file.h"
|
||||
#include "lcd.h"
|
||||
#include "system.h"
|
||||
|
||||
#define LE16(x) (htole16(x))&0xff, ((htole16(x))>>8)&0xff
|
||||
#define LE32(x) (htole32(x))&0xff, ((htole32(x))>>8)&0xff, ((htole32(x))>>16)&0xff, ((htole32(x))>>24)&0xff
|
||||
/**
|
||||
* Save to 24 bit bitmap.
|
||||
*/
|
||||
int save_bmp_file( char* filename, struct bitmap *bm, struct plugin_api* rb )
|
||||
{
|
||||
/* I'm not really sure about this one :) */
|
||||
int line_width = bm->width*3+((bm->width*3)%4?4-((bm->width*3)%4):0);
|
||||
|
||||
const unsigned char header[] =
|
||||
{
|
||||
0x42, 0x4d, /* signature - 'BM' */
|
||||
LE32( bm->height*line_width + 54 + 4*0 ), /* file size in bytes */
|
||||
0x00, 0x00, 0x00, 0x00, /* 0, 0 */
|
||||
LE32( 54 + 4*0 ), /* offset to bitmap */
|
||||
0x28, 0x00, 0x00, 0x00, /* size of this struct (40) */
|
||||
LE32( bm->width ), /* bmap width in pixels */
|
||||
LE32( bm->height ), /* bmap height in pixels */
|
||||
0x01, 0x00, /* num planes - always 1 */
|
||||
LE16( 24 ), /* bits per pixel */
|
||||
LE32( 0 ), /* compression flag */
|
||||
LE32( bm->height*line_width ), /* image size in bytes */
|
||||
0xc4, 0x0e, 0x00, 0x00, /* horz resolution */
|
||||
0xc4, 0x0e, 0x00, 0x00, /* vert resolution */
|
||||
LE32( 0 ), /* 0 -> color table size */
|
||||
LE32( 0 ) /* important color count */
|
||||
};
|
||||
|
||||
int fh;
|
||||
int x,y;
|
||||
if( bm->format != FORMAT_NATIVE ) return -1;
|
||||
fh = rb->PREFIX(creat)( filename, O_WRONLY );
|
||||
if( fh < 0 ) return -1;
|
||||
|
||||
rb->write( fh, header, sizeof( header ) );
|
||||
for( y = bm->height-1; y >= 0; y-- )
|
||||
{
|
||||
for( x = 0; x < bm->width; x++ )
|
||||
{
|
||||
fb_data *d = (fb_data*)( bm->data ) + (x+y*bm->width);
|
||||
unsigned char c[] =
|
||||
{
|
||||
RGB_UNPACK_BLUE( *d ),
|
||||
RGB_UNPACK_GREEN( *d ),
|
||||
RGB_UNPACK_RED( *d )
|
||||
};
|
||||
rb->write( fh, c, 3 );
|
||||
}
|
||||
for( x = 0; x < 3*bm->width - line_width; x++ )
|
||||
{
|
||||
unsigned char c = 0;
|
||||
rb->write( fh, &c, 1 );
|
||||
}
|
||||
}
|
||||
rb->close( fh );
|
||||
return 1;
|
||||
}
|
30
apps/plugins/lib/bmp.h
Normal file
30
apps/plugins/lib/bmp.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2006 by Antoine Cellerier <dionoea -at- videolan -dot- org>
|
||||
*
|
||||
* All files in this archive are subject to the GNU General Public License.
|
||||
* See the file COPYING in the source tree root for full license agreement.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef _LIB_BMP_H_
|
||||
#define _LIB_BMP_H_
|
||||
|
||||
#include "lcd.h"
|
||||
#include "plugin.h"
|
||||
|
||||
/**
|
||||
* Save bitmap to file
|
||||
*/
|
||||
int save_bmp_file( char* filename, struct bitmap *bm, struct plugin_api* rb );
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue