`
yuyututuw
  • 浏览: 27858 次
  • 性别: Icon_minigender_1
  • 来自: 广州
最近访客 更多访客>>
社区版块
存档分类
最新评论

24bitbmp to bmp565

 
阅读更多

24bitbmp to bmp565
2011年10月22日
  /*对开发手机应用的有作用*/
  /*资源来自互联网*/
  #include
  #include
  //#define ALIGNMENT_FIX
  typedef struct _bitmap_file_header bitmap_file_header;
  struct _bitmap_file_header
  {
  unsigned short Type;
  unsigned int Size;
  unsigned short Reserved1;
  unsigned short Reserved2;
  unsigned int OffSet;
  };
  typedef struct _bitmap_info_header bitmap_info_header;
  struct _bitmap_info_header
  {
  unsigned int Size;
  long Width;
  long Height;
  short int Planes;
  short int BitCount;
  unsigned int Compression;
  unsigned int SizeImage;
  long XPelsPerMeter;
  long YPelsPerMeter;
  unsigned int ClrUsed;
  unsigned int ClrImportant;
  };
  int main(int argc, char* argv[])
  {
  #ifdef ALIGNMENT_FIX
  int pre_append_bytes;
  int post_append_bytes;
  #endif
  int i,j;
  int bytes_per_line;
  int end_fix_byte;
  unsigned char read_byte[3];
  unsigned short int write_data;
  char write_string[11];
  char file_name[1024];
  bitmap_file_header is_file_header;
  bitmap_info_header is_info_header;
  FILE *fp;
  FILE *out_fp;
  if (argc != 3)
  {
  printf("bmp24_to565.exe input.bmp output.hex\n");
  return -1;
  }
  memset(file_name,0,1024);
  sprintf(file_name,"./%s",argv[1]);
  fp = fopen(file_name,"rb");
  if (NULL == fp)
  {
  printf("can't open file:%s",file_name);
  return -1;
  }
  /* 读取文件头 */
  fread(&is_file_header.Type,sizeof(is_file_header.Type),1,fp);
  fread(&is_file_header.Size,sizeof(is_file_header.Size),1,fp);
  fread(&is_file_header.Reserved1,sizeof(is_file_header.Reserved1),1,fp);
  fread(&is_file_header.Reserved2,sizeof(is_file_header.Reserved2),1,fp);
  fread(&is_file_header.OffSet,sizeof(is_file_header.OffSet),1,fp);
  if (0x4d42 != is_file_header.Type)
  {
  printf("not support file format\n");
  return -1;
  }
  /* 读取信息头 */
  fread(&is_info_header,sizeof(is_info_header),1,fp);
  /* 类型判断*/
  if(24 != is_info_header.BitCount)
  {
  printf("only support 24 deep bitmap\n");
  return -1;
  }
  /* 有无调色板 */
  if(0 != is_info_header.ClrUsed)
  {
  printf("only support 24 deep bitmap without color plant\n");
  return -1;
  }
  /* 是否压缩 */
  if(0 != is_info_header.Compression)
  {
  printf("not support Compression bitmap\n");
  return -1;
  }
  #ifdef ALIGNMENT_FIX
  /* 原24bbp补齐的字节数,为4则没有补齐*/
  pre_append_bytes = 4 - ((is_info_header.Width * 3) % 4);
  /* 补齐的字节术,为4则不需要补齐*/
  post_append_bytes = 4 - ((is_info_header.Width * 2) % 4);
  #endif
  /* open to write */
  memset(file_name,0,1024);
  sprintf(file_name,"./%s",argv[2]);
  out_fp = fopen(file_name,"w");
  if (NULL == out_fp)
  {
  printf("can't open file:%s",file_name);
  return -1;
  }
  if (0 == ((is_info_header.Width * 3) % 4))
  bytes_per_line = (is_info_header.Width * 3);
  else
  bytes_per_line = (is_info_header.Width * 3) + (4 - (is_info_header.Width * 3) % 4);
  /* convert data */
  for (i=0; i 16 */
  write_data = (read_byte[0] >> 3) | ((read_byte[1] & 0xFC) > 8;
  sprintf(write_string,"0x%02x,0x%02x,",read_byte[0],read_byte[1]);
  fwrite(write_string,10,1,out_fp);
  }
  #ifdef ALIGNMENT_FIX
  /* 24bbp 是否有补齐的bytes */
  if (4 != pre_append_bytes)
  {
  fread(&read_byte,pre_append_bytes,1,fp); /* 跳过补全的0x00 */
  }
  /* 生成的RGB565是否需要对齐*/
  if (4 != post_append_bytes)
  {
  /* RGB565 只可能补一个 0x0000*/
  /* 调试发现输出不需要补齐*/
  sprintf(write_string,"0x00,0x00,");
  fwrite(write_string,10,1,out_fp);
  }
  #endif
  }
  fclose(fp);
  fclose(out_fp);
  return 0;
  }
  批量转换脚本
  #!/usr/bin/env python
  import os,re,subprocess
  filelist=os.listdir(os.getcwd())
  test = re.compile("\.[bB][mM][pP]$", re.IGNORECASE)
  bmpfiles = filter(test.search, filelist)
  for file in bmpfiles:
  subprocess.Popen('bmp24_to565.exe %s %shex' %(file,file[:-3]), shell=True)
分享到:
评论

相关推荐

    24bitBMP图像的直方图显示

    最基础的数字图像的c++代码显示一24bit BMP图像的直方图

    比较两幅Bmp并输出不同

    比较两幅bitmap图像,找出不同,并将第一副图像中与第二幅不同的pixel取反输出。

    显示8bitBMP图像的直方图

    最基础的图像处理编程 能够显示一8bitBMP图像的直方图

    基于Hash的随机LSB信息隐藏程序

    包含波形小幅扰动抗攻击 自己编写的 包含24bitBMP文件的读取与像素分离 快速傅立叶变换 散列LSB等相关算法的头文件 与系统无关 可以通过G++编译 在Win/Linux环境下都可以正常工作 也可以将头文件提取出来应用于其他...

    MFC图片插入.sln

    首先要知道添加的图片是什么格式的 建议添加bmp格式的。 操作时先把图片添加到资源中,然后再picture控件单击右键属性,选哪个bitbmp。然后找到你添加的那个。

Global site tag (gtag.js) - Google Analytics