1
0
Fork 0

Finish parsing of styles

This commit is contained in:
Hans-Joerg Schurr 2020-03-18 22:39:25 +01:00
parent cb5c2ccab4
commit 2913fd751f
1 changed files with 23 additions and 24 deletions

View File

@ -80,12 +80,14 @@ struct hvif_matrix
};
/* TODO: This is most likely wrong */
#define ID_TRANSFORMATION (hvif_matrix){1.0, 0.0, 0.0, 0.0, 1.0, 0.0}
#define ID_TRANSFORMATION \
(hvif_matrix) { 1.0, 0.0, 0.0, 0.0, 1.0, 0.0 }
#define hvif_read(V, BUFFER) V = _Generic((V)\
, uint32_t : hvif_read_uint32 \
, float: hvif_read_float \
, hvif_matrix: hvif_read_hvif_matrix)(BUFFER)
#define hvif_read(V, BUFFER) \
V = _Generic((V), uint32_t \
: hvif_read_uint32, float \
: hvif_read_float, hvif_matrix \
: hvif_read_hvif_matrix)(BUFFER)
static inline uint32_t
hvif_read_uint32(char buffer[static 1])
{
@ -110,14 +112,10 @@ hvif_read_float(char buffer[static 1])
static inline hvif_matrix
hvif_read_hvif_matrix(char buffer[static 1])
{
return (hvif_matrix){
hvif_read_float(buffer),
hvif_read_float(&buffer[3]),
hvif_read_float(&buffer[6]),
hvif_read_float(&buffer[9]),
hvif_read_float(&buffer[12]),
hvif_read_float(&buffer[15])
};
return (
hvif_matrix){ hvif_read_float(buffer), hvif_read_float(&buffer[3]),
hvif_read_float(&buffer[6]), hvif_read_float(&buffer[9]),
hvif_read_float(&buffer[12]), hvif_read_float(&buffer[15]) };
}
typedef uint32_t hvif_color; /* 8bit each: alpha, blue, green, red */
@ -140,6 +138,7 @@ struct hvif_style
uint8_t stops;
hvif_color* colors;
float* offsets;
hvif_matrix transformation;
};
struct hvif_image
@ -197,13 +196,16 @@ read_gradient_style(hvif_style* style, FILE* file, char* style_buffer)
uint8_t gradient_flags = style_buffer[1];
uint8_t gradient_stops = style_buffer[2];
if (gradient_type >= HVIF_GRADIENT_TYPE_MAX)
return ERROR_STYLE;
if (gradient_type >= HVIF_GRADIENT_TYPE_MAX) return ERROR_STYLE;
style->gradient_type = gradient_type;
bool gray = gradient_flags & GRADIENT_FLAG_GRAYS;
bool alpha = !(gradient_flags & GRADIENT_FLAG_NO_ALPHA);
/* structure:
* if transformable [matrix]
* then number of stops entries of the form: [stop][color] */
hvif_matrix transformation;
if (gradient_flags & GRADIENT_FLAG_TRANSFORM) {
/* The transformation matrix is 6 hvif-floats: 18 bytes */
@ -213,12 +215,12 @@ read_gradient_style(hvif_style* style, FILE* file, char* style_buffer)
} else {
transformation = ID_TRANSFORMATION;
}
style->transformation = transformation;
style->offsets = calloc(gradient_stops, sizeof(float));
style->colors = calloc(gradient_stops, sizeof(hvif_color));
char buffer[4];
/* TODO allocate color, stops */
/* structure:
* if transformable [matrix]
* then number of stops entries of the form: [stop][color] */
for (unsigned i = 0; i < gradient_stops; ++i) {
if (fread(buffer, 1, 1, file) != 1) { return ERROR_EOF; }
float offset = buffer[0] / 255.0;
@ -240,13 +242,10 @@ read_gradient_style(hvif_style* style, FILE* file, char* style_buffer)
c = decode_color(buffer, gray, alpha);
}
}
style->offsets[i] = offset;
style->colors[i] = c;
}
/* parsing based on flags */
/* if transformable: a matrix of floats:
* matrix size is static and probably 6, it's an affine transformation
* just push it into a double (or float?)[6] and get it over with */
return SUCCESS;
}