rotate.c

来自「卡耐基SSD6全部选择题和练习题解决方法。」· C语言 代码 · 共 43 行

C
43
字号
#include <stdio.h>
#include <stdlib.h>
#include "defs.h"
#include "cache.h"


/* Here is an our naive implementation */
char rotate_descr[] = "Naive Row-wise Traversal of src";

void rotate(int dim, pixel *src, pixel *dst) {
	int i, j;
	int max,m, n;
	int ratio = 8;
	if(dim == 1024)
		ratio = 4;
	

	max = dim/ratio;
	for(m = 0; m < max ; m ++){
		for(n = 0; n < max ; n ++)
		{
			int xNum = m*ratio;
			int yNum = n*ratio;
			for(i=xNum; i < xNum + ratio; i++) {
				for(j=yNum; j < yNum + ratio; j++) {
					COPY(&dst[PIXEL(dim-1-j,i,dim)], &src[PIXEL(i,j,dim)]);
				}
			}
		}
	}

	return;
}



/* Add additional functions to test here */
void register_rotate_functions() {
	add_rotate_function(&rotate, rotate_descr);
	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?