return p->pixels[p->w * (p->h - v - 1) + u];
}
+int raster_width(const raster_t* p)
+{
+ return p->w;
+}
+
+int raster_height(const raster_t* p)
+{
+ return p->h;
+}
+
+void* raster_data(const raster_t* p)
+{
+ size_t size = p->w * p->h;
+ rgba_t* data = mem_alloc(size * sizeof(rgba_t));
+
+ for (int i = 0; i < size; ++i) {
+ data[i] = rgba_from_color(p->pixels[i]);
+ }
+ return data;
+}
+
void raster_clear(raster_t* p, color_t fill)
{
size_t size = width * height;
for (int i = 0; i < size; ++i)
{
- rgbachan_t a, r, g, b;
- color_split(p->pixels[i], &r, &g, &b, &a);
- uint32_t argb = PACK(argb, 3, a);
- argb = PACK(argb, 2, r);
- argb = PACK(argb, 1, g);
- argb = PACK(argb, 0, b);
+ struct {
+ rgbachan_t b, g, r, a;
+ } argb;
+ color_split(p->pixels[i], &argb.r, &argb.g, &argb.b, &argb.a);
_DO_OR_DIE(fwrite(&argb, sizeof(argb), 1, file));
}
fprintf(stderr, "Failed reading color values from %s: %s\n", filename, strerror(errno));
return NULL;
}
- rgba_t rgba = PACK(rgba, 3, (uint8_t)r);
- rgba = PACK(rgba, 2, (uint8_t)g);
- rgba = PACK(rgba, 1, (uint8_t)b);
- rgba = PACK(rgba, 0, 255);
- p->pixels[y * w + x] = color_from_rgba(rgba);
+ union {
+ rgba_t rgba;
+ struct {
+ rgbachan_t r, g, b, a;
+ } chan;
+ } u;
+ u.chan.r = (rgbachan_t)r;
+ u.chan.g = (rgbachan_t)g;
+ u.chan.b = (rgbachan_t)b;
+ u.chan.a = 255;
+ p->pixels[y * w + x] = color_from_rgba(u.rgba);
}
}
size_t size = width * height;
for (int i = 0; i < size; ++i)
{
- uint32_t argb;
- _DO_OR_DIE(fread(&argb, sizeof(argb), 1, file));
- rgba_t rgba = PACK(rgba, 3, UNPACK(argb, 2));
- rgba = PACK(rgba, 2, UNPACK(argb, 1));
- rgba = PACK(rgba, 1, UNPACK(argb, 0));
- rgba = PACK(rgba, 0, UNPACK(argb, 3));
- p->pixels[i] = color_from_rgba(rgba);
+ union {
+ rgba_t rgba;
+ struct {
+ rgbachan_t r, g, b, a;
+ } chan;
+ } u;
+ _DO_OR_DIE(fread(&u, sizeof(u), 1, file));
+ rgbachan_t t = u.chan.r;
+ u.chan.r = u.chan.a;
+ u.chan.a = t;
+ t = u.chan.g;
+ u.chan.g = u.chan.b;
+ u.chan.b = t;
+ t = u.chan.r;
+ u.chan.r = u.chan.g;
+ u.chan.g = u.chan.b;
+ u.chan.b = u.chan.a;
+ u.chan.a = t;
+ p->pixels[i] = color_from_rgba(u.rgba);
}
fclose(file);
raster_material(p, model_specular(model), model_shininess(model));
p->current = model;
IF_RENDER_PROGRESS(tri = 0);
- for (const list_t* ti = model_geometry(model); ti; ti = ti->link) {
+ array_it_t it = array_begin(model_geometry(model));
+ for (tri_t* t; t = array_it_tri_next(&it);) {
#if VERBOSITY >= 4
if (++tri % 100 == 0) {
printf(PROGRESS_FMT, model_name(model), tri, model_size(model));
fflush(stdout);
}
#endif
- raster_draw_tri(p, (tri_t*)ti->val);
+ raster_draw_tri(p, t);
}
#if VERBOSITY >= 4
printf(PROGRESS_FMT"\n", model_name(model), tri, model_size(model));