Continue test rasterizer
- Support for creating .cquery file via "make cquery" - Render some path for testing purposes - Fix bugs in path parser
This commit is contained in:
parent
6818012f69
commit
a5c305d98c
|
@ -30,3 +30,4 @@ depcomp
|
||||||
hvif
|
hvif
|
||||||
install-sh
|
install-sh
|
||||||
missing
|
missing
|
||||||
|
.cquery
|
||||||
|
|
|
@ -26,3 +26,9 @@ hvif_SOURCES = \
|
||||||
src/hvif-cairo.h \
|
src/hvif-cairo.h \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
|
cquery:
|
||||||
|
echo '%clang' > .cquery
|
||||||
|
echo '%c -std=gnu11' >> .cquery
|
||||||
|
echo '$(CAIRO_CFLAGS)' | sed "s/ /\\n/g" >> .cquery
|
||||||
|
|
||||||
|
.PHONY: cquery
|
||||||
|
|
|
@ -1,18 +1,62 @@
|
||||||
#include "hvif-light.h"
|
#include "hvif-light.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <assert.h>
|
||||||
#include <cairo.h>
|
#include <cairo.h>
|
||||||
|
|
||||||
#define INTERNAL_DATASTRUCTURES
|
#define INTERNAL_DATASTRUCTURES
|
||||||
#include "hvif-light.c"
|
#include "hvif-light.c"
|
||||||
#undef INTERNAL_DATASTRUCTURES
|
#undef INTERNAL_DATASTRUCTURES
|
||||||
|
|
||||||
|
/* TODO:
|
||||||
|
* 1. Draw the path in each shape as outline
|
||||||
|
* 2. Then do the same for the styles
|
||||||
|
* 3. Put everything together
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
create_path(cairo_t* cr, hvif_path* path)
|
||||||
|
{
|
||||||
|
assert(path->num_points > 0);
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < path->num_points; ++i) {
|
||||||
|
hvif_point p = path->points[3 * i];
|
||||||
|
hvif_point cp1 = path->points[3 * i + 1];
|
||||||
|
hvif_point cp2 = path->points[3 * i + 2];
|
||||||
|
cairo_curve_to(cr, cp1.x, cp1.y, cp2.x, cp2.y, p.x, p.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (path->closed)
|
||||||
|
cairo_close_path(cr);
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
hvif_render_image(const char* filename, hvif_image* image)
|
hvif_render_image(const char* filename, hvif_image* image)
|
||||||
{
|
{
|
||||||
cairo_surface_t* surface =
|
cairo_surface_t* surface =
|
||||||
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 240, 80);
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 254, 254);
|
||||||
cairo_t* cr = cairo_create(surface);
|
cairo_t* cr = cairo_create(surface);
|
||||||
|
cairo_scale(cr, 4.0, 4.0);
|
||||||
|
|
||||||
|
cairo_set_line_width(cr, 0.2);
|
||||||
|
|
||||||
|
double r = 0;
|
||||||
|
double delta = 1.0 / image->num_shapes;
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < image->num_shapes; ++i) {
|
||||||
|
cairo_set_source_rgb(cr, r, 0, 0);
|
||||||
|
r = r + delta;
|
||||||
|
hvif_shape s = image->shapes[i];
|
||||||
|
if (s.hinting)
|
||||||
|
printf("shape %u has hinting\n", i);
|
||||||
|
else
|
||||||
|
printf("shape %u has no hinting\n", i);
|
||||||
|
for (unsigned j = 0; j < s.num_paths; ++j) {
|
||||||
|
hvif_path* p = &image->paths[s.path_idxs[j]];
|
||||||
|
create_path(cr, p);
|
||||||
|
cairo_stroke(cr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cairo_destroy(cr);
|
cairo_destroy(cr);
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef HVIF_CAIRO_H
|
#ifndef HVIF_CAIRO_H
|
||||||
#define HVIF_CAIRO_H
|
#define HVIF_CAIRO_H
|
||||||
|
|
||||||
#include "hvif-ligh.h"
|
#include "hvif-light.h"
|
||||||
|
|
||||||
bool hvif_render_image(const char* filename, hvif_image* image);
|
bool hvif_render_image(const char* filename, hvif_image* image);
|
||||||
|
|
||||||
|
|
|
@ -463,7 +463,7 @@ read_path_points(FILE* file, hvif_path* path)
|
||||||
printf("%s: read v line.\n", __func__);
|
printf("%s: read v line.\n", __func__);
|
||||||
#endif
|
#endif
|
||||||
point = last;
|
point = last;
|
||||||
status = read_coordinate(file, &point.x);
|
status = read_coordinate(file, &point.y);
|
||||||
if (status != SUCCESS) return status;
|
if (status != SUCCESS) return status;
|
||||||
point_in = point_out = point;
|
point_in = point_out = point;
|
||||||
break;
|
break;
|
||||||
|
@ -485,17 +485,14 @@ read_path_points(FILE* file, hvif_path* path)
|
||||||
if (status != SUCCESS) return status;
|
if (status != SUCCESS) return status;
|
||||||
status = read_coordinate(file, &point.y);
|
status = read_coordinate(file, &point.y);
|
||||||
if (status != SUCCESS) return status;
|
if (status != SUCCESS) return status;
|
||||||
point_in = point_out = point;
|
|
||||||
status = read_coordinate(file, &point_in.x);
|
status = read_coordinate(file, &point_in.x);
|
||||||
if (status != SUCCESS) return status;
|
if (status != SUCCESS) return status;
|
||||||
status = read_coordinate(file, &point_in.y);
|
status = read_coordinate(file, &point_in.y);
|
||||||
if (status != SUCCESS) return status;
|
if (status != SUCCESS) return status;
|
||||||
point_in = point_out = point;
|
|
||||||
status = read_coordinate(file, &point_out.x);
|
status = read_coordinate(file, &point_out.x);
|
||||||
if (status != SUCCESS) return status;
|
if (status != SUCCESS) return status;
|
||||||
status = read_coordinate(file, &point_out.y);
|
status = read_coordinate(file, &point_out.y);
|
||||||
if (status != SUCCESS) return status;
|
if (status != SUCCESS) return status;
|
||||||
point_in = point_out = point;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
unsigned base = i * 3;
|
unsigned base = i * 3;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "hvif-light.h"
|
#include "hvif-light.h"
|
||||||
|
#include "hvif-cairo.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -36,6 +37,9 @@ main(int argc, char* argv[argc + 1])
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
puts("Reading image succeeded.");
|
puts("Reading image succeeded.");
|
||||||
|
|
||||||
|
hvif_render_image("test.png", result.image);
|
||||||
|
|
||||||
hvif_free(result.image);
|
hvif_free(result.image);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
Loading…
Reference in New Issue