Compare commits

...

4 Commits

6 changed files with 105 additions and 57 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
.cache
refs
file_example*
*.py

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "intern/wizapp"]
path = intern/wizapp
url = https://git.thewizardapprentice.com/abdelrahman/wizapp-stdlib.git

11
compile
View File

@ -2,9 +2,18 @@
CC=clang
CFLAGS="-g -Wall -Werror -pedantic -fsanitize=address -fsanitize=undefined"
INCLUDES="-Isrc"
INCLUDES="\
-Isrc \
-Iintern/wizapp/aliases \
-Iintern/wizapp/cpath/include \
-Iintern/wizapp/dstr/include \
$(find intern/wizapp/mem/include -type d | xargs -I{} echo -n "-I{} ") \
"
SRC="\
./src/*.c \
intern/wizapp/cpath/src/*.c \
intern/wizapp/dstr/src/*.c \
intern/wizapp/mem/src/*/*.c \
"
OUT=tiffread

1
intern/wizapp Submodule

@ -0,0 +1 @@
Subproject commit be64571b0ec136fa785f02acca555e2f03dbd02d

View File

@ -1,62 +1,9 @@
#include "aliases.h"
#include "tiffread.h"
#include <netinet/in.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#define TAG_MAX_COUNT (UINT16_MAX * sizeof(const char *))
// Technically, the type parameter is 2-bytes long, but there aren't so many
// types specified in the spec, so UINT8_MAX should be sufficient
#define TYPE_MAX_COUNT (UINT8_MAX * sizeof(const char *))
// clang-format off
enum {
TIFF_ORDER_LITTLE_ENDIAN = 0x4949,
TIFF_ORDER_BIG_ENDIAN = 0x4d4d,
};
// clang-format on
typedef struct hdr TiffHdr;
struct hdr {
uint16_t order;
uint16_t magic;
uint32_t first_ifd_offset;
};
enum tiff_public_tags {
#include "tiff_public_tags.inc"
};
const char *tag_names[TAG_MAX_COUNT] = {
#define TIFF_TAG_LOOKUP
#include "tiff_public_tags.inc"
#undef TIFF_TAG_LOOKUP
};
enum tiff_field_types {
#include "tiff_field_types.inc"
};
const char *filed_type_names[TYPE_MAX_COUNT] = {
#define TIFF_TYPE_LOOKUP
#include "tiff_field_types.inc"
#undef TIFF_TYPE_LOOKUP
};
typedef struct field TiffField;
struct field {
uint16_t tag;
uint16_t type;
uint32_t count;
uint32_t value_offset;
};
typedef struct IFD TiffIFD;
struct IFD {
uint16_t count;
TiffField *fields;
uint32_t next_ifd;
};
int main(int argc, char *argv[]) {
const char *file_to_open = argc > 1 ? argv[1] : "./resources/test.tif";
@ -79,7 +26,7 @@ int main(int argc, char *argv[]) {
TiffField fields[ifd.count];
memset(fields, 0, sizeof(TiffField) * ifd.count);
for (uint32_t i = 0; i < ifd.count; ++i) {
for (u32 i = 0; i < ifd.count; ++i) {
fread(fields + i, sizeof(TiffField), 1, fp);
printf("ENTRY %02u\n", i);
printf("\t TAG: %04u (%s)\n", fields[i].tag,

87
src/tiffread.h Normal file
View File

@ -0,0 +1,87 @@
#ifndef TIFFREAD_H
#define TIFFREAD_H
#include "aliases.h"
#define TAG_MAX_COUNT (UINT16_MAX * sizeof(const char *))
// Technically, the type parameter is 2-bytes long, but there aren't so many
// types specified in the spec, so UINT8_MAX should be sufficient
#define TYPE_MAX_COUNT (UINT8_MAX * sizeof(const char *))
// clang-format off
enum {
TIFF_ORDER_LITTLE_ENDIAN = 0x4949,
TIFF_ORDER_BIG_ENDIAN = 0x4d4d,
};
// clang-format on
typedef struct hdr TiffHdr;
struct hdr {
u16 order;
u16 magic;
u32 first_ifd_offset;
};
// clang-format off
enum tiff_public_tags {
#include "tiff_public_tags.inc"
};
const char *tag_names[TAG_MAX_COUNT] = {
#define TIFF_TAG_LOOKUP
#include "tiff_public_tags.inc"
#undef TIFF_TAG_LOOKUP
};
enum tiff_field_types {
#include "tiff_field_types.inc"
};
const char *filed_type_names[TYPE_MAX_COUNT] = {
#define TIFF_TYPE_LOOKUP
#include "tiff_field_types.inc"
#undef TIFF_TYPE_LOOKUP
};
// clang-format on
typedef struct field TiffField;
struct field {
u16 tag;
u16 type;
u32 count;
u32 value_offset;
};
typedef struct IFD TiffIFD;
struct IFD {
u16 count;
TiffField *fields;
u32 next_ifd;
};
// clang-format off
enum tiff_compression {
TIFF_COMPRESSION_UNCOMPRESSED = 0x0001,
TIFF_COMPRESSION_CCITT_1D = 0x0002,
TIFF_COMPRESSION_GROUP_3_FAX = 0x0003,
TIFF_COMPRESSION_GROUP_4_FAX = 0x0004,
TIFF_COMPRESSION_LZW = 0x0005,
TIFF_COMPRESSION_JPEG = 0x0006,
TIFF_COMPRESSION_PACK_BITS = 0x8005,
};
// clang-format on
// clang-format off
enum tiff_photometric_interpretation {
TIFF_PHOTOMETRIC_INTERPRETATION_WHITE_IS_ZERO = 0x0000,
TIFF_PHOTOMETRIC_INTERPRETATION_BLACK_IS_ZERO = 0x0001,
TIFF_PHOTOMETRIC_INTERPRETATION_RGB = 0x0002,
TIFF_PHOTOMETRIC_INTERPRETATION_RGB_PALETTE = 0x0003,
TIFF_PHOTOMETRIC_INTERPRETATION_TRANSPARENCY_MASK = 0x0004,
TIFF_PHOTOMETRIC_INTERPRETATION_CMYK = 0x0005,
TIFF_PHOTOMETRIC_INTERPRETATION_YCbCr = 0x0006,
TIFF_PHOTOMETRIC_INTERPRETATION_CIELab = 0x0008,
};
// clang-format on
#endif // !TIFFREAD_H