24位深的bmp图片转换为16位深RGB565格式的bmp图片源码

本文详细介绍了如何将24位深的bmp图像转换为16位深的RGB565格式。通过源码解析,展示了颜色深度转换的具体步骤和算法,适用于图像处理和嵌入式系统中的资源优化。
摘要由CSDN通过智能技术生成
/**
    24位深的bmp图片转换为16位深RGB565格式的bmp图片
 **/
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

typedef unsigned char uint8;
typedef char int8;
typedef unsigned short  uint16; //32bit system
typedef short  int16;
typedef unsigned int uint32;//32bit system
typedef int int32;

struct bmp_filehead //14B
{
    //2B 'BM'=0x424d;   
    uint16 bmtype; //'BM',2B  
    uint32 bmSize; //size,4B  
    uint32 bmReserved;//0x00,4B
    uint32 bmOffBits;//4B,... 54

}head1;

struct bmphead //40B
{
    uint32 bmpOffBits;//4B,... 40
    uint32 bmp_wide;//4B,wide
    uint32 bmp_high;//4B,high 
    uint16 bmplans;//2B,0 or 1
    uint16 bitcount;//2B ,24
    uint32 bmpyasuo;//4B,0
    uint32 imagesize;//4B,w*h*3

    uint32 biXPelsPerMeter;
    uint32 biYPelsPerMeter;
    uint32 biClrUsed;
    uint32 biClrImportant;
}head2;

struct BGR_data //40B
{
    uint8 B_data;
    uint8 G_data;
    uint8 R_data;
}clr_data[1024*768]; //img size must less than 1024*768 

bool bmp565_write(unsigned char *image, uint32 width, uint32 height, const char *filename)      
{
    unsigned char buffer[1024*1024] = {
  0};
    uint32 file_size;     
    uint32 data_size;     
    unsigned int widthAlignBytes;     
    FILE *fp;     

    // 文件头     
    unsigned char header[66] = {     
        // BITMAPFILEINFO     
        'B', 'M',               // [0-1] bfType:必须是BM字符     
        0, 0, 0, 0,             // [2-5] bfSize:总文件大小      
        0, 0, 0, 0,             // [6-9] brReserved1,bfReserved2:保留     
        sizeof(header), 0, 0, 0,
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值