Reorder functions
This commit is contained in:
parent
484d30d84c
commit
3f022acf9c
@ -59,9 +59,9 @@ TiffImage read_fields(const TiffReader *reader);
|
||||
Pixel *load_image_pixels(TiffReader *reader, Arena *arena);
|
||||
bool read_strip_data(TiffReader *reader, Arena *arena);
|
||||
void read_strips(const TiffReader *reader, Pixel *buf);
|
||||
void read_strip_data_field(const TiffReader *reader, StripDataField *field);
|
||||
bool read_field(const TiffField *field, TiffImage *img);
|
||||
bool validate_image_type(const TiffImage *img);
|
||||
void read_strip_data_field(const TiffReader *reader, StripDataField *field);
|
||||
void read_from_file_with_offset(FILE *fp, void *dst, u64 count, u64 offset);
|
||||
|
||||
Image *read_baseline_tiff(const char *file, Arena *arena) {
|
||||
@ -358,6 +358,42 @@ void read_strips(const TiffReader *reader, Pixel *buf) {
|
||||
}
|
||||
}
|
||||
|
||||
void read_strip_data_field(const TiffReader *reader, StripDataField *field) {
|
||||
u16 tiff_long_byte_count = field_types[TIFF_FIELD_TYPE_LONG].byte_count;
|
||||
|
||||
bool value_is_file_offset = field->length_in_bytes > tiff_long_byte_count;
|
||||
u32 offset = field->type_byte_count * field->strip_index;
|
||||
|
||||
if (!value_is_file_offset) {
|
||||
u8 *value = (u8 *)&(field->value_from_file->long_val);
|
||||
memcpy(field->strip_value, value + offset, field->type_byte_count);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
read_from_file_with_offset(reader->fp, field->strip_value,
|
||||
field->type_byte_count,
|
||||
field->value_from_file->long_val + offset);
|
||||
|
||||
u16 tiff_short_byte_count = field_types[TIFF_FIELD_TYPE_SHORT].byte_count;
|
||||
switch (reader->header.order) {
|
||||
case TIFF_ORDER_BIG_ENDIAN:
|
||||
if (IS_LITTLE_ENDIAN) {
|
||||
*(field->strip_value) = field->type_byte_count > tiff_short_byte_count
|
||||
? ntohl(*(field->strip_value))
|
||||
: ntohs(*(field->strip_value));
|
||||
}
|
||||
break;
|
||||
case TIFF_ORDER_LITTLE_ENDIAN:
|
||||
if (IS_BIG_ENDIAN) {
|
||||
*(field->strip_value) = field->type_byte_count > tiff_short_byte_count
|
||||
? htonl(*(field->strip_value))
|
||||
: htons(*(field->strip_value));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool read_field(const TiffField *field, TiffImage *img) {
|
||||
switch (field->tag) {
|
||||
case TIFF_PUBLIC_TAG_IMAGE_WIDTH:
|
||||
@ -530,42 +566,6 @@ bool validate_image_type(const TiffImage *img) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void read_strip_data_field(const TiffReader *reader, StripDataField *field) {
|
||||
u16 tiff_long_byte_count = field_types[TIFF_FIELD_TYPE_LONG].byte_count;
|
||||
|
||||
bool value_is_file_offset = field->length_in_bytes > tiff_long_byte_count;
|
||||
u32 offset = field->type_byte_count * field->strip_index;
|
||||
|
||||
if (!value_is_file_offset) {
|
||||
u8 *value = (u8 *)&(field->value_from_file->long_val);
|
||||
memcpy(field->strip_value, value + offset, field->type_byte_count);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
read_from_file_with_offset(reader->fp, field->strip_value,
|
||||
field->type_byte_count,
|
||||
field->value_from_file->long_val + offset);
|
||||
|
||||
u16 tiff_short_byte_count = field_types[TIFF_FIELD_TYPE_SHORT].byte_count;
|
||||
switch (reader->header.order) {
|
||||
case TIFF_ORDER_BIG_ENDIAN:
|
||||
if (IS_LITTLE_ENDIAN) {
|
||||
*(field->strip_value) = field->type_byte_count > tiff_short_byte_count
|
||||
? ntohl(*(field->strip_value))
|
||||
: ntohs(*(field->strip_value));
|
||||
}
|
||||
break;
|
||||
case TIFF_ORDER_LITTLE_ENDIAN:
|
||||
if (IS_BIG_ENDIAN) {
|
||||
*(field->strip_value) = field->type_byte_count > tiff_short_byte_count
|
||||
? htonl(*(field->strip_value))
|
||||
: htons(*(field->strip_value));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void read_from_file_with_offset(FILE *fp, void *dst, u64 count, u64 offset) {
|
||||
if (!fp || !dst) {
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user