直接上代码
enum PixelFlip
{
__NoFlip = 0,
__Horizontally,
__Vertically,
__Diagonally,
};
enum PixelChannel
{
__U8 = 1, // 8 bit
__U24 = 3, // 8:8:8 bit
};
void flip(uint8_t *data, int width, int height, PixelFlip state, PixelChannel channel)
{
if( state == PixelFlip::__NoFlip ) {
return;
}
int cx = width / 2;
int cy = height / 2;
uint8_t *front = NULL;
uint8_t *back = NULL;
uint8_t d;
switch (state) {
case PixelFlip::__Horizontally: {
for(int i = 0; i < height; i ++) {
front = data + (width * i * channel);
back = data + (width * (i + 1) * channel - channel);
for(int j = 0; j < cx; j ++) {
for(int c = 0; c <

本文介绍了一种针对单通道和三通道图像的像素翻转函数优化,包括水平、垂直和对角线翻转,并提供了针对不同通道类型(如8位、24位)的专用代码示例。通过代码重构,展示了如何简化处理过程并提高性能。
最低0.47元/天 解锁文章
2855

被折叠的 条评论
为什么被折叠?



