加入BMP库,加入常见位操作
This commit is contained in:
123
bsp_Device/bsp_BMP.cpp
Normal file
123
bsp_Device/bsp_BMP.cpp
Normal file
@@ -0,0 +1,123 @@
|
||||
/*----------------------------------------------------------------------------------------------------
|
||||
#
|
||||
# Copyright (c) 2022 Yuankang Liang(XerolySkinner)
|
||||
#
|
||||
# 本软件按原样提供,无任何明示或暗示
|
||||
# 在任何情况下,作者都不承担任何损害赔偿责任
|
||||
#
|
||||
# 使用的许可声明:
|
||||
# 1. 不得歪曲本软件的来源,你不能声称你编写了原始软件.
|
||||
# 2. 免费授予以任何目的,前提是版权声明出现在所有副本中.
|
||||
# 并且版权声明和许可声明同时出现.
|
||||
# 3. 你有使用,复制,修改,分发,和销售本软件的许可.
|
||||
# 4. 如果你在产品中使用,产品文档中的声明是赞赏的但不是必须的.
|
||||
# 5. 本通知不得从任何来源删除或更改.
|
||||
#
|
||||
# Yuankang Liang(XerolySkinner)
|
||||
# E-mail:zabbcccbbaz@163.com
|
||||
# QQ:2715099320
|
||||
# Mobile Phone:13005636215
|
||||
#
|
||||
# All rights reserved.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file bsp_BMP.cpp
|
||||
* @brief 用来构造BMP图片
|
||||
* @mainpage 主要信息
|
||||
* @author Yuankang Liang(XerolySkinner)
|
||||
* @email zabbcccbbaz@163.com
|
||||
* @version V1.0.0
|
||||
* @date 2022-11-24 20:22
|
||||
*/
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// 头文件
|
||||
#include "bsp_BMP.h"
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// 类函数
|
||||
/**
|
||||
* @brief 设置像素
|
||||
* @param x x像素
|
||||
* @param y y像素
|
||||
*/
|
||||
void bsp_BMP::pels(u32 x, u32 y) {
|
||||
bsp_BMP::BITMAPINFO.bmiHeader.biXPelsPerMeter = x;
|
||||
bsp_BMP::BITMAPINFO.bmiHeader.biYPelsPerMeter = y;}
|
||||
/**
|
||||
* @brief 给予数据空间
|
||||
* @return 返回给与的数据头
|
||||
*/
|
||||
u32 bsp_BMP::giveData(void) {
|
||||
free(dat);
|
||||
dat = (u8*)malloc(Size);
|
||||
return (u32)dat;}
|
||||
/**
|
||||
* @brief 释放数据空间
|
||||
*/
|
||||
void bsp_BMP::delData(void) {
|
||||
free(dat);}
|
||||
/**
|
||||
* @brief 设置调色板
|
||||
* @param R 红色
|
||||
* @param G 绿色
|
||||
* @param B 蓝色
|
||||
* @param i 索引号
|
||||
*/
|
||||
void bsp_BMP::ColorsSet(u8 R, u8 G, u8 B,u32 i) {
|
||||
BITMAPINFO.bmiColors[i].rgbBlue = B;
|
||||
BITMAPINFO.bmiColors[i].rgbGreen = G;
|
||||
BITMAPINFO.bmiColors[i].rgbRed = R;
|
||||
BITMAPINFO.bmiColors[i].rgbReserved = 0;}
|
||||
/**
|
||||
* @brief 设置图片大小
|
||||
* @param Width 图片宽度
|
||||
* @param Height 图片高度
|
||||
*/
|
||||
void bsp_BMP::sizeSet(u32 x, u32 y) {
|
||||
free(dat);
|
||||
Size = x * y;
|
||||
BITMAPINFO.bmiHeader.biWidth = x; // 色彩宽度
|
||||
BITMAPINFO.bmiHeader.biHeight = y; // 色彩高度
|
||||
BITMAPINFO.bmfHeader.bfOffBits =
|
||||
sizeof(_BITMAPINFO); // 位图数据偏倚
|
||||
BITMAPINFO.bmfHeader.bfSize =
|
||||
x * y +
|
||||
BITMAPINFO.bmfHeader.bfOffBits; // 文件大小
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// 构造函数
|
||||
/**
|
||||
* @brief 构造BMP数据头
|
||||
* @param Width 图片宽度
|
||||
* @param Height 图片高度
|
||||
*/
|
||||
bsp_BMP::bsp_BMP(u32 Width, u32 Height) {
|
||||
bsp_BMP::dat = NULL;
|
||||
bsp_BMP::Size = Width * Height;
|
||||
BITMAPINFO.bmiHeader.biWidth = Width; // 色彩宽度
|
||||
BITMAPINFO.bmiHeader.biHeight = Height; // 色彩高度
|
||||
BITMAPINFO.bmfHeader.bfType = 0x4D42; // 恒为保护字
|
||||
BITMAPINFO.bmfHeader.bfReserved1 = 0; // 保留字
|
||||
BITMAPINFO.bmfHeader.bfReserved2 = 0; // 保留字
|
||||
BITMAPINFO.bmiHeader.biCompression = 0; // 无压缩
|
||||
BITMAPINFO.bmiHeader.biSizeImage = 0; // 无压缩下为0
|
||||
BITMAPINFO.bmiHeader.biPlanes = 1; // 恒为保护字
|
||||
BITMAPINFO.bmiHeader.biClrUsed = 0; // 使用全部颜色
|
||||
BITMAPINFO.bmiHeader.biClrImportant = 0; // 全部颜色都重要
|
||||
BITMAPINFO.bmiHeader.biXPelsPerMeter = 0; // 像素-不太重要
|
||||
BITMAPINFO.bmiHeader.biYPelsPerMeter = 0; // 像素-不太重要
|
||||
BITMAPINFO.bmiHeader.biSize = 40; // 信息头大小
|
||||
BITMAPINFO.bmfHeader.bfOffBits =
|
||||
sizeof(_BITMAPINFO); // 位图数据偏倚
|
||||
BITMAPINFO.bmfHeader.bfSize =
|
||||
Width * Height+
|
||||
BITMAPINFO.bmfHeader.bfOffBits; // 文件大小
|
||||
BITMAPINFO.bmiHeader.biBitCount = 8; // 色彩深度
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
bsp_BMP::~bsp_BMP(void) {
|
||||
free(dat);}
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
113
bsp_Device/bsp_BMP.h
Normal file
113
bsp_Device/bsp_BMP.h
Normal file
@@ -0,0 +1,113 @@
|
||||
/*----------------------------------------------------------------------------------------------------
|
||||
#
|
||||
# Copyright (c) 2022 Yuankang Liang(XerolySkinner)
|
||||
#
|
||||
# 本软件按原样提供,无任何明示或暗示
|
||||
# 在任何情况下,作者都不承担任何损害赔偿责任
|
||||
#
|
||||
# 使用的许可声明:
|
||||
# 1. 不得歪曲本软件的来源,你不能声称你编写了原始软件.
|
||||
# 2. 免费授予以任何目的,前提是版权声明出现在所有副本中.
|
||||
# 并且版权声明和许可声明同时出现.
|
||||
# 3. 你有使用,复制,修改,分发,和销售本软件的许可.
|
||||
# 4. 如果你在产品中使用,产品文档中的声明是赞赏的但不是必须的.
|
||||
# 5. 本通知不得从任何来源删除或更改.
|
||||
#
|
||||
# Yuankang Liang(XerolySkinner)
|
||||
# E-mail:zabbcccbbaz@163.com
|
||||
# QQ:2715099320
|
||||
# Mobile Phone:13005636215
|
||||
#
|
||||
# All rights reserved.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file bsp_BMP.h
|
||||
* @brief 用来构造BMP图片
|
||||
* @mainpage 主要信息
|
||||
* @author Yuankang Liang(XerolySkinner)
|
||||
* @email zabbcccbbaz@163.com
|
||||
* @version V1.0.0
|
||||
* @date 2022-11-24 20:22
|
||||
*/
|
||||
#pragma once
|
||||
#ifdef __cplusplus
|
||||
#include "varint.h"
|
||||
#include <stdlib.h>
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// 文件头
|
||||
#pragma pack(1)
|
||||
/**
|
||||
* @brief 位图文件头
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
u16 bfType; //文件标志.固定为'BM',用来识别BMP位图类型
|
||||
u32 bfSize; //文件大小,占四个字节
|
||||
u16 bfReserved1; //保留,总为0
|
||||
u16 bfReserved2; //保留,总为0
|
||||
u32 bfOffBits; //从文件开始到位图数据(bitmap data)开始之间的的偏移量
|
||||
}_BITMAPFILEHEADER;
|
||||
/**
|
||||
* @brief 位图信息头
|
||||
*/
|
||||
typedef struct {
|
||||
u32 biSize; //BITMAPINFOHEADER结构所需要的字数。
|
||||
u32 biWidth; //图象的宽度,以象素为单位
|
||||
u32 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
|
||||
u32 biXPelsPerMeter; //水平分辨率,用象素/米表示
|
||||
u32 biYPelsPerMeter; //垂直分辨率,用象素/米表示
|
||||
u32 biClrUsed; //位图实际使用的彩色表中的颜色索引数
|
||||
u32 biClrImportant; //对图象显示有重要影响的颜色索引的数目,如果是0,表示都重要。
|
||||
}_BITMAPINFOHEADER;
|
||||
/**
|
||||
* @brief 调色板
|
||||
*/
|
||||
typedef struct{
|
||||
u8 rgbBlue; //指定蓝色强度
|
||||
u8 rgbGreen; //指定绿色强度
|
||||
u8 rgbRed; //指定红色强度
|
||||
u8 rgbReserved; //保留,设置为0
|
||||
}_RGBQUAD;
|
||||
/**
|
||||
* @brief BMP文件头
|
||||
*/
|
||||
typedef struct{
|
||||
_BITMAPFILEHEADER bmfHeader; //位图文件头
|
||||
_BITMAPINFOHEADER bmiHeader; //位图信息头
|
||||
_RGBQUAD bmiColors[256]; //调色板
|
||||
}_BITMAPINFO;
|
||||
#pragma pack()
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// 头文件
|
||||
#pragma once
|
||||
/**
|
||||
* @brief 构建一个BMP类
|
||||
*/
|
||||
class bsp_BMP {
|
||||
public:
|
||||
bsp_BMP(u32 Width, u32 Height);
|
||||
~bsp_BMP(void);
|
||||
public:
|
||||
void pels(u32 x, u32 y);
|
||||
u32 giveData(void);
|
||||
void delData(void);
|
||||
void ColorsSet(u8 R, u8 G, u8 B,u32 i);
|
||||
void sizeSet(u32 x, u32 y);
|
||||
public:
|
||||
_BITMAPINFO BITMAPINFO; ///< 文件头
|
||||
u32 Size; ///< 文件大小
|
||||
u8* dat; ///< 数据区
|
||||
};
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
#endif
|
||||
@@ -31,6 +31,7 @@
|
||||
* @date 2022-11-23 02:46
|
||||
*/
|
||||
#pragma once
|
||||
#ifdef __cplusplus
|
||||
#include <stdlib.h>
|
||||
#include "varint.h"
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -79,3 +80,4 @@ class bsp_Integral {
|
||||
float dt; ///< 时间参数
|
||||
};
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
#endif
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file bsp_SD.cpp
|
||||
* @file bsp_SD.h
|
||||
* @brief 操作SD卡的库
|
||||
* @mainpage 主要信息
|
||||
* @author Yuankang Liang(XerolySkinner)
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file bsp_flash.h
|
||||
* @file bsp_flash.c
|
||||
* @brief 写STM32的Flash库
|
||||
* @mainpage 主要信息
|
||||
* @author Yuankang Liang(XerolySkinner)
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file varint
|
||||
* @file varint.h
|
||||
* @brief 全局共用的标准类型表
|
||||
* @mainpage 主要信息
|
||||
* @author Yuankang Liang(XerolySkinner)
|
||||
@@ -57,4 +57,29 @@ typedef volatile i16 vi16; ///< 16λ
|
||||
typedef volatile i32 vi32; ///< 32位有符号易变类型
|
||||
typedef volatile i64 vi64; ///< 64位有符号易变类型
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// 位宏
|
||||
#define P8(x) ((u8*)(&(x))) ///< 强制转换变成u8的指针
|
||||
#define Pn8(x,y) (((u8*)(&(x)))[y]) ///< 强制转换变成u8的数组
|
||||
#define P16(x) ((u16*)(&(x))) ///< 强制转换变成u16的指针
|
||||
#define Pn16(x,y) (((u16*)(&(x)))[y]) ///< 强制转换变成u16的数组
|
||||
#define P32(x) ((u32*)(&(x))) ///< 强制转换变成u32的指针
|
||||
#define Pn32(x,y) (((u32*)(&(x)))[y]) ///< 强制转换变成u32的数组
|
||||
|
||||
#define DelLb(x) (x & (x - 1)) ///< 移除最低位的1
|
||||
#define qDelLb(x) (x=(x & (x - 1))) ///< 移除并保存最低位的1
|
||||
|
||||
#define toBool(x) (x!=0) ///< 数布尔化
|
||||
#define uBit(x,y) (x&(1<<y)) ///< 挑选某一位
|
||||
#define tBit(x,y) (toBool(uBit(x,y))) ///< 挑选某一位并且布尔化
|
||||
|
||||
#define sBit(x,y) (x|(1<<y)) ///< 置高某一位
|
||||
#define rBit(x,y) (x&(~(1<<y))) ///< 拉低某一位
|
||||
#define mBit(x,y,z) ((z)?sBit(x,y):rBit(x,y)) ///< 选择性拉高拉低某一位
|
||||
|
||||
#define LpAdd(x,y) ((x+1)<y?x+1:0) ///< 带最高限制的加法
|
||||
#define LpDec(x,y) (x>0?x-1:y-1) ///< 带最低限制的减法
|
||||
#define qLpAdd(x,y) (x=(x+1)<y?x+1:0) ///< 带最高限制的自增
|
||||
#define qLpDec(x,y) (x=x>0?x-1:y-1) ///< 带最低限制的自减
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
Reference in New Issue
Block a user