CS3413/Assignment9/src/main.c

46 lines
1.1 KiB
C
Raw Normal View History

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#include <stdbool.h>
#include "png.h"
2023-12-04 16:17:13 -04:00
int main(int argc, char *argv[]) {
if (argc != 2) {
printf("Usage: %s <png file>\n", argv[0]);
exit(1);
}
if (strlen(argv[1]) > PATH_MAX) {
printf("Path too long\n");
exit(1);
}
char *path = argv[1];
char* png_buffer = load_file(get_fd(path));
if (!is_png(png_buffer)) {
printf("It's not a PNG file\n");
exit(1);
} else {
printf("It's a PNG file\n");
}
png_chunk **chunks = get_png_chunks(png_buffer);
2023-12-04 19:35:12 -04:00
free(png_buffer);
int size = get_number_of_chunks(chunks);
for (int i = 0; i < size; i++) {
// Check if header is IDAT or IEND
bool is_idat = memcmp(chunks[i]->type, "IDAT", 4) == 0;
bool is_iend = memcmp(chunks[i]->type, "IEND", 4) == 0;
if (is_idat || is_iend) {
2023-12-04 18:54:29 -04:00
printf("Found %.4s chunk\n", chunks[i]->type);
if (is_idat) {
xor_data(chunks[i]);
}
} else {
2023-12-04 18:54:29 -04:00
printf("Found unknown: %.4s\n", chunks[i]->type);
}
printf("Chunk size is:%d\n", chunks[i]->length);
}
2023-12-04 19:44:06 -04:00
// write_png_chunks(path, chunks);
2023-12-04 19:35:12 -04:00
destroy_chunks(chunks);
return EXIT_SUCCESS;
2023-12-04 16:17:13 -04:00
}