Skip to content

Commit

Permalink
剪切变换
Browse files Browse the repository at this point in the history
  • Loading branch information
duguying committed Jul 20, 2014
1 parent 7f5b5de commit b78bbb3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
26 changes: 24 additions & 2 deletions src/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,30 @@ void rotate_left(Matrix* matrix){
tmp = NULL;
}

void cut(size_t x1, size_t y1, size_t x2, size_t y2, Matrix* matrix){
;
void cut(size_t x1, size_t y1, size_t width, size_t height, Matrix* matrix){
size_t len = 0;
RGBPx* tmp = NULL;
size_t x = 0, y = 0, w = 0, h = 0;

w = matrix->width;
h = matrix->height;

len = width * height * sizeof(RGBPx);
tmp = (RGBPx*)malloc(len);
memset(tmp, 0, len);

for (y = 0; y < height; ++y)
{
for (x = 0; x < width; ++x)
{
tmp[x + y * width] = matrix->matrix[(x + x1) + (y + y1) * w];
}
}

matrix->width = width;
matrix->height = height;
free(matrix->matrix);
matrix->matrix = tmp;
}

void zoom_in(Matrix* matrix){
Expand Down
2 changes: 1 addition & 1 deletion src/transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void rotate_right(Matrix* matrix);

void rotate_left(Matrix* matrix);

void cut(size_t x1, size_t y1, size_t x2, size_t y2, Matrix* matrix);
void cut(size_t x1, size_t y1, size_t width, size_t height, Matrix* matrix);

void zoom_in(Matrix* matrix);

Expand Down
5 changes: 4 additions & 1 deletion tests/bmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ void draw(RGBPx* data, size_t width, size_t height){
SetPixel(hdc, x, y, RGB(data[y*width+x].R , data[y*width+x].G , data[y*width+x].B));
}
}

ReleaseDC(NULL, hdc);
}

int main(int argc, char const *argv[])
Expand All @@ -28,7 +30,8 @@ int main(int argc, char const *argv[])

// roll_x(data);
roll_y(data);
rotate_left(data);
// rotate_left(data);
cut(190, 150, 250, 350, data);

draw(data->matrix, data->width, data->height);
free_matrix(data);
Expand Down

0 comments on commit b78bbb3

Please sign in to comment.