图片已经取模生成点阵数组,每1位控制像素点是否显示,如何镜像翻转?
比如下面这张图:
使用取模软件生成点阵数组:
生成的数组如下:
调用将图片数组显示出来:
show_image_by_ascii(gImage_upload, 32, 32, '*'); 三、在x方向镜像 static uint8_t reverse8(uint8_t c){ c = ( c & 0x55 ) << 1 | ( c & 0xAA ) >> 1; c = ( c & 0x33 ) << 2 | ( c & 0xCC ) >> 2; c = ( c & 0x0F ) << 4 | ( c & 0xF0 ) >> 4; return c;}int image_mirror_x(uint8_t *image, uint32_t width, uint32_t height){ uint32_t bytes_per_line, lines; uint32_t i, j, k, offset; uint8_t t, v; bytes_per_line = width / 8; lines = height; printf("bytes_per_line is %dn", bytes_per_line); printf("lines is %dn", lines); for (i = 0; i < lines; i++) { // line mirror. offset = bytes_per_line*i; for (j = 0; j < bytes_per_line/2; j++) { t = image[offset+j]; image[offset+j] = image[offset+4-j-1]; image[offset+4-j-1] = t; } for (j = 0; j < bytes_per_line; j++) { // byte mirror image[offset+j] = reverse8(image[offset+j]); } }} 四、在Y方向镜像 int image_mirror_y(uint8_t *image, uint32_t width, uint32_t height){ uint32_t bytes_per_line, lines; uint32_t i, j, k, offset, other_offset, total_bytes; uint8_t t, v; // width: 32, height: 16. // 32 / 8 = 4; bytes_per_line = width / 8; lines = height; total_bytes = bytes_per_line * lines; printf("bytes_per_line is %dn", bytes_per_line); printf("lines is %dn", lines); printf("total_bytes is %dn", total_bytes); for (i = 0; i < lines/2; i++) { // line mirror. offset = bytes_per_line*i; other_offset = total_bytes - offset-4; for (j = 0; j < bytes_per_line; j++) { t = image[offset+j]; image[offset+j] = image[other_offset+j]; image[other_offset + j] = t; } }}将图片镜像之后:
image_mirror_y(gImage_upload, 32, 32);结果如下:
免责声明:文章源自网络,版权归原作者所有,如有侵犯联系删除。