201306131732rotate_180 方法的作用就是把buffer 中的數據按像素倒轉過來(如果說一個 PIXEL = R,G,B,A)

如果說一個 PIXEL = R,G,B,A
那 #define PIXEL_SIZE   4
這個範例很常用在處理影像反轉程式


rotate_180 方法的作用就是把buffer 中的數據按像素倒轉過來
例如:原始數據

{(0x00,0x01,0x02,0x03),(0x04,0x05,0x06,0x07),(0x08,0x09,0x0a,0x0b),(0x0c,0x0d,0x0e,0x0f)};

180 度旋轉後數據
{(0x0c,0x0d,0x0e,0x0f),(0x08,0x09,0x0a,0x0b),(0x04,0x05,0x06,0x07)(0x00,0x01,0x02,0x03)};


/* printf example */
#include
#include
#define PIXEL_SIZE   4
void reverse_array(int arr[], int length);
void *rotate_180(void *_dst,const void *_src,int len);
unsigned char strarray_1[16] = {0x00};
unsigned char strarray_2[16] = {0x00, 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};

void main(){
  int i = 0;
  rotate_180(strarray_1,strarray_2,16);
  for( i = 0; i < 16; i++) {
    printf("The strarray_1[%d] is %d\r\n",i,strarray_1[i]);
  }
}
void *rotate_180(void *_dst,const void *_src,int len)
{
  int pixelSize = PIXEL_SIZE, size = 0;
  int step = len / pixelSize;
  unsigned char *dst = (unsigned char *)_dst;
  const unsigned char *src = (unsigned char *)_src + len;
  while((step--) > 0){
    size = pixelSize;
    src -=size;
    while((size--) > 0){
    *dst++ = *src++;
    }
    src -=pixelSize;
  }
  return _dst;
}

沒有上一則|日誌首頁|沒有下一則
回應





Powered by Xuite
    沒有新回應!
關鍵字