Commit c3be1b66 authored by Probyygolova Daniil's avatar Probyygolova Daniil
Browse files

fix mistakes part 3

parent 8efd9af0
......@@ -18,6 +18,7 @@
void bmp_header_print( struct bmp_header const* header, FILE* f ) {
FOR_BMP_HEADER( PRINT_FIELD )
}
uint32_t padding(const uint64_t width){
......@@ -53,20 +54,13 @@ static bool write_header( FILE* f, struct bmp_header *const header ) {
return fwrite( header, sizeof( struct bmp_header ), 1, f );
}
enum status_valid_header {
VALID,
NO_VALID,
};
enum status_valid_header valid_header(struct bmp_header* header){
if(header->bfType!= BMP_TYPE)
return NO_VALID;
if(header->biBitCount!= BIT_COUNT)
return NO_VALID;
if(header->biCompression!=0)
return NO_VALID;
bool valid_header(struct bmp_header* header){
return VALID;
return header->bfType == BMP_TYPE &&
header->biBitCount == BIT_COUNT &&
header->biCompression == 0;
}
enum read_status from_bmp( FILE* in, struct image* img ){
......@@ -76,8 +70,8 @@ enum read_status from_bmp( FILE* in, struct image* img ){
//fread(header, sizeof( struct bmp_header), 1, file);
// Valid header
enum status_valid_header valid_h = valid_header(&header);
if (valid_h == NO_VALID) return READ_INVALID_HEADER;
bool valid_h = valid_header(&header);
if (!valid_h ) return READ_INVALID_HEADER;
struct pixel* data = malloc(sizeof(struct pixel) * (header.biWidth) * (header.biHeight));
......@@ -92,7 +86,10 @@ enum read_status from_bmp( FILE* in, struct image* img ){
fseek(in, pad, SEEK_CUR);
}
if (count < img->height) return READ_ERROR;
if (count < img->height) {
free(img->data);
return READ_ERROR;
}
return READ_OK;
}
......@@ -108,7 +105,7 @@ enum write_status to_bmp( FILE* out, struct image const* img ){
size_t count = 0;
const uint8_t dump =0;
if(!write_header(out, &header)) return WRITE_HEADER_ERROR;
if(!write_header(out, &header)) {free(img->data); return WRITE_HEADER_ERROR;}
fseek(out, sizeof(struct bmp_header), SEEK_SET);
......@@ -118,6 +115,7 @@ enum write_status to_bmp( FILE* out, struct image const* img ){
}
if(count < height){
free(img->data);
return WRITE_ERROR;
}
return WRITE_OK;
......
No preview for this file type
#include <stdbool.h>
#include <stdio.h>
#include <malloc.h>
#include "rotation.h"
#include "bmp.h"
#include "bmp_read_write.h"
#include "util.h"
const char* array_read_status[] = {
static const char* array_read_status[] = {
[READ_OK] = "ok",
[READ_INVALID_HEADER] = "Invalid header bmp",
[READ_NOT_NAME] = "Wrong file name",
......@@ -15,7 +16,7 @@ const char* array_read_status[] = {
[READ_ERROR] = "Reading error"
};
const char* array_write_status[] = {
static const char* array_write_status[] = {
[WRITE_OK] = "ok",
[WRITE_ERROR] = "error while writing",
[WRITE_HEADER_ERROR] = "write header error",
......@@ -41,6 +42,7 @@ int main( int argc, char** argv ) {
err( "Failed to open BMP file or reading header.\n" );
}
//START
struct image img = {0};
......@@ -59,5 +61,8 @@ int main( int argc, char** argv ) {
err(array_write_status[write_status]);
}
free(img.data);
free(rot_img.data);
return 0;
}
view-header/out.bmp

2.13 MB | W: 0px | H: 0px

view-header/out.bmp

2.13 MB | W: 0px | H: 0px

view-header/out.bmp
view-header/out.bmp
view-header/out.bmp
view-header/out.bmp
  • 2-up
  • Swipe
  • Onion skin
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