Move all TIFF type definitions to the source file
This commit is contained in:
parent
c2391df946
commit
1c667f4128
@ -8,6 +8,7 @@
|
||||
#include <netinet/in.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
@ -34,6 +35,160 @@
|
||||
|
||||
#define TEMP_ARENA_CAPACITY (20 * 1024 * 1024)
|
||||
|
||||
#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,
|
||||
};
|
||||
|
||||
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,
|
||||
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
|
||||
|
||||
typedef struct short_long_value ShortLongValue;
|
||||
struct short_long_value {
|
||||
union {
|
||||
u16 short_val;
|
||||
u32 long_val;
|
||||
};
|
||||
};
|
||||
|
||||
typedef struct hdr TiffHdr;
|
||||
struct hdr {
|
||||
u16 order;
|
||||
u16 magic;
|
||||
u32 first_ifd_offset;
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
ALPHA_TYPE_UNDEFINED = 0,
|
||||
ALPHA_TYPE_ASSOCIATED,
|
||||
ALPHA_TYPE_UNASSOCIATED,
|
||||
} AlphaType;
|
||||
|
||||
typedef struct tiff_alpha TiffAlpha;
|
||||
struct tiff_alpha {
|
||||
AlphaType type;
|
||||
u32 sample_offset;
|
||||
};
|
||||
|
||||
typedef struct tiff_sample_bits TiffSampleBits;
|
||||
struct tiff_sample_bits {
|
||||
u16 r;
|
||||
u16 g;
|
||||
u16 b;
|
||||
u16 a;
|
||||
};
|
||||
|
||||
typedef struct tiff_strip TiffStrip;
|
||||
struct tiff_strip {
|
||||
u32 offset;
|
||||
u32 byte_count;
|
||||
};
|
||||
|
||||
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;
|
||||
u16 strip_offsets_type_byte_count;
|
||||
ShortLongValue strip_offsets;
|
||||
bool strip_offsets_offset;
|
||||
u32 rows_per_strip;
|
||||
u16 strip_byte_count_type_byte_count;
|
||||
ShortLongValue 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;
|
||||
TiffAlpha alpha;
|
||||
TiffSampleBits rgba_bits_per_sample;
|
||||
TiffStrip *strips;
|
||||
};
|
||||
|
||||
typedef struct tiff_reader TiffReader;
|
||||
struct tiff_reader {
|
||||
FILE *fp;
|
||||
|
@ -6,163 +6,7 @@
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
#include "aliases.h"
|
||||
#include "image.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#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,
|
||||
};
|
||||
|
||||
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,
|
||||
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
|
||||
|
||||
typedef struct short_long_value ShortLongValue;
|
||||
struct short_long_value {
|
||||
union {
|
||||
u16 short_val;
|
||||
u32 long_val;
|
||||
};
|
||||
};
|
||||
|
||||
typedef struct hdr TiffHdr;
|
||||
struct hdr {
|
||||
u16 order;
|
||||
u16 magic;
|
||||
u32 first_ifd_offset;
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
ALPHA_TYPE_UNDEFINED = 0,
|
||||
ALPHA_TYPE_ASSOCIATED,
|
||||
ALPHA_TYPE_UNASSOCIATED,
|
||||
} AlphaType;
|
||||
|
||||
typedef struct tiff_alpha TiffAlpha;
|
||||
struct tiff_alpha {
|
||||
AlphaType type;
|
||||
u32 sample_offset;
|
||||
};
|
||||
|
||||
typedef struct tiff_sample_bits TiffSampleBits;
|
||||
struct tiff_sample_bits {
|
||||
u16 r;
|
||||
u16 g;
|
||||
u16 b;
|
||||
u16 a;
|
||||
};
|
||||
|
||||
typedef struct tiff_strip TiffStrip;
|
||||
struct tiff_strip {
|
||||
u32 offset;
|
||||
u32 byte_count;
|
||||
};
|
||||
|
||||
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;
|
||||
u16 strip_offsets_type_byte_count;
|
||||
ShortLongValue strip_offsets;
|
||||
bool strip_offsets_offset;
|
||||
u32 rows_per_strip;
|
||||
u16 strip_byte_count_type_byte_count;
|
||||
ShortLongValue 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;
|
||||
TiffAlpha alpha;
|
||||
TiffSampleBits rgba_bits_per_sample;
|
||||
TiffStrip *strips;
|
||||
};
|
||||
|
||||
Image *read_baseline_tiff(const char *file, Arena *arena);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user