下面的代码是我的老师给我的。我只是不明白这是如何缩放bmp图像。我知道关于bmp图像的基础知识(wikipedia上的信息)。我知道这种方法应该用任何比例乘以新图像的行和列。我试图手动运行代码,但它让我更加困惑。任何帮助都感激不尽。谢谢!不明白这段代码是如何缩放bmp图像的
int enlarge(PIXEL* original, int rows, int cols, int scale,
PIXEL** new, int* newrows, int* newcols)
{
//scaling the new rows & cols
*newcols = cols * scale;
*newrows = rows * scale;
//memory allocated for enlaged bmp
*new = (PIXEL*)malloc(*newrows * *newcols * sizeof(PIXEL));
int row, col, sx, sy;
//transverse through every row
for (row = 0; row < rows; row++)
//transvere through every col
for (col = 0; col < cols; col++){
//im unsure what this is for
PIXEL* o = original + (row * cols) + col;
for(sy = 0; sy < scale; sy++)
for(sx = 0; sx < scale; sx++)
{
//im unsure what this is for
PIXEL* n = *new + (scale * row) * *newcols + (scale * col) + (sy * *newcols) + sx;
*n = *o;
}
}
return 0;
}
这是PIXEL的结构。
typedef struct {
unsigned char r;
unsigned char g;
unsigned char b;
} PIXEL;
有额外的代码,但我不认为这是需要这个问题。
内两个环路填写与像素的副本放大的版本的方通过'O'指向。 'o'只是您在所有像素上循环的上下文中的“当前像素”。 – harold
它在每个像素处做了什么? – name