80 lines
2.7 KiB
C
80 lines
2.7 KiB
C
/*
|
|
* Copyright Notice
|
|
* ----------------
|
|
* Copyright © 1998, 1999 by: Glenn Randers-Pehrson
|
|
* 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:
|
|
* Copyright © 1996 by: Massachusetts Institute of Technology (MIT)
|
|
* This W3C specification is being provided by the copyright holders under
|
|
* 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
|
|
* and conditions:
|
|
* 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
|
|
* this NOTICE appears on ALL copies of the specification or portions thereof,
|
|
* including modifications, that you make.
|
|
* THIS SPECIFICATION IS PROVIDED ”AS IS,” AND COPYRIGHT HOLD-ERS
|
|
* MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
|
|
* IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, COPYRIGHT
|
|
* HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES OF MER-CHANTABILITY
|
|
* OR FITNESS FOR ANY PARTICULAR PURPOSE OR
|
|
* THAT THE USE OF THE SPECIFICATION WILL NOT INFRINGE ANY
|
|
* THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER
|
|
* RIGHTS. COPYRIGHT HOLDERS WILL BEAR NO LIABILITY FOR ANY
|
|
* USE OF THIS SPECIFICATION.
|
|
* The name and trademarks of copyright holders may NOT be used in
|
|
* ad-vertising or publicity pertaining to the specification without specific, written
|
|
* prior permission. Title to copyright in this specification and any associated
|
|
* documentation will at all times remain with copyright holders.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <arpa/inet.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <zlib.h>
|
|
#include <string.h>
|
|
|
|
// http://www.libpng.org/pub/png/spec/1.2/PNG-Rationale.html#R.PNG-file-signature
|
|
#define PNG_SIGNATURE "\211PNG\r\n\032\n"
|
|
#define PNG_SIGNATURE_SIZE 8
|
|
|
|
#define KEY 42
|
|
|
|
typedef struct png_chunk {
|
|
uint32_t length;
|
|
char type[4];
|
|
char *data;
|
|
uint32_t crc;
|
|
} png_chunk;
|
|
|
|
// Get file descriptor 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(int fd);
|
|
|
|
// 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 all PNG chunks
|
|
png_chunk **get_png_chunks(char *buffer);
|
|
|
|
// Get number of chunks
|
|
int get_number_of_chunks(png_chunk **chunks);
|
|
|
|
// XOR chunk with key
|
|
void xor_data(png_chunk *chunk);
|
|
|
|
// Destroy all chunks
|
|
void destroy_chunks(png_chunk **chunks);
|
|
|
|
// Write PNG chunks to file
|
|
void write_png_chunks(char *path, png_chunk **chunks); |