2023-12-04 18:39:21 -04:00
|
|
|
#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[]) {
|
2023-12-04 18:39:21 -04:00
|
|
|
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);
|
|
|
|
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) {
|
|
|
|
printf("Found %s chunk\n", chunks[i]->type);
|
|
|
|
} else {
|
|
|
|
printf("Found unknown: %s\n", chunks[i]->type);
|
|
|
|
}
|
|
|
|
printf("Chunk size is:%d\n", chunks[i]->length);
|
|
|
|
}
|
2023-12-04 16:17:13 -04:00
|
|
|
}
|