Compare commits

...

19 Commits

Author SHA1 Message Date
cae1791eba Add a9 file submissions 2023-12-05 13:33:01 -04:00
6ff99deff7 Add a8 file submissions 2023-12-05 13:32:04 -04:00
c6dd294bc0 Remove unused import a9 2023-12-05 13:29:57 -04:00
6a6fd9c37c Tests in a9 2023-12-05 13:28:08 -04:00
112535e8e7 Use LF in a9 2023-12-05 13:28:08 -04:00
93635bc1d6 Remove unneeded function 2023-12-05 12:57:16 -04:00
530ab9a135 Add comments and error checking to A9 2023-12-05 12:47:36 -04:00
bea609e01c Use exit define 2023-12-04 20:55:45 -04:00
136a4fe960 Code reformatting 2023-12-04 20:55:07 -04:00
123e0f56bc Add test shell scripts 2023-12-04 20:53:40 -04:00
e79158e3f1 Make Tests pass 2023-12-04 20:53:31 -04:00
73234d0764 Make operation reversable
Before didn't write the final IEND chunk
2023-12-04 20:29:04 -04:00
0a18d16eb0 For submission 2023-12-04 20:24:05 -04:00
862af7192c Minor code cleanup 2023-12-04 20:19:20 -04:00
a62d97f575 Reformat stuff 2023-12-04 20:09:46 -04:00
d81bbe423e WORKS ON TEST1 2023-12-04 20:02:21 -04:00
9f9d7a1925 Fix 2023-12-04 19:44:06 -04:00
2769651fe1 Just need to bugfix now 2023-12-04 19:35:12 -04:00
3aa01cdc2b Working reader 2023-12-04 18:54:29 -04:00
12 changed files with 363 additions and 260 deletions

Binary file not shown.

View File

@ -0,0 +1,8 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="All CTest" type="CTestRunConfiguration" factoryName="CTestRun" PROGRAM_PARAMS="--extra-verbose" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" WORKING_DIR="file://$CMakeCurrentLocalGenerationDir$" PASS_PARENT_ENVS_2="true" CONFIG_NAME="Debug" RUN_PATH="$CTestCurrentExecutableName$" EXPLICIT_BUILD_TARGET_NAME="all" TEST_MODE="PATTERN">
<method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
<option name="BeforeTestRunTask" enabled="true" />
</method>
</configuration>
</component>

View File

@ -0,0 +1,10 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Test All" type="CMakeRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="Assignment9" TARGET_NAME="Assignment9" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="Assignment9" RUN_TARGET_NAME="Assignment9">
<method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
<option name="RunConfigurationTask" enabled="false" run_configuration_name="Test1" run_configuration_type="CMakeRunConfiguration" />
<option name="RunConfigurationTask" enabled="true" run_configuration_name="Test3" run_configuration_type="CMakeRunConfiguration" />
<option name="RunConfigurationTask" enabled="true" run_configuration_name="Test4" run_configuration_type="CMakeRunConfiguration" />
</method>
</configuration>
</component>

View File

@ -0,0 +1,8 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="images" type="CTestRunConfiguration" factoryName="CTestRun" PROGRAM_PARAMS="--extra-verbose" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" WORKING_DIR="file://$CMakeCurrentLocalGenerationDir$" PASS_PARENT_ENVS_2="true" CONFIG_NAME="Debug" RUN_PATH="$CTestCurrentExecutableName$" EXPLICIT_BUILD_TARGET_NAME="all" TEST_METHOD="images" TEST_MODE="SUITE_TEST">
<method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
<option name="BeforeTestRunTask" enabled="true" />
</method>
</configuration>
</component>

View File

@ -0,0 +1,8 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="output" type="CTestRunConfiguration" factoryName="CTestRun" PROGRAM_PARAMS="--extra-verbose" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" WORKING_DIR="file://$CMakeCurrentLocalGenerationDir$" PASS_PARENT_ENVS_2="true" CONFIG_NAME="Debug" RUN_PATH="$CTestCurrentExecutableName$" EXPLICIT_BUILD_TARGET_NAME="all" TEST_METHOD="output" TEST_MODE="SUITE_TEST">
<method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
<option name="BeforeTestRunTask" enabled="true" />
</method>
</configuration>
</component>

View File

@ -3,4 +3,8 @@ project(Assignment9 C)
set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD 99)
add_executable(Assignment9 src/main.c add_executable(Assignment9 src/main.c
src/png.c src/png.c
src/png.h) src/png.h)
enable_testing()
add_test(NAME output COMMAND test_text.sh WORKING_DIRECTORY ../tests)
add_test(NAME images COMMAND test_images.sh WORKING_DIRECTORY ../tests)

View File

@ -1,39 +1,50 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <limits.h> #include <limits.h>
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>
#include "png.h" #include "png.h"
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
if (argc != 2) { // Error handling
printf("Usage: %s <png file>\n", argv[0]); if (argc != 2) {
exit(1); printf("Usage: %s <png file>\n", argv[0]);
} exit(EXIT_FAILURE);
if (strlen(argv[1]) > PATH_MAX) { }
printf("Path too long\n"); if (strlen(argv[1]) > PATH_MAX) {
exit(1); printf("Path too long\n");
} exit(EXIT_FAILURE);
char *path = argv[1]; }
// Read file
char* png_buffer = load_file(get_fd(path)); char *path = argv[1];
if (!is_png(png_buffer)) { char *png_buffer = load_file(path);
printf("It's not a PNG file\n"); if (!is_png(png_buffer)) {
exit(1); printf("It's not a PNG file\n");
} else { exit(EXIT_FAILURE);
printf("It's a PNG file\n"); } else {
} printf("It's a PNG file\n");
png_chunk **chunks = get_png_chunks(png_buffer); }
int size = get_number_of_chunks(chunks); png_chunk **chunks = get_png_chunks(png_buffer);
for (int i = 0; i < size; i++) { free(png_buffer);
// Check if header is IDAT or IEND // Done with buffer, as chunks are a structured way to access the data
bool is_idat = memcmp(chunks[i]->type, "IDAT", 4) == 0; // Iterate over chunks to display info and "decrypt" IDAT chunks
bool is_iend = memcmp(chunks[i]->type, "IEND", 4) == 0; int size = get_number_of_chunks(chunks);
if (is_idat || is_iend) { for (int i = 0; i < size; i++) {
printf("Found %s chunk\n", chunks[i]->type); // Check if header is IDAT or IEND
} else { bool is_idat = memcmp(chunks[i]->type, "IDAT", 4) == 0;
printf("Found unknown: %s\n", chunks[i]->type); bool is_iend = memcmp(chunks[i]->type, "IEND", 4) == 0;
} if (is_idat || is_iend) {
printf("Chunk size is:%d\n", chunks[i]->length); printf("Found %.4s\n", chunks[i]->type);
} if (is_idat) {
} xor_data(chunks[i]);
}
} else {
printf("Found unknown: %.4s\n", chunks[i]->type);
}
printf("Chunk size is:%d\n", chunks[i]->length);
}
// Write file and free memory
write_png_chunks(path, chunks);
destroy_chunks(chunks);
return EXIT_SUCCESS;
}

View File

@ -1,146 +1,159 @@
/* /*
* Copyright Notice * Copyright Notice
* ---------------- * ----------------
* Copyright © 1998, 1999 by: Glenn Randers-Pehrson * Copyright © 1998, 1999 by: Glenn Randers-Pehrson
* This specification is a modification of the PNG 1.0 specification. It is being * This specification is a modification of the PNG 1.0 specification. It is being
* provided by the copyright holder under the provisions of the 1996 MIT copyright and license: * provided by the copyright holder under the provisions of the 1996 MIT copyright and license:
* Copyright © 1996 by: Massachusetts Institute of Technology (MIT) * Copyright © 1996 by: Massachusetts Institute of Technology (MIT)
* This W3C specification is being provided by the copyright holders under * This W3C specification is being provided by the copyright holders under
* the following license. By obtaining, using and/or copying this specification, you * the following license. By obtaining, using and/or copying this specification, you
* agree that you have read, understood, and will comply with the following terms * agree that you have read, understood, and will comply with the following terms
* and conditions: * and conditions:
* Permission to use, copy, and distribute this specification for any purpose * Permission to use, copy, and distribute this specification for any purpose
* and without fee or royalty is hereby granted, provided that the full text of * and without fee or royalty is hereby granted, provided that the full text of
* this NOTICE appears on ALL copies of the specification or portions thereof, * this NOTICE appears on ALL copies of the specification or portions thereof,
* including modifications, that you make. * including modifications, that you make.
* THIS SPECIFICATION IS PROVIDED ”AS IS,” AND COPYRIGHT HOLD-ERS * THIS SPECIFICATION IS PROVIDED ”AS IS,” AND COPYRIGHT HOLD-ERS
* MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR * MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
* IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, COPYRIGHT * IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, COPYRIGHT
* HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES OF MER-CHANTABILITY * HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY
* OR FITNESS FOR ANY PARTICULAR PURPOSE OR * OR FITNESS FOR ANY PARTICULAR PURPOSE OR
* THAT THE USE OF THE SPECIFICATION WILL NOT INFRINGE ANY * THAT THE USE OF THE SPECIFICATION WILL NOT INFRINGE ANY
* THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER * THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER
* RIGHTS. COPYRIGHT HOLDERS WILL BEAR NO LIABILITY FOR ANY * RIGHTS. COPYRIGHT HOLDERS WILL BEAR NO LIABILITY FOR ANY
* USE OF THIS SPECIFICATION. * USE OF THIS SPECIFICATION.
* The name and trademarks of copyright holders may NOT be used in * The name and trademarks of copyright holders may NOT be used in
* ad-vertising or publicity pertaining to the specification without specific, written * advertising or publicity pertaining to the specification without specific, written
* prior permission. Title to copyright in this specification and any associated * prior permission. Title to copyright in this specification and any associated
* documentation will at all times remain with copyright holders. * documentation will at all times remain with copyright holders.
*/ */
#include <arpa/inet.h> #include <arpa/inet.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <zlib.h> #include <string.h>
#include <string.h> #include <stdbool.h>
#include "png.h" #include "png.h"
int get_fd(char *path) { FILE *get_file(char *path) {
FILE *fp = fopen(path, "rb"); FILE *fp = fopen(path, "rb");
if (fp == NULL) { if (fp == NULL) {
perror("fopen"); perror("fopen");
exit(1); exit(EXIT_FAILURE);
} }
int fd = fileno(fp); return fp;
if (fd == -1) { }
perror("fileno");
exit(1); char *load_file(char *path) {
} FILE *fp = get_file(path);
return fd; fseek(fp, 0, SEEK_END);
} long size = ftell(fp);
rewind(fp);
FILE *get_fp(int fd) { char *buffer = malloc(size);
FILE *fp = fdopen(fd, "rb"); if (buffer == NULL) {
if (fp == NULL) { perror("malloc");
perror("fdopen"); exit(EXIT_FAILURE);
exit(1); }
} fread(buffer, 1, size, fp);
return fp; fclose(fp);
} return buffer;
}
char *load_file(int fd) {
FILE *fp = get_fp(fd); int is_png(char *buffer) {
fseek(fp, 0, SEEK_END); return memcmp(buffer, PNG_SIGNATURE, PNG_SIGNATURE_SIZE) == 0;
long size = ftell(fp); }
rewind(fp);
char *buffer = malloc(size); png_chunk *get_png_chunk(char *buffer, unsigned int offset) {
if (buffer == NULL) { png_chunk *chunk = malloc(sizeof(png_chunk));
perror("malloc"); if (chunk == NULL) {
exit(1); perror("malloc");
} exit(EXIT_FAILURE);
fread(buffer, 1, size, fp); }
// Iterate over buffer and convert from network byte order to host byte order memcpy(&chunk->length, buffer + offset + 0, 4);
//for (int i = 0; i < size; i += 4) { // Convert length to host byte order because PNG lengths is in network byte order/Big Endian
// uint32_t *ptr = (uint32_t *)(buffer + i); chunk->length = ntohl(chunk->length);
// *ptr = ntohl(*ptr); memcpy(&chunk->type, buffer + offset + 4, 4);
//} chunk->data = malloc(chunk->length);
fclose(fp); if (chunk->data == NULL) {
return buffer; perror("malloc");
} exit(EXIT_FAILURE);
}
int is_png(char *buffer) { memcpy(chunk->data, buffer + offset + 8, chunk->length);
return memcmp(buffer, PNG_SIGNATURE, PNG_SIGNATURE_SIZE) == 0; memcpy(&chunk->crc, buffer + offset + 8 + chunk->length, 4);
} return chunk;
}
png_chunk *get_png_chunk(char *buffer, int offset) {
png_chunk *chunk = malloc(sizeof(png_chunk)); png_chunk **get_png_chunks(char *buffer) {
if (chunk == NULL) { png_chunk **chunks = malloc(sizeof(png_chunk *));
perror("malloc"); if (chunks == NULL) {
exit(1); perror("malloc");
} exit(EXIT_FAILURE);
memcpy(&chunk->length, buffer + offset + 0, 4); }
chunk->length = ntohl(chunk->length); // Running offset of the buffer
memcpy(&chunk->type, buffer + offset + 4, 4); unsigned int offset = PNG_SIGNATURE_SIZE;
chunk->data = malloc(chunk->length); // Index of the current chunk
if (chunk->data == NULL) { int i = 0;
perror("malloc"); while (true) {
exit(1); chunks[i] = get_png_chunk(buffer, offset);
} // 12 = 4 (length) + 4 (type) + 4 (crc)
memcpy(chunk->data, buffer + offset + 8, chunk->length); offset += 12 + chunks[i]->length;
memcpy(&chunk->crc, buffer + offset + 8 + chunk->length, 4); if (memcmp(chunks[i]->type, "IEND", 4) == 0) {
return chunk; break;
} }
i++;
png_chunk **get_png_chunks(char *buffer) { // Add one because realloc is 1-indexed when multiplying by sizeof
png_chunk **chunks = malloc(sizeof(png_chunk *)); png_chunk **err_check = realloc(chunks, sizeof(png_chunk *) * (i + 1));
if (chunks == NULL) { if (err_check == NULL) {
perror("malloc"); destroy_chunks(chunks);
exit(1); perror("realloc");
} exit(EXIT_FAILURE);
int offset = PNG_SIGNATURE_SIZE; }
int i = 0; chunks = err_check;
while (1) { }
chunks[i] = get_png_chunk(buffer, offset); return chunks;
offset += chunks[i]->length; }
if (memcmp(chunks[i]->type, "IEND", 4) == 0) {
break; int get_number_of_chunks(png_chunk **chunks) {
} int i = 0;
i++; while (memcmp(chunks[i]->type, "IEND", 4) != 0) {
chunks = realloc(chunks, sizeof(png_chunk *) * (i + 1)); i++;
if (chunks == NULL) { }
perror("realloc"); // Add one for the IEND chunk
exit(1); return ++i;
} }
}
return chunks; void xor_data(png_chunk *chunk) {
} for (int i = 0; i < chunk->length; i++) {
chunk->data[i] ^= KEY;
int is_chunk_valid(png_chunk *chunk) { }
uint32_t crc = htonl(chunk->crc); }
//uint32_t calculated_crc = crc32(0, chunk->type, 4);
//calculated_crc = crc32(calculated_crc, chunk->data, chunk->length); void destroy_chunks(png_chunk **chunks) {
//return crc == calculated_crc; unsigned int size = get_number_of_chunks(chunks);
return 1; for (int i = 0; i < size; i++) {
} free(chunks[i]->data);
free(chunks[i]);
int is_chunk_critical(png_chunk *chunk) { }
return chunk->type[0] >= 'A' && chunk->type[0] <= 'Z'; free(chunks);
} }
int get_number_of_chunks(png_chunk **chunks) { void write_png_chunks(char *path, png_chunk **chunks) {
int i = 0; FILE *fp = fopen(path, "wb");
while (chunks[i] != NULL) { if (fp == NULL) {
i++; perror("fopen");
} exit(EXIT_FAILURE);
return i; }
} fwrite(PNG_SIGNATURE, PNG_SIGNATURE_SIZE, 1, fp);
unsigned int size = get_number_of_chunks(chunks);
for (int i = 0; i < size; i++) {
// Convert length to network byte order for writing
chunks[i]->length = htonl(chunks[i]->length);
fwrite(&chunks[i]->length, 4, 1, fp);
fwrite(chunks[i]->type, 4, 1, fp);
// Convert back so we can accurately use it to write the length of the data
chunks[i]->length = ntohl(chunks[i]->length);
fwrite(chunks[i]->data, chunks[i]->length, 1, fp);
fwrite(&chunks[i]->crc, 4, 1, fp);
}
fclose(fp);
}

View File

@ -1,74 +1,75 @@
/* /*
* Copyright Notice * Copyright Notice
* ---------------- * ----------------
* Copyright © 1998, 1999 by: Glenn Randers-Pehrson * Copyright © 1998, 1999 by: Glenn Randers-Pehrson
* This specification is a modification of the PNG 1.0 specification. It is being * This specification is a modification of the PNG 1.0 specification. It is being
* provided by the copyright holder under the provisions of the 1996 MIT copyright and license: * provided by the copyright holder under the provisions of the 1996 MIT copyright and license:
* Copyright © 1996 by: Massachusetts Institute of Technology (MIT) * Copyright © 1996 by: Massachusetts Institute of Technology (MIT)
* This W3C specification is being provided by the copyright holders under * This W3C specification is being provided by the copyright holders under
* the following license. By obtaining, using and/or copying this specification, you * the following license. By obtaining, using and/or copying this specification, you
* agree that you have read, understood, and will comply with the following terms * agree that you have read, understood, and will comply with the following terms
* and conditions: * and conditions:
* Permission to use, copy, and distribute this specification for any purpose * Permission to use, copy, and distribute this specification for any purpose
* and without fee or royalty is hereby granted, provided that the full text of * and without fee or royalty is hereby granted, provided that the full text of
* this NOTICE appears on ALL copies of the specification or portions thereof, * this NOTICE appears on ALL copies of the specification or portions thereof,
* including modifications, that you make. * including modifications, that you make.
* THIS SPECIFICATION IS PROVIDED ”AS IS,” AND COPYRIGHT HOLD-ERS * THIS SPECIFICATION IS PROVIDED ”AS IS,” AND COPYRIGHT HOLD-ERS
* MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR * MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
* IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, COPYRIGHT * IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, COPYRIGHT
* HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES OF MER-CHANTABILITY * HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY
* OR FITNESS FOR ANY PARTICULAR PURPOSE OR * OR FITNESS FOR ANY PARTICULAR PURPOSE OR
* THAT THE USE OF THE SPECIFICATION WILL NOT INFRINGE ANY * THAT THE USE OF THE SPECIFICATION WILL NOT INFRINGE ANY
* THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER * THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER
* RIGHTS. COPYRIGHT HOLDERS WILL BEAR NO LIABILITY FOR ANY * RIGHTS. COPYRIGHT HOLDERS WILL BEAR NO LIABILITY FOR ANY
* USE OF THIS SPECIFICATION. * USE OF THIS SPECIFICATION.
* The name and trademarks of copyright holders may NOT be used in * The name and trademarks of copyright holders may NOT be used in
* ad-vertising or publicity pertaining to the specification without specific, written * advertising or publicity pertaining to the specification without specific, written
* prior permission. Title to copyright in this specification and any associated * prior permission. Title to copyright in this specification and any associated
* documentation will at all times remain with copyright holders. * documentation will at all times remain with copyright holders.
*/ */
#pragma once #pragma once
#include <arpa/inet.h> // Needed for uint types
#include <stdio.h> #include <arpa/inet.h>
#include <stdlib.h>
#include <zlib.h> // http://www.libpng.org/pub/png/spec/1.2/PNG-Rationale.html#R.PNG-file-signature
#include <string.h> #define PNG_SIGNATURE "\211PNG\r\n\032\n"
#define PNG_SIGNATURE_SIZE 8
// http://www.libpng.org/pub/png/spec/1.2/PNG-Rationale.html#R.PNG-file-signature
#define PNG_SIGNATURE "\211PNG\r\n\032\n" // The key used to "encrypt/decrypt" the PNG chunks
#define PNG_SIGNATURE_SIZE 8 #define KEY 42
typedef struct png_chunk {
uint32_t length; typedef struct png_chunk {
char type[4]; uint32_t length;
char *data; char type[4];
uint32_t crc; char *data;
} png_chunk; uint32_t crc;
} png_chunk;
// Get file descriptor from path
int get_fd(char *path); // Get FILE from path
int get_fd(char *path);
// Get FILE* from file descriptor
FILE *get_fp(int fd); // Store file in heap memory
char *load_file(char *path);
// Store file in heap memory
char *load_file(int fd); // Check if file is a PNG
int is_png(char *buffer);
// Check if file is a PNG
int is_png(char *buffer); // Get PNG chunk
png_chunk *get_png_chunk(char *buffer, unsigned int offset);
// Get PNG chunk
png_chunk *get_png_chunk(char *buffer, int offset); // Get all PNG chunks
png_chunk **get_png_chunks(char *buffer);
// Get all PNG chunks
png_chunk **get_png_chunks(char *buffer); // Get number of chunks
int get_number_of_chunks(png_chunk **chunks);
// Get number of chunks
int get_number_of_chunks(png_chunk **chunks); // XOR chunk with key
void xor_data(png_chunk *chunk);
// Check if chunk is critical
int is_chunk_critical(png_chunk *chunk); // Destroy all chunks
void destroy_chunks(png_chunk **chunks);
// Is chunk valid?
int is_chunk_valid(png_chunk *chunk); // Write PNG chunks to file
void write_png_chunks(char *path, png_chunk **chunks);

Binary file not shown.

View File

@ -0,0 +1,22 @@
#!/usr/bin/env bash
# Executable path
EXECUTABLE=../build/Assignment9
test_reverse() {
start=$(date +%s)
cp "$1" in.png
cp in.png out.png
$EXECUTABLE out.png > /dev/null
$EXECUTABLE out.png > /dev/null
diff in.png out.png
rm in.png out.png
end=$(date +%s)
echo "Test $1 took $((end - start)) seconds"
}
test_reverse test1.png
# test_reverse test2.png # This png is invalid, so it will fail
test_reverse test3.png
test_reverse test4.png

View File

@ -0,0 +1,18 @@
#!/usr/bin/env bash
EXECUTABLE=../build/Assignment9
# Test the text output
$EXECUTABLE test1.png | diff output1.txt -
$EXECUTABLE test2.png | diff output2.txt -
$EXECUTABLE test3.png | diff output3.txt -
$EXECUTABLE test4.png | diff output4.txt -
# Reverse the images
$EXECUTABLE test1.png > /dev/null
$EXECUTABLE test2.png > /dev/null
$EXECUTABLE test3.png > /dev/null
$EXECUTABLE test4.png > /dev/null
echo "If there is no diff output, then the test passed."