|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "trop.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tpixel.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tpixelutils.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
9f5a1b |
#ifdef _WIN32
|
|
Shinya Kitaoka |
120a6e |
#include <emmintrin.h> // per SSE2</emmintrin.h>
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
Shinya Kitaoka |
120a6e |
inline double luminance(TPixel32 *pix) {
|
|
Shinya Kitaoka |
120a6e |
return 0.2126 * pix->r + 0.7152 * pix->g + 0.0722 * pix->b;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Shinya Kitaoka |
120a6e |
inline double luminance(TPixel64 *pix) {
|
|
Shinya Kitaoka |
120a6e |
return 0.2126 * pix->r + 0.7152 * pix->g + 0.0722 * pix->b;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Shinya Kitaoka |
120a6e |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
#define FOR_EACH_PIXEL_BEGIN_LOOP(UpType, up, DownType, down, OutType, out) \
|
|
Shinya Kitaoka |
120a6e |
{ \
|
|
Shinya Kitaoka |
120a6e |
int upWrap = up->getWrap(); \
|
|
Shinya Kitaoka |
120a6e |
int downWrap = down->getWrap(); \
|
|
Shinya Kitaoka |
120a6e |
int outWrap = out->getWrap(); \
|
|
Shinya Kitaoka |
120a6e |
\
|
|
Shinya Kitaoka |
120a6e |
up->lock(); \
|
|
Shinya Kitaoka |
120a6e |
down->lock(); \
|
|
Shinya Kitaoka |
120a6e |
out->lock(); \
|
|
Shinya Kitaoka |
120a6e |
UpType *upPix = 0, *upRow = up->pixels(); \
|
|
Shinya Kitaoka |
120a6e |
DownType *downPix, *downRow = down->pixels(); \
|
|
Shinya Kitaoka |
120a6e |
OutType *outPix, *outRow = out->pixels(); \
|
|
Shinya Kitaoka |
120a6e |
UpType *endPix; \
|
|
Shinya Kitaoka |
120a6e |
int upLx = up->getLx(); \
|
|
Shinya Kitaoka |
120a6e |
UpType *lastPix = upRow + upWrap * (up->getLy() - 1) + upLx; \
|
|
Shinya Kitaoka |
120a6e |
while (upPix < lastPix) { \
|
|
Shinya Kitaoka |
120a6e |
upPix = upRow; \
|
|
Shinya Kitaoka |
120a6e |
downPix = downRow; \
|
|
Shinya Kitaoka |
120a6e |
outPix = outRow; \
|
|
Shinya Kitaoka |
120a6e |
endPix = upPix + upLx; \
|
|
Shinya Kitaoka |
120a6e |
while (upPix < endPix) {
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
#define FOR_EACH_PIXEL_END_LOOP(up, down, out) \
|
|
Shinya Kitaoka |
120a6e |
++upPix; \
|
|
Shinya Kitaoka |
120a6e |
++downPix; \
|
|
Shinya Kitaoka |
120a6e |
++outPix; \
|
|
Shinya Kitaoka |
120a6e |
} \
|
|
Shinya Kitaoka |
120a6e |
upRow += upWrap; \
|
|
Shinya Kitaoka |
120a6e |
downRow += downWrap; \
|
|
Shinya Kitaoka |
120a6e |
outRow += outWrap; \
|
|
Shinya Kitaoka |
120a6e |
} \
|
|
Shinya Kitaoka |
120a6e |
up->unlock(); \
|
|
Shinya Kitaoka |
120a6e |
down->unlock(); \
|
|
Shinya Kitaoka |
120a6e |
out->unlock(); \
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
#define FOR_EACH_PIXEL_32_BEGIN_LOOP \
|
|
Shinya Kitaoka |
120a6e |
assert(up32 &&down32 &&out32); \
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_BEGIN_LOOP(TPixelRGBM32, up32, TPixelRGBM32, down32, \
|
|
Shinya Kitaoka |
120a6e |
TPixelRGBM32, out32)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
#define FOR_EACH_PIXEL_32_END_LOOP \
|
|
Shinya Kitaoka |
120a6e |
assert(up32 &&down32 &&out32); \
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_END_LOOP(up32, down32, out32)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
#define FOR_EACH_PIXEL_64_BEGIN_LOOP \
|
|
Shinya Kitaoka |
120a6e |
assert(up64 &&down64 &&out64); \
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_BEGIN_LOOP(TPixelRGBM64, up64, TPixelRGBM64, down64, \
|
|
Shinya Kitaoka |
120a6e |
TPixelRGBM64, out64)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
#define FOR_EACH_PIXEL_64_END_LOOP \
|
|
Shinya Kitaoka |
120a6e |
assert(up64 &&down64 &&out64); \
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_END_LOOP(up64, down64, out64)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
#define FOR_EACH_PIXEL_8_BEGIN_LOOP \
|
|
Shinya Kitaoka |
120a6e |
assert(up8 &&down8 &&out8); \
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_BEGIN_LOOP(TPixelGR8, up8, TPixelGR8, down8, TPixelGR8, out8)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
#define FOR_EACH_PIXEL_8_END_LOOP \
|
|
Shinya Kitaoka |
120a6e |
assert(up8 &&down8 &&out8); \
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_END_LOOP(up32, down32, out32)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TRop::add(const TRasterP &rup, const TRasterP &rdown, const TRasterP &rout,
|
|
Shinya Kitaoka |
120a6e |
double v) {
|
|
Shinya Kitaoka |
120a6e |
TRaster32P up32 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P down32 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P out32 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (up32 && down32 && out32) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TINT32 r, g, b, m;
|
|
Shinya Kitaoka |
120a6e |
if (upPix->m == 0)
|
|
Shinya Kitaoka |
120a6e |
*outPix = *downPix;
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
r = downPix->r + tround(upPix->r * v);
|
|
Shinya Kitaoka |
120a6e |
g = downPix->g + tround(upPix->g * v);
|
|
Shinya Kitaoka |
120a6e |
b = downPix->b + tround(upPix->b * v);
|
|
Shinya Kitaoka |
120a6e |
m = downPix->m + tround(upPix->m * v);
|
|
Shinya Kitaoka |
120a6e |
outPix->r = (UCHAR)tcrop<tint32>(r, (TINT32)0, (TINT32)255);</tint32>
|
|
Shinya Kitaoka |
120a6e |
outPix->g = (UCHAR)tcrop<tint32>(g, (TINT32)0, (TINT32)255);</tint32>
|
|
Shinya Kitaoka |
120a6e |
outPix->b = (UCHAR)tcrop<tint32>(b, (TINT32)0, (TINT32)255);</tint32>
|
|
Shinya Kitaoka |
120a6e |
outPix->m = (UCHAR)tcrop<tint32>(m, (TINT32)0, (TINT32)255);</tint32>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
TRaster64P up64 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P down64 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P out64 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (up64 && down64 && out64) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TINT32 r, g, b, m;
|
|
Shinya Kitaoka |
120a6e |
r = downPix->r + tround(upPix->r * v);
|
|
Shinya Kitaoka |
120a6e |
g = downPix->g + tround(upPix->g * v);
|
|
Shinya Kitaoka |
120a6e |
b = downPix->b + tround(upPix->b * v);
|
|
Shinya Kitaoka |
120a6e |
m = downPix->m + tround(upPix->m * v);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
outPix->r = (USHORT)tcrop<tint32>(r, 0, 0xffff);</tint32>
|
|
Shinya Kitaoka |
120a6e |
outPix->g = (USHORT)tcrop<tint32>(g, 0, 0xffff);</tint32>
|
|
Shinya Kitaoka |
120a6e |
outPix->b = (USHORT)tcrop<tint32>(b, 0, 0xffff);</tint32>
|
|
Shinya Kitaoka |
120a6e |
outPix->m = (USHORT)tcrop<tint32>(m, 0, 0xffff);</tint32>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P up8 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P down8 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P out8 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (up8 && down8 && out8) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_8_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
USHORT value = troundp(upPix->value * v) + downPix->value;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
outPix->value = (UCHAR)tcrop<ushort>(value, 0, 255);</ushort>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_8_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
throw TRopException("TRop::add invalid raster combination");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TRop::add(const TRasterP &rup, const TRasterP &rdown,
|
|
Shinya Kitaoka |
120a6e |
const TRasterP &rout) {
|
|
Shinya Kitaoka |
120a6e |
TRaster32P up32 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P down32 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P out32 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (up32 && down32 && out32) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
USHORT r, g, b, m;
|
|
Shinya Kitaoka |
120a6e |
r = downPix->r + upPix->r;
|
|
Shinya Kitaoka |
120a6e |
g = downPix->g + upPix->g;
|
|
Shinya Kitaoka |
120a6e |
b = downPix->b + upPix->b;
|
|
Shinya Kitaoka |
120a6e |
m = downPix->m + upPix->m;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
outPix->r = (UCHAR)tcrop<ushort>(r, 0, 255);</ushort>
|
|
Shinya Kitaoka |
120a6e |
outPix->g = (UCHAR)tcrop<ushort>(g, 0, 255);</ushort>
|
|
Shinya Kitaoka |
120a6e |
outPix->b = (UCHAR)tcrop<ushort>(b, 0, 255);</ushort>
|
|
Shinya Kitaoka |
120a6e |
outPix->m = (UCHAR)tcrop<ushort>(m, 0, 255);</ushort>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
TRaster64P up64 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P down64 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P out64 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (up64 && down64 && out64) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TINT32 r, g, b, m;
|
|
Shinya Kitaoka |
120a6e |
r = downPix->r + upPix->r;
|
|
Shinya Kitaoka |
120a6e |
g = downPix->g + upPix->g;
|
|
Shinya Kitaoka |
120a6e |
b = downPix->b + upPix->b;
|
|
Shinya Kitaoka |
120a6e |
m = downPix->m + upPix->m;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
outPix->r = (USHORT)tcrop<tint32>(r, 0, 0xffff);</tint32>
|
|
Shinya Kitaoka |
120a6e |
outPix->g = (USHORT)tcrop<tint32>(g, 0, 0xffff);</tint32>
|
|
Shinya Kitaoka |
120a6e |
outPix->b = (USHORT)tcrop<tint32>(b, 0, 0xffff);</tint32>
|
|
Shinya Kitaoka |
120a6e |
outPix->m = (USHORT)tcrop<tint32>(m, 0, 0xffff);</tint32>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P up8 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P down8 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P out8 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (up8 && down8 && out8) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_8_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
USHORT value = upPix->value + downPix->value;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
outPix->value = (UCHAR)tcrop<ushort>(value, 0, 255);</ushort>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_8_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
throw TRopException("TRop::add invalid raster combination");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TRop::colordodge(const TRasterP &rup, const TRasterP &rdown,
|
|
Shinya Kitaoka |
120a6e |
const TRasterP &rout) {
|
|
Shinya Kitaoka |
120a6e |
TRaster32P up32 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P down32 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P out32 = rout;
|
|
Shinya Kitaoka |
120a6e |
if (up32 && down32 && out32) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_BEGIN_LOOP
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
USHORT r, g, b, m;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
r = (USHORT)((downPix->r << 8) / (256.0 - upPix->r));
|
|
Shinya Kitaoka |
120a6e |
g = (USHORT)((downPix->g << 8) / (256.0 - upPix->g));
|
|
Shinya Kitaoka |
120a6e |
b = (USHORT)((downPix->b << 8) / (256.0 - upPix->b));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m = downPix->m + upPix->m;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
outPix->r = (UCHAR)tcrop<ushort>(r, 0, 255);</ushort>
|
|
Shinya Kitaoka |
120a6e |
outPix->g = (UCHAR)tcrop<ushort>(g, 0, 255);</ushort>
|
|
Shinya Kitaoka |
120a6e |
outPix->b = (UCHAR)tcrop<ushort>(b, 0, 255);</ushort>
|
|
Shinya Kitaoka |
120a6e |
outPix->m = (UCHAR)tcrop<ushort>(m, 0, 255);</ushort>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
TRaster64P up64 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P down64 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P out64 = rout;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (up64 && down64 && out64) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_BEGIN_LOOP
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TINT32 r, g, b, m;
|
|
Shinya Kitaoka |
120a6e |
r = (TINT32)(65536.0 * (downPix->r / (65536.0 - upPix->r)));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
g = (TINT32)(65536.0 * (downPix->g / (65536.0 - upPix->g)));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
b = (TINT32)(65536.0 * (downPix->b / (65536.0 - upPix->b)));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m = downPix->m + upPix->m;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
outPix->r = (USHORT)tcrop<tint32>(r, 0, 0xffff);</tint32>
|
|
Shinya Kitaoka |
120a6e |
outPix->g = (USHORT)tcrop<tint32>(g, 0, 0xffff);</tint32>
|
|
Shinya Kitaoka |
120a6e |
outPix->b = (USHORT)tcrop<tint32>(b, 0, 0xffff);</tint32>
|
|
Shinya Kitaoka |
120a6e |
outPix->m = (USHORT)tcrop<tint32>(m, 0, 0xffff);</tint32>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P up8 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P down8 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P out8 = rout;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (up8 && down8 && out8) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_8_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
USHORT value;
|
|
Shinya Kitaoka |
120a6e |
if (downPix->value)
|
|
Shinya Kitaoka |
120a6e |
value = (USHORT)((downPix->value << 8) / (255.0 - upPix->value));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
outPix->value = (UCHAR)tcrop<ushort>(value, 0, 255);</ushort>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_8_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
throw TRopException("TRop::color dodge invalid raster combination");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TRop::colorburn(const TRasterP &rup, const TRasterP &rdown,
|
|
Shinya Kitaoka |
120a6e |
const TRasterP &rout) {
|
|
Shinya Kitaoka |
120a6e |
TRaster32P up32 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P down32 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P out32 = rout;
|
|
Shinya Kitaoka |
120a6e |
if (up32 && down32 && out32) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
// downPix->r=0;
|
|
Shinya Kitaoka |
120a6e |
// downPix->g=255;
|
|
Shinya Kitaoka |
120a6e |
// downPix->b=0;
|
|
Shinya Kitaoka |
120a6e |
double r, g, b;
|
|
Shinya Kitaoka |
120a6e |
if (upPix->m) {
|
|
Shinya Kitaoka |
120a6e |
if (downPix->r == 0 || downPix->r == 255)
|
|
Shinya Kitaoka |
120a6e |
r = downPix->r;
|
|
Shinya Kitaoka |
120a6e |
else if (upPix->r)
|
|
Shinya Kitaoka |
120a6e |
r = 255 - (((255 - downPix->r) << 8) / (double)upPix->r);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
r = 0;
|
|
Shinya Kitaoka |
120a6e |
if (downPix->g == 0 || downPix->g == 255)
|
|
Shinya Kitaoka |
120a6e |
g = downPix->g;
|
|
Shinya Kitaoka |
120a6e |
else if (upPix->g)
|
|
Shinya Kitaoka |
120a6e |
g = 255 - (((255 - downPix->g) << 8) / (double)upPix->g);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
g = 0;
|
|
Shinya Kitaoka |
120a6e |
if (downPix->b == 0 || downPix->b == 255)
|
|
Shinya Kitaoka |
120a6e |
b = downPix->b;
|
|
Shinya Kitaoka |
120a6e |
else if (upPix->b)
|
|
Shinya Kitaoka |
120a6e |
b = 255 - (((255 - downPix->b) << 8) / (double)upPix->b);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
b = 0;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (upPix->m != 255) {
|
|
Shinya Kitaoka |
120a6e |
TPixel32 tmpPix;
|
|
Shinya Kitaoka |
120a6e |
tmpPix.r = (UCHAR)tcrop<double>(r, .0, 255.0);</double>
|
|
Shinya Kitaoka |
120a6e |
tmpPix.g = (UCHAR)tcrop<double>(g, .0, 255.0);</double>
|
|
Shinya Kitaoka |
120a6e |
tmpPix.b = (UCHAR)tcrop<double>(b, .0, 255.0);</double>
|
|
Shinya Kitaoka |
120a6e |
tmpPix.m = upPix->m;
|
|
Shinya Kitaoka |
120a6e |
;
|
|
Shinya Kitaoka |
120a6e |
overPix<tpixel32, uchar="">(*outPix, *downPix, tmpPix);</tpixel32,>
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
outPix->r = (UCHAR)tcrop<double>(r, .0, 255.0);</double>
|
|
Shinya Kitaoka |
120a6e |
outPix->g = (UCHAR)tcrop<double>(g, .0, 255.0);</double>
|
|
Shinya Kitaoka |
120a6e |
outPix->b = (UCHAR)tcrop<double>(b, .0, 255.0);</double>
|
|
Shinya Kitaoka |
120a6e |
outPix->m = downPix->m;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
outPix = downPix;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
TRaster64P up64 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P down64 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P out64 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (up64 && down64 && out64) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
double r, g, b;
|
|
Shinya Kitaoka |
120a6e |
if (upPix->m) {
|
|
Shinya Kitaoka |
120a6e |
if (downPix->r == 0 || downPix->r == 65535)
|
|
Shinya Kitaoka |
120a6e |
r = downPix->r;
|
|
Shinya Kitaoka |
120a6e |
else if (upPix->r)
|
|
Shinya Kitaoka |
120a6e |
r = 65535 - 65536 * ((65535.0 - downPix->r) / (double)upPix->r);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
r = 0;
|
|
Shinya Kitaoka |
120a6e |
if (downPix->g == 0 || downPix->g == 65535)
|
|
Shinya Kitaoka |
120a6e |
g = downPix->g;
|
|
Shinya Kitaoka |
120a6e |
else if (upPix->g)
|
|
Shinya Kitaoka |
120a6e |
g = 65535 - 65536 * ((65535.0 - downPix->g) / (double)upPix->g);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
g = 0;
|
|
Shinya Kitaoka |
120a6e |
if (downPix->b == 0 || downPix->b == 65535)
|
|
Shinya Kitaoka |
120a6e |
b = downPix->b;
|
|
Shinya Kitaoka |
120a6e |
else if (upPix->b)
|
|
Shinya Kitaoka |
120a6e |
b = 65535 - 65536 * ((65535.0 - downPix->b) / (double)upPix->b);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
b = 0;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (upPix->m != 65535) {
|
|
Shinya Kitaoka |
120a6e |
TPixel64 tmpPix;
|
|
Shinya Kitaoka |
120a6e |
tmpPix.r = (USHORT)tcrop<double>(r, .0, 65535.0);</double>
|
|
Shinya Kitaoka |
120a6e |
tmpPix.g = (USHORT)tcrop<double>(g, .0, 65535.0);</double>
|
|
Shinya Kitaoka |
120a6e |
tmpPix.b = (USHORT)tcrop<double>(b, .0, 65535.0);</double>
|
|
Shinya Kitaoka |
120a6e |
tmpPix.m = upPix->m;
|
|
Shinya Kitaoka |
120a6e |
overPix<tpixel64, ushort="">(*outPix, *downPix, tmpPix);</tpixel64,>
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
outPix->r = (USHORT)tcrop<double>(r, .0, 65535.0);</double>
|
|
Shinya Kitaoka |
120a6e |
outPix->g = (USHORT)tcrop<double>(g, .0, 65535.0);</double>
|
|
Shinya Kitaoka |
120a6e |
outPix->b = (USHORT)tcrop<double>(b, .0, 65535.0);</double>
|
|
Shinya Kitaoka |
120a6e |
outPix->m = downPix->m;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
outPix = downPix;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
throw TRopException("TRop::color burn invalid raster combination");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TRop::screen(const TRasterP &rup, const TRasterP &rdown,
|
|
Shinya Kitaoka |
120a6e |
const TRasterP &rout) {
|
|
Shinya Kitaoka |
120a6e |
TRaster32P up32 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P down32 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P out32 = rout;
|
|
Shinya Kitaoka |
120a6e |
if (up32 && down32 && out32) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
double r, g, b;
|
|
Shinya Kitaoka |
120a6e |
r = 256 - ((256 - upPix->r) * (256 - downPix->r) >> 8);
|
|
Shinya Kitaoka |
120a6e |
g = 256 - ((256 - upPix->g) * (256 - downPix->g) >> 8);
|
|
Shinya Kitaoka |
120a6e |
b = 256 - ((256 - upPix->b) * (256 - downPix->b) >> 8);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (upPix->m != 255) {
|
|
Shinya Kitaoka |
120a6e |
double m;
|
|
Shinya Kitaoka |
120a6e |
m = 256 - ((256 - upPix->m) * (256 - downPix->m) >> 8);
|
|
Shinya Kitaoka |
120a6e |
TPixel32 tmpPix;
|
|
Shinya Kitaoka |
120a6e |
tmpPix.r = (UCHAR)tcrop<double>(r, 0, 255);</double>
|
|
Shinya Kitaoka |
120a6e |
tmpPix.g = (UCHAR)tcrop<double>(g, 0, 255);</double>
|
|
Shinya Kitaoka |
120a6e |
tmpPix.b = (UCHAR)tcrop<double>(b, 0, 255);</double>
|
|
Shinya Kitaoka |
120a6e |
tmpPix.m = (UCHAR)tcrop<double>(m, 0, 255);</double>
|
|
Shinya Kitaoka |
120a6e |
overPix<tpixel32, uchar="">(*outPix, *downPix, tmpPix);</tpixel32,>
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
outPix->r = (UCHAR)tcrop<double>(r, 0, 255);</double>
|
|
Shinya Kitaoka |
120a6e |
outPix->g = (UCHAR)tcrop<double>(g, 0, 255);</double>
|
|
Shinya Kitaoka |
120a6e |
outPix->b = (UCHAR)tcrop<double>(b, 0, 255);</double>
|
|
Shinya Kitaoka |
120a6e |
outPix->m = upPix->m;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
TRaster64P up64 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P down64 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P out64 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (up64 && down64 && out64) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
double r, g, b;
|
|
Shinya Kitaoka |
120a6e |
r = 65536 - (65536 - upPix->r) * ((65536 - downPix->r) / 65536.0);
|
|
Shinya Kitaoka |
120a6e |
g = 65536 - (65536 - upPix->g) * ((65536 - downPix->g) / 65536.0);
|
|
Shinya Kitaoka |
120a6e |
b = 65536 - (65536 - upPix->b) * ((65536 - downPix->b) / 65536.0);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (upPix->m != 65535) {
|
|
Shinya Kitaoka |
120a6e |
double m;
|
|
Shinya Kitaoka |
120a6e |
m = 65536 - (65536 - upPix->m) * ((65536 - downPix->m) / 65536.0);
|
|
Shinya Kitaoka |
120a6e |
TPixel64 tmpPix;
|
|
Shinya Kitaoka |
120a6e |
tmpPix.r = (USHORT)tcrop<double>(r, 0, 65535);</double>
|
|
Shinya Kitaoka |
120a6e |
tmpPix.g = (USHORT)tcrop<double>(g, 0, 65535);</double>
|
|
Shinya Kitaoka |
120a6e |
tmpPix.b = (USHORT)tcrop<double>(b, 0, 65535);</double>
|
|
Shinya Kitaoka |
120a6e |
tmpPix.m = (USHORT)tcrop<double>(m, 0, 65535);</double>
|
|
Shinya Kitaoka |
120a6e |
overPix<tpixel64, ushort="">(*outPix, *downPix, tmpPix);</tpixel64,>
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
outPix->r = (USHORT)tcrop<double>(r, 0, 65535);</double>
|
|
Shinya Kitaoka |
120a6e |
outPix->g = (USHORT)tcrop<double>(g, 0, 65535);</double>
|
|
Shinya Kitaoka |
120a6e |
outPix->b = (USHORT)tcrop<double>(b, 0, 65535);</double>
|
|
Shinya Kitaoka |
120a6e |
outPix->m = upPix->m;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P up8 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P down8 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P out8 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (up8 && down8 && out8) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_8_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
USHORT value;
|
|
Shinya Kitaoka |
120a6e |
if (downPix->value)
|
|
Shinya Kitaoka |
120a6e |
value = (USHORT)((downPix->value << 8) / (255.0 - upPix->value));
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
outPix->value = (UCHAR)tcrop<ushort>(value, 0, 255);</ushort>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_8_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
throw TRopException("TRop::color dodge invalid raster combination");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TRop::sub(const TRasterP &rup, const TRasterP &rdown, const TRasterP &rout,
|
|
Shinya Kitaoka |
120a6e |
bool matte) {
|
|
Shinya Kitaoka |
120a6e |
TRaster32P up32 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P down32 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P out32 = rout;
|
|
Shinya Kitaoka |
120a6e |
if (matte) {
|
|
Shinya Kitaoka |
120a6e |
if (up32 && down32 && out32) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
SHORT r = downPix->r - upPix->r;
|
|
Shinya Kitaoka |
120a6e |
SHORT g = downPix->g - upPix->g;
|
|
Shinya Kitaoka |
120a6e |
SHORT b = downPix->b - upPix->b;
|
|
Shinya Kitaoka |
120a6e |
SHORT m = downPix->m - upPix->m;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
outPix->r = (UCHAR)tcrop<short>(r, 0, 255);</short>
|
|
Shinya Kitaoka |
120a6e |
outPix->g = (UCHAR)tcrop<short>(g, 0, 255);</short>
|
|
Shinya Kitaoka |
120a6e |
outPix->b = (UCHAR)tcrop<short>(b, 0, 255);</short>
|
|
Shinya Kitaoka |
120a6e |
outPix->m = (UCHAR)tcrop<short>(m, 0, 255);</short>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
TRaster64P up64 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P down64 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P out64 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (up64 && down64 && out64) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TINT32 r = downPix->r - upPix->r;
|
|
Shinya Kitaoka |
120a6e |
TINT32 g = downPix->g - upPix->g;
|
|
Shinya Kitaoka |
120a6e |
TINT32 b = downPix->b - upPix->b;
|
|
Shinya Kitaoka |
120a6e |
TINT32 m = downPix->m - upPix->m;
|
|
Shinya Kitaoka |
120a6e |
outPix->r = (USHORT)tcrop<tint32>(r, 0, 0xffff);</tint32>
|
|
Shinya Kitaoka |
120a6e |
outPix->g = (USHORT)tcrop<tint32>(g, 0, 0xffff);</tint32>
|
|
Shinya Kitaoka |
120a6e |
outPix->b = (USHORT)tcrop<tint32>(b, 0, 0xffff);</tint32>
|
|
Shinya Kitaoka |
120a6e |
outPix->m = (USHORT)tcrop<tint32>(m, 0, 0xffff);</tint32>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P up8 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P down8 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P out8 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (up8 && down8 && out8) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_8_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
SHORT value = upPix->value - downPix->value;
|
|
Shinya Kitaoka |
120a6e |
outPix->value = (UCHAR)tcrop<short>(value, 0, 255);</short>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_8_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
throw TRopException("TRop::sub invalid raster combination");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
if (up32 && down32 && out32) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
SHORT r = downPix->r - upPix->r;
|
|
Shinya Kitaoka |
120a6e |
SHORT g = downPix->g - upPix->g;
|
|
Shinya Kitaoka |
120a6e |
SHORT b = downPix->b - upPix->b;
|
|
Shinya Kitaoka |
120a6e |
SHORT m = downPix->m; // - upPix->m;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
outPix->r = (UCHAR)tcrop<short>(r, 0, 255);</short>
|
|
Shinya Kitaoka |
120a6e |
outPix->g = (UCHAR)tcrop<short>(g, 0, 255);</short>
|
|
Shinya Kitaoka |
120a6e |
outPix->b = (UCHAR)tcrop<short>(b, 0, 255);</short>
|
|
Shinya Kitaoka |
120a6e |
outPix->m = (UCHAR)tcrop<short>(m, 0, 255);</short>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
TRaster64P up64 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P down64 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P out64 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (up64 && down64 && out64) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TINT32 r = downPix->r - upPix->r;
|
|
Shinya Kitaoka |
120a6e |
TINT32 g = downPix->g - upPix->g;
|
|
Shinya Kitaoka |
120a6e |
TINT32 b = downPix->b - upPix->b;
|
|
Shinya Kitaoka |
120a6e |
TINT32 m = downPix->m; // - upPix->m;
|
|
Shinya Kitaoka |
120a6e |
outPix->r = (USHORT)tcrop<tint32>(r, 0, 0xffff);</tint32>
|
|
Shinya Kitaoka |
120a6e |
outPix->g = (USHORT)tcrop<tint32>(g, 0, 0xffff);</tint32>
|
|
Shinya Kitaoka |
120a6e |
outPix->b = (USHORT)tcrop<tint32>(b, 0, 0xffff);</tint32>
|
|
Shinya Kitaoka |
120a6e |
outPix->m = (USHORT)tcrop<tint32>(m, 0, 0xffff);</tint32>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P up8 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P down8 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P out8 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (up8 && down8 && out8) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_8_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
SHORT value = upPix->value - downPix->value;
|
|
Shinya Kitaoka |
120a6e |
outPix->value = (UCHAR)tcrop<short>(value, 0, 255);</short>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_8_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
throw TRopException("TRop::sub invalid raster combination");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TRop::mult(const TRasterP &rup, const TRasterP &rdown,
|
|
Shinya Kitaoka |
120a6e |
const TRasterP &rout, int v, bool matte) {
|
|
Shinya Kitaoka |
120a6e |
/*
|
|
Shinya Kitaoka |
120a6e |
Let U be 'up', D be 'down' and M be 'multiplied' (the result), and suppose for
|
|
Shinya Kitaoka |
120a6e |
the moment
|
|
Shinya Kitaoka |
120a6e |
that pixels are both NOT premultiplied and normalized to [0, 1].
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
The additional value v is used to add to RGB components of the U pixel:
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
U'_rgb = (U_rgb + v / 255)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
The matte component is either U_m D_m in case (matte == true), or D_m in case
|
|
Shinya Kitaoka |
120a6e |
(matte == false).
|
|
Shinya Kitaoka |
120a6e |
Please, observe that in the case (matte == false) that choice makes the product
|
|
Shinya Kitaoka |
120a6e |
NOT COMMUTATIVE,
|
|
Shinya Kitaoka |
120a6e |
but I think that's justified - it's simply the most obvious use case.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
In case (matte == true), each channel is multiplied independently, and that's
|
|
Shinya Kitaoka |
120a6e |
it.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
The matter is more complicated when (matte == false). The problem in this case
|
|
Shinya Kitaoka |
120a6e |
is dealing with rgb
|
|
Shinya Kitaoka |
120a6e |
components when U and D both have some transparency. When U is fully
|
|
Shinya Kitaoka |
120a6e |
transparent, we expect the
|
|
Shinya Kitaoka |
120a6e |
result to be D, and vice-versa, which is non-trivial.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
We REQUIRE that (let's denote r only here):
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
M_r = M_r_u = U_r (1 - D_m) + U_r D_r D_m, when U_m == 1 (When U is fully
|
|
Shinya Kitaoka |
120a6e |
opaque, M_r is a D_m-linear
|
|
Shinya Kitaoka |
120a6e |
combination of
|
|
Shinya Kitaoka |
120a6e |
U_r and U_r D_r)
|
|
Shinya Kitaoka |
120a6e |
M_r = M_r_d = D_r (1 - U_m) + U_r D_r U_m, when D_m == 1 (Vice-versa, when
|
|
Shinya Kitaoka |
120a6e |
it's D that is fully opaque)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
Finally, we're building a weighted sum, by U_m and D_m of the two above:
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
M_r = (M_r_u * U_m + M_r_d * D_m) / (U_m + D_m) =
|
|
Shinya Kitaoka |
120a6e |
= (...) =
|
|
Shinya Kitaoka |
120a6e |
= [ U_r U_m (1 - D_m) + D_r D_m (1 - U_m) + 2 U_r U_m D_r D_m ] / (U_m +
|
|
Shinya Kitaoka |
120a6e |
D_m)
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// 32-bit images case
|
|
Shinya Kitaoka |
120a6e |
TRaster32P up32 = rup, down32 = rdown, out32 = rout;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (up32 && down32 && out32) {
|
|
Shinya Kitaoka |
120a6e |
static const float maxChannelF = float(TPixel32::maxChannelValue);
|
|
Shinya Kitaoka |
120a6e |
static const UCHAR maxChannelC = UCHAR(TPixel32::maxChannelValue);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
float vf = v;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (matte) {
|
|
Shinya Kitaoka |
120a6e |
float dnMf, upMf_norm, outMf;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_BEGIN_LOOP // Awful... should be explicit...
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
dnMf = downPix->m;
|
|
Shinya Kitaoka |
120a6e |
upMf_norm = upPix->m / maxChannelF;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
outMf = downPix->m * upMf_norm;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
outPix->r =
|
|
Shinya Kitaoka |
120a6e |
tcrop((upPix->r / upMf_norm + vf) * (downPix->r / dnMf), 0.0f, outMf);
|
|
Shinya Kitaoka |
120a6e |
outPix->g =
|
|
Shinya Kitaoka |
120a6e |
tcrop((upPix->g / upMf_norm + vf) * (downPix->g / dnMf), 0.0f, outMf);
|
|
Shinya Kitaoka |
120a6e |
outPix->b =
|
|
Shinya Kitaoka |
120a6e |
tcrop((upPix->b / upMf_norm + vf) * (downPix->b / dnMf), 0.0f, outMf);
|
|
Shinya Kitaoka |
120a6e |
outPix->m = outMf;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// NOTE: + 0.5f in the crop arguments could take care of rounding...
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
float umf_norm, dmf_norm, umdmf_norm, outMf;
|
|
Shinya Kitaoka |
120a6e |
float mSumf, uf, df, ufdf, normalizer;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_BEGIN_LOOP
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
mSumf = upPix->m + float(downPix->m);
|
|
Shinya Kitaoka |
120a6e |
if (mSumf > 0.0f) {
|
|
Shinya Kitaoka |
120a6e |
umf_norm = upPix->m / maxChannelF, dmf_norm = downPix->m / maxChannelF;
|
|
Shinya Kitaoka |
120a6e |
outMf = upPix->m +
|
|
Shinya Kitaoka |
120a6e |
(1.0f - umf_norm) *
|
|
Shinya Kitaoka |
120a6e |
downPix->m; // umf_norm should be ensured in [0.0, 1.0].
|
|
Shinya Kitaoka |
120a6e |
// Convex combination should be in the conversion range.
|
|
Shinya Kitaoka |
120a6e |
normalizer = outMf / (maxChannelF * mSumf);
|
|
Shinya Kitaoka |
120a6e |
umdmf_norm = umf_norm * dmf_norm;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
uf = upPix->r + vf * umdmf_norm, df = downPix->r, ufdf = uf * df;
|
|
Shinya Kitaoka |
120a6e |
outPix->r = tcrop((uf * (maxChannelC - downPix->m) +
|
|
Shinya Kitaoka |
120a6e |
df * (maxChannelC - upPix->m) + ufdf + ufdf) *
|
|
Shinya Kitaoka |
120a6e |
normalizer,
|
|
Shinya Kitaoka |
120a6e |
0.0f, outMf);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
uf = upPix->g + vf * umdmf_norm, df = downPix->g, ufdf = uf * df;
|
|
Shinya Kitaoka |
120a6e |
outPix->g = tcrop((uf * (maxChannelC - downPix->m) +
|
|
Shinya Kitaoka |
120a6e |
df * (maxChannelC - upPix->m) + ufdf + ufdf) *
|
|
Shinya Kitaoka |
120a6e |
normalizer,
|
|
Shinya Kitaoka |
120a6e |
0.0f, outMf);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
uf = upPix->b + vf * umdmf_norm, df = downPix->b, ufdf = uf * df;
|
|
Shinya Kitaoka |
120a6e |
outPix->b = tcrop((uf * (maxChannelC - downPix->m) +
|
|
Shinya Kitaoka |
120a6e |
df * (maxChannelC - upPix->m) + ufdf + ufdf) *
|
|
Shinya Kitaoka |
120a6e |
normalizer,
|
|
Shinya Kitaoka |
120a6e |
0.0f, outMf);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
outPix->m = outMf;
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
*outPix = TPixel32::Transparent;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// 64-bit images case
|
|
Shinya Kitaoka |
120a6e |
TRaster64P up64 = rup, down64 = rdown, out64 = rout;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (up64 && down64 && out64) {
|
|
Shinya Kitaoka |
120a6e |
static const double maxChannelF = double(TPixel64::maxChannelValue);
|
|
Shinya Kitaoka |
120a6e |
static const USHORT maxChannelC = USHORT(TPixel64::maxChannelValue);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
double vf =
|
|
Shinya Kitaoka |
120a6e |
v * (TPixel64::maxChannelValue / double(TPixel32::maxChannelValue));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (matte) {
|
|
Shinya Kitaoka |
120a6e |
double dnMf, upMf_norm, outMf;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_BEGIN_LOOP
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
dnMf = downPix->m;
|
|
Shinya Kitaoka |
120a6e |
upMf_norm = upPix->m / maxChannelF;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
outMf = downPix->m * upMf_norm;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
outPix->r =
|
|
Shinya Kitaoka |
120a6e |
tcrop((upPix->r / upMf_norm + vf) * (downPix->r / dnMf), 0.0, outMf);
|
|
Shinya Kitaoka |
120a6e |
outPix->g =
|
|
Shinya Kitaoka |
120a6e |
tcrop((upPix->g / upMf_norm + vf) * (downPix->g / dnMf), 0.0, outMf);
|
|
Shinya Kitaoka |
120a6e |
outPix->b =
|
|
Shinya Kitaoka |
120a6e |
tcrop((upPix->b / upMf_norm + vf) * (downPix->b / dnMf), 0.0, outMf);
|
|
Shinya Kitaoka |
120a6e |
outPix->m = outMf;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
double umf_norm, dmf_norm, umdmf_norm, outMf;
|
|
Shinya Kitaoka |
120a6e |
double mSumf, uf, df, ufdf, normalizer;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
mSumf = upPix->m + double(downPix->m);
|
|
Shinya Kitaoka |
120a6e |
if (mSumf > 0.0) {
|
|
Shinya Kitaoka |
120a6e |
umf_norm = upPix->m / maxChannelF, dmf_norm = downPix->m / maxChannelF;
|
|
Shinya Kitaoka |
120a6e |
outMf = upPix->m + (1.0 - umf_norm) * downPix->m;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
normalizer = outMf / (maxChannelF * mSumf);
|
|
Shinya Kitaoka |
120a6e |
umdmf_norm = umf_norm * dmf_norm;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
uf = upPix->r + vf * umdmf_norm, df = downPix->r, ufdf = uf * df;
|
|
Shinya Kitaoka |
120a6e |
outPix->r = tcrop((uf * (maxChannelC - downPix->m) +
|
|
Shinya Kitaoka |
120a6e |
df * (maxChannelC - upPix->m) + ufdf + ufdf) *
|
|
Shinya Kitaoka |
120a6e |
normalizer,
|
|
Shinya Kitaoka |
120a6e |
0.0, outMf);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
uf = upPix->g + vf * umdmf_norm, df = downPix->g, ufdf = uf * df;
|
|
Shinya Kitaoka |
120a6e |
outPix->g = tcrop((uf * (maxChannelC - downPix->m) +
|
|
Shinya Kitaoka |
120a6e |
df * (maxChannelC - upPix->m) + ufdf + ufdf) *
|
|
Shinya Kitaoka |
120a6e |
normalizer,
|
|
Shinya Kitaoka |
120a6e |
0.0, outMf);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
uf = upPix->b + vf * umdmf_norm, df = downPix->b, ufdf = uf * df;
|
|
Shinya Kitaoka |
120a6e |
outPix->b = tcrop((uf * (maxChannelC - downPix->m) +
|
|
Shinya Kitaoka |
120a6e |
df * (maxChannelC - upPix->m) + ufdf + ufdf) *
|
|
Shinya Kitaoka |
120a6e |
normalizer,
|
|
Shinya Kitaoka |
120a6e |
0.0, outMf);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
outPix->m = outMf;
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
*outPix = TPixel64::Transparent;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// According to the specifics, throw an exception. I think it's not
|
|
Shinya Kitaoka |
120a6e |
// appropriate, though.
|
|
Shinya Kitaoka |
120a6e |
throw TRopException("TRop::mult invalid raster combination");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TRop::ropin(const TRasterP &source, const TRasterP &matte,
|
|
Shinya Kitaoka |
120a6e |
const TRasterP &rout) {
|
|
Shinya Kitaoka |
120a6e |
TRaster32P source32 = source;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P matte32 = matte;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P out32 = rout;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P source64 = source;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P matte64 = matte;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P out64 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (source32 && matte32 && out32) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_BEGIN_LOOP(TPixelRGBM32, source32, TPixelRGBM32, matte32,
|
|
Shinya Kitaoka |
120a6e |
TPixelRGBM32, out32)
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (downPix->m == 0)
|
|
Shinya Kitaoka |
120a6e |
outPix->r = outPix->g = outPix->b = outPix->m = 0;
|
|
Shinya Kitaoka |
120a6e |
else if (downPix->m == 255)
|
|
Shinya Kitaoka |
120a6e |
*outPix = *upPix;
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
/*
|
|
Shinya Kitaoka |
120a6e |
__m128i zeros = _mm_setzero_si128();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
__m128i upPix_packed_i= _mm_unpacklo_epi8(_mm_cvtsi32_si128(*(DWORD*)upPix),
|
|
Shinya Kitaoka |
120a6e |
zeros);
|
|
Shinya Kitaoka |
120a6e |
__m128 upPix_packed = _mm_cvtepi32_ps(_mm_unpacklo_epi16(upPix_packed_i,
|
|
Shinya Kitaoka |
120a6e |
zeros));
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
float fac = downPix->m / 255.0;
|
|
Shinya Kitaoka |
120a6e |
__m128 fac_packed = _mm_load1_ps(&fac);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
upPix_packed = _mm_mul_ps(upPix_packed, fac_packed);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
__m128i outPix_packed_i = _mm_cvtps_epi32(upPix_packed);
|
|
Shinya Kitaoka |
120a6e |
outPix_packed_i = _mm_packs_epi32(outPix_packed_i, zeros);
|
|
Shinya Kitaoka |
120a6e |
outPix_packed_i = _mm_packus_epi16(outPix_packed_i, zeros);
|
|
Shinya Kitaoka |
120a6e |
*(DWORD*)(outPix) = _mm_cvtsi128_si32(outPix_packed_i);
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
const int MAGICFAC = (257U * 256U + 1U);
|
|
Shinya Kitaoka |
120a6e |
UINT fac = MAGICFAC * downPix->m;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
outPix->r = (UINT)(upPix->r * fac + (1U << 23)) >> 24;
|
|
Shinya Kitaoka |
120a6e |
outPix->g = (UINT)(upPix->g * fac + (1U << 23)) >> 24;
|
|
Shinya Kitaoka |
120a6e |
outPix->b = (UINT)(upPix->b * fac + (1U << 23)) >> 24;
|
|
Shinya Kitaoka |
120a6e |
outPix->m = (UINT)(upPix->m * fac + (1U << 23)) >> 24;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_END_LOOP(source32, matte32, out32)
|
|
Shinya Kitaoka |
120a6e |
} else if (source64 && matte64 && out64)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_BEGIN_LOOP(TPixelRGBM64, source64, TPixelRGBM64, matte64,
|
|
Shinya Kitaoka |
120a6e |
TPixelRGBM64, out64)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (downPix->m == 0)
|
|
Shinya Kitaoka |
120a6e |
outPix->r = outPix->g = outPix->b = outPix->m = 0;
|
|
Shinya Kitaoka |
120a6e |
else if (downPix->m == 65535)
|
|
Shinya Kitaoka |
120a6e |
*outPix = *upPix;
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
/*
|
|
Shinya Kitaoka |
120a6e |
__m128i zeros = _mm_setzero_si128();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
__m128i upPix_packed_i= _mm_unpacklo_epi8(_mm_cvtsi32_si128(*(DWORD*)upPix),
|
|
Shinya Kitaoka |
120a6e |
zeros);
|
|
Shinya Kitaoka |
120a6e |
__m128 upPix_packed = _mm_cvtepi32_ps(_mm_unpacklo_epi16(upPix_packed_i,
|
|
Shinya Kitaoka |
120a6e |
zeros));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
float fac = downPix->m / 255.0;
|
|
Shinya Kitaoka |
120a6e |
__m128 fac_packed = _mm_load1_ps(&fac);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
upPix_packed = _mm_mul_ps(upPix_packed, fac_packed);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
__m128i outPix_packed_i = _mm_cvtps_epi32(upPix_packed);
|
|
Shinya Kitaoka |
120a6e |
outPix_packed_i = _mm_packs_epi32(outPix_packed_i, zeros);
|
|
Shinya Kitaoka |
120a6e |
outPix_packed_i = _mm_packus_epi16(outPix_packed_i, zeros);
|
|
Shinya Kitaoka |
120a6e |
*(DWORD*)(outPix) = _mm_cvtsi128_si32(outPix_packed_i);
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Shinya Kitaoka |
120a6e |
double fac = downPix->m / 65535.0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
outPix->r = (USHORT)(upPix->r * fac);
|
|
Shinya Kitaoka |
120a6e |
outPix->g = (USHORT)(upPix->g * fac);
|
|
Shinya Kitaoka |
120a6e |
outPix->b = (USHORT)(upPix->b * fac);
|
|
Shinya Kitaoka |
120a6e |
outPix->m = (USHORT)(upPix->m * fac);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_END_LOOP(source64, matte64, out64)
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
throw TRopException("TRop::in invalid raster combination");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TRop::ropout(const TRasterP &source, const TRasterP &matte,
|
|
Shinya Kitaoka |
120a6e |
const TRasterP &rout) {
|
|
Shinya Kitaoka |
120a6e |
TRaster32P source32 = source;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P matte32 = matte;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P out32 = rout;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P source64 = source;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P matte64 = matte;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P out64 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (source32 && matte32 && out32) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_BEGIN_LOOP(TPixelRGBM32, source32, TPixelRGBM32, matte32,
|
|
Shinya Kitaoka |
120a6e |
TPixelRGBM32, out32)
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (downPix->m == 255)
|
|
Shinya Kitaoka |
120a6e |
outPix->r = outPix->g = outPix->b = outPix->m = 0;
|
|
Shinya Kitaoka |
120a6e |
else if (downPix->m == 0)
|
|
Shinya Kitaoka |
120a6e |
*outPix = *upPix;
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
const int MAGICFAC = (257U * 256U + 1U);
|
|
Shinya Kitaoka |
120a6e |
UINT fac = MAGICFAC * (255 - downPix->m);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
outPix->r = (UINT)(upPix->r * fac + (1U << 23)) >> 24;
|
|
Shinya Kitaoka |
120a6e |
outPix->g = (UINT)(upPix->g * fac + (1U << 23)) >> 24;
|
|
Shinya Kitaoka |
120a6e |
outPix->b = (UINT)(upPix->b * fac + (1U << 23)) >> 24;
|
|
Shinya Kitaoka |
120a6e |
outPix->m = (UINT)(upPix->m * fac + (1U << 23)) >> 24;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_END_LOOP(source32, matte32, out32)
|
|
Shinya Kitaoka |
120a6e |
} else if (source64 && matte64 && out64) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_BEGIN_LOOP(TPixelRGBM64, source64, TPixelRGBM64, matte64,
|
|
Shinya Kitaoka |
120a6e |
TPixelRGBM64, out64)
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (downPix->m == 65535)
|
|
Shinya Kitaoka |
120a6e |
outPix->r = outPix->g = outPix->b = outPix->m = 0;
|
|
Shinya Kitaoka |
120a6e |
else if (downPix->m == 0)
|
|
Shinya Kitaoka |
120a6e |
*outPix = *upPix;
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
double fac = (65535 - downPix->m) / 65535.0;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
outPix->r = (USHORT)(upPix->r * fac);
|
|
Shinya Kitaoka |
120a6e |
outPix->g = (USHORT)(upPix->g * fac);
|
|
Shinya Kitaoka |
120a6e |
outPix->b = (USHORT)(upPix->b * fac);
|
|
Shinya Kitaoka |
120a6e |
outPix->m = (USHORT)(upPix->m * fac);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_END_LOOP(source64, matte64, out64)
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
throw TRopException("TRop::out invalid raster combination");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TRop::atop(const TRasterP &rup, const TRasterP &rdown,
|
|
Shinya Kitaoka |
120a6e |
const TRasterP &rout) {
|
|
Shinya Kitaoka |
120a6e |
// calcola rup ATOP rdown
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// da ottimizzare...
|
|
Shinya Kitaoka |
120a6e |
TRaster32P up32 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P down32 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P out32 = rout;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P up64 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P down64 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P out64 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (up32 && down32 && out32) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TPixel32 tmpPix(0, 0, 0, 0);
|
|
Shinya Kitaoka |
120a6e |
if (downPix->m != 0) {
|
|
Shinya Kitaoka |
120a6e |
const int MAGICFAC = (257U * 256U + 1U);
|
|
Shinya Kitaoka |
120a6e |
UINT fac = MAGICFAC * downPix->m;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
tmpPix.r = (UINT)(upPix->r * fac + (1U << 23)) >> 24;
|
|
Shinya Kitaoka |
120a6e |
tmpPix.g = (UINT)(upPix->g * fac + (1U << 23)) >> 24;
|
|
Shinya Kitaoka |
120a6e |
tmpPix.b = (UINT)(upPix->b * fac + (1U << 23)) >> 24;
|
|
Shinya Kitaoka |
120a6e |
tmpPix.m = (UINT)(upPix->m * fac + (1U << 23)) >> 24;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
overPix<tpixel32, uchar="">(*outPix, *downPix, tmpPix);</tpixel32,>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else if (up64 && down64 && out64) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TPixel64 tmpPix(0, 0, 0, 0);
|
|
Shinya Kitaoka |
120a6e |
if (downPix->m != 0) {
|
|
Shinya Kitaoka |
120a6e |
double fac = downPix->m / 65535.0;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
tmpPix.r = (USHORT)(upPix->r * fac);
|
|
Shinya Kitaoka |
120a6e |
tmpPix.g = (USHORT)(upPix->g * fac);
|
|
Shinya Kitaoka |
120a6e |
tmpPix.b = (USHORT)(upPix->b * fac);
|
|
Shinya Kitaoka |
120a6e |
tmpPix.m = (USHORT)(upPix->m * fac);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
overPix<tpixel64, ushort="">(*outPix, *downPix, tmpPix);</tpixel64,>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
throw TRopException("TRop::atop invalid raster combination");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TRop::txor(const TRasterP &rup, const TRasterP &rdown,
|
|
Shinya Kitaoka |
120a6e |
const TRasterP &rout) {
|
|
Shinya Kitaoka |
120a6e |
// da ottimizzare...
|
|
Shinya Kitaoka |
120a6e |
TRaster32P up32 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P down32 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P out32 = rout;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P up64 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P down64 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P out64 = rout;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (up32 && down32 && out32) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_BEGIN_LOOP
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TUINT32 notUpM = 255 - upPix->m;
|
|
Shinya Kitaoka |
120a6e |
TUINT32 notDownM = 255 - downPix->m;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TUINT32 r = notUpM + upPix->r * (notDownM);
|
|
Shinya Kitaoka |
120a6e |
TUINT32 g = notUpM + upPix->g * (notDownM);
|
|
Shinya Kitaoka |
120a6e |
TUINT32 b = notUpM + upPix->b * (notDownM);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
outPix->r = (UCHAR)tcrop<tuint32>(0, 255, r);</tuint32>
|
|
Shinya Kitaoka |
120a6e |
outPix->g = (UCHAR)tcrop<tuint32>(0, 255, g);</tuint32>
|
|
Shinya Kitaoka |
120a6e |
outPix->b = (UCHAR)tcrop<tuint32>(0, 255, b);</tuint32>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else if (up64 && down64 && out64) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_BEGIN_LOOP
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TUINT32 notUpM = 65535 - upPix->m;
|
|
Shinya Kitaoka |
120a6e |
TUINT32 notDownM = 65535 - downPix->m;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TUINT32 r = notUpM + upPix->r * (notDownM);
|
|
Shinya Kitaoka |
120a6e |
TUINT32 g = notUpM + upPix->g * (notDownM);
|
|
Shinya Kitaoka |
120a6e |
TUINT32 b = notUpM + upPix->b * (notDownM);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
outPix->r = (USHORT)tcrop<tuint32>(0, 65535, r);</tuint32>
|
|
Shinya Kitaoka |
120a6e |
outPix->g = (USHORT)tcrop<tuint32>(0, 65535, g);</tuint32>
|
|
Shinya Kitaoka |
120a6e |
outPix->b = (USHORT)tcrop<tuint32>(0, 65535, b);</tuint32>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
throw TRopException("TRop::xor invalid raster combination");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TRop::crossDissolve(const TRasterP &rup, const TRasterP &rdown,
|
|
Shinya Kitaoka |
120a6e |
const TRasterP &rout, UCHAR v) {
|
|
Shinya Kitaoka |
120a6e |
TRaster32P up32 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P down32 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P out32 = rout;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P up64 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P down64 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P out64 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (up32 && down32 && out32) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
outPix->r = (upPix->r * v + downPix->r * (255 - v)) / 255;
|
|
Shinya Kitaoka |
120a6e |
outPix->g = (upPix->g * v + downPix->g * (255 - v)) / 255;
|
|
Shinya Kitaoka |
120a6e |
outPix->b = (upPix->b * v + downPix->b * (255 - v)) / 255;
|
|
Shinya Kitaoka |
120a6e |
outPix->m = (upPix->m * v + downPix->m * (255 - v)) / 255;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else if (up64 && down64 && out64) {
|
|
Shinya Kitaoka |
120a6e |
USHORT vv = v * 257;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
outPix->r = (upPix->r * vv + downPix->r * (65535 - vv)) / 65535;
|
|
Shinya Kitaoka |
120a6e |
outPix->g = (upPix->g * vv + downPix->g * (65535 - vv)) / 65535;
|
|
Shinya Kitaoka |
120a6e |
outPix->b = (upPix->b * vv + downPix->b * (65535 - vv)) / 65535;
|
|
Shinya Kitaoka |
120a6e |
outPix->m = (upPix->m * vv + downPix->m * (65535 - vv)) / 65535;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
throw TRopException("TRop::crossDissolve invalid raster combination");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TRop::darken(const TRasterP &rup, const TRasterP &rdown,
|
|
Shinya Kitaoka |
120a6e |
const TRasterP &rout) {
|
|
Shinya Kitaoka |
120a6e |
TRaster32P up32 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P down32 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P out32 = rout;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P up64 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P down64 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P out64 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (up32 && down32 && out32) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
double value0 = luminance(upPix);
|
|
Shinya Kitaoka |
120a6e |
double value1 = luminance(downPix);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (value0 < value1)
|
|
Shinya Kitaoka |
120a6e |
*outPix = *upPix;
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
*outPix = *downPix;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else if (up64 && down64 && out64) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
double value0 = luminance(upPix);
|
|
Shinya Kitaoka |
120a6e |
double value1 = luminance(downPix);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (value0 < value1)
|
|
Shinya Kitaoka |
120a6e |
*outPix = *upPix;
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
*outPix = *downPix;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
throw TRopException("TRop::darken invalid raster combination");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TRop::lighten(const TRasterP &rup, const TRasterP &rdown,
|
|
Shinya Kitaoka |
120a6e |
const TRasterP &rout) {
|
|
Shinya Kitaoka |
120a6e |
TRaster32P up32 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P down32 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P out32 = rout;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P up64 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P down64 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P out64 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (up32 && down32 && out32) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
double value0 = luminance(upPix);
|
|
Shinya Kitaoka |
120a6e |
double value1 = luminance(downPix);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (value0 > value1) {
|
|
Shinya Kitaoka |
120a6e |
TINT32 r, g, b, m;
|
|
Shinya Kitaoka |
120a6e |
if (upPix->m == 0)
|
|
Shinya Kitaoka |
120a6e |
*outPix = *downPix;
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
r = downPix->r + upPix->r;
|
|
Shinya Kitaoka |
120a6e |
g = downPix->g + upPix->g;
|
|
Shinya Kitaoka |
120a6e |
b = downPix->b + upPix->b;
|
|
Shinya Kitaoka |
120a6e |
m = downPix->m + upPix->m;
|
|
Shinya Kitaoka |
120a6e |
outPix->r = (UCHAR)tcrop<tint32>(r, (TINT32)0, (TINT32)255);</tint32>
|
|
Shinya Kitaoka |
120a6e |
outPix->g = (UCHAR)tcrop<tint32>(g, (TINT32)0, (TINT32)255);</tint32>
|
|
Shinya Kitaoka |
120a6e |
outPix->b = (UCHAR)tcrop<tint32>(b, (TINT32)0, (TINT32)255);</tint32>
|
|
Shinya Kitaoka |
120a6e |
outPix->m = (UCHAR)tcrop<tint32>(m, (TINT32)0, (TINT32)255);</tint32>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
*outPix = *downPix;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else if (up64 && down64 && out64) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
double value0 = luminance(upPix);
|
|
Shinya Kitaoka |
120a6e |
double value1 = luminance(downPix);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (value0 > value1) {
|
|
Shinya Kitaoka |
120a6e |
TINT32 r, g, b, m;
|
|
Shinya Kitaoka |
120a6e |
if (upPix->m == 0)
|
|
Shinya Kitaoka |
120a6e |
*outPix = *downPix;
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
r = downPix->r + upPix->r;
|
|
Shinya Kitaoka |
120a6e |
g = downPix->g + upPix->g;
|
|
Shinya Kitaoka |
120a6e |
b = downPix->b + upPix->b;
|
|
Shinya Kitaoka |
120a6e |
m = downPix->m + upPix->m;
|
|
Shinya Kitaoka |
120a6e |
outPix->r = (USHORT)tcrop<tint32>(r, (TINT32)0, (TINT32)65535);</tint32>
|
|
Shinya Kitaoka |
120a6e |
outPix->g = (USHORT)tcrop<tint32>(g, (TINT32)0, (TINT32)65535);</tint32>
|
|
Shinya Kitaoka |
120a6e |
outPix->b = (USHORT)tcrop<tint32>(b, (TINT32)0, (TINT32)65535);</tint32>
|
|
Shinya Kitaoka |
120a6e |
outPix->m = (USHORT)tcrop<tint32>(m, (TINT32)0, (TINT32)65535);</tint32>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
*outPix = *downPix;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
throw TRopException("TRop::lighten invalid raster combination");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TRop::ropmin(const TRasterP &rup, const TRasterP &rdown,
|
|
Shinya Kitaoka |
120a6e |
const TRasterP &rout, bool matte) {
|
|
Shinya Kitaoka |
120a6e |
TRaster32P up32 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P down32 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P out32 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (up32 && down32 && out32) {
|
|
Shinya Kitaoka |
120a6e |
if (matte) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
outPix->r = upPix->r < downPix->r ? upPix->r : downPix->r;
|
|
Shinya Kitaoka |
120a6e |
outPix->g = upPix->g < downPix->g ? upPix->g : downPix->g;
|
|
Shinya Kitaoka |
120a6e |
outPix->b = upPix->b < downPix->b ? upPix->b : downPix->b;
|
|
Shinya Kitaoka |
120a6e |
outPix->m = upPix->m < downPix->m ? upPix->m : downPix->m;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
if (upPix->m >= 255) {
|
|
Shinya Kitaoka |
120a6e |
outPix->r = upPix->r < downPix->r ? upPix->r : downPix->r;
|
|
Shinya Kitaoka |
120a6e |
outPix->g = upPix->g < downPix->g ? upPix->g : downPix->g;
|
|
Shinya Kitaoka |
120a6e |
outPix->b = upPix->b < downPix->b ? upPix->b : downPix->b;
|
|
Shinya Kitaoka |
120a6e |
outPix->m = upPix->m < downPix->m ? upPix->m : downPix->m;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
} else if (upPix->m) {
|
|
Shinya Kitaoka |
120a6e |
TPixel32 tmp;
|
|
Shinya Kitaoka |
120a6e |
tmp.r = upPix->r < downPix->r ? upPix->r : downPix->r;
|
|
Shinya Kitaoka |
120a6e |
tmp.g = upPix->g < downPix->g ? upPix->g : downPix->g;
|
|
Shinya Kitaoka |
120a6e |
tmp.b = upPix->b < downPix->b ? upPix->b : downPix->b;
|
|
Shinya Kitaoka |
120a6e |
// tmp.m = upPix->m < downPix->m ? upPix->m : downPix->m;
|
|
Shinya Kitaoka |
120a6e |
outPix->r = upPix->m * (tmp.r - downPix->r) / 255.0 + downPix->r;
|
|
Shinya Kitaoka |
120a6e |
outPix->g = upPix->m * (tmp.g - downPix->g) / 255.0 + downPix->g;
|
|
Shinya Kitaoka |
120a6e |
outPix->b = upPix->m * (tmp.b - downPix->b) / 255.0 + downPix->b;
|
|
Shinya Kitaoka |
120a6e |
outPix->m = upPix->m * (tmp.m - downPix->m) / 255.0 + downPix->m;
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
*outPix = *downPix;
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
TRaster64P up64 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P down64 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P out64 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (up64 && down64 && out64) {
|
|
Shinya Kitaoka |
120a6e |
if (matte) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
outPix->r = upPix->r < downPix->r ? upPix->r : downPix->r;
|
|
Shinya Kitaoka |
120a6e |
outPix->g = upPix->g < downPix->g ? upPix->g : downPix->g;
|
|
Shinya Kitaoka |
120a6e |
outPix->b = upPix->b < downPix->b ? upPix->b : downPix->b;
|
|
Shinya Kitaoka |
120a6e |
outPix->m = upPix->m < downPix->m ? upPix->m : downPix->m;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
if (upPix->m >= 65535) {
|
|
Shinya Kitaoka |
120a6e |
outPix->r = upPix->r < downPix->r ? upPix->r : downPix->r;
|
|
Shinya Kitaoka |
120a6e |
outPix->g = upPix->g < downPix->g ? upPix->g : downPix->g;
|
|
Shinya Kitaoka |
120a6e |
outPix->b = upPix->b < downPix->b ? upPix->b : downPix->b;
|
|
Shinya Kitaoka |
120a6e |
outPix->m = upPix->m < downPix->m ? upPix->m : downPix->m;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
} else if (upPix->m) {
|
|
Shinya Kitaoka |
120a6e |
TPixel32 tmp;
|
|
Shinya Kitaoka |
120a6e |
tmp.r = upPix->r < downPix->r ? upPix->r : downPix->r;
|
|
Shinya Kitaoka |
120a6e |
tmp.g = upPix->g < downPix->g ? upPix->g : downPix->g;
|
|
Shinya Kitaoka |
120a6e |
tmp.b = upPix->b < downPix->b ? upPix->b : downPix->b;
|
|
Shinya Kitaoka |
120a6e |
// tmp.m = upPix->m < downPix->m ? upPix->m : downPix->m;
|
|
Shinya Kitaoka |
120a6e |
outPix->r = upPix->m * (tmp.r - downPix->r) / 65535.0 + downPix->r;
|
|
Shinya Kitaoka |
120a6e |
outPix->g = upPix->m * (tmp.g - downPix->g) / 65535.0 + downPix->g;
|
|
Shinya Kitaoka |
120a6e |
outPix->b = upPix->m * (tmp.b - downPix->b) / 65535.0 + downPix->b;
|
|
Shinya Kitaoka |
120a6e |
outPix->m = upPix->m * (tmp.m - downPix->m) / 65535.0 + downPix->m;
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
*outPix = *downPix;
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P up8 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P down8 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P out8 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (up8 && down8 && out8) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_8_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
outPix->value =
|
|
Shinya Kitaoka |
120a6e |
upPix->value < downPix->value ? upPix->value : downPix->value;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_8_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
throw TRopException("TRop::min invalid raster combination");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TRop::ropmax(const TRasterP &rup, const TRasterP &rdown,
|
|
Shinya Kitaoka |
120a6e |
const TRasterP &rout) {
|
|
Shinya Kitaoka |
120a6e |
TRaster32P up32 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P down32 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P out32 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (up32 && down32 && out32) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
outPix->r = upPix->r > downPix->r ? upPix->r : downPix->r;
|
|
Shinya Kitaoka |
120a6e |
outPix->g = upPix->g > downPix->g ? upPix->g : downPix->g;
|
|
Shinya Kitaoka |
120a6e |
outPix->b = upPix->b > downPix->b ? upPix->b : downPix->b;
|
|
Shinya Kitaoka |
120a6e |
outPix->m = upPix->m > downPix->m ? upPix->m : downPix->m;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
TRaster64P up64 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P down64 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P out64 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (up64 && down64 && out64) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
outPix->r = upPix->r > downPix->r ? upPix->r : downPix->r;
|
|
Shinya Kitaoka |
120a6e |
outPix->g = upPix->g > downPix->g ? upPix->g : downPix->g;
|
|
Shinya Kitaoka |
120a6e |
outPix->b = upPix->b > downPix->b ? upPix->b : downPix->b;
|
|
Shinya Kitaoka |
120a6e |
outPix->m = upPix->m > downPix->m ? upPix->m : downPix->m;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P up8 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P down8 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P out8 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (up8 && down8 && out8) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_8_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
outPix->value =
|
|
Shinya Kitaoka |
120a6e |
upPix->value > downPix->value ? upPix->value : downPix->value;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_8_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
throw TRopException("TRop::max invalid raster combination");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TRop::linearburn(const TRasterP &rup, const TRasterP &rdown,
|
|
Shinya Kitaoka |
120a6e |
const TRasterP &rout) {
|
|
Shinya Kitaoka |
120a6e |
TRaster32P up32 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P down32 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P out32 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (up32 && down32 && out32) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
if (upPix->m) {
|
|
Shinya Kitaoka |
120a6e |
TPixel32 app;
|
|
Shinya Kitaoka |
120a6e |
if (downPix->m) {
|
|
Shinya Kitaoka |
120a6e |
TINT32 r, g, b, m;
|
|
Shinya Kitaoka |
120a6e |
TPixel32 tmpPix;
|
|
Shinya Kitaoka |
120a6e |
tmpPix = depremultiply(*downPix);
|
|
Shinya Kitaoka |
120a6e |
r = tmpPix.r + upPix->r - 255;
|
|
Shinya Kitaoka |
120a6e |
g = tmpPix.g + upPix->g - 255;
|
|
Shinya Kitaoka |
120a6e |
b = tmpPix.b + upPix->b - 255;
|
|
Shinya Kitaoka |
120a6e |
m = tmpPix.m + upPix->m - 255;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
app.r = (UCHAR)tcrop<tint32>(r, (TINT32)0, (TINT32)255);</tint32>
|
|
Shinya Kitaoka |
120a6e |
app.g = (UCHAR)tcrop<tint32>(g, (TINT32)0, (TINT32)255);</tint32>
|
|
Shinya Kitaoka |
120a6e |
app.b = (UCHAR)tcrop<tint32>(b, (TINT32)0, (TINT32)255);</tint32>
|
|
Shinya Kitaoka |
120a6e |
// app.m = (UCHAR)tcrop<tint32> (m, (TINT32)0, (TINT32)255);</tint32>
|
|
Shinya Kitaoka |
120a6e |
app.m = upPix->m;
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
app = *upPix;
|
|
Shinya Kitaoka |
120a6e |
overPix<tpixel32, uchar="">(*outPix, *downPix, app);</tpixel32,>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
TRaster64P up64 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P down64 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P out64 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (up64 && down64 && out64) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (upPix->m) {
|
|
Shinya Kitaoka |
120a6e |
TPixel64 app;
|
|
Shinya Kitaoka |
120a6e |
if (downPix->m) {
|
|
Shinya Kitaoka |
120a6e |
TINT32 r, g, b, m;
|
|
Shinya Kitaoka |
120a6e |
TPixel64 tmpPix;
|
|
Shinya Kitaoka |
120a6e |
tmpPix = depremultiply(*downPix);
|
|
Shinya Kitaoka |
120a6e |
r = tmpPix.r + upPix->r - 65535;
|
|
Shinya Kitaoka |
120a6e |
g = tmpPix.g + upPix->g - 65535;
|
|
Shinya Kitaoka |
120a6e |
b = tmpPix.b + upPix->b - 65535;
|
|
Shinya Kitaoka |
120a6e |
m = tmpPix.m + upPix->m - 65535;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
app.r = (USHORT)tcrop<tint32>(r, 0, 0xffff);</tint32>
|
|
Shinya Kitaoka |
120a6e |
app.g = (USHORT)tcrop<tint32>(g, 0, 0xffff);</tint32>
|
|
Shinya Kitaoka |
120a6e |
app.b = (USHORT)tcrop<tint32>(b, 0, 0xffff);</tint32>
|
|
Shinya Kitaoka |
120a6e |
// app.m = (UCHAR)tcrop<tint32> (m, (TINT32)0, (TINT32)255);</tint32>
|
|
Shinya Kitaoka |
120a6e |
app.m = upPix->m;
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
app = *upPix;
|
|
Shinya Kitaoka |
120a6e |
overPix<tpixel64, ushort="">(*outPix, *downPix, app);</tpixel64,>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P up8 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P down8 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P out8 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (up8 && down8 && out8) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_8_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
USHORT value = troundp(upPix->value + downPix->value - 255);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
outPix->value = (UCHAR)tcrop<ushort>(value, 0, 255);</ushort>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_8_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
throw TRopException("TRop::max invalid raster combination");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TRop::overlay(const TRasterP &rup, const TRasterP &rdown,
|
|
Shinya Kitaoka |
120a6e |
const TRasterP &rout) {
|
|
Shinya Kitaoka |
120a6e |
TRaster32P up32 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P down32 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P out32 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (up32 && down32 && out32) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
if (upPix->m) {
|
|
Shinya Kitaoka |
120a6e |
TPixel32 app;
|
|
Shinya Kitaoka |
120a6e |
TPixel32 tmpPix, tmp2Pix;
|
|
Shinya Kitaoka |
120a6e |
if (downPix->m) {
|
|
Shinya Kitaoka |
120a6e |
tmpPix = *downPix;
|
|
Shinya Kitaoka |
120a6e |
tmp2Pix = depremultiply(*upPix);
|
|
Shinya Kitaoka |
120a6e |
if (tmpPix.r < 128)
|
|
Shinya Kitaoka |
120a6e |
app.r = troundp(2 * tmp2Pix.r * (tmpPix.r / 255.0));
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
SHORT r =
|
|
Shinya Kitaoka |
120a6e |
255 *
|
|
Shinya Kitaoka |
120a6e |
(1 - 2 * (1.0 - tmpPix.r / 255.0) * (1.0 - tmp2Pix.r / 255.0));
|
|
Shinya Kitaoka |
120a6e |
app.r = (UCHAR)tcrop<short>(r, 0, 255);</short>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (tmpPix.g < 128)
|
|
Shinya Kitaoka |
120a6e |
app.g = troundp(2 * tmp2Pix.g * (tmpPix.g / 255.0));
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
SHORT g =
|
|
Shinya Kitaoka |
120a6e |
255 *
|
|
Shinya Kitaoka |
120a6e |
(1 - 2 * (1.0 - tmpPix.g / 255.0) * (1.0 - tmp2Pix.g / 255.0));
|
|
Shinya Kitaoka |
120a6e |
app.g = (UCHAR)tcrop<short>(g, 0, 255);</short>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (tmpPix.b < 128)
|
|
Shinya Kitaoka |
120a6e |
app.b = troundp(2 * tmp2Pix.b * (tmpPix.b / 255.0));
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
SHORT b =
|
|
Shinya Kitaoka |
120a6e |
255 *
|
|
Shinya Kitaoka |
120a6e |
(1 - 2 * (1.0 - tmpPix.b / 255.0) * (1.0 - tmp2Pix.b / 255.0));
|
|
Shinya Kitaoka |
120a6e |
app.b = (UCHAR)tcrop<short>(b, 0, 255);</short>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
app.m = tmp2Pix.m;
|
|
Shinya Kitaoka |
120a6e |
app = premultiply(app);
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
app = *upPix;
|
|
Shinya Kitaoka |
120a6e |
overPix<tpixel32, uchar="">(*outPix, *downPix, app);</tpixel32,>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_32_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
TRaster64P up64 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P down64 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P out64 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (up64 && down64 && out64) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (upPix->m) {
|
|
Shinya Kitaoka |
120a6e |
TPixel64 app;
|
|
Shinya Kitaoka |
120a6e |
TPixel64 tmpPix, tmp2Pix;
|
|
Shinya Kitaoka |
120a6e |
if (downPix->m) {
|
|
Shinya Kitaoka |
120a6e |
tmpPix = *downPix;
|
|
Shinya Kitaoka |
120a6e |
tmp2Pix = depremultiply(*upPix);
|
|
Shinya Kitaoka |
120a6e |
if (tmpPix.r < 32768)
|
|
Shinya Kitaoka |
120a6e |
app.r = troundp(2 * tmp2Pix.r * (tmpPix.r / 65535.0));
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
SHORT r = 65535 * (1 -
|
|
Shinya Kitaoka |
120a6e |
2 * (1.0 - tmpPix.r / 65535.0) *
|
|
Shinya Kitaoka |
120a6e |
(1.0 - tmp2Pix.r / 65535.0));
|
|
Shinya Kitaoka |
120a6e |
app.r = (USHORT)tcrop<tint32>(r, 0, 65535);</tint32>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (tmpPix.g < 32768)
|
|
Shinya Kitaoka |
120a6e |
app.g = troundp(2 * tmp2Pix.g * (tmpPix.g / 65535.0));
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
SHORT g = 65535 * (1 -
|
|
Shinya Kitaoka |
120a6e |
2 * (1.0 - tmpPix.g / 65535.0) *
|
|
Shinya Kitaoka |
120a6e |
(1.0 - tmp2Pix.g / 65535.0));
|
|
Shinya Kitaoka |
120a6e |
app.g = (USHORT)tcrop<tint32>(g, 0, 65535);</tint32>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (tmpPix.b < 32768)
|
|
Shinya Kitaoka |
120a6e |
app.b = troundp(2 * tmp2Pix.b * (tmpPix.b / 65535.0));
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
SHORT b = 65535 * (1 -
|
|
Shinya Kitaoka |
120a6e |
2 * (1.0 - tmpPix.b / 65535.0) *
|
|
Shinya Kitaoka |
120a6e |
(1.0 - tmp2Pix.b / 65535.0));
|
|
Shinya Kitaoka |
120a6e |
app.b = (USHORT)tcrop<tint32>(b, 0, 65535);</tint32>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
app.m = tmp2Pix.m;
|
|
Shinya Kitaoka |
120a6e |
app = premultiply(app);
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
app = *upPix;
|
|
Shinya Kitaoka |
120a6e |
overPix<tpixel64, ushort="">(*outPix, *downPix, app);</tpixel64,>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_64_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P up8 = rup;
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P down8 = rdown;
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P out8 = rout;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (up8 && down8 && out8) {
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_8_BEGIN_LOOP
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
USHORT value;
|
|
Shinya Kitaoka |
120a6e |
if (downPix->value < 128)
|
|
Shinya Kitaoka |
120a6e |
value = troundp(2 * upPix->value * (downPix->value / 255.0));
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
value = 255 * (1 -
|
|
Shinya Kitaoka |
120a6e |
2 * (1.0 - downPix->value / 255.0) *
|
|
Shinya Kitaoka |
120a6e |
(1.0 - upPix->value / 255.0));
|
|
Shinya Kitaoka |
120a6e |
outPix->value = (UCHAR)tcrop<ushort>(value, 0, 255);</ushort>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FOR_EACH_PIXEL_8_END_LOOP
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
throw TRopException("TRop::max invalid raster combination");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TRop::premultiply(const TRasterP &ras) {
|
|
Shinya Kitaoka |
120a6e |
ras->lock();
|
|
Shinya Kitaoka |
120a6e |
TRaster32P ras32 = ras;
|
|
Shinya Kitaoka |
120a6e |
if (ras32) {
|
|
Shinya Kitaoka |
120a6e |
TPixel32 *endPix, *upPix = 0, *upRow = ras32->pixels();
|
|
Shinya Kitaoka |
120a6e |
TPixel32 *lastPix =
|
|
Shinya Kitaoka |
120a6e |
upRow + ras32->getWrap() * (ras32->getLy() - 1) + ras32->getLx();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
while (upPix < lastPix) {
|
|
Shinya Kitaoka |
120a6e |
upPix = upRow;
|
|
Shinya Kitaoka |
120a6e |
endPix = upPix + ras32->getLx();
|
|
Shinya Kitaoka |
120a6e |
while (upPix < endPix) {
|
|
Shinya Kitaoka |
120a6e |
premult(*upPix);
|
|
Shinya Kitaoka |
120a6e |
++upPix;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
upRow += ras32->getWrap();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
TRaster64P ras64 = ras;
|
|
Shinya Kitaoka |
120a6e |
if (ras64) {
|
|
Shinya Kitaoka |
120a6e |
TPixel64 *endPix, *upPix = 0, *upRow = ras64->pixels();
|
|
Shinya Kitaoka |
120a6e |
TPixel64 *lastPix =
|
|
Shinya Kitaoka |
120a6e |
upRow + ras64->getWrap() * (ras64->getLy() - 1) + ras64->getLx();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
while (upPix < lastPix) {
|
|
Shinya Kitaoka |
120a6e |
upPix = upRow;
|
|
Shinya Kitaoka |
120a6e |
endPix = upPix + ras64->getLx();
|
|
Shinya Kitaoka |
120a6e |
while (upPix < endPix) {
|
|
Shinya Kitaoka |
120a6e |
premult(*upPix);
|
|
Shinya Kitaoka |
120a6e |
++upPix;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
upRow += ras64->getWrap();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
ras->unlock();
|
|
Shinya Kitaoka |
120a6e |
throw TException("TRop::premultiply invalid raster type");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
ras->unlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TRop::depremultiply(const TRasterP &ras) {
|
|
Shinya Kitaoka |
120a6e |
ras->lock();
|
|
Shinya Kitaoka |
120a6e |
TRaster32P ras32 = ras;
|
|
Shinya Kitaoka |
120a6e |
if (ras32) {
|
|
Shinya Kitaoka |
120a6e |
TPixel32 *endPix, *upPix = 0, *upRow = ras32->pixels();
|
|
Shinya Kitaoka |
120a6e |
TPixel32 *lastPix =
|
|
Shinya Kitaoka |
120a6e |
upRow + ras32->getWrap() * (ras32->getLy() - 1) + ras32->getLx();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
while (upPix < lastPix) {
|
|
Shinya Kitaoka |
120a6e |
upPix = upRow;
|
|
Shinya Kitaoka |
120a6e |
endPix = upPix + ras32->getLx();
|
|
Shinya Kitaoka |
120a6e |
while (upPix < endPix) {
|
|
Shinya Kitaoka |
120a6e |
depremult(*upPix);
|
|
Shinya Kitaoka |
120a6e |
++upPix;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
upRow += ras32->getWrap();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
TRaster64P ras64 = ras;
|
|
Shinya Kitaoka |
120a6e |
if (ras64) {
|
|
Shinya Kitaoka |
120a6e |
TPixel64 *endPix, *upPix = 0, *upRow = ras64->pixels();
|
|
Shinya Kitaoka |
120a6e |
TPixel64 *lastPix =
|
|
Shinya Kitaoka |
120a6e |
upRow + ras64->getWrap() * (ras64->getLy() - 1) + ras64->getLx();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
while (upPix < lastPix) {
|
|
Shinya Kitaoka |
120a6e |
upPix = upRow;
|
|
Shinya Kitaoka |
120a6e |
endPix = upPix + ras64->getLx();
|
|
Shinya Kitaoka |
120a6e |
while (upPix < endPix) {
|
|
Shinya Kitaoka |
120a6e |
depremult(*upPix);
|
|
Shinya Kitaoka |
120a6e |
++upPix;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
upRow += ras64->getWrap();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
ras->unlock();
|
|
Shinya Kitaoka |
120a6e |
throw TException("TRop::depremultiply invalid raster type");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
ras->unlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TRop::whiteTransp(const TRasterP &ras) {
|
|
Shinya Kitaoka |
120a6e |
ras->lock();
|
|
Shinya Kitaoka |
120a6e |
TRaster32P ras32 = ras;
|
|
Shinya Kitaoka |
120a6e |
if (ras32) {
|
|
Shinya Kitaoka |
120a6e |
TPixel32 *endPix, *upPix = 0, *upRow = ras32->pixels();
|
|
Shinya Kitaoka |
120a6e |
TPixel32 *lastPix =
|
|
Shinya Kitaoka |
120a6e |
upRow + ras32->getWrap() * (ras32->getLy() - 1) + ras32->getLx();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
while (upPix < lastPix) {
|
|
Shinya Kitaoka |
120a6e |
upPix = upRow;
|
|
Shinya Kitaoka |
120a6e |
endPix = upPix + ras32->getLx();
|
|
Shinya Kitaoka |
120a6e |
while (upPix < endPix) {
|
|
Shinya Kitaoka |
120a6e |
if (*upPix == TPixel::White) *upPix = TPixel::Transparent;
|
|
Shinya Kitaoka |
120a6e |
++upPix;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
upRow += ras32->getWrap();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
TRaster64P ras64 = ras;
|
|
Shinya Kitaoka |
120a6e |
if (ras64) {
|
|
Shinya Kitaoka |
120a6e |
TPixel64 *endPix, *upPix = 0, *upRow = ras64->pixels();
|
|
Shinya Kitaoka |
120a6e |
TPixel64 *lastPix =
|
|
Shinya Kitaoka |
120a6e |
upRow + ras64->getWrap() * (ras64->getLy() - 1) + ras64->getLx();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
while (upPix < lastPix) {
|
|
Shinya Kitaoka |
120a6e |
upPix = upRow;
|
|
Shinya Kitaoka |
120a6e |
endPix = upPix + ras64->getLx();
|
|
Shinya Kitaoka |
120a6e |
while (upPix < endPix) {
|
|
Shinya Kitaoka |
120a6e |
if (*upPix == TPixel64::White) *upPix = TPixel64::Transparent;
|
|
Shinya Kitaoka |
120a6e |
++upPix;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
upRow += ras64->getWrap();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
ras->unlock();
|
|
Shinya Kitaoka |
120a6e |
throw TException("TRop::premultiply invalid raster type");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
ras->unlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename chan=""></typename>
|
|
Shinya Kitaoka |
120a6e |
const double *premultiplyTable() {
|
|
Shinya Kitaoka |
120a6e |
static double *table = 0;
|
|
Shinya Kitaoka |
120a6e |
if (!table) {
|
|
Shinya Kitaoka |
120a6e |
int maxChannelValue = (std::numeric_limits<chan>::max)();</chan>
|
|
Shinya Kitaoka |
120a6e |
int chanValuesCount = maxChannelValue + 1;
|
|
Shinya Kitaoka |
120a6e |
double maxD = maxChannelValue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
table = new double[chanValuesCount];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < chanValuesCount; ++i) table[i] = i / maxD;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
return table;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template DVAPI const double *premultiplyTable<uchar>();</uchar>
|
|
Toshihiro Shimizu |
890ddd |
template DVAPI const double *premultiplyTable<ushort>();</ushort>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename chan=""></typename>
|
|
Shinya Kitaoka |
120a6e |
const double *depremultiplyTable() {
|
|
Shinya Kitaoka |
120a6e |
static double *table = 0;
|
|
Shinya Kitaoka |
120a6e |
if (!table) {
|
|
Shinya Kitaoka |
120a6e |
int maxChannelValue = (std::numeric_limits<chan>::max)();</chan>
|
|
Shinya Kitaoka |
120a6e |
int chanValuesCount = maxChannelValue + 1;
|
|
Shinya Kitaoka |
120a6e |
double maxD = maxChannelValue;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
table = new double[chanValuesCount];
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
table[0] = 0.0;
|
|
Shinya Kitaoka |
120a6e |
for (int i = 1; i < chanValuesCount; ++i) table[i] = maxD / i;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
return table;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template DVAPI const double *depremultiplyTable<uchar>();</uchar>
|
|
Toshihiro Shimizu |
890ddd |
template DVAPI const double *depremultiplyTable<ushort>();</ushort>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#undef FOR_EACH_PIXEL_BEGIN_LOOP
|
|
Toshihiro Shimizu |
890ddd |
#undef FOR_EACH_PIXEL_32_BEGIN_LOOP
|
|
Toshihiro Shimizu |
890ddd |
#undef FOR_EACH_PIXEL_64_BEGIN_LOOP
|
|
Toshihiro Shimizu |
890ddd |
#undef FOR_EACH_PIXEL_8_BEGIN_LOOP
|
|
Toshihiro Shimizu |
890ddd |
#undef FOR_EACH_PIXEL_END_LOOP
|
|
Toshihiro Shimizu |
890ddd |
#undef FOR_EACH_PIXEL_32_END_LOOP
|
|
Toshihiro Shimizu |
890ddd |
#undef FOR_EACH_PIXEL_64_END_LOOP
|
|
Toshihiro Shimizu |
890ddd |
#undef FOR_EACH_PIXEL_8_END_LOOP
|