src/blend.c
l_int32
pixelLinearMapToTargetColor(l_uint32   scolor,
                            l_uint32   srcmap,
                            l_uint32   dstmap,
                            l_uint32  *pdcolor)
{
l_int32    srval, sgval, sbval, drval, dgval, dbval;
l_int32    srmap, sgmap, sbmap, drmap, dgmap, dbmap;

    PROCNAME("pixelLinearMapToTargetColor");

    if (!pdcolor)
        return ERROR_INT("&dcolor not defined", procName, 1);
    *pdcolor = 0;

    extractRGBValues(scolor, &srval, &sgval, &sbval);
    extractRGBValues(srcmap, &srmap, &sgmap, &sbmap);
    extractRGBValues(dstmap, &drmap, &dgmap, &dbmap);
    srmap = L_MIN(254, L_MAX(1, srmap));
    sgmap = L_MIN(254, L_MAX(1, sgmap));
    sbmap = L_MIN(254, L_MAX(1, sbmap));

    if (srval < srmap)
        drval = (srval * drmap) / srmap;
    else
        drval = drmap + ((255 - drmap) * (srval - srmap)) / (255 - srmap);
    if (sgval < sgmap)
        dgval = (sgval * dgmap) / sgmap;
    else
        dgval = dgmap + ((255 - dgmap) * (sgval - sgmap)) / (255 - sgmap);
    if (sbval < sbmap)
        dbval = (sbval * dbmap) / sbmap;
    else
        dbval = dbmap + ((255 - dbmap) * (sbval - sbmap)) / (255 - sbmap);

    composeRGBPixel(drval, dgval, dbval, pdcolor);
    return 0;
}
/*!
 *  pixelLinearMapToTargetColor()
 *
 *      Input:  scolor (rgb source color: 0xrrggbb00)
 *              srcmap (source mapping color: 0xrrggbb00)
 *              dstmap (target mapping color: 0xrrggbb00)
 *              &pdcolor (<return> rgb dest color: 0xrrggbb00)
 *      Return: 0 if OK, 1 on error
 *
 *  Notes:
 *      (1) This does this does a piecewise linear mapping of each
 *          component of @scolor to @dcolor, based on the relation
 *          between the components of @srcmap and @dstmap.  It is the
 *          same transformation, performed on a single color, as mapped
 *          on every pixel in a pix by pixLinearMapToTargetColor().
 *      (2) For each component, if the sval is larger than the smap,
 *          the dval will be pushed up from dmap towards white.
 *          Otherwise, dval will be pushed down from dmap towards black.
 *          This is because you can visualize the transformation as
 *          a linear stretching where smap moves to dmap, and everything
 *          else follows linearly with 0 and 255 fixed.
 *      (3) The mapping will in general change the hue of @scolor.
 *          However, if the @srcmap and @dstmap targets are related by
 *          a transformation given by pixelFractionalShift(), the hue
 *          will be invariant.
 */


(1) This does this does a piecewise linear mapping of each
component of @scolor to @dcolor, based on the relation
between the components of @srcmap and @dstmap.  It is the
same transformation, performed on a single color, as mapped
on every pixel in a pix by pixLinearMapToTargetColor().
(2) For each component, if the sval is larger than the smap,
the dval will be pushed up from dmap towards white.
Otherwise, dval will be pushed down from dmap towards black.
This is because you can visualize the transformation as
a linear stretching where smap moves to dmap, and everything
else follows linearly with 0 and 255 fixed.
(3) The mapping will in general change the hue of @scolor.
However, if the @srcmap and @dstmap targets are related by
a transformation given by pixelFractionalShift(), the hue
will be invariant.
( 1 ) This does this does a piecewise linear mapping of each component of @scolor to @dcolor based on the relation between the components of @srcmap and @dstmap . It is the same transformation performed on a single color as mapped on every pixel in a pix by pixLinearMapToTargetColor () . ( 2 ) For each component if the sval is larger than the smap the dval will be pushed up from dmap towards white . Otherwise dval will be pushed down from dmap towards black . This is because you can visualize the transformation as a linear stretching where smap moves to dmap and everything else follows linearly with 0 and 255 fixed . ( 3 ) The mapping will in general change the hue of @scolor . However if the @srcmap and @dstmap targets are related by a transformation given by pixelFractionalShift () the hue will be invariant .
l_int32
pixelLinearMapToTargetColor(l_uint32   scolor,
                            l_uint32   srcmap,
                            l_uint32   dstmap,
                            l_uint32  *pdcolor)
{
l_int32    srval, sgval, sbval, drval, dgval, dbval;
l_int32    srmap, sgmap, sbmap, drmap, dgmap, dbmap;
    PROCNAME("pixelLinearMapToTargetColor");
    if (!pdcolor)
        return ERROR_INT("&dcolor not defined", procName, 1);
    *pdcolor = 0;
    extractRGBValues(scolor, &srval, &sgval, &sbval);
    extractRGBValues(srcmap, &srmap, &sgmap, &sbmap);
    extractRGBValues(dstmap, &drmap, &dgmap, &dbmap);
    srmap = L_MIN(254, L_MAX(1, srmap));
    sgmap = L_MIN(254, L_MAX(1, sgmap));
    sbmap = L_MIN(254, L_MAX(1, sbmap));
    if (srval < srmap)
        drval = (srval * drmap) / srmap;
    else
        drval = drmap + ((255 - drmap) * (srval - srmap)) / (255 - srmap);
    if (sgval < sgmap)
        dgval = (sgval * dgmap) / sgmap;
    else
        dgval = dgmap + ((255 - dgmap) * (sgval - sgmap)) / (255 - sgmap);
    if (sbval < sbmap)
        dbval = (sbval * dbmap) / sbmap;
    else
        dbval = dbmap + ((255 - dbmap) * (sbval - sbmap)) / (255 - sbmap);
    composeRGBPixel(drval, dgval, dbval, pdcolor);
    return 0;
}
l_int32 pixelLinearMapToTargetColor ( l_uint32 scolor , l_uint32 srcmap , l_uint32 dstmap , l_uint32 * pdcolor ) { l_int32 srval , sgval , sbval , drval , dgval , dbval ; l_int32 srmap , sgmap , sbmap , drmap , dgmap , dbmap ; PROCNAME ( " " ) ; if ( ! pdcolor ) return ERROR_INT ( " " , procName , 1 ) ; * pdcolor = 0 ; extractRGBValues ( scolor , & srval , & sgval , & sbval ) ; extractRGBValues ( srcmap , & srmap , & sgmap , & sbmap ) ; extractRGBValues ( dstmap , & drmap , & dgmap , & dbmap ) ; srmap = L_MIN ( 254 , L_MAX ( 1 , srmap ) ) ; sgmap = L_MIN ( 254 , L_MAX ( 1 , sgmap ) ) ; sbmap = L_MIN ( 254 , L_MAX ( 1 , sbmap ) ) ; if ( srval < srmap ) drval = ( srval * drmap ) / srmap ; else drval = drmap + ( ( 255 - drmap ) * ( srval - srmap ) ) / ( 255 - srmap ) ; if ( sgval < sgmap ) dgval = ( sgval * dgmap ) / sgmap ; else dgval = dgmap + ( ( 255 - dgmap ) * ( sgval - sgmap ) ) / ( 255 - sgmap ) ; if ( sbval < sbmap ) dbval = ( sbval * dbmap ) / sbmap ; else dbval = dbmap + ( ( 255 - dbmap ) * ( sbval - sbmap ) ) / ( 255 - sbmap ) ; composeRGBPixel ( drval , dgval , dbval , pdcolor ) ; return 0 ; }
pixelLinearMapToTargetColor()
      Input:  scolor (rgb source color: 0xrrggbb00)
              srcmap (source mapping color: 0xrrggbb00)
              dstmap (target mapping color: 0xrrggbb00)
              &pdcolor (<return> rgb dest color: 0xrrggbb00)
      Return: 0 if OK, 1 on error
pixelLinearMapToTargetColor () Input : scolor ( rgb source color : 0xrrggbb00 ) srcmap ( source mapping color : 0xrrggbb00 ) dstmap ( target mapping color : 0xrrggbb00 ) &pdcolor ( <return > rgb dest color : 0xrrggbb00 ) Return : 0 if OK 1 on error