|
|
@ -35,10 +35,7 @@ int image_new(int width, int height, Image* img) {
|
|
|
|
// initialize bitmap...
|
|
|
|
// initialize bitmap...
|
|
|
|
img->bitmap = malloc(height * sizeof(int*));
|
|
|
|
img->bitmap = malloc(height * sizeof(int*));
|
|
|
|
for (int i = 0; i < height; i++) {
|
|
|
|
for (int i = 0; i < height; i++) {
|
|
|
|
img->bitmap[i] = malloc(width * sizeof(int*));
|
|
|
|
img->bitmap[i] = malloc(3 * width * sizeof(int));
|
|
|
|
for (int j = 0; j < width; j++) {
|
|
|
|
|
|
|
|
img->bitmap[i][j] = malloc(3 * sizeof(int));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//*image = *img;
|
|
|
|
//*image = *img;
|
|
|
@ -93,10 +90,10 @@ int image_save(Image* image, char* path) {
|
|
|
|
int line;
|
|
|
|
int line;
|
|
|
|
for (line = 0; line < image->height; line++) {
|
|
|
|
for (line = 0; line < image->height; line++) {
|
|
|
|
byte_pos = 0;
|
|
|
|
byte_pos = 0;
|
|
|
|
for (int px = 0; px < image->width; px++) {
|
|
|
|
for (int px = 0; px < image->width * 3; px += 3) {
|
|
|
|
bytes[byte_offset + byte_pos++] = image->bitmap[line][px][2];
|
|
|
|
bytes[byte_offset + byte_pos++] = image->bitmap[line][px + 2];
|
|
|
|
bytes[byte_offset + byte_pos++] = image->bitmap[line][px][1];
|
|
|
|
bytes[byte_offset + byte_pos++] = image->bitmap[line][px + 1];
|
|
|
|
bytes[byte_offset + byte_pos++] = image->bitmap[line][px][0];
|
|
|
|
bytes[byte_offset + byte_pos++] = image->bitmap[line][px + 0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
byte_offset += align_to_four_bytes(byte_pos);
|
|
|
|
byte_offset += align_to_four_bytes(byte_pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -114,9 +111,18 @@ int image_save(Image* image, char* path) {
|
|
|
|
int image_set_px(Image* image, int x, int y, int r, int g, int b) {
|
|
|
|
int image_set_px(Image* image, int x, int y, int r, int g, int b) {
|
|
|
|
if (!image_check_coords(image, x, y)) return 0;
|
|
|
|
if (!image_check_coords(image, x, y)) return 0;
|
|
|
|
|
|
|
|
|
|
|
|
image->bitmap[y][x][0] = (char) r;
|
|
|
|
image->bitmap[y][(3 * x) + 0] = (char) r;
|
|
|
|
image->bitmap[y][x][1] = (char) g;
|
|
|
|
image->bitmap[y][(3 * x) + 1] = (char) g;
|
|
|
|
image->bitmap[y][x][2] = (char) b;
|
|
|
|
image->bitmap[y][(3 * x) + 2] = (char) b;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int image_set_px_c(Image* image, int x, int y, Color* color) {
|
|
|
|
|
|
|
|
if (!image_check_coords(image, x, y)) return 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
image->bitmap[y][(3 * x) + 0] = (char) color->r;
|
|
|
|
|
|
|
|
image->bitmap[y][(3 * x) + 1] = (char) color->g;
|
|
|
|
|
|
|
|
image->bitmap[y][(3 * x) + 2] = (char) color->b;
|
|
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -128,9 +134,6 @@ int image_check_coords(Image* image, int x, int y) {
|
|
|
|
|
|
|
|
|
|
|
|
int image_destroy(Image* image) {
|
|
|
|
int image_destroy(Image* image) {
|
|
|
|
for (int i = 0; i < image->height; i++) {
|
|
|
|
for (int i = 0; i < image->height; i++) {
|
|
|
|
for (int j = 0; j < image->width; j++) {
|
|
|
|
|
|
|
|
free(image->bitmap[i][j]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
free(image->bitmap[i]);
|
|
|
|
free(image->bitmap[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(image->bitmap);
|
|
|
|
free(image->bitmap);
|
|
|
@ -138,3 +141,26 @@ int image_destroy(Image* image) {
|
|
|
|
return 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////// Colors
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Color* color_new(int r, int g, int b) {
|
|
|
|
|
|
|
|
Color* c = malloc(sizeof(Color));
|
|
|
|
|
|
|
|
c->r = r;
|
|
|
|
|
|
|
|
c->g = g;
|
|
|
|
|
|
|
|
c->b = b;
|
|
|
|
|
|
|
|
return c;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int image_draw_rect(Image* image, int x1, int y1, int x2, int y2, Color* color) {
|
|
|
|
|
|
|
|
int retval = 1;
|
|
|
|
|
|
|
|
int y;
|
|
|
|
|
|
|
|
for (; x1 < x2; x1++) {
|
|
|
|
|
|
|
|
for (y = y1; y < y2; y++) {
|
|
|
|
|
|
|
|
if (!image_set_px_c(image, x1, y, color)) retval = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|