针对邻近插值算法更改的一个版本,原因邻近插值算法会丢失掉一些像素,这个版本图像缩放不会导致像素丢失的问题,未优化版本,有兴趣供参考,本文做整理记录
//
void map_zoom(loadmap_t *dst_map ,loadmap_t *src_map, int zoom_factor)
{
//dst_map 输出图像结构 src_map输入图像结构 zoom_factor图像缩小系数
dst_map->frame.w = ceil((double)src_map->frame.w / zoom_factor);
dst_map->frame.h = ceil((double)src_map->frame.h / zoom_factor);
int dst_width = dst_map->frame.w;
int dst_height = dst_map->frame.h;
int src_width = src_map->frame.w;
int src_height = src_map->frame.h;
int dstx,dsty;
dst_map->ori_img_buf = NULL;
xfree(dst_map->ori_img_buf);
dst_map->ori_img_buf = (unsigned char * )xmalloc(dst_width * dst_height, "relocation zoom map");
unsigned char *dst = dst_map->ori_img_buf;
unsigned char *src = src_map ->ori_img_buf;
if ( (0 == dst_width) || (0 == dst_height)
||(0 == src_width) || (0 == src_height)) return;
for (int x = 0; x < src_width; x++)
{
for (int y = 0; y < src_height; y++)
{
dsty = y / zoom_factor;
dstx = x / zoom_factor;
if( (src[ y * src_width + x] == MAP_HIT_FLAG) &&
(dst[dsty * dst_width + dstx] != MAP_HIT_FLAG))
{
dst[dsty * dst_width + dstx] = MAP_HIT_FLAG;
}
}
}
}

huangea的博客

