Read PNG Magic
This commit is contained in:
parent
f0434c3de9
commit
fd0f3fb901
23
img_png.c
Normal file
23
img_png.c
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#include <stddef.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "img_png.h"
|
||||||
|
|
||||||
|
uint8_t* img_png_decode(FILE *fp) {
|
||||||
|
unsigned char buffer[8];
|
||||||
|
size_t bufsize = sizeof(buffer) / sizeof((buffer)[0]);
|
||||||
|
|
||||||
|
size_t ret = fread(buffer, sizeof(*buffer), bufsize, fp);
|
||||||
|
|
||||||
|
if(ret != bufsize) {
|
||||||
|
fprintf(stderr, "fread() failed. Expected %zu bytes, got %zu\n", bufsize, ret);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("PNG Magic: %#04x%02x%02x%02x%02x%02x%02x%02x\n", buffer[0], buffer[1], buffer[2],
|
||||||
|
buffer[3], buffer[4], buffer[5], buffer[6], buffer[7]);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -1,6 +1,13 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
const char img_png_signature[] = {0x89, };
|
//const unsigned char img_png_signature[] = {0x89, 'P', 'N', 'G', '\r', '\n', 0x1a, '\n'};
|
||||||
|
|
||||||
|
struct img_png_chunk {
|
||||||
|
int length;
|
||||||
|
int chunk_type;
|
||||||
|
char* chunk_data;
|
||||||
|
int crc;
|
||||||
|
};
|
||||||
|
|
||||||
uint8_t* img_png_decode (FILE* fp);
|
uint8_t* img_png_decode (FILE* fp);
|
||||||
|
10
main.c
10
main.c
@ -1,9 +1,10 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include "img_png.h"
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
if(argc != 2) {
|
if(argc != 2) {
|
||||||
fprintf(stderr, "Usage: ./imgvwr FILE");
|
fprintf(stderr, "Usage: ./imgvwr FILE\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -13,5 +14,12 @@ int main(int argc, char** argv) {
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*if(!img_png_decode(fp_image)) {
|
||||||
|
fprintf(stderr, "Could not parse PNG file!\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
img_png_decode(fp_image);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user