Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- #include "transformations.h"
- struct bmp_header* read_bmp_header(FILE* stream){
- if(stream == NULL){
- return NULL;
- }
- struct bmp_header* bmpHeader =malloc(sizeof(struct bmp_header));
- int res = fread (bmpHeader, sizeof (struct bmp_header), 1, stream);
- if( !res ) {
- free(bmpHeader);
- return NULL;
- }
- return bmpHeader;
- }
- struct pixel* read_data(FILE* stream, const struct bmp_header* header){
- if (stream == NULL || header == NULL){
- return NULL;
- }
- uint32_t height = header->height;
- uint32_t width = header->width;
- uint32_t padding = width%4;
- struct pixel* image_data = malloc(sizeof(struct pixel)*height*width);
- fseek (stream, sizeof(struct bmp_header), 0);
- for (uint32_t i = 0; i < height; i++){
- //
- for(uint32_t j = 0;j<width;j++){
- //
- fread (&image_data[(i*width)+j], sizeof (struct pixel), 1, stream);
- }
- //
- fseek (stream, padding, SEEK_CUR);
- //
- }
- return image_data;
- }
- struct bmp_image* read_bmp(FILE* stream){
- struct bmp_image* image = malloc(sizeof(struct bmp_image));
- if(stream == NULL){
- return NULL;
- }
- image->header = read_bmp_header(stream);
- image->data = read_data(stream, image->header);
- for (int i = 0; i < image->header->width*image->header->height; ++i) {
- printf("%d %d %d\n", image->data[i].red, image->data[i].green, image->data[i].blue);
- }
- return image;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement