First botched attempt at reading image data :D

This commit is contained in:
2024-04-21 18:55:02 +01:00
parent 0bd448a8a9
commit 8040dd7381
9 changed files with 369 additions and 74 deletions

109
src/tiff/tiffread.h Normal file
View File

@@ -0,0 +1,109 @@
#ifndef TIFFREAD_H
#define TIFFREAD_H
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
#include "aliases.h"
#include "image.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_byte_order {
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"
};
internal 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"
};
typedef struct field_type TiffFieldType;
struct field_type {
const char *name;
u16 byte_count;
};
internal TiffFieldType field_types[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,
};
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,
TIFF_PHOTOMETRIC_INTERPRETATION_INVALID,
};
enum tiff_planar_configuration {
TIFF_PLANAR_CONFIG_CHUNKY = 0x0001,
TIFF_PLANAR_CONFIG_PLANAR = 0x0002,
};
// clang-format on
Image *read_baseline_tiff(const char *file, const Allocator *allocator);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // !TIFFREAD_H