return p->pixels + p->w * y + x;
}
+color_t raster_uv(const raster_t* p, vec_t uv)
+{
+ uv.x = scal_clamp(uv.x, S(0.0), S(1.0));
+ uv.y = scal_clamp(uv.y, S(0.0), S(1.0));
+ uv.y = S(1.0) - uv.y;
+ int x = (int)((scal_t)p->w * uv.x);
+ int y = (int)((scal_t)p->h * uv.y);
+ if (p->w <= x) {
+ x = p->w - 1;
+ }
+ if (p->h <= y) {
+ y = p->h - 1;
+ }
+ return *raster_color(p, x, y);
+}
+
int raster_width(const raster_t* p)
{
return p->w;
_DO_OR_DIE(fread(&paletteColorCount, sizeof(paletteColorCount), 1, file));
_DO_OR_DIE(fread(&importantPaletteColorCount, sizeof(importantPaletteColorCount), 1, file));
+ if ((int)width < 0 || (int)height < 0) {
+ fprintf(stderr, "Unexpected file format in %s: Try a ppm file instead\n", filename);
+ fclose(file);
+ return NULL;
+ }
p = raster_alloc((int)width, (int)height, COLOR_WHITE);
size = width * height;