1. 正向分割为若干8*8 块
下面的程序为通用程序,可以分割任意块
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/videodev2.h> //v4l2 头文件
#include <string.h>
#include <sys/mman.h>
#include <linux/fb.h>int main(void){char i[]={1, 2, 3, 4, 5, 6, 7, 8,9,10,11,12, 13,14,15,16,17,18,19,20, 21,22,23,24,25,26,27,28, 29,30,31,32,33,34,35,36, 37,38,39,40,41,42,43,44, 45,46,47,48,49,50,51,52, 53,54,55,56,57,58,59,60, 61,62,63,64};int width=8; //被分割数据宽度int heigth=8; //被分割数据高度int fwidth=4; //分割块的宽度 分割成4×2块int fheigth=2; //分割块的高度char o[width*heigth]; //分割后的数据int t=0;for(int c=0;c<heigth/fheigth;c++){for(int b=c*width*fheigth;b<width+c*fheigth*width;b=b+fwidth){for(int a=0;a<fheigth;a++){memcpy(&o[t],&i[a*width+b],fwidth);t=t+fwidth;}}}
//-------------------------------------------------------------- char (*p1)[2][4]=(char (*)[2][4])o; //显示4×2 块for(int a=0;a<8;a++){for(int b=0;b<2;b++){for(int c=0;c<4;c++){printf("%d ",p1[a][b][c]);}printf("\n");}puts("-----------");}return 0;
}
2. 8*8 块逆向 转化为帧
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/videodev2.h> //v4l2 头文件
#include <string.h>
#include <sys/mman.h>
#include <linux/fb.h>int main(void){
/* char i[]={1, 2, 3, 4, 5, 6, 7, 8,9,10,11,12, 13,14,15,16,17,18,19,20, 21,22,23,24,25,26,27,28, 29,30,31,32,33,34,35,36, 37,38,39,40,41,42,43,44, 45,46,47,48,49,50,51,52, 53,54,55,56,57,58,59,60, 61,62,63,64};*/char io[]={1, 2, 3, 4, 9, 10, 11, 12, 17, 18, 19, 20, 25, 26, 27, 28, 5, 6, 7, 8, 13, 14, 15, 16, 21, 22, 23, 24, 29, 30, 31, 32, 33, 34, 35, 36, 41, 42, 43, 44, 49, 50, 51, 52, 57, 58, 59, 60, 37, 38, 39, 40, 45, 46, 47, 48, 53, 54, 55, 56, 61, 62, 63, 64};int width=8; //被分割数据宽度int heigth=8; //被分割数据高度int fwidth=4; //分割块的宽度 int fheigth=4; //分割块的高度/* char o[width*heigth]; //分割后的数据int t=0;for(int c=0;c<heigth/fheigth;c++){for(int b=c*width*fheigth;b<width+c*fheigth*width;b=b+fwidth){for(int a=0;a<fheigth;a++){ memcpy(&o[t],&i[a*width+b],fwidth);t=t+fwidth;}}}
*/ char oo[width*heigth]; int ot=0;for(int c=0;c<heigth/fheigth;c++){for(int a=0;a<fheigth;a++){for(int b=0;b<width/fwidth;b++){memcpy(&oo[ot],&io[b*fwidth*fheigth+a*fwidth+c*fheigth*fwidth*width/fwidth],fwidth);ot=ot+fwidth;}}}
//-------------------------------------------------------------- char (*p1)[4][4]=(char (*)[4][4])oo; //显示for(int a=0;a<4;a++){for(int b=0;b<4;b++){for(int c=0;c<4;c++){printf("%d, ",p1[a][b][c]);}printf("\n");}puts("-----------");}return 0;
}
实话头都绕晕了,看能不能再想一个好理解的方法。查表法简单,但数据大了就不实用了,如果要程序生成大数据的表,感觉又多了一个环节。而且也不容易
但Z 型排列可以用查表法。