#include "pixbuf-util.h"
+#include <algorithm>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
+#include <utility>
+
+#include <cairo.h>
+#include <gio/gio.h>
+#include <glib-object.h>
+#include <pango/pangocairo.h>
+
#include <config.h>
#include "debug.h"
#include "exif.h"
#include "filedata.h"
#include "main-defines.h"
+#include "typedefs.h"
#include "ui-fileops.h"
-#include <cmath>
-
/*
*-----------------------------------------------------------------------------
prs = gdk_pixbuf_get_rowstride(pb);
p_pix = gdk_pixbuf_get_pixels(pb);
+ const gint p_step = has_alpha ? 4 : 3;
+
for (i = 0; i < h; i++)
{
- pp = p_pix + (y + i) * prs + (x * (has_alpha ? 4 : 3));
+ pp = p_pix + (y + i) * prs + (x * p_step);
for (j = 0; j < w; j++)
{
- *pp = (r * a + *pp * (256-a)) >> 8;
- pp++;
- *pp = (g * a + *pp * (256-a)) >> 8;
- pp++;
- *pp = (b * a + *pp * (256-a)) >> 8;
- pp++;
- if (has_alpha) pp++;
+ pp[0] = (r * a + pp[0] * (256-a)) >> 8;
+ pp[1] = (g * a + pp[1] * (256-a)) >> 8;
+ pp[2] = (b * a + pp[2] * (256-a)) >> 8;
+ pp += p_step;
}
}
}
prs = gdk_pixbuf_get_rowstride(pb);
p_pix = gdk_pixbuf_get_pixels(pb);
+ const gint p_step = has_alpha ? 4 : 3;
+
for (i = 0; i < h; i++)
{
- pp = p_pix + (y + i) * prs + (x * (has_alpha ? 4 : 3));
+ pp = p_pix + (y + i) * prs + (x * p_step);
for (j = 0; j < w; j++)
{
*pp = r; pp++;
*/
void util_clip_triangle(gint x1, gint y1, gint x2, gint y2, gint x3, gint y3,
- gint *rx, gint *ry, gint *rw, gint *rh)
+ gint &rx, gint &ry, gint &rw, gint &rh)
{
- gint tx;
- gint ty;
- gint tw;
- gint th;
-
- tx = MIN(x1, x2);
- tx = MIN(tx, x3);
- ty = MIN(y1, y2);
- ty = MIN(ty, y3);
- tw = MAX(abs(x1 - x2), abs(x2 - x3));
- tw = MAX(tw, abs(x3 - x1));
- th = MAX(abs(y1 - y2), abs(y2 - y3));
- th = MAX(th, abs(y3 - y1));
-
- *rx = tx;
- *ry = ty;
- *rw = tw;
- *rh = th;
+ rx = std::min({x1, x2, x3});
+ ry = std::min({y1, y2, y3});
+ rw = std::max({abs(x1 - x2), abs(x2 - x3), abs(x3 - x1)});
+ rh = std::max({abs(y1 - y2), abs(y2 - y3), abs(y3 - y1)});
}
void pixbuf_draw_triangle(GdkPixbuf *pb,
gint slope1_x;
gint slope1_y;
gint y;
- gint t;
gboolean middle = FALSE;
if (!pb) return;
&rx, &ry, &rw, &rh)) return;
util_clip_triangle(x1, y1, x2, y2, x3, y3,
- &tx, &ty, &tw, &th);
+ tx, ty, tw, th);
if (!util_clip_region(rx, ry, rw, rh,
tx, ty, tw, th,
if (y1 > y2)
{
- t = x1; x1 = x2; x2 = t;
- t = y1; y1 = y2; y2 = t;
+ std::swap(x1, x2);
+ std::swap(y1, y2);
}
if (y2 > y3)
{
- t = x2; x2 = x3; x3 = t;
- t = y2; y2 = y3; y3 = t;
+ std::swap(x2, x3);
+ std::swap(y2, y3);
}
if (y1 > y2)
{
- t = x1; x1 = x2; x2 = t;
- t = y1; y1 = y2; y2 = t;
+ std::swap(x1, x2);
+ std::swap(y1, y2);
}
slope1 = static_cast<gdouble>(y2 - y1);
if (xa > xb)
{
- t = xa; xa = xb; xb = t;
+ std::swap(xa, xb);
}
xa = CLAMP(xa, fx1, fx2);
while (xa < xb)
{
- *pp = (r * a + *pp * (256-a)) >> 8;
- pp++;
- *pp = (g * a + *pp * (256-a)) >> 8;
- pp++;
- *pp = (b * a + *pp * (256-a)) >> 8;
- pp++;
- if (has_alpha) pp++;
+ pp[0] = (r * a + pp[0] * (256-a)) >> 8;
+ pp[1] = (g * a + pp[1] * (256-a)) >> 8;
+ pp[2] = (b * a + pp[2] * (256-a)) >> 8;
+ pp += p_step;
xa++;
}
if (x1 > x2)
{
- gdouble t;
-
- t = x1; x1 = x2; x2 = t;
- t = y1; y1 = y2; y2 = t;
+ std::swap(x1, x2);
+ std::swap(y1, y2);
flip = TRUE;
}
}
else
{
- gdouble t;
-
if (y1 < clip_y || y2 > clip_y + clip_h) return FALSE;
- t = x1; x1 = x2; x2 = t;
- t = y1; y1 = y2; y2 = t;
+ std::swap(x1, x2);
+ std::swap(y1, y2);
flip = !flip;
}
{
if (rx1 > rx2)
{
- gdouble t;
- t = rx1; rx1 = rx2; rx2 = t;
- t = ry1; ry1 = ry2; ry2 = t;
+ std::swap(rx1, rx2);
+ std::swap(ry1, ry2);
}
slope = rx2 - rx1;
{
if (ry1 > ry2)
{
- gdouble t;
- t = rx1; rx1 = rx2; rx2 = t;
- t = ry1; ry1 = ry2; ry2 = t;
+ std::swap(rx1, rx2);
+ std::swap(ry1, ry2);
}
slope = ry2 - ry1;
for (i = x1; i < x2; i++)
{
if (vertical) n = a - a * abs(i - s) / border;
- *pp = (r * n + *pp * (256-n)) >> 8;
- pp++;
- *pp = (g * n + *pp * (256-n)) >> 8;
- pp++;
- *pp = (b * n + *pp * (256-n)) >> 8;
- pp++;
- if (has_alpha) pp++;
+ pp[0] = (r * n + pp[0] * (256-n)) >> 8;
+ pp[1] = (g * n + pp[1] * (256-n)) >> 8;
+ pp[2] = (b * n + pp[2] * (256-n)) >> 8;
+ pp += p_step;
}
}
}
r = MIN(border, (gint)hypot(i - sx, j - sy));
n = a - a * r / border;
- *pp = (r * n + *pp * (256-n)) >> 8;
- pp++;
- *pp = (g * n + *pp * (256-n)) >> 8;
- pp++;
- *pp = (b * n + *pp * (256-n)) >> 8;
- pp++;
- if (has_alpha) pp++;
+ pp[0] = (r * n + pp[0] * (256-n)) >> 8;
+ pp[1] = (g * n + pp[1] * (256-n)) >> 8;
+ pp[2] = (b * n + pp[2] * (256-n)) >> 8;
+ pp += p_step;
}
}
}
prs = gdk_pixbuf_get_rowstride(pb);
p_pix = gdk_pixbuf_get_pixels(pb);
+ const gint p_step = has_alpha ? 4 : 3;
+
for (i = 0; i < h; i++)
{
- pp = p_pix + (y + i) * prs + (x * (has_alpha ? 4 : 3));
+ pp = p_pix + (y + i) * prs + (x * p_step);
for (j = 0; j < w; j++)
{
guint8 grey;
grey = (pp[0] + pp[1] + pp[2]) / 3;
- *pp = grey;
- pp++;
- *pp = grey;
- pp++;
- *pp = grey;
- pp++;
- if (has_alpha) pp++;
+ pp[0] = grey;
+ pp[1] = grey;
+ pp[2] = grey;
+ pp += p_step;
}
}
}
prs = gdk_pixbuf_get_rowstride(pb);
p_pix = gdk_pixbuf_get_pixels(pb);
+ const gint p_step = has_alpha ? 4 : 3;
+
for (i = 0; i < h; i++)
{
- pp = p_pix + (y + i) * prs + (x * (has_alpha ? 4 : 3));
+ pp = p_pix + (y + i) * prs + (x * p_step);
for (j = 0; j < w; j++)
{
if (pp[0] == 255 || pp[1] == 255 || pp[2] == 255 || pp[0] == 0 || pp[1] == 0 || pp[2] == 0)
{
- *pp = 255;
- pp++;
- *pp = 0;
- pp++;
- *pp = 0;
- pp++;
- if (has_alpha) pp++;
- }
- else
- {
- pp = pp + 3;
- if (has_alpha) pp++;
+ pp[0] = 255;
+ pp[1] = 0;
+ pp[2] = 0;
}
+ pp += p_step;
}
}
}