Just need to bugfix now

This commit is contained in:
2023-12-04 19:35:12 -04:00
parent 3aa01cdc2b
commit 2769651fe1
3 changed files with 25 additions and 6 deletions

View File

@@ -31,8 +31,8 @@
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <zlib.h>
#include <string.h>
#include <stdbool.h>
#include "png.h"
int get_fd(char *path) {
@@ -77,7 +77,7 @@ int is_png(char *buffer) {
return memcmp(buffer, PNG_SIGNATURE, PNG_SIGNATURE_SIZE) == 0;
}
png_chunk *get_png_chunk(char *buffer, int offset) {
png_chunk *get_png_chunk(char *buffer, unsigned int offset) {
png_chunk *chunk = malloc(sizeof(png_chunk));
if (chunk == NULL) {
perror("malloc");
@@ -102,7 +102,7 @@ png_chunk **get_png_chunks(char *buffer) {
perror("malloc");
exit(1);
}
int offset = PNG_SIGNATURE_SIZE;
unsigned int offset = PNG_SIGNATURE_SIZE;
int i = 0;
while (1) {
chunks[i] = get_png_chunk(buffer, offset);
@@ -123,7 +123,10 @@ png_chunk **get_png_chunks(char *buffer) {
int get_number_of_chunks(png_chunk **chunks) {
int i = 0;
while (chunks[i] != NULL) {
while (true) {
if (memcmp(chunks[i]->type, "IEND", 4) == 0) {
break;
}
i++;
}
return i;
@@ -135,6 +138,16 @@ void xor_data(png_chunk *chunk) {
}
}
void destroy_chunks(png_chunk **chunks) {
for (int i = 0; get_number_of_chunks(chunks); i++) {
free(chunks[i]->data);
free(chunks[i]);
}
free(chunks);
}
void write_png_chunks(char *path, png_chunk **chunks) {
FILE *fp = fopen(path, "wb");
if (fp == NULL) {