📄 magicsquare.c
字号:
/****************************************************************
* MagicSquare transform:
*
* update on
****************************************************************/
#include "bmp.h"
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <sys/param.h>
#include <tina/sys.h>
#include <tina/sysfuncs.h>
#include <tina/mathfuncs.h>
#include <tina/vision.h>
#include <tina/visionfuncs.h>
#include <tina/file_gen.h>
#include <tina/tv.h>
#include <tina/tvfuncs.h>
#include <tina/toolsfuncs.h>
extern void magicsquare_matrix(int** r, int** c, int height, int width);
void MagicSquare_Trans(int nTrans)
{
Imrect *srcIm, *destIm ;
int width, height;
int type;
BYTE pix;
int lx, ux, ly, uy, i, j, k;
Imregion *roi;
if (stack_check_types(IMRECT, NULL) == false)
{
error("MagicSquare : wrong types on stack", warning);
return;
}
srcIm = (Imrect *) stack_pop(&type);
width = srcIm->width;
height = srcIm->height;
if (width != height)
{
error("MagicSquare:width != height", warning);
return;
}
roi = srcIm->region;
if (roi == NULL) return ;
lx = roi->lx;
ux = roi->ux;
ly = roi->ly;
uy = roi->uy;
destIm = im_alloc( height, width, roi, int_v );
int **r, **c;
r = int_matrix(height, width);
c = int_matrix(height, width);
magicsquare_matrix(r, c, height, width);
/* for(k = 0; k < nTrans; k++)
{*/
for (i = 0; i < height ; i++)
{
for (j = 0; j< width ; j++)
{
IM_PIX_GET(srcIm, i, j, pix);
IM_PIX_SET(destIm, r[i][j], c[i][j], pix);
}
}
/*srcIm = destIm;
}
*/
free_int_matrix(r, height);
free_int_matrix(c, height);
mono_image_set(destIm);
stack_push(destIm, IMRECT, im_free);
printf("\n=== MagicSquare transform is finished! ===\n");
/*printf("\n=== MagicSquare transform complete! ===\n");*/
}
void R_MagicSquare_Trans(int nTrans)
{
Imrect *srcIm, *destIm ;
int width, height;
int type;
BYTE pix;
int lx, ux, ly, uy, i, j, k;
Imregion *roi;
if (stack_check_types(IMRECT, NULL) == false)
{
error("MagicSquare : wrong types on stack", warning);
return;
}
srcIm = (Imrect *) stack_pop(&type);
width = srcIm->width;
height = srcIm->height;
if (width != height)
{
error("MagicSquare:width != height", warning);
return;
}
roi = srcIm->region;
if (roi == NULL) return ;
lx = roi->lx;
ux = roi->ux;
ly = roi->ly;
uy = roi->uy;
destIm = im_alloc( height, width, roi, int_v );
int **r, **c;
r = int_matrix(height, width);
c = int_matrix(height, width);
magicsquare_matrix(r, c, height, width);
/* for(k = 0; k < nTrans; k++)
{*/
for (i = 0; i < height ; i++)
{
for (j = 0; j< width ; j++)
{
IM_PIX_GET(srcIm, r[i][j], c[i][j], pix);
IM_PIX_SET(destIm, i, j, pix);
}
}
/*srcIm = destIm;
}
*/
free_int_matrix(r, height);
free_int_matrix(c, height);
mono_image_set(destIm);
stack_push(destIm, IMRECT, im_free);
printf("\n=== R_MagicSquare transform is finished! ===\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -