Scan line of Bitmap

本文详细介绍了位图(BMP)文件格式中像素数组的组织方式。为了确保内存地址对齐和文件存储效率,每行像素数据需填充至4字节的整数倍,并且在内存加载时每个像素行的起始地址也必须是4字节的倍数。这些规定对于理解BMP文件的内部结构至关重要。


The pixel array is a block of 32-bit DWORDs, that describes the image pixel by pixel.
Padding bytes (not necessarily 0) must be appended to the end of the rows in order to bring up the length of the rows to a multiple of four bytes.
When the pixel array is loaded into memory, each row must begin at a memory address that is a multiple of 4.
This address/offset restriction is mandatory only for Pixel Arrays loaded in memory.

For file storage purposes, only the size of each row must be a multiple of 4 bytes while the file offset can be arbitrary.
(出于存储目的,行的大小必须为4的倍数,而偏移量则可以为任意值。)

Reference: http://en.wikipedia.org/wiki/BMP_file_format#cite_note-DIBhelp-5


void vhost_rdma_net_construct(struct vhost_user_queue *queues, int idx) { g_vhost_rdma_net_dev[idx].queues = queues; g_vhost_rdma_net_dev[idx].started = false; } int vhost_rdma_pool_init(struct vhost_rdma_pool* pool, const char* name, uint32_t num, uint32_t size, bool start_zero, void (*cleanup)(void*)) { void *mem; uint32_t bmp_size; struct rte_bitmap *bmp; if (!start_zero) { num += 1; } pool->objs = rte_zmalloc(name, num * size, RTE_CACHE_LINE_SIZE); if (pool->objs == NULL) { RDMA_LOG_ERR("Failed to allocate memory for objs"); return -1; } bmp_size = rte_bitmap_get_memory_footprint(num); mem = rte_zmalloc(name, bmp_size, RTE_CACHE_LINE_SIZE); if (mem == NULL) { rte_free(pool->objs); RDMA_LOG_ERR("Failed to allocate memory for bitmap"); return -1; } bmp = rte_bitmap_init(num, mem, bmp_size); if (bmp == NULL) { rte_free(mem); rte_free(pool->objs); RDMA_LOG_ERR("Failed to init bitmap"); return -1; } /* set all available */ for(uint64_t i = 0; i < num; i++) { rte_bitmap_set(bmp, i); } if (!start_zero) { rte_bitmap_clear(bmp, 0); } pool->bitmap = bmp; pool->bitmap_mem = mem; pool->num = num; pool->size = size; pool->cleanup = cleanup; return 0; } void* vhost_rdma_pool_get(struct vhost_rdma_pool* pool, uint32_t idx) { uint64_t set; set = rte_bitmap_get(pool->bitmap, idx); if (set) { return NULL; } else { return (char*)pool->objs + pool->size * idx; } } void* vhost_rdma_pool_alloc(struct vhost_rdma_pool* pool, uint32_t *idx) { int found; uint32_t pos = 0; uint64_t slab = 0; void* obj; __rte_bitmap_scan_init(pool->bitmap); found = rte_bitmap_scan(pool->bitmap, &pos, &slab); if (found) { *idx = pos + __builtin_ctzll(slab); obj = (char*)pool->objs + pool->size * *idx; memset(obj, 0, pool->size); rte_bitmap_clear(pool->bitmap, *idx); return obj; } return NULL; } void vhost_rdma_pool_free(struct vhost_rdma_pool* pool, uint32_t idx) { // FIXME: lock? rte_bitmap_set(pool->bitmap, idx); } void vhost_rdma_pool_destroy(struct vhost_rdma_pool* pool) { rte_free(pool->objs); rte_bitmap_free(pool->bitmap); rte_free(pool->bitmap_mem); } 同上
最新发布
10-10
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值