Commit 60ff5cd3 authored by Alexei Podtelezhnikov's avatar Alexei Podtelezhnikov

* graph/gblany.h: Consolidate for easier editing.

* graph/gblhbgr.h, graph/gblhrgb.h, graph/gblvbgr.h, graph/gblvrgb.h,
graph/gblcolor.h, graph/gblbgra.h, graph/gblspans.h: Deleted.
parent 937252e8
2021-01-13 Alexei Podtelezhnikov <apodtele@gmail.com>
* graph/gblany.h: Consolidate for easier editing.
* graph/gblhbgr.h, graph/gblhrgb.h, graph/gblvbgr.h, graph/gblvrgb.h,
graph/gblcolor.h, graph/gblbgra.h, graph/gblspans.h: Deleted.
2021-01-12 Alexei Podtelezhnikov <apodtele@gmail.com>
* src/ftmulti.c (main): Fix crash.
......
......@@ -54,7 +54,48 @@ GCONCAT( _gblender_spans_, GDST_TYPE )( int y,
GDST_COPY_VAR
#include "gblspans.h"
GBLENDER_VARS;
unsigned char* dst_origin = surface->origin - y * surface->bitmap.pitch;
gblender_use_channels( blender, 0 );
GBLENDER_VARS_SET(blender,color);
/* make compiler happy */
(void)(r);
(void)(g);
(void)(b);
for ( ; count--; spans++ )
{
unsigned char* dst = dst_origin + spans->x * GDST_INCR;
unsigned short w = spans->len;
int a = GBLENDER_SHADE_INDEX( spans->coverage );
if ( a == GBLENDER_SHADE_COUNT-1 )
for ( ; w-- ; dst += GDST_INCR )
{
GDST_COPY(dst);
}
else if ( a )
for ( ; w-- ; dst += GDST_INCR )
{
GBlenderPixel back;
GDST_READ(dst,back);
GBLENDER_LOOKUP( blender, back );
#ifdef GBLENDER_STORE_BYTES
GDST_STOREB(dst,_gcells,a);
#else
GDST_STOREP(dst,_gcells,a);
#endif
}
}
GBLENDER_CLOSE(blender);
}
......@@ -69,7 +110,65 @@ GCONCAT( _gblender_blit_gray8_, GDST_TYPE )( GBlenderBlit blit,
GDST_COPY_VAR
#include "gblcolor.h"
GBLENDER_VARS;
int h = blit->height;
const unsigned char* src_line = blit->src_line;
unsigned char* dst_line = blit->dst_line;
gblender_use_channels( blender, 0 );
GBLENDER_VARS_SET(blender,color);
/* make compiler happy */
(void)(r);
(void)(g);
(void)(b);
do
{
const unsigned char* src = src_line + (blit->src_x);
unsigned char* dst = dst_line + blit->dst_x*GDST_INCR;
int w = blit->width;
do
{
int a = GBLENDER_SHADE_INDEX(src[0]);
if ( a == 0 )
{
/* nothing */
}
else if ( a == GBLENDER_SHADE_COUNT-1 )
{
GDST_COPY(dst);
}
else
{
GBlenderPixel back;
GDST_READ(dst,back);
GBLENDER_LOOKUP( blender, back );
#ifdef GBLENDER_STORE_BYTES
GDST_STOREB(dst,_gcells,a);
#else
GDST_STOREP(dst,_gcells,a);
#endif
}
src += 1;
dst += GDST_INCR;
}
while (--w > 0);
src_line += blit->src_pitch;
dst_line += blit->dst_pitch;
}
while (--h > 0);
GBLENDER_CLOSE(blender);
}
......@@ -84,7 +183,84 @@ GCONCAT( _gblender_blit_hrgb_, GDST_TYPE )( GBlenderBlit blit,
GDST_COPY_VAR
#include "gblhrgb.h"
GBLENDER_CHANNEL_VARS;
int h = blit->height;
const unsigned char* src_line = blit->src_line;
unsigned char* dst_line = blit->dst_line;
gblender_use_channels( blender, 1 );
GBLENDER_CHANNEL_VARS_SET(blender,r,g,b);
do
{
const unsigned char* src = src_line + blit->src_x*3;
unsigned char* dst = dst_line + blit->dst_x*GDST_INCR;
int w = blit->width;
do
{
unsigned int ar = GBLENDER_SHADE_INDEX(src[0]);
unsigned int ag = GBLENDER_SHADE_INDEX(src[1]);
unsigned int ab = GBLENDER_SHADE_INDEX(src[2]);
unsigned int aa = (ar << 16) | (ag << 8) | ab;
if ( aa == 0 )
{
/* nothing */
}
else if ( aa == (((GBLENDER_SHADE_COUNT-1) << 16) |
((GBLENDER_SHADE_COUNT-1) << 8) |
(GBLENDER_SHADE_COUNT-1) ) )
{
GDST_COPY(dst);
}
else
{
GBlenderPixel back;
int pix_r, pix_g, pix_b;
GDST_READ(dst,back);
{
unsigned int back_r = (back >> 16) & 255;
GBLENDER_LOOKUP_R( blender, back_r );
pix_r = _grcells[ar];
}
{
unsigned int back_g = (back >> 8) & 255;
GBLENDER_LOOKUP_G( blender, back_g );
pix_g = _ggcells[ag];
}
{
unsigned int back_b = (back) & 255;
GBLENDER_LOOKUP_B( blender, back_b );
pix_b = _gbcells[ab];
}
GDST_STOREC(dst,pix_r,pix_g,pix_b);
}
src += 3;
dst += GDST_INCR;
}
while (--w > 0);
src_line += blit->src_pitch;
dst_line += blit->dst_pitch;
}
while (--h > 0);
GBLENDER_CHANNEL_CLOSE(blender);
}
......@@ -99,7 +275,84 @@ GCONCAT( _gblender_blit_hbgr_, GDST_TYPE )( GBlenderBlit blit,
GDST_COPY_VAR
#include "gblhbgr.h"
GBLENDER_CHANNEL_VARS;
int h = blit->height;
const unsigned char* src_line = blit->src_line;
unsigned char* dst_line = blit->dst_line;
gblender_use_channels( blender, 1 );
GBLENDER_CHANNEL_VARS_SET(blender,r,g,b);
do
{
const unsigned char* src = src_line + blit->src_x*3;
unsigned char* dst = dst_line + blit->dst_x*GDST_INCR;
int w = blit->width;
do
{
unsigned int ab = GBLENDER_SHADE_INDEX(src[0]);
unsigned int ag = GBLENDER_SHADE_INDEX(src[1]);
unsigned int ar = GBLENDER_SHADE_INDEX(src[2]);
unsigned int aa = (ar << 16) | (ag << 8) | ab;
if ( aa == 0 )
{
/* nothing */
}
else if ( aa == (((GBLENDER_SHADE_COUNT-1) << 16) |
((GBLENDER_SHADE_COUNT-1) << 8) |
(GBLENDER_SHADE_COUNT-1) ) )
{
GDST_COPY(dst);
}
else
{
GBlenderPixel back;
int pix_r, pix_g, pix_b;
GDST_READ(dst,back);
{
unsigned int back_r = (back >> 16) & 255;
GBLENDER_LOOKUP_R( blender, back_r );
pix_r = _grcells[ar];
}
{
unsigned int back_g = (back >> 8) & 255;
GBLENDER_LOOKUP_G( blender, back_g );
pix_g = _ggcells[ag];
}
{
unsigned int back_b = (back) & 255;
GBLENDER_LOOKUP_B( blender, back_b );
pix_b = _gbcells[ab];
}
GDST_STOREC(dst,pix_r,pix_g,pix_b);
}
src += 3;
dst += GDST_INCR;
}
while (--w > 0);
src_line += blit->src_pitch;
dst_line += blit->dst_pitch;
}
while (--h > 0);
GBLENDER_CHANNEL_CLOSE(blender);
}
......@@ -114,7 +367,85 @@ GCONCAT( _gblender_blit_vrgb_, GDST_TYPE )( GBlenderBlit blit,
GDST_COPY_VAR
#include "gblvrgb.h"
GBLENDER_CHANNEL_VARS;
int h = blit->height;
const unsigned char* src_line = blit->src_line;
int src_pitch = blit->src_pitch;
unsigned char* dst_line = blit->dst_line;
gblender_use_channels( blender, 1 );
GBLENDER_CHANNEL_VARS_SET(blender,r,g,b);
do
{
const unsigned char* src = src_line + blit->src_x;
unsigned char* dst = dst_line + blit->dst_x*GDST_INCR;
int w = blit->width;
do
{
unsigned int ar = GBLENDER_SHADE_INDEX(src[0]);
unsigned int ag = GBLENDER_SHADE_INDEX(src[src_pitch]);
unsigned int ab = GBLENDER_SHADE_INDEX(src[src_pitch << 1]);
GBlenderPixel aa = ((GBlenderPixel)ar << 16) | (ag << 8) | ab;
if ( aa == 0 )
{
/* nothing */
}
else if ( aa == (((GBLENDER_SHADE_COUNT-1) << 16) |
((GBLENDER_SHADE_COUNT-1) << 8) |
(GBLENDER_SHADE_COUNT-1) ) )
{
GDST_COPY(dst);
}
else
{
GBlenderPixel back;
int pix_r, pix_g, pix_b;
GDST_READ(dst,back);
{
unsigned int back_r = (back >> 16) & 255;
GBLENDER_LOOKUP_R( blender, back_r );
pix_r = _grcells[ar];
}
{
unsigned int back_g = (back >> 8) & 255;
GBLENDER_LOOKUP_G( blender, back_g );
pix_g = _ggcells[ag];
}
{
unsigned int back_b = (back) & 255;
GBLENDER_LOOKUP_B( blender, back_b );
pix_b = _gbcells[ab];
}
GDST_STOREC(dst,pix_r,pix_g,pix_b);
}
src += 1;
dst += GDST_INCR;
}
while (--w > 0);
src_line += blit->src_pitch*3;
dst_line += blit->dst_pitch;
}
while (--h > 0);
GBLENDER_CHANNEL_CLOSE(blender);
}
......@@ -129,7 +460,85 @@ GCONCAT( _gblender_blit_vbgr_, GDST_TYPE )( GBlenderBlit blit,
GDST_COPY_VAR
#include "gblvbgr.h"
GBLENDER_CHANNEL_VARS;
int h = blit->height;
const unsigned char* src_line = blit->src_line;
int src_pitch = blit->src_pitch;
unsigned char* dst_line = blit->dst_line;
gblender_use_channels( blender, 1 );
GBLENDER_CHANNEL_VARS_SET(blender,r,g,b);
do
{
const unsigned char* src = src_line + blit->src_x;
unsigned char* dst = dst_line + blit->dst_x*GDST_INCR;
int w = blit->width;
do
{
unsigned int ab = GBLENDER_SHADE_INDEX(src[0]);
unsigned int ag = GBLENDER_SHADE_INDEX(src[src_pitch]);
unsigned int ar = GBLENDER_SHADE_INDEX(src[src_pitch << 1]);
GBlenderPixel aa = ((GBlenderPixel)ar << 16) | (ag << 8) | ab;
if ( aa == 0 )
{
/* nothing */
}
else if ( aa == (((GBLENDER_SHADE_COUNT-1) << 16) |
((GBLENDER_SHADE_COUNT-1) << 8) |
(GBLENDER_SHADE_COUNT-1) ) )
{
GDST_COPY(dst);
}
else
{
GBlenderPixel back;
int pix_r, pix_g, pix_b;
GDST_READ(dst,back);
{
unsigned int back_r = (back >> 16) & 255;
GBLENDER_LOOKUP_R( blender, back_r );
pix_r = _grcells[ar];
}
{
unsigned int back_g = (back >> 8) & 255;
GBLENDER_LOOKUP_G( blender, back_g );
pix_g = _ggcells[ag];
}
{
unsigned int back_b = (back) & 255;
GBLENDER_LOOKUP_B( blender, back_b );
pix_b = _gbcells[ab];
}
GDST_STOREC(dst,pix_r,pix_g,pix_b);
}
src += 1;
dst += GDST_INCR;
}
while (--w > 0);
src_line += blit->src_pitch*3;
dst_line += blit->dst_pitch;
}
while (--h > 0);
GBLENDER_CHANNEL_CLOSE(blender);
}
......@@ -139,7 +548,80 @@ GCONCAT( _gblender_blit_bgra_, GDST_TYPE )( GBlenderBlit blit,
{
(void)color; /* unused */
#include "gblbgra.h"
int h = blit->height;
const unsigned char* src_line = blit->src_line;
unsigned char* dst_line = blit->dst_line;
do
{
const unsigned char* src = src_line + blit->src_x * 4;
unsigned char* dst = dst_line + blit->dst_x * GDST_INCR;
int w = blit->width;
do
{
unsigned int pix_b = src[0];
unsigned int pix_g = src[1];
unsigned int pix_r = src[2];
unsigned int a = src[3];
if ( a == 0 )
{
/* nothing */
}
else if ( a == 255 )
{
GDST_STOREC(dst,pix_r,pix_g,pix_b);
}
else
{
GBlenderPixel back;
GDST_READ(dst,back);
{
unsigned int ba = 255 - a;
unsigned int back_r = (back >> 16) & 255;
unsigned int back_g = (back >> 8) & 255;
unsigned int back_b = (back) & 255;
#if 1 /* premultiplied blending without gamma correction */
pix_r = (back_r * ba / 255 + pix_r);
pix_g = (back_g * ba / 255 + pix_g);
pix_b = (back_b * ba / 255 + pix_b);
#else /* gamma-corrected blending */
const unsigned char* gamma_ramp_inv = blit->blender->gamma_ramp_inv;
const unsigned short* gamma_ramp = blit->blender->gamma_ramp;
back_r = gamma_ramp[back_r];
back_g = gamma_ramp[back_g];
back_b = gamma_ramp[back_b];
/* premultiplication undone */
pix_r = gamma_ramp[pix_r * 255 / a];
pix_g = gamma_ramp[pix_g * 255 / a];
pix_b = gamma_ramp[pix_b * 255 / a];
pix_r = gamma_ramp_inv[(back_r * ba + pix_r * a + 127) / 255];
pix_g = gamma_ramp_inv[(back_g * ba + pix_g * a + 127) / 255];
pix_b = gamma_ramp_inv[(back_b * ba + pix_b * a + 127) / 255];
#endif
}
GDST_STOREC(dst,pix_r,pix_g,pix_b);
}
src += 4;
dst += GDST_INCR;
} while ( --w > 0 );
src_line += blit->src_pitch;
dst_line += blit->dst_pitch;
} while ( --h > 0 );
}
......
int h = blit->height;
const unsigned char* src_line = blit->src_line;
unsigned char* dst_line = blit->dst_line;
do
{
const unsigned char* src = src_line + blit->src_x * 4;
unsigned char* dst = dst_line + blit->dst_x * GDST_INCR;
int w = blit->width;
do
{
unsigned int pix_b = src[0];
unsigned int pix_g = src[1];
unsigned int pix_r = src[2];
unsigned int a = src[3];
if ( a == 0 )
{
/* nothing */
}
else if ( a == 255 )
{
GDST_STOREC(dst,pix_r,pix_g,pix_b);
}
else
{
GBlenderPixel back;
GDST_READ(dst,back);
{
unsigned int ba = 255 - a;
unsigned int back_r = (back >> 16) & 255;
unsigned int back_g = (back >> 8) & 255;
unsigned int back_b = (back) & 255;
#if 1 /* premultiplied blending without gamma correction */
pix_r = (back_r * ba / 255 + pix_r);
pix_g = (back_g * ba / 255 + pix_g);
pix_b = (back_b * ba / 255 + pix_b);
#else /* gamma-corrected blending */
const unsigned char* gamma_ramp_inv = blit->blender->gamma_ramp_inv;
const unsigned short* gamma_ramp = blit->blender->gamma_ramp;
back_r = gamma_ramp[back_r];
back_g = gamma_ramp[back_g];
back_b = gamma_ramp[back_b];
/* premultiplication undone */
pix_r = gamma_ramp[pix_r * 255 / a];
pix_g = gamma_ramp[pix_g * 255 / a];
pix_b = gamma_ramp[pix_b * 255 / a];
pix_r = gamma_ramp_inv[(back_r * ba + pix_r * a + 127) / 255];
pix_g = gamma_ramp_inv[(back_g * ba + pix_g * a + 127) / 255];
pix_b = gamma_ramp_inv[(back_b * ba + pix_b * a + 127) / 255];
#endif
}
GDST_STOREC(dst,pix_r,pix_g,pix_b);
}
src += 4;
dst += GDST_INCR;
} while ( --w > 0 );
src_line += blit->src_pitch;
dst_line += blit->dst_pitch;
} while ( --h > 0 );