summaryrefslogtreecommitdiff
path: root/render/pixmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'render/pixmap.c')
-rw-r--r--render/pixmap.c118
1 files changed, 62 insertions, 56 deletions
diff --git a/render/pixmap.c b/render/pixmap.c
index ac99de80..0902c901 100644
--- a/render/pixmap.c
+++ b/render/pixmap.c
@@ -29,22 +29,11 @@ fz_newpixmap(fz_pixmap **pixp, int x, int y, int w, int h, int n, int a)
return nil;
}
-fz_pixmap *
-fz_keeppixmap(fz_pixmap *pix)
-{
- pix->refcount ++;
- return pix;
-}
-
void
-fz_droppixmap(fz_pixmap *pix)
+fz_freepixmap(fz_pixmap *pix)
{
- pix->refcount --;
- if (pix->refcount == 0)
- {
- fz_free(pix->samples);
- fz_free(pix);
- }
+ fz_free(pix->samples);
+ fz_free(pix);
}
void
@@ -57,76 +46,93 @@ void
fz_debugpixmap(fz_pixmap *pix)
{
int x, y;
- assert(pix->n == 3 && pix->a == 1);
+
FILE *f = fopen("out.ppm", "w");
- fprintf(f, "P6\n%d %d\n255\n", pix->w, pix->h);
- for (y = 0; y < pix->h; y++)
- for (x = 0; x < pix->w; x++)
- {
- int r = (pix->samples[x * 4 + y * pix->stride + 0] * 255) >> 14;
- int g = (pix->samples[x * 4 + y * pix->stride + 1] * 255) >> 14;
- int b = (pix->samples[x * 4 + y * pix->stride + 2] * 255) >> 14;
- putc(r, f);
- putc(g, f);
- putc(b, f);
- }
+
+ if (pix->n == 3 && pix->a == 1)
+ {
+ fprintf(f, "P6\n%d %d\n255\n", pix->w, pix->h);
+ for (y = 0; y < pix->h; y++)
+ for (x = 0; x < pix->w; x++)
+ {
+ int r = (pix->samples[x * 4 + y * pix->stride + 0] * 255) >> 14;
+ int g = (pix->samples[x * 4 + y * pix->stride + 1] * 255) >> 14;
+ int b = (pix->samples[x * 4 + y * pix->stride + 2] * 255) >> 14;
+ int a = (pix->samples[x * 4 + y * pix->stride + 3] * 255) >> 14;
+ putc(((r * a) / 255) + (255 - a), f);
+ putc(((g * a) / 255) + (255 - a), f);
+ putc(((b * a) / 255) + (255 - a), f);
+ // putc(a, f);
+ // putc(a, f);
+ // putc(a, f);
+ }
+ }
+ else if (pix->n == 0 && pix->a == 1)
+ {
+ fprintf(f, "P5\n%d %d\n255\n", pix->w, pix->h);
+ for (y = 0; y < pix->h; y++)
+ for (x = 0; x < pix->w; x++)
+ {
+ int a = (pix->samples[x + y * pix->stride] * 255) >> 14;
+ putc(a, f);
+ }
+ }
fclose(f);
}
void
-fz_blendover(fz_pixmap *dst, fz_pixmap *fg, fz_pixmap *bg)
+fz_blendover(fz_pixmap *src, fz_pixmap *dst)
{
- int x, y;
-
-printf("dst=%d,%d fg=%d,%d bg=%d,%d\n",
-dst->n, dst->a,
-fg->n, fg->a,
-bg->n, bg->a);
+ int x, y, k;
- assert(fg->n == bg->n);
- assert(fg->n == 3);
- assert(fg->a == 1);
- assert(bg->a == 1);
+ assert(dst->n == src->n);
+ assert(dst->a == 1);
+ assert(src->n == 3);
+ assert(src->a == 1);
for (y = 0; y < dst->h; y++)
{
- short *bgp = &fg->samples[y * fg->stride];
- short *fgp = &bg->samples[y * bg->stride];
- short *dstp = &dst->samples[y * dst->stride];
+ short *s = &src->samples[y * src->stride];
+ short *d = &dst->samples[y * dst->stride];
+
for (x = 0; x < dst->w; x++)
{
- dstp[0] = ((fgp[3] * (fgp[0] - bgp[0])) >> 14) + bgp[0];
- dstp[1] = ((fgp[3] * (fgp[1] - bgp[1])) >> 14) + bgp[1];
- dstp[2] = ((fgp[3] * (fgp[2] - bgp[2])) >> 14) + bgp[2];
- dstp[3] = ((fgp[3] * (fgp[3] - bgp[3])) >> 14) + bgp[3];
- dstp += 4;
- fgp += 4;
- bgp += 4;
+ int sa = s[3];
+ int ssa = (1 << 14) - sa;
+
+ d[0] = ((s[0] * sa) >> 14) + ((d[0] * ssa) >> 14);
+ d[1] = ((s[1] * sa) >> 14) + ((d[1] * ssa) >> 14);
+ d[2] = ((s[2] * sa) >> 14) + ((d[2] * ssa) >> 14);
+ d[3] = sa + ((ssa * d[3]) >> 14);
+
+ s += 4;
+ d += 4;
}
}
}
void
-fz_blendmask(fz_pixmap *dst, fz_pixmap *src, fz_pixmap *mask)
+fz_blendmask(fz_pixmap *dst, fz_pixmap *src, fz_pixmap *msk)
{
int x, y, k;
assert(src->n == dst->n);
- assert(src->a == 0);
- assert(mask->n == 0);
- assert(mask->a == 1);
+ assert(src->a == 1);
+ assert(msk->n == 0);
+ assert(msk->a == 1);
assert(dst->a == 1);
for (y = 0; y < dst->h; y++)
{
- short *dstp = &dst->samples[y * dst->stride];
- short *srcp = &src->samples[y * src->stride];
- short *mskp = &mask->samples[y * mask->stride];
+ short *d = &dst->samples[y * dst->stride];
+ short *s = &src->samples[y * src->stride];
+ short *m = &msk->samples[y * msk->stride];
+
for (x = 0; x < dst->w; x++)
{
for (k = 0; k < dst->n; k++)
- *dstp++ = *srcp++;
- *dstp++ = *mskp++;
+ *d++ = *s++;
+ *d++ = (*m++ * *s++) >> 14;
}
}
}