c语言实现bitmap
来源:互联网 发布:阿里万网域名注册官网 编辑:程序博客网 时间:2024/04/30 20:45
c语言实现的bitmap,功能可用,已经过测试,如果需要其他操作(字节序转换、清空等),可自行添加。
大家可在此下载源代码:下载源代码
/* bitmap.h * * Copyright (C) 2013, 2013 chashen. All Rights Reserved. * Written by chashen * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */#ifndef _BITMAP_H_#define _BITMAP_H_typedef struct tagBitmap{ unsigned int uiMemSize; /* bitmap所占内存大小,不包括本头部 */ unsigned int uiMaxBitID; /* 最大有效位 */ unsigned char aucPtr[0]; /* bitmap数据区 */}BITMAP_S;BITMAP_S *Bitmap_Create(unsigned int uiMaxBitID);void Bitmap_Destroy(BITMAP_S *pstBitmap);void Bitmap_Set(BITMAP_S *pstBitmap, unsigned int uiPos);void Bitmap_Reset(BITMAP_S *pstBitmap, unsigned int uiPos);int Bitmap_Check(BITMAP_S *pstBitmap, unsigned int uiPos);#endif /* _BITMAP_H_ */
/* bitmap.c * * Copyright (C) 2013, 2013 chashen. All Rights Reserved. * Written by chashen * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */#include <stdlib.h>#include <string.h>#include "bitmap.h"/******************************************************************** Function Name: Bitmap_Create Date Created: 2013-11-07 Author: chashen Description: 创建指定最大有效位的位图 Input: unsigned int uiMaxBitID, 最大有效位 Output: none Return: BITMAP_S *, 创建成功 NULL, 创建失败 Caution: ---------------------------------------------------------------- Modifiction History DATE NAME DESCRIPTION ------------------------------------------------------------ YYYY-MM-DD ----------------------------------------------------------------********************************************************************/BITMAP_S *Bitmap_Create(unsigned int uiMaxBitID){ BITMAP_S *pstBitmap = NULL; unsigned int uiLen = sizeof(BITMAP_S); unsigned int uiMemSize = (uiMaxBitID + 1) / 8; unsigned int uiRemainder = (uiMaxBitID + 1) % 8; if (uiRemainder != 0) { uiMemSize++; } uiLen += uiMemSize; pstBitmap = malloc(uiLen); if (pstBitmap != NULL) { memset(pstBitmap, 0, uiLen); pstBitmap->uiMemSize = uiMemSize; pstBitmap->uiMaxBitID = uiMaxBitID; } return pstBitmap;}/******************************************************************** Function Name: Bitmap_Destroy Date Created: 2013-11-07 Author: chashen Description: 销毁位图 Input: none Output: none Return: void Caution: ---------------------------------------------------------------- Modifiction History DATE NAME DESCRIPTION ------------------------------------------------------------ YYYY-MM-DD ----------------------------------------------------------------********************************************************************/void Bitmap_Destroy(BITMAP_S *pstBitmap){ free(pstBitmap); pstBitmap = NULL;}/******************************************************************** Function Name: Bitmap_Set Date Created: 2013-11-07 Author: chashen Description: 设置位图的指定位 Input: BITMAP_S *pstBitmap, 位图指针 unsigned int uiPos, 指定的设置位 Output: none Return: void Caution: ---------------------------------------------------------------- Modifiction History DATE NAME DESCRIPTION ------------------------------------------------------------ YYYY-MM-DD ----------------------------------------------------------------********************************************************************/void Bitmap_Set(BITMAP_S *pstBitmap, unsigned int uiPos){ pstBitmap->aucPtr[uiPos / 8] |= (0x80 >> uiPos % 8);}/******************************************************************** Function Name: Bitmap_Reset Date Created: 2013-11-07 Author: chashen Description: 重置位图的指定位 Input: BITMAP_S *pstBitmap, 位图指针 unsigned int uiPos, 指定的重置位 Output: none Return: void Caution: ---------------------------------------------------------------- Modifiction History DATE NAME DESCRIPTION ------------------------------------------------------------ YYYY-MM-DD ----------------------------------------------------------------********************************************************************/void Bitmap_Reset(BITMAP_S *pstBitmap, unsigned int uiPos){ pstBitmap->aucPtr[uiPos / 8] &= (~(0x80 >> uiPos % 8));}/******************************************************************** Function Name: Bitmap_Check Date Created: 2013-11-07 Author: chashen Description: 检查位图的指定位是否设置 Input: BITMAP_S *pstBitmap, 位图指针 unsigned int uiPos, 指定的检查位 Output: none Return: 1, 指定位设置 0, 指定位没有设置 Caution: ---------------------------------------------------------------- Modifiction History DATE NAME DESCRIPTION ------------------------------------------------------------ YYYY-MM-DD ----------------------------------------------------------------********************************************************************/int Bitmap_Check(BITMAP_S *pstBitmap, unsigned int uiPos){ int iRet = 0; if ((pstBitmap->aucPtr[uiPos / 8] & (0x80 >> (uiPos % 8))) != 0) { iRet = 1; } return iRet;}
- c语言实现bitmap
- bitmap C语言实现
- C语言实现位图(bitmap)
- bitmap应用及C语言实现
- bitmap应用及C语言实现
- C实现bitmap位图
- C实现bitmap位图
- C实现bitmap位图
- C实现bitmap位图
- C实现bitmap位图
- 使用C语言生成bitmap
- 算法学习 - bitmap实现(c++)
- C语言实现bitmap,取两个数组的交集等操作
- 海量数据处理系列——C语言下实现bitmap算法
- 海量数据处理系列——C语言下实现bitmap算法
- 海量数据处理系列——C语言下实现bitmap算法
- 海量数据处理系列——C语言下实现bitmap算法
- 用c语言保存bitmap图像
- acm文件的输入输出
- google proxy 问题
- 暂且把两年后工作的目标定位为豆瓣
- Android如何实现压缩图片后再上传至服务器
- oracle新建数据库
- c语言实现bitmap
- java synchronized详解 二
- C++ 程序编译的一些莫名其妙的错误。【2013.11.7】
- Python 调试工具
- Linux系统下基于Kvm创建虚拟机时网络网桥的配置使用说明
- 常用的mysql语句
- struts2+jquery+ajax表单验证
- Android平台第三方应用分享到微信开发
- iOS公司开发者账号申请分享攻略