|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "trop.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzCore includes
|
|
Toshihiro Shimizu |
890ddd |
#include "tpixelgr.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "trandom.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tpixelutils.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//******************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// Conversion functions
|
|
Toshihiro Shimizu |
890ddd |
//******************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Campbell Barton |
8c6c57 |
static void do_convert(const TRaster64P &dst, const TRaster32P &src) {
|
|
Shinya Kitaoka |
120a6e |
assert(dst->getSize() == src->getSize());
|
|
Shinya Kitaoka |
120a6e |
int lx = src->getLx();
|
|
Shinya Kitaoka |
120a6e |
for (int y = 0; y < src->getLy(); y++) {
|
|
Shinya Kitaoka |
120a6e |
TPixel64 *outPix = dst->pixels(y);
|
|
Shinya Kitaoka |
120a6e |
TPixel32 *inPix = src->pixels(y);
|
|
Shinya Kitaoka |
120a6e |
TPixel32 *inEndPix = inPix + lx;
|
|
Shinya Kitaoka |
120a6e |
for (; inPix < inEndPix; ++outPix, ++inPix) {
|
|
Shinya Kitaoka |
120a6e |
outPix->r = ushortFromByte(inPix->r);
|
|
Shinya Kitaoka |
120a6e |
outPix->g = ushortFromByte(inPix->g);
|
|
Shinya Kitaoka |
120a6e |
outPix->b = ushortFromByte(inPix->b);
|
|
Shinya Kitaoka |
120a6e |
outPix->m = ushortFromByte(inPix->m);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Campbell Barton |
8c6c57 |
static void do_convert(const TRasterGR8P &dst, const TRaster32P &src) {
|
|
Shinya Kitaoka |
120a6e |
assert(dst->getSize() == src->getSize());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int lx = src->getLx();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
for (int y = 0; y < src->getLy(); ++y) {
|
|
Shinya Kitaoka |
120a6e |
TPixelGR8 *outPix = dst->pixels(y);
|
|
Shinya Kitaoka |
120a6e |
TPixel32 *inPix = src->pixels(y), *inEndPix = inPix + lx;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
for (; inPix < inEndPix; ++outPix, ++inPix)
|
|
Shinya Kitaoka |
120a6e |
*outPix = TPixelGR8::from(overPix(TPixel32::White, *inPix));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Campbell Barton |
8c6c57 |
static void do_convert(const TRasterGR16P &dst, const TRaster32P &src) {
|
|
Shinya Kitaoka |
120a6e |
assert(dst->getSize() == src->getSize());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int lx = src->getLx();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
for (int y = 0; y < src->getLy(); ++y) {
|
|
Shinya Kitaoka |
120a6e |
TPixelGR16 *outPix = dst->pixels(y);
|
|
Shinya Kitaoka |
120a6e |
TPixel32 *inPix = src->pixels(y), *inEndPix = inPix + lx;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
for (; inPix < inEndPix; ++outPix, ++inPix)
|
|
Shinya Kitaoka |
120a6e |
outPix->value =
|
|
Shinya Kitaoka |
120a6e |
257 * (TPixelGR8::from(overPix(TPixel32::White, *inPix))).value;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Campbell Barton |
8c6c57 |
static void do_convert(const TRasterGR16P &dst, const TRaster64P &src) {
|
|
Shinya Kitaoka |
120a6e |
assert(dst->getSize() == src->getSize());
|
|
Shinya Kitaoka |
120a6e |
int lx = src->getLx();
|
|
Shinya Kitaoka |
120a6e |
for (int y = 0; y < src->getLy(); y++) {
|
|
Shinya Kitaoka |
120a6e |
TPixelGR16 *outPix = dst->pixels(y);
|
|
Shinya Kitaoka |
120a6e |
TPixel64 *inPix = src->pixels(y);
|
|
Shinya Kitaoka |
120a6e |
TPixel64 *inEndPix = inPix + lx;
|
|
Shinya Kitaoka |
120a6e |
while (inPix < inEndPix) {
|
|
Shinya Kitaoka |
120a6e |
outPix->value = (inPix->r + 2 * inPix->g + inPix->b) >> 2;
|
|
Shinya Kitaoka |
120a6e |
outPix++;
|
|
Shinya Kitaoka |
120a6e |
inPix++;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Campbell Barton |
8c6c57 |
static void do_convert(const TRaster32P &dst, const TRasterGR8P &src) {
|
|
Shinya Kitaoka |
120a6e |
assert(dst->getSize() == src->getSize());
|
|
Shinya Kitaoka |
120a6e |
int lx = src->getLx();
|
|
Shinya Kitaoka |
120a6e |
for (int y = 0; y < src->getLy(); y++) {
|
|
Shinya Kitaoka |
120a6e |
TPixel32 *outPix = dst->pixels(y);
|
|
Shinya Kitaoka |
120a6e |
TPixelGR8 *inPix = src->pixels(y);
|
|
Shinya Kitaoka |
120a6e |
TPixelGR8 *inEndPix = inPix + lx;
|
|
Shinya Kitaoka |
120a6e |
while (inPix < inEndPix) {
|
|
Shinya Kitaoka |
120a6e |
outPix->r = inPix->value;
|
|
Shinya Kitaoka |
120a6e |
outPix->g = inPix->value;
|
|
Shinya Kitaoka |
120a6e |
outPix->b = inPix->value;
|
|
Shinya Kitaoka |
120a6e |
outPix->m = 0xff;
|
|
Shinya Kitaoka |
120a6e |
outPix++;
|
|
Shinya Kitaoka |
120a6e |
inPix++;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define USHORT2BYTE_MAGICFAC (256U * 255U + 1U)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
inline UCHAR ditherUcharFromUshort(USHORT in, UINT rndNum) {
|
|
Shinya Kitaoka |
120a6e |
return ((((in * USHORT2BYTE_MAGICFAC) - ((in * USHORT2BYTE_MAGICFAC) >> 24)) +
|
|
Shinya Kitaoka |
120a6e |
rndNum) >>
|
|
Shinya Kitaoka |
120a6e |
24);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
inline void ditherRgbmFromRgbm64(TPixel32 &out, const TPixel64 &in,
|
|
Shinya Kitaoka |
120a6e |
TRandom &rnd) {
|
|
Shinya Kitaoka |
120a6e |
UINT randomRound;
|
|
Shinya Kitaoka |
120a6e |
randomRound = rnd.getUInt() & ((1U << 24) - 1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
out.r = ditherUcharFromUshort(in.r, randomRound);
|
|
Shinya Kitaoka |
120a6e |
out.g = ditherUcharFromUshort(in.g, randomRound);
|
|
Shinya Kitaoka |
120a6e |
out.b = ditherUcharFromUshort(in.b, randomRound);
|
|
Shinya Kitaoka |
120a6e |
out.m = ditherUcharFromUshort(in.m, randomRound);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
inline void ditherConvert(TRaster64P inRas, TRaster32P outRas) {
|
|
Shinya Kitaoka |
120a6e |
int inWrap = inRas->getWrap();
|
|
Shinya Kitaoka |
120a6e |
int outWrap = outRas->getWrap();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TPixel64 *inPix = 0, *inRow = inRas->pixels();
|
|
Shinya Kitaoka |
120a6e |
TPixel32 *outPix, *outRow = outRas->pixels();
|
|
Shinya Kitaoka |
120a6e |
TPixel64 *endPix;
|
|
Shinya Kitaoka |
120a6e |
int inLx = inRas->getLx();
|
|
Shinya Kitaoka |
120a6e |
TPixel64 *lastPix = inRow + inWrap * (inRas->getLy() - 1) + inLx;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TRandom rnd(130266);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
while (inPix < lastPix) {
|
|
Shinya Kitaoka |
120a6e |
inPix = inRow;
|
|
Shinya Kitaoka |
120a6e |
outPix = outRow;
|
|
Shinya Kitaoka |
120a6e |
endPix = inPix + inLx;
|
|
Shinya Kitaoka |
120a6e |
while (inPix < endPix) {
|
|
Shinya Kitaoka |
120a6e |
ditherRgbmFromRgbm64(*outPix, *inPix, rnd);
|
|
Shinya Kitaoka |
120a6e |
inPix++;
|
|
Shinya Kitaoka |
120a6e |
outPix++;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
inRow += inWrap;
|
|
Shinya Kitaoka |
120a6e |
outRow += outWrap;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//******************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// Obsolete conversion functions
|
|
Toshihiro Shimizu |
890ddd |
//******************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Campbell Barton |
8c6c57 |
static void do_convert(const TRasterCM32P &dst, const TRasterGR8P &src) {
|
|
Shinya Kitaoka |
120a6e |
assert(dst->getSize() == src->getSize());
|
|
Shinya Kitaoka |
120a6e |
TPixelCM32 bg = TPixelCM32(0, 0, TPixelCM32::getMaxTone());
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int lx = src->getLx();
|
|
Shinya Kitaoka |
120a6e |
for (int y = 0; y < src->getLy(); y++) {
|
|
Shinya Kitaoka |
120a6e |
TPixelCM32 *outPix = dst->pixels(y);
|
|
Shinya Kitaoka |
120a6e |
TPixelGR8 *inPix = src->pixels(y);
|
|
Shinya Kitaoka |
120a6e |
TPixelGR8 *inEndPix = inPix + lx;
|
|
Shinya Kitaoka |
120a6e |
while (inPix < inEndPix) {
|
|
Shinya Kitaoka |
120a6e |
*outPix = (inPix->value == 255) ? bg : TPixelCM32(1, 0, inPix->value);
|
|
Shinya Kitaoka |
120a6e |
outPix++;
|
|
Shinya Kitaoka |
120a6e |
inPix++;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Campbell Barton |
8c6c57 |
static void do_convert(const TRasterCM32P &dst, const TRaster32P &src) {
|
|
Shinya Kitaoka |
120a6e |
assert(dst->getSize() == src->getSize());
|
|
Shinya Kitaoka |
120a6e |
TPixelCM32 bg = TPixelCM32(0, 0, TPixelCM32::getMaxTone());
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int lx = src->getLx();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
bool isOverlay = false;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
for (int y = 0; y < src->getLy(); y++) // if it is an overlay, I use the
|
|
Shinya Kitaoka |
120a6e |
// matte value for inks, otherwise I
|
|
Shinya Kitaoka |
120a6e |
// use the brightness.
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
TPixel32 *inPix = src->pixels(y);
|
|
Shinya Kitaoka |
120a6e |
TPixel32 *inEndPix = inPix + lx;
|
|
Shinya Kitaoka |
120a6e |
while (inPix < inEndPix) {
|
|
Shinya Kitaoka |
120a6e |
if (inPix->m != 255) {
|
|
Shinya Kitaoka |
120a6e |
isOverlay = true;
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
inPix++;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (isOverlay) break;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (isOverlay)
|
|
Shinya Kitaoka |
120a6e |
for (int y = 0; y < src->getLy(); y++) {
|
|
Shinya Kitaoka |
120a6e |
TPixelCM32 *outPix = dst->pixels(y);
|
|
Shinya Kitaoka |
120a6e |
TPixel32 *inPix = src->pixels(y);
|
|
Shinya Kitaoka |
120a6e |
TPixel32 *inEndPix = inPix + lx;
|
|
Shinya Kitaoka |
120a6e |
while (inPix < inEndPix) {
|
|
Shinya Kitaoka |
120a6e |
*outPix = (inPix->m == 0) ? bg : TPixelCM32(1, 0, 255 - inPix->m);
|
|
Shinya Kitaoka |
120a6e |
outPix++;
|
|
Shinya Kitaoka |
120a6e |
inPix++;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
for (int y = 0; y < src->getLy(); y++) {
|
|
Shinya Kitaoka |
120a6e |
TPixelCM32 *outPix = dst->pixels(y);
|
|
Shinya Kitaoka |
120a6e |
TPixel32 *inPix = src->pixels(y);
|
|
Shinya Kitaoka |
120a6e |
TPixel32 *inEndPix = inPix + lx;
|
|
Shinya Kitaoka |
120a6e |
while (inPix < inEndPix) {
|
|
Shinya Kitaoka |
120a6e |
UCHAR val = TPixelGR8::from(*inPix).value;
|
|
Shinya Kitaoka |
120a6e |
*outPix = (val == 255) ? bg : TPixelCM32(1, 0, val);
|
|
Shinya Kitaoka |
120a6e |
outPix++;
|
|
Shinya Kitaoka |
120a6e |
inPix++;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Campbell Barton |
8c6c57 |
static void do_convert(const TRasterYUV422P &dst, const TRaster32P &src) {
|
|
Shinya Kitaoka |
120a6e |
assert(src->getLx() & 0);
|
|
Shinya Kitaoka |
120a6e |
long y1, y2, u, v, u1, u2, v1, v2;
|
|
Shinya Kitaoka |
120a6e |
TPixel32 *pix = (TPixel32 *)src->pixels();
|
|
Shinya Kitaoka |
120a6e |
TPixel32 *lastPix = &(src->pixels(src->getLy() - 1)[src->getLx() - 1]);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
UCHAR *out = dst->getRawData();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
while (pix < lastPix) {
|
|
Shinya Kitaoka |
120a6e |
/* first pixel gives Y and 0.5 of chroma */
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
y1 = 16829 * pix->r + 33039 * pix->g + 6416 * pix->b;
|
|
Shinya Kitaoka |
120a6e |
u1 = -4831 * pix->r + -9488 * pix->g + 14319 * pix->b;
|
|
Shinya Kitaoka |
120a6e |
v1 = 14322 * pix->r + -11992 * pix->g + -2330 * pix->b;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/* second pixel gives Y and 0.5 of chroma */
|
|
Shinya Kitaoka |
120a6e |
++pix;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
y2 = 16829 * pix->r + 33039 * pix->g + 6416 * pix->b;
|
|
Shinya Kitaoka |
120a6e |
u2 = -4831 * pix->r + -9488 * pix->g + 14319 * pix->b;
|
|
Shinya Kitaoka |
120a6e |
v2 = 14322 * pix->r + -11992 * pix->g + -2330 * pix->b;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/* average the chroma */
|
|
Shinya Kitaoka |
120a6e |
u = u1 + u2;
|
|
Shinya Kitaoka |
120a6e |
v = v1 + v2;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/* round the chroma */
|
|
Shinya Kitaoka |
120a6e |
u1 = (u + 0x008000) >> 16;
|
|
Shinya Kitaoka |
120a6e |
v1 = (v + 0x008000) >> 16;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/* limit the chroma */
|
|
Shinya Kitaoka |
120a6e |
if (u1 < -112) u1 = -112;
|
|
shun-iwasawa |
481b59 |
if (u1 > 111) u1 = 111;
|
|
Shinya Kitaoka |
120a6e |
if (v1 < -112) v1 = -112;
|
|
shun-iwasawa |
481b59 |
if (v1 > 111) v1 = 111;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/* limit the lum */
|
|
Shinya Kitaoka |
120a6e |
if (y1 > 0x00dbffff) y1 = 0x00dbffff;
|
|
Shinya Kitaoka |
120a6e |
if (y2 > 0x00dbffff) y2 = 0x00dbffff;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/* save the results */
|
|
Shinya Kitaoka |
120a6e |
*out++ = (UCHAR)(u1 + 128);
|
|
Shinya Kitaoka |
120a6e |
*out++ = (UCHAR)((y1 >> 16) + 16);
|
|
Shinya Kitaoka |
120a6e |
*out++ = (UCHAR)(v1 + 128);
|
|
Shinya Kitaoka |
120a6e |
*out++ = (UCHAR)((y2 >> 16) + 16);
|
|
Shinya Kitaoka |
120a6e |
++pix;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Campbell Barton |
8c6c57 |
static void do_convert(const TRaster32P &dst, const TRasterYUV422P &src) {
|
|
Shinya Kitaoka |
120a6e |
int long r, g, b, y1, y2, u, v;
|
|
Shinya Kitaoka |
120a6e |
TPixel32 *buf = dst->pixels();
|
|
Shinya Kitaoka |
120a6e |
const UCHAR *in = src->getRawData();
|
|
Shinya Kitaoka |
120a6e |
const UCHAR *last = in + src->getRowSize() * src->getLy() - 1;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
while (in < last) {
|
|
Shinya Kitaoka |
120a6e |
u = *in;
|
|
Shinya Kitaoka |
120a6e |
u -= 128;
|
|
Shinya Kitaoka |
120a6e |
in++;
|
|
Shinya Kitaoka |
120a6e |
y1 = *in;
|
|
Shinya Kitaoka |
120a6e |
y1 -= 16;
|
|
Shinya Kitaoka |
120a6e |
in++;
|
|
Shinya Kitaoka |
120a6e |
v = *in;
|
|
Shinya Kitaoka |
120a6e |
v -= 128;
|
|
Shinya Kitaoka |
120a6e |
in++;
|
|
Shinya Kitaoka |
120a6e |
y2 = *in;
|
|
Shinya Kitaoka |
120a6e |
y2 -= 16;
|
|
Shinya Kitaoka |
120a6e |
in++;
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
481b59 |
r = 76310 * y1 + 104635 * v;
|
|
Shinya Kitaoka |
120a6e |
if (r > 0xFFFFFF) r = 0xFFFFFF;
|
|
shun-iwasawa |
481b59 |
if (r <= 0xFFFF) r = 0;
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
481b59 |
g = 76310 * y1 + -25690 * u + -53294 * v;
|
|
Shinya Kitaoka |
120a6e |
if (g > 0xFFFFFF) g = 0xFFFFFF;
|
|
shun-iwasawa |
481b59 |
if (g <= 0xFFFF) g = 0;
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
481b59 |
b = 76310 * y1 + 132278 * u;
|
|
Shinya Kitaoka |
120a6e |
if (b > 0xFFFFFF) b = 0xFFFFFF;
|
|
shun-iwasawa |
481b59 |
if (b <= 0xFFFF) b = 0;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
buf->r = (UCHAR)(r >> 16);
|
|
Shinya Kitaoka |
120a6e |
buf->g = (UCHAR)(g >> 16);
|
|
Shinya Kitaoka |
120a6e |
buf->b = (UCHAR)(b >> 16);
|
|
Shinya Kitaoka |
120a6e |
buf->m = (UCHAR)255;
|
|
Shinya Kitaoka |
120a6e |
buf++;
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
481b59 |
r = 76310 * y2 + 104635 * v;
|
|
Shinya Kitaoka |
120a6e |
if (r > 0xFFFFFF) r = 0xFFFFFF;
|
|
shun-iwasawa |
481b59 |
if (r <= 0xFFFF) r = 0;
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
481b59 |
g = 76310 * y2 + -25690 * u + -53294 * v;
|
|
Shinya Kitaoka |
120a6e |
if (g > 0xFFFFFF) g = 0xFFFFFF;
|
|
shun-iwasawa |
481b59 |
if (g <= 0xFFFF) g = 0;
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
481b59 |
b = 76310 * y2 + 132278 * u;
|
|
Shinya Kitaoka |
120a6e |
if (b > 0xFFFFFF) b = 0xFFFFFF;
|
|
shun-iwasawa |
481b59 |
if (b <= 0xFFFF) b = 0;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
buf->r = (UCHAR)(r >> 16);
|
|
Shinya Kitaoka |
120a6e |
buf->g = (UCHAR)(g >> 16);
|
|
Shinya Kitaoka |
120a6e |
buf->b = (UCHAR)(b >> 16);
|
|
Shinya Kitaoka |
120a6e |
buf->m = (UCHAR)255;
|
|
Shinya Kitaoka |
120a6e |
buf++;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//******************************************************************
|
|
shun-iwasawa |
481b59 |
// Conversion from/to double raster
|
|
shun-iwasawa |
481b59 |
//******************************************************************
|
|
shun-iwasawa |
481b59 |
|
|
shun-iwasawa |
481b59 |
static void do_convert(const TRasterFP &dst, const TRaster32P &src) {
|
|
shun-iwasawa |
481b59 |
assert(dst->getSize() == src->getSize());
|
|
shun-iwasawa |
481b59 |
int lx = src->getLx();
|
|
shun-iwasawa |
481b59 |
for (int y = 0; y < src->getLy(); y++) {
|
|
shun-iwasawa |
481b59 |
TPixelF *outPix = dst->pixels(y);
|
|
shun-iwasawa |
481b59 |
TPixel32 *inPix = src->pixels(y);
|
|
shun-iwasawa |
481b59 |
TPixel32 *inEndPix = inPix + lx;
|
|
shun-iwasawa |
481b59 |
for (; inPix < inEndPix; ++outPix, ++inPix) {
|
|
shun-iwasawa |
481b59 |
outPix->r = (float)inPix->r / (float)TPixel32::maxChannelValue;
|
|
shun-iwasawa |
481b59 |
outPix->g = (float)inPix->g / (float)TPixel32::maxChannelValue;
|
|
shun-iwasawa |
481b59 |
outPix->b = (float)inPix->b / (float)TPixel32::maxChannelValue;
|
|
shun-iwasawa |
481b59 |
outPix->m = (float)inPix->m / (float)TPixel32::maxChannelValue;
|
|
shun-iwasawa |
481b59 |
}
|
|
shun-iwasawa |
481b59 |
}
|
|
shun-iwasawa |
481b59 |
}
|
|
shun-iwasawa |
481b59 |
|
|
shun-iwasawa |
481b59 |
//-----------------------------------------------------------------------------
|
|
shun-iwasawa |
481b59 |
|
|
shun-iwasawa |
481b59 |
static void do_convert(const TRasterFP &dst, const TRaster64P &src) {
|
|
shun-iwasawa |
481b59 |
assert(dst->getSize() == src->getSize());
|
|
shun-iwasawa |
481b59 |
int lx = src->getLx();
|
|
shun-iwasawa |
481b59 |
for (int y = 0; y < src->getLy(); y++) {
|
|
shun-iwasawa |
481b59 |
TPixelF *outPix = dst->pixels(y);
|
|
shun-iwasawa |
481b59 |
TPixel64 *inPix = src->pixels(y);
|
|
shun-iwasawa |
481b59 |
TPixel64 *inEndPix = inPix + lx;
|
|
shun-iwasawa |
481b59 |
for (; inPix < inEndPix; ++outPix, ++inPix) {
|
|
shun-iwasawa |
481b59 |
outPix->r = (float)inPix->r / (float)TPixel64::maxChannelValue;
|
|
shun-iwasawa |
481b59 |
outPix->g = (float)inPix->g / (float)TPixel64::maxChannelValue;
|
|
shun-iwasawa |
481b59 |
outPix->b = (float)inPix->b / (float)TPixel64::maxChannelValue;
|
|
shun-iwasawa |
481b59 |
outPix->m = (float)inPix->m / (float)TPixel64::maxChannelValue;
|
|
shun-iwasawa |
481b59 |
}
|
|
shun-iwasawa |
481b59 |
}
|
|
shun-iwasawa |
481b59 |
}
|
|
shun-iwasawa |
481b59 |
|
|
shun-iwasawa |
481b59 |
//-----------------------------------------------------------------------------
|
|
shun-iwasawa |
481b59 |
|
|
shun-iwasawa |
481b59 |
static void do_convert(const TRaster32P &dst, const TRasterFP &src) {
|
|
shun-iwasawa |
481b59 |
auto clamp01 = [](float val) {
|
|
shun-iwasawa |
481b59 |
return (val < 0.f) ? 0.f : (val > 1.f) ? 1.f : val;
|
|
shun-iwasawa |
481b59 |
};
|
|
shun-iwasawa |
481b59 |
assert(dst->getSize() == src->getSize());
|
|
shun-iwasawa |
481b59 |
int lx = src->getLx();
|
|
shun-iwasawa |
481b59 |
for (int y = 0; y < src->getLy(); y++) {
|
|
shun-iwasawa |
481b59 |
TPixel32 *outPix = dst->pixels(y);
|
|
shun-iwasawa |
481b59 |
TPixelF *inPix = src->pixels(y);
|
|
shun-iwasawa |
481b59 |
TPixelF *inEndPix = inPix + lx;
|
|
shun-iwasawa |
481b59 |
for (; inPix < inEndPix; ++outPix, ++inPix) {
|
|
shun-iwasawa |
481b59 |
outPix->r = (TPixel32::Channel)(
|
|
shun-iwasawa |
481b59 |
clamp01(inPix->r) * (float)TPixel32::maxChannelValue + 0.5f);
|
|
shun-iwasawa |
481b59 |
outPix->g = (TPixel32::Channel)(
|
|
shun-iwasawa |
481b59 |
clamp01(inPix->g) * (float)TPixel32::maxChannelValue + 0.5f);
|
|
shun-iwasawa |
481b59 |
outPix->b = (TPixel32::Channel)(
|
|
shun-iwasawa |
481b59 |
clamp01(inPix->b) * (float)TPixel32::maxChannelValue + 0.5f);
|
|
shun-iwasawa |
481b59 |
outPix->m = (TPixel32::Channel)(
|
|
shun-iwasawa |
481b59 |
clamp01(inPix->m) * (float)TPixel32::maxChannelValue + 0.5f);
|
|
shun-iwasawa |
481b59 |
}
|
|
shun-iwasawa |
481b59 |
}
|
|
shun-iwasawa |
481b59 |
}
|
|
shun-iwasawa |
481b59 |
|
|
shun-iwasawa |
481b59 |
//-----------------------------------------------------------------------------
|
|
shun-iwasawa |
481b59 |
|
|
shun-iwasawa |
481b59 |
static void do_convert(const TRaster64P &dst, const TRasterFP &src) {
|
|
shun-iwasawa |
481b59 |
auto clamp01 = [](float val) {
|
|
shun-iwasawa |
481b59 |
return (val < 0.f) ? 0.f : (val > 1.f) ? 1.f : val;
|
|
shun-iwasawa |
481b59 |
};
|
|
shun-iwasawa |
481b59 |
assert(dst->getSize() == src->getSize());
|
|
shun-iwasawa |
481b59 |
int lx = src->getLx();
|
|
shun-iwasawa |
481b59 |
for (int y = 0; y < src->getLy(); y++) {
|
|
shun-iwasawa |
481b59 |
TPixel64 *outPix = dst->pixels(y);
|
|
shun-iwasawa |
481b59 |
TPixelF *inPix = src->pixels(y);
|
|
shun-iwasawa |
481b59 |
TPixelF *inEndPix = inPix + lx;
|
|
shun-iwasawa |
481b59 |
for (; inPix < inEndPix; ++outPix, ++inPix) {
|
|
shun-iwasawa |
481b59 |
outPix->r = (TPixel64::Channel)(
|
|
shun-iwasawa |
481b59 |
clamp01(inPix->r) * (float)TPixel64::maxChannelValue + 0.5f);
|
|
shun-iwasawa |
481b59 |
outPix->g = (TPixel64::Channel)(
|
|
shun-iwasawa |
481b59 |
clamp01(inPix->g) * (float)TPixel64::maxChannelValue + 0.5f);
|
|
shun-iwasawa |
481b59 |
outPix->b = (TPixel64::Channel)(
|
|
shun-iwasawa |
481b59 |
clamp01(inPix->b) * (float)TPixel64::maxChannelValue + 0.5f);
|
|
shun-iwasawa |
481b59 |
outPix->m = (TPixel64::Channel)(
|
|
shun-iwasawa |
481b59 |
clamp01(inPix->m) * (float)TPixel64::maxChannelValue + 0.5f);
|
|
shun-iwasawa |
481b59 |
}
|
|
shun-iwasawa |
481b59 |
}
|
|
shun-iwasawa |
481b59 |
}
|
|
shun-iwasawa |
481b59 |
|
|
shun-iwasawa |
481b59 |
//******************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// Main conversion function
|
|
Toshihiro Shimizu |
890ddd |
//******************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TRop::convert(TRasterP dst, const TRasterP &src) {
|
|
Shinya Kitaoka |
120a6e |
if (dst->getSize() != src->getSize())
|
|
Shinya Kitaoka |
120a6e |
throw TRopException("convert: size mismatch");
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
481b59 |
TRaster32P dst32 = dst;
|
|
shun-iwasawa |
481b59 |
TRasterGR8P dst8 = dst;
|
|
shun-iwasawa |
481b59 |
TRasterGR16P dst16 = dst;
|
|
shun-iwasawa |
481b59 |
TRaster64P dst64 = dst;
|
|
shun-iwasawa |
481b59 |
TRasterCM32P dstCm = dst;
|
|
shun-iwasawa |
481b59 |
TRasterYUV422P dstYUV = dst;
|
|
shun-iwasawa |
481b59 |
TRasterFP dstF = dst;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TRaster32P src32 = src;
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P src8 = src;
|
|
Shinya Kitaoka |
120a6e |
TRaster64P src64 = src;
|
|
Shinya Kitaoka |
120a6e |
TRasterYUV422P srcYUV = src;
|
|
shun-iwasawa |
481b59 |
TRasterFP srcF = src;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
src->lock();
|
|
Shinya Kitaoka |
120a6e |
dst->lock();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (dst64 && src32)
|
|
Shinya Kitaoka |
120a6e |
do_convert(dst64, src32);
|
|
Shinya Kitaoka |
120a6e |
else if (dst8 && src32)
|
|
Shinya Kitaoka |
120a6e |
do_convert(dst8, src32);
|
|
Shinya Kitaoka |
120a6e |
else if (dst16 && src32)
|
|
Shinya Kitaoka |
120a6e |
do_convert(dst16, src32);
|
|
Shinya Kitaoka |
120a6e |
else if (dst32 && src64)
|
|
Shinya Kitaoka |
120a6e |
ditherConvert(src64, dst32);
|
|
Shinya Kitaoka |
120a6e |
else if (dst16 && src64)
|
|
Shinya Kitaoka |
120a6e |
do_convert(dst16, src64);
|
|
Shinya Kitaoka |
120a6e |
else if (dst32 && src8)
|
|
Shinya Kitaoka |
120a6e |
do_convert(dst32, src8);
|
|
Shinya Kitaoka |
120a6e |
else if (dstYUV && src32)
|
|
Shinya Kitaoka |
120a6e |
do_convert(dstYUV, src32); // Obsolete conversions
|
|
Shinya Kitaoka |
120a6e |
else if (dst32 && srcYUV)
|
|
Shinya Kitaoka |
120a6e |
do_convert(dst32, srcYUV); //
|
|
Shinya Kitaoka |
120a6e |
else if (dstCm && src32)
|
|
Shinya Kitaoka |
120a6e |
do_convert(dstCm, src32); //
|
|
Shinya Kitaoka |
120a6e |
else if (dstCm && src8)
|
|
Shinya Kitaoka |
120a6e |
do_convert(dstCm, src8); //
|
|
shun-iwasawa |
481b59 |
// conversion from/to double
|
|
shun-iwasawa |
481b59 |
else if (dstF && src32)
|
|
shun-iwasawa |
481b59 |
do_convert(dstF, src32);
|
|
shun-iwasawa |
481b59 |
else if (dstF && src64)
|
|
shun-iwasawa |
481b59 |
do_convert(dstF, src64);
|
|
shun-iwasawa |
481b59 |
else if (dst32 && srcF)
|
|
shun-iwasawa |
481b59 |
do_convert(dst32, srcF);
|
|
shun-iwasawa |
481b59 |
else if (dst64 && srcF)
|
|
shun-iwasawa |
481b59 |
do_convert(dst64, srcF);
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
dst->unlock();
|
|
Shinya Kitaoka |
120a6e |
src->unlock();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
throw TRopException("unsupported pixel type");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
481b59 |
dst->setLinear(src->isLinear());
|
|
Shinya Kitaoka |
120a6e |
dst->unlock();
|
|
Shinya Kitaoka |
120a6e |
src->unlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|