Files
player/Project/Src/JPEG/bmp.h
2025-06-27 00:32:57 +08:00

113 lines
4.2 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef __BMP_H__
#define __BMP_H__
#include "base.h"
//////////////////////////////////////////////////////////////////////////////////
//本程序只供学习使用,未经作者许可,不得用于其它任何用途
//ALIENTEK STM32F407开发板
//图片解码 驱动代码-bmp解码部分
//正点原子@ALIENTEK
//技术论坛:www.openedv.com
//创建日期:2014/5/15
//版本V1.0
//版权所有,盗版必究。
//Copyright(C) 广州市星翼电子科技有限公司 2014-2024
//All rights reserved
//********************************************************************************
//升级说明
//V1.1 20140722
//修改minibmp_decode函数,使图片在设定区域的正中央显示
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////用户配置区///////////////////////////////
#define BMP_USE_MALLOC 1 //定义是否使用malloc,这里我们选择使用malloc
#define BMP_DBUF_SIZE 2048 //定义bmp解码数组的大小(最少应为LCD宽度*3)
//////////////////////////////////////////////END/////////////////////////////////
//BMP信息头
typedef __packed struct
{
u32 biSize ; //说明BITMAPINFOHEADER结构所需要的字数。
long biWidth ; //说明图象的宽度,以象素为单位
long biHeight ; //说明图象的高度,以象素为单位
u16 biPlanes ; //为目标设备说明位面数其值将总是被设为1
u16 biBitCount ; //说明比特数/象素其值为1、4、8、16、24、或32
u32 biCompression ; //说明图象数据压缩的类型。其值可以是下述值之一:
//BI_RGB没有压缩
//BI_RLE8每个象素8比特的RLE压缩编码压缩格式由2字节组成(重复象素计数和颜色索引)
//BI_RLE4每个象素4比特的RLE压缩编码压缩格式由2字节组成
//BI_BITFIELDS每个象素的比特由指定的掩码决定。
u32 biSizeImage ; //说明图象的大小以字节为单位。当用BI_RGB格式时可设置为0
long biXPelsPerMeter ; //说明水平分辨率,用象素/米表示
long biYPelsPerMeter ; //说明垂直分辨率,用象素/米表示
u32 biClrUsed ; //说明位图实际使用的彩色表中的颜色索引数
u32 biClrImportant ; //说明对图象显示有重要影响的颜色索引的数目如果是0表示都重要。
}BITMAPINFOHEADER ;
//BMP头文件
typedef __packed struct
{
u16 bfType ; //文件标志.只对'BM',用来识别BMP位图类型
u32 bfSize ; //文件大小,占四个字节
u16 bfReserved1 ;//保留
u16 bfReserved2 ;//保留
u32 bfOffBits ; //从文件开始到位图数据(bitmap data)开始之间的的偏移量
}BITMAPFILEHEADER ;
//彩色表
typedef __packed struct
{
u8 rgbBlue ; //指定蓝色强度
u8 rgbGreen ; //指定绿色强度
u8 rgbRed ; //指定红色强度
u8 rgbReserved ;//保留设置为0
}RGBQUAD ;
//位图信息头
typedef __packed struct
{
BITMAPFILEHEADER bmfHeader;
BITMAPINFOHEADER bmiHeader;
u32 RGB_MASK[3]; //调色板用于存放RGB掩码.
//RGBQUAD bmiColors[256];
}BITMAPINFO;
typedef RGBQUAD * LPRGBQUAD;//彩色表
//图象数据压缩的类型
#define BI_RGB 0 //没有压缩.RGB 5,5,5.
#define BI_RLE8 1 //每个象素8比特的RLE压缩编码压缩格式由2字节组成(重复象素计数和颜色索引)
#define BI_RLE4 2 //每个象素4比特的RLE压缩编码压缩格式由2字节组成
#define BI_BITFIELDS 3 //每个象素的比特由指定的掩码决定。
typedef struct
{
int x_size;
int y_size;
u16 *data;
}BMP_DecodeStruct;
int BMP_Decode(const u8 *filename,BMP_DecodeStruct *bmp) ;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//BMP编解码函数
u8 stdbmp_decode(const u8 *filename);
u8 minibmp_decode(u8 *filename,u16 x,u16 y,u16 width,u16 height,u16 acolor,u8 mode);//尺寸小于240*320的bmp图片解码.
u8 bmp_encode(u8 *filename,u16 x,u16 y,u16 width,u16 height,u8 mode);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#endif