Start implementing reading fields from scratch
This commit is contained in:
@@ -7,19 +7,10 @@ extern "C" {
|
||||
|
||||
#include "aliases.h"
|
||||
#include "image.h"
|
||||
#include <stdbool.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;
|
||||
@@ -27,34 +18,6 @@ struct hdr {
|
||||
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;
|
||||
@@ -71,6 +34,45 @@ struct IFD {
|
||||
};
|
||||
|
||||
// clang-format off
|
||||
enum tiff_byte_order {
|
||||
TIFF_ORDER_LITTLE_ENDIAN = 0x4949,
|
||||
TIFF_ORDER_BIG_ENDIAN = 0x4d4d,
|
||||
};
|
||||
|
||||
enum tiff_public_tags {
|
||||
#include "tiff_public_tags.inc"
|
||||
};
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
typedef enum tiff_image_type_names {
|
||||
TIFF_IMAGE_TYPE_INVALID = 0,
|
||||
TIFF_IMAGE_TYPE_BILEVEL = 1,
|
||||
TIFF_IMAGE_TYPE_GRAYSCALE = TIFF_PUBLIC_TAG_BITS_PER_SAMPLE,
|
||||
TIFF_IMAGE_TYPE_PALETTE = TIFF_PUBLIC_TAG_BITS_PER_SAMPLE | TIFF_PUBLIC_TAG_COLOR_MAP,
|
||||
TIFF_IMAGE_TYPE_RGB = TIFF_PUBLIC_TAG_BITS_PER_SAMPLE | TIFF_PUBLIC_TAG_SAMPLES_PER_PIXEL,
|
||||
} TiffImageType;
|
||||
|
||||
enum tiff_extra_samples {
|
||||
TIFF_EXTRA_SAMPLE_UNSPECIFIED = 0x0000,
|
||||
TIFF_EXTRA_SAMPLE_ASSOCIATED_ALPHA = 0x0001,
|
||||
TIFF_EXTRA_SAMPLE_UNASSOCIATED_ALPHA = 0x0002,
|
||||
};
|
||||
|
||||
enum tiff_compression {
|
||||
TIFF_COMPRESSION_UNCOMPRESSED = 0x0001,
|
||||
TIFF_COMPRESSION_CCITT_1D = 0x0002,
|
||||
@@ -100,6 +102,28 @@ enum tiff_planar_configuration {
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
typedef struct tiff_image TiffImage;
|
||||
struct tiff_image {
|
||||
TiffImageType type;
|
||||
u32 image_width;
|
||||
u32 image_length;
|
||||
u32 bits_per_sample;
|
||||
u32 sample_count;
|
||||
bool bits_per_sample_offset;
|
||||
u16 compression;
|
||||
u16 photometric_interpretation;
|
||||
u32 strip_offsets;
|
||||
bool strip_offsets_offset;
|
||||
u32 rows_per_strip;
|
||||
u32 strip_byte_counts;
|
||||
bool strip_byte_counts_offset;
|
||||
u32 strip_count;
|
||||
u32 color_map;
|
||||
u32 extra_samples;
|
||||
u32 extra_samples_count;
|
||||
bool extra_samples_offset;
|
||||
};
|
||||
|
||||
Image *read_baseline_tiff(const char *file, const Allocator *allocator);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
Reference in New Issue
Block a user