33 lines
828 B
C
33 lines
828 B
C
#include "liblocky.h"
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
void blky_image_convert_to_normalized_coord(
|
|
const double verts[8], double* x, double* y) {
|
|
assert(0 <= *x && *x < 1);
|
|
assert(0 <= *y && *y < 1);
|
|
|
|
const double rx = 1-*x, ry = 1-*y;
|
|
|
|
const double top_xf = *x*verts[6] + rx*verts[0];
|
|
const double bot_xf = *x*verts[4] + rx*verts[2];
|
|
|
|
const double lef_yf = *y*verts[3] + ry*verts[1];
|
|
const double rig_yf = *y*verts[5] + ry*verts[7];
|
|
|
|
const double ans_x = *y*bot_xf + ry*top_xf;
|
|
const double ans_y = *x*rig_yf + rx*lef_yf;
|
|
|
|
*x = ans_x;
|
|
*y = ans_y;
|
|
}
|
|
|
|
uint64_t blky_image_offset(
|
|
uint32_t w, uint32_t h, const double verts[8], double x, double y) {
|
|
blky_image_convert_to_normalized_coord(verts, &x, &y);
|
|
const uint32_t xi = (uint32_t) (x*w);
|
|
const uint32_t yi = (uint32_t) (y*h);
|
|
return yi*w + xi;
|
|
}
|