Преглед на файлове

Increase img2twit's output contrast when rendering the final image.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@3528 92316355-f0b4-4df1-b90c-862c8a59935f
master
sam преди 15 години
родител
ревизия
8ff3640960
променени са 1 файла, в които са добавени 30 реда и са изтрити 22 реда
  1. +30
    -22
      examples/img2twit.cpp

+ 30
- 22
examples/img2twit.cpp Целия файл

@@ -465,7 +465,7 @@ static inline void set_point(int index, float x, float y, float r,
} }


static inline void get_point(int index, float *x, float *y, float *r, static inline void get_point(int index, float *x, float *y, float *r,
float *g, float *b, float *s)
float *g, float *b, float *s, bool final = false)
{ {
uint32_t pt = points[index]; uint32_t pt = points[index];


@@ -480,9 +480,18 @@ static inline void get_point(int index, float *x, float *y, float *r,
*x = (fx + dx) * RANGE_X /*+ 0.5 * (index & 1)*/; *x = (fx + dx) * RANGE_X /*+ 0.5 * (index & 1)*/;
*y = (fy + dy) * RANGE_Y /*+ 0.5 * (index & 1)*/; *y = (fy + dy) * RANGE_Y /*+ 0.5 * (index & 1)*/;


*b = int2midrange(pt % RANGE_R, RANGE_R); pt /= RANGE_R;
*g = int2midrange(pt % RANGE_G, RANGE_G); pt /= RANGE_G;
*r = int2midrange(pt % RANGE_B, RANGE_B); pt /= RANGE_B;
if(final)
{
*b = int2fullrange(pt % RANGE_R, RANGE_R); pt /= RANGE_R;
*g = int2fullrange(pt % RANGE_G, RANGE_G); pt /= RANGE_G;
*r = int2fullrange(pt % RANGE_B, RANGE_B); pt /= RANGE_B;
}
else
{
*b = int2midrange(pt % RANGE_R, RANGE_R); pt /= RANGE_R;
*g = int2midrange(pt % RANGE_G, RANGE_G); pt /= RANGE_G;
*r = int2midrange(pt % RANGE_B, RANGE_B); pt /= RANGE_B;
}
} }


static inline float clip(float x, int modulo) static inline float clip(float x, int modulo)
@@ -625,7 +634,8 @@ static uint32_t apply_op(uint8_t op, uint32_t val)
} }
} }


static void render(pipi_image_t *dst, int rx, int ry, int rw, int rh)
static void render(pipi_image_t *dst,
int rx, int ry, int rw, int rh, bool final)
{ {
int lookup[dw * RANGE_X * 2 * dh * RANGE_Y * 2]; int lookup[dw * RANGE_X * 2 * dh * RANGE_Y * 2];
pipi_pixels_t *p = pipi_get_pixels(dst, PIPI_PIXELS_RGBA_F32); pipi_pixels_t *p = pipi_get_pixels(dst, PIPI_PIXELS_RGBA_F32);
@@ -644,16 +654,17 @@ static void render(pipi_image_t *dst, int rx, int ry, int rw, int rh)
} }


/* Add fake points to close the triangulation */ /* Add fake points to close the triangulation */
dt.insert(K::Point_2(-p->w, -p->h));
dt.insert(K::Point_2(2 * p->w, -p->h));
dt.insert(K::Point_2(-p->w, 2 * p->h));
dt.insert(K::Point_2(2 * p->w, 2 * p->h));
dt.insert(K::Point_2(-dw * RANGE_X, -dh * RANGE_Y));
dt.insert(K::Point_2(2 * dw * RANGE_X, -dh * RANGE_Y));
dt.insert(K::Point_2(-dw * RANGE_X, 2 * dh * RANGE_Y));
dt.insert(K::Point_2(2 * dw * RANGE_X, 2 * dh * RANGE_Y));


for(y = ry; y < ry + rh; y++) for(y = ry; y < ry + rh; y++)
{ {
for(x = rx; x < rx + rw; x++) for(x = rx; x < rx + rw; x++)
{ {
K::Point_2 m(x, y);
K::Point_2 m((float)x * dw * RANGE_X / p->w,
(float)y * dh * RANGE_Y / p->h);
Point_coordinate_vector coords; Point_coordinate_vector coords;
CGAL::Triple< CGAL::Triple<
std::back_insert_iterator<Point_coordinate_vector>, std::back_insert_iterator<Point_coordinate_vector>,
@@ -671,13 +682,14 @@ static void render(pipi_image_t *dst, int rx, int ry, int rw, int rh)
fx = (*it).first.x(); fx = (*it).first.x();
fy = (*it).first.y(); fy = (*it).first.y();


if(fx < 0 || fy < 0 || fx > p->w - 1 || fy > p->h - 1)
if(fx < 0 || fy < 0
|| fx > dw * RANGE_X - 1 || fy > dh * RANGE_Y - 1)
continue; continue;


int index = lookup[(int)(fx * 2) int index = lookup[(int)(fx * 2)
+ dw * RANGE_X * 2 * (int)(fy * 2)]; + dw * RANGE_X * 2 * (int)(fy * 2)];


get_point(index, &fx, &fy, &fr, &fg, &fb, &fs);
get_point(index, &fx, &fy, &fr, &fg, &fb, &fs, final);


//float k = pow((*it).second * (1.0 + fs), 1.2); //float k = pow((*it).second * (1.0 + fs), 1.2);
float k = (*it).second * (1.00f + fs); float k = (*it).second * (1.00f + fs);
@@ -1054,7 +1066,7 @@ int main(int argc, char *argv[])


/* Render what we just computed */ /* Render what we just computed */
tmp = pipi_new(dw * RANGE_X, dh * RANGE_Y); tmp = pipi_new(dw * RANGE_X, dh * RANGE_Y);
render(tmp, 0, 0, dw * RANGE_X, dh * RANGE_Y);
render(tmp, 0, 0, dw * RANGE_X, dh * RANGE_Y, false);
error = pipi_measure_rmsd(src, tmp); error = pipi_measure_rmsd(src, tmp);


if(DEBUG_MODE) if(DEBUG_MODE)
@@ -1113,7 +1125,7 @@ int main(int argc, char *argv[])
points[pt] = candidates[i]; points[pt] = candidates[i];


render(scrap, zonex * RANGE_X, zoney * RANGE_Y, render(scrap, zonex * RANGE_X, zoney * RANGE_Y,
zonew * RANGE_X, zoneh * RANGE_Y);
zonew * RANGE_X, zoneh * RANGE_Y, false);


double newerr = pipi_measure_rmsd(src, scrap); double newerr = pipi_measure_rmsd(src, scrap);
if(newerr < besterr) if(newerr < besterr)
@@ -1130,9 +1142,9 @@ int main(int argc, char *argv[])
{ {
points[pt] = candidates[bestop]; points[pt] = candidates[bestop];
/* Redraw image if the last check wasn't the best one */ /* Redraw image if the last check wasn't the best one */
if(bestop != 2)
if(bestop != 0)
render(scrap, zonex * RANGE_X, zoney * RANGE_Y, render(scrap, zonex * RANGE_X, zoney * RANGE_Y,
zonew * RANGE_X, zoneh * RANGE_Y);
zonew * RANGE_X, zoneh * RANGE_Y, false);


pipi_free(tmp); pipi_free(tmp);
tmp = scrap; tmp = scrap;
@@ -1218,12 +1230,8 @@ int main(int argc, char *argv[])
npoints = dw * dh * POINTS_PER_CELL; npoints = dw * dh * POINTS_PER_CELL;


/* Render these points to a new image */ /* Render these points to a new image */
tmp = pipi_new(dw * RANGE_X, dh * RANGE_Y);
render(tmp, 0, 0, dw * RANGE_X, dh * RANGE_Y);

/* TODO: render directly to the final image; scaling sucks */
dst = pipi_resize(tmp, width, height);
pipi_free(tmp);
dst = pipi_new(width, height);
render(dst, 0, 0, width, height, true);


/* Save image and bail out */ /* Save image and bail out */
pipi_save(dst, dstname); pipi_save(dst, dstname);


Зареждане…
Отказ
Запис