Commit f54c9caf authored by draftsquire's avatar draftsquire
Browse files

Pixels** successfully replaced with pixels*

parent f39372ce
No preview for this file type
man.bmp

1.17 MB

......@@ -66,9 +66,12 @@ enum bmp_read_status from_bmp( FILE* in, struct image* const read ){
if (header.biBitCount !=24) return READ_INVALID_BITS;
// uint32_t pixels_count = header.biHeight * header.biWidth;
create_image(read,header.biWidth,header.biHeight);
struct pixel* current_address= read->pixels;
size_t padding = (size_t)bmp_line_padding(header.biWidth);
for (size_t i =0;i< (size_t)header.biHeight;i++){
if(fread(read->pixels[i],sizeof(struct pixel),header.biWidth,in) != header.biWidth) return READ_PIXELS_LOSS;
if(fread(current_address,sizeof(struct pixel)*header.biWidth,1,in) != 1) return READ_PIXELS_LOSS;
fseek(in,padding , SEEK_CUR);
current_address+=header.biWidth;
}
// if (successfully_read_pixels!=pixels_count) return READ_PIXELS_LOSS;
return READ_OK;
......@@ -112,9 +115,11 @@ enum bmp_write_status to_bmp(FILE* out, struct image* const write){
//uint32_t successfully_written_pixels=0;
if(fwrite(&header, sizeof(struct bmp_header), 1, out)!=1) return WRITE_HEADER_ERROR;
uint8_t filling_byte = 0x6F;
struct pixel* current_adress= write->pixels;
for (size_t i =0;i<(size_t)header.biHeight;i++){
if (fwrite(write->pixels[i],sizeof(struct pixel),header.biWidth,out)!= header.biWidth) return WRITE_PIXELS_LOSS;
if (fwrite(current_adress,sizeof(struct pixel)*header.biWidth,1,out)!= 1) return WRITE_PIXELS_LOSS;
fwrite(&filling_byte, sizeof(uint8_t), (size_t)bmp_line_padding(header.biWidth), out);
current_adress+=header.biWidth;
}
//if (successfully_written_pixels!=pixels_to_write) return WRITE_PIXELS_LOSS;
return WRITE_OK;
......
......@@ -3,16 +3,12 @@
void create_image(struct image* image, uint32_t width, uint32_t height) {
image->width = width;
image->height = height;
image->pixels = malloc(sizeof(struct pixel*) * height);
for (size_t i = 0; i <(size_t) height; i++) {
image->pixels[i] = malloc(sizeof(struct pixel) * width);
}
image->pixels = malloc(sizeof(struct pixel)*(size_t)(width*height) );
}
void destroy_image(struct image* image){
for (size_t i = 0; i < (size_t)image->height; i++) {
free(image->pixels[i]);
}
free(image->pixels);
}
......@@ -11,7 +11,7 @@ struct pixel{
struct image{
uint32_t height;
uint32_t width;
struct pixel** pixels;
struct pixel* pixels;
};
void create_image(struct image* image, uint32_t width, uint32_t height);
void destroy_image(struct image* image);
......
#include "transformation.h"
#include <stdio.h>
struct image rotate(struct image* const source ) {
uint32_t rotated_width = source->height;
uint32_t rotated_height=source->width;
struct image rotated_image = {0};
create_image(&rotated_image,rotated_width,rotated_height);
fprintf(stdout, "%" PRIu32"\n", rotated_image.height);
for (size_t i=0; i< (size_t)rotated_width;i++){
for(size_t j=0; j<(size_t)rotated_height;j++){
rotated_image.pixels[j][rotated_width-1-i]=source->pixels[i][j];
for(size_t j=0; j<(size_t)rotated_height;++j){
//rotated_image.pixels[j][rotated_width-1-i]=source->pixels[i];
rotated_image.pixels[i+j*rotated_width]=source->pixels[rotated_height*(i+1)-j-1];
}
}
return rotated_image;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment