tiger525 2006-6-10 03:58
求bmp图片转为abmp!
求bmp图片转为abmp软件(转换为160x60)!
有源码,但我一点不懂,跪求高手帮忙!
作手写区主题图片用!(权智M28自带主题软件,准备用手写区键盘)
最好是输出单一abmp资源!
附EasySkin的bmp2abmp源码(是T3等机型才行,我要低分的):
[img]http://www.tompda.com/bbs/img/addon.gif[/img][url=http://www.tompda.com/bbs/download.asp?id=0603/tompda_735313_source.rar]0603/tompda_735313_source.rar[/url]
------------------------------------
bmp2abmp.h:
#include <stdio.h>
#define compressedBE 0x80
#define compressedLE 0x01
#define directColorLE 0x20
#define RED_BITS 5
#define GREEN_BITS 6
#define BLUE_BITS 5
#define MAX_RED ( ( 1 << RED_BITS ) - 1 )
#define MAX_GREEN ( ( 1 << GREEN_BITS ) - 1 )
#define MAX_BLUE ( ( 1 << BLUE_BITS ) - 1 )
typedef enum {
palmPixelFormatIndexed = 0,
palmPixelFormat565,
palmPixelFormat565LE,
palmPixelFormatIndexedLE,
} PalmPixelFormatType;
/* Currently assumes little endian system */
typedef short Int16;
typedef unsigned short UInt16;
typedef signed char Int8;
typedef unsigned char UInt8;
typedef unsigned long UInt32;
typedef long Int32;
typedef char Boolean;
#define false 0
#define true 1
typedef struct {
Int16 width;
Int16 height;
UInt16 rowBytes;
UInt8 flags;
UInt8 reserved0;
UInt8 pixelSize;
UInt8 version;
UInt8 size;
UInt8 pixelFormat;
UInt8 unused;
UInt8 compressionType;
UInt16 density;
UInt32 transparentValue;
UInt32 nextBitmapOffset;
} PalmBitmapTypeV3;
typedef enum {
palmBitmapCompressionTypeScanLine = 0,
palmBitmapCompressionTypeRLE,
palmBitmapCompressionTypePackBits,
palmBitmapCompressionTypeEnd,
palmBitmapCompressionTypeBest = 0x64,
palmBitmapCompressionTypeNone = 0xFF
} PalmBitmapCompressionType;
typedef UInt16 UInt32NP[ 2 ];
typedef struct {
UInt16 magic;
UInt32NP fileSize;
UInt16 res1;
UInt16 res2;
UInt32NP offset;
UInt32NP infoSize;
UInt32NP width;
UInt32NP height;
UInt16 planes;
UInt16 bitsPerPixel;
UInt32NP compressionType;
UInt32NP imageSize;
UInt32NP xRes;
UInt32NP yRes;
UInt32NP nColors;
UInt32NP nImpColors;
} BMPHeaderType;
tiger525 编辑于 2006-6-9 20:19:36
tiger525 2006-6-10 04:00
bmp2abmp.c:
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "bmp2abmp.h"
#undef WINDOWS
#ifdef __GNUCC__
#define STRICMP strcasecmp
#else
#define STRICMP stricmp
#endif
#define resourceAttribute 0x0001
FILE *in = NULL;
FILE *out = NULL;
int interactive = true;
UInt8* inBitmap;
UInt8* outBitmap;
void SafeFree( void** p )
{
if ( *p != NULL ) {
free( *p );
*p = NULL;
}
}
void CleanUp( void )
{
SafeFree( ( void** )&inBitmap );
SafeFree( ( void** )&outBitmap );
fcloseall();
}
void msg(char* title, char *s, ...)
{
char out[ 2048 ];
va_list argptr;
if ( ! interactive )
return;
va_start(argptr,s);
vsprintf(out,s,argptr);
va_end(argptr);
#ifdef WINDOWS
MessageBox( NULL, out, title, MB_OK );
#else
fprintf( stderr, "%s\n", out );
#endif
CleanUp();
exit(1);
}
void err(char *s, ...)
{
char out[ 2048 ];
va_list argptr;
va_start(argptr,s);
vsprintf(out,s,argptr);
va_end(argptr);
#ifdef WINDOWS
MessageBox( NULL, out, "Error", MB_OK );
#else
fprintf( stderr, "Fatal error: %s.\n", out );
#endif
CleanUp();
exit(1);
}
FILE *myfopen(char *s,char *m)
{
FILE *f=fopen(s,m);
if(f==NULL) err("Cannot open %s.",s);
return f;
}
int myfgetc(FILE *f)
{
int c=fgetc(f);
if(c==-1) err("Error reading font!");
return c;
}
void* mymalloc( int n )
{
void* p = malloc( n );
if ( p == NULL ) err("Error allocating %ld bytes.", n );
return p;
}
int myfread( void* p, int n, int m, FILE* f )
{
if ( m != fread( p, n, m, f ) )
err("Error reading %d x %d bytes.", n, m );
return m;
}
void myseek(FILE *f, unsigned long x)
{
if(fseek(f,x,SEEK_SET)<0 ||
ftell(f)!=(long)x) err("Error seeking!");
return;
}
UInt32 UInt32LE( UInt32 in )
{
UInt8* p;
UInt32 n;
int i;
p = ( UInt8* )&n;
for ( i = 0 ; i < 4 ; i++ ) {
p[ i ] = in % 256;
in /= 256;
}
return n;
}
UInt16 UInt16LE( UInt16 in )
{
UInt8* p;
int i;
p = ( UInt8* )&in;
return p[ 0 ] + 256 * p[ 1 ];
}
UInt32 UInt32LEP( UInt16* inP )
{
return UInt16LE( inP[ 0 ] ) + 65536 * UInt16LE( inP[ 1 ] );
}
#ifdef WINDOWS
int getname(char *s)
{
int r;
OPENFILENAME ofn;
*s=0;
ZeroMemory(&ofn, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = NULL;
ofn.lpstrFile = s;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFilter = "Palm databases\0*.prc;*.pdb\0All files\0*.*\0";
ofn.lpstrTitle = "Select database to compress";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
return GetOpenFileName(&ofn);
}
#endif
static void WrongFormat( void )
{
err("Unsupported input format");
}
static UInt16 Convert888To565( UInt8* c )
{
return ( ( c[ 2 ] >> 3 ) << 11 ) | ( ( c[ 1 ] >> 2 ) << 5 ) | ( c[ 0 ] >> 3 );
}
static void ConvertRow( UInt8* dest, UInt8* src, UInt16 width )
{
int x;
UInt16* dest16;
dest16 = ( void* )dest;
for ( x = 0 ; x < width ; x++ ) {
dest16[ x ] = UInt16LE( Convert888To565( src + x * 3 ) );
}
}
#define SEQUENCE_LIMIT 126
Int16 GetRunLength( UInt16* data, UInt16 cols )
{
UInt16 i;
for ( i = 1 ; i < cols && data[ i ] == data[ 0 ] && i < SEQUENCE_LIMIT ; i++ ) ;
return i;
}
UInt8* PackRow( UInt8* out, UInt16* in, UInt16 cols )
{
UInt16 x;
UInt16* inEnd;
while ( cols ) {
Int16 count;
count = GetRunLength( in, cols );
if ( 2 <= count ) {
*out++ = ( UInt8 )( 1 - count );
*out++ = *( UInt8* )in;
*out++ = *( 1 + ( UInt8*
tiger525 2006-6-10 04:03
for ( i = 1 ; i < cols && i < SEQUENCE_LIMIT && ( i + 1 == cols || in[ i ] != in[ i + 1 ] ) ; i++ );
*out++ = ( UInt8 )( i - 1 );
while ( i-- ) {
*out++ = *( UInt8* )in;
*out++ = *( 1 + ( UInt8* )in );
in++;
cols--;
}
}
}
return out;
}
void* PackData( UInt16* inData, UInt16 cols, UInt16 rows, UInt32* newSizeP )
{
UInt8* outData;
UInt8* p;
UInt16 row;
/* Implement packbits compression */
//return NULL;
outData = malloc( rows * cols * ( sizeof( UInt16 ) + 1 ) + 4 );
if ( outData == NULL )
return NULL;
p = outData + 4;
for ( row = 0 ; row < rows ; row++ ) {
p = PackRow( p, inData + row * cols, cols );
}
if ( rows * cols * sizeof( UInt16 ) <= p - outData ) {
free( outData );
return NULL;
}
*newSizeP = ( p - outData );
*( UInt32* )outData = UInt32LE( *newSizeP - 4 );
return outData;
}
UInt8* ScanLineCompressRow( Boolean firstLine, UInt8* out, UInt8* in, UInt16 rowBytes )
{
UInt8* startOut;
UInt8* endIn;
static UInt8* prevLine;
UInt8* startIn;
startIn = in;
startOut = out;
endIn = in + rowBytes;
while ( in < endIn ) {
UInt8* octupleMarker;
UInt8 mask;
octupleMarker = out;
*octupleMarker = 0;
out++;
for ( mask = 0x80 ; mask != 0 && in < endIn ; mask >>= 1 ) {
if ( firstLine || *in != *prevLine ) {
*octupleMarker |= mask;
*out++ = *in;
}
in++;
prevLine++;
}
}
prevLine = startIn;
return out;
}
void* ScanLineData( UInt8* inData, UInt16 byteWidth, UInt16 rows, UInt32* newSizeP )
{
UInt8* outData;
UInt8* p;
UInt16 row;
/* Implement scanline compression */
outData = malloc( rows * byteWidth * 2 + 4 );
if ( outData == NULL )
return NULL;
p = outData + 4;
for ( row = 0 ; row < rows ; row++ ) {
p = ScanLineCompressRow( row == 0, p, inData + row * byteWidth, byteWidth );
}
if ( rows * byteWidth <= p - outData + 4 ) {
free( outData );
return NULL;
}
*newSizeP = ( p - outData );
*( UInt32* )outData = UInt32LE( *newSizeP - 4 );
return outData;
}
void* CompressData( void* bitmap, UInt16 cols, UInt16 rows, UInt32* newSizeP, UInt8* type )
{
void* scanLine;
UInt32 scanLineSize;
void* pack;
UInt32 packSize;
pack = PackData( bitmap, cols, rows, &packSize );
scanLine = ScanLineData( bitmap, cols * sizeof( UInt16 ), rows, &scanLineSize );
if ( pack == NULL ) {
if ( scanLine != NULL ) {
*type = palmBitmapCompressionTypeScanLine;
*newSizeP = scanLineSize;
}
return scanLine;
}
if ( scanLine == NULL ) {
if ( pack != NULL ) {
*type = palmBitmapCompressionTypePackBits;
*newSizeP = packSize;
}
return pack;
}
if ( packSize < scanLineSize ) {
free( scanLine );
*type = palmBitmapCompressionTypePackBits;
*newSizeP = packSize;
return pack;
}
else {
free( pack );
*type = palmBitmapCompressionTypeScanLine;
*newSizeP = scanLineSize;
return scanLine;
}
}
int main(int argc, char **argv)
{
int i;
int x;
int y;
UInt32 pos,pos2,pos3;
UInt32 inLength;
UInt32 outLength;
UInt16 width;
UInt16 height;
UInt32 inRowLen;
UInt16 outRowLen;
void* compressedBitmap;
UInt32 compressedSize;
BMPHeaderType inH;
PalmBitmapTypeV3 outH;
interactive = 1;
inBitmap = NULL;
outBitmap = NULL;
if ( argc != 3 )
wushaohua 2006-6-10 23:45
高手帮帮忙呀,顶!
wushaohua 2006-6-11 05:08
高手不出来,自己搞定!原来应该改动EasySkin的原文件!
改动EasySkin.tcl成功实现!
wushaohua 2006-6-12 01:42
搞好是搞好了,但是不知怎么了,皮肤图片时不时地出现变大一倍的现象,点击一下又恢复正常!(不规则出现)
wushaohua 2006-7-24 00:09
有没有支持低分机型的bmp2abmp程序呀!