|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#if _MSC_VER >= 1400
|
|
Toshihiro Shimizu |
890ddd |
#define _CRT_SECURE_NO_DEPRECATE 1
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// STColSelPic.h: interface for the CSTColSelPic class.
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//////////////////////////////////////////////////////////////////////
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#if !defined(AFX_STCOLSELPIC_H__80D708B0_FCA2_11D5_B949_0040F674BE6A__INCLUDED_)
|
|
Toshihiro Shimizu |
890ddd |
#define AFX_STCOLSELPIC_H__80D708B0_FCA2_11D5_B949_0040F674BE6A__INCLUDED_
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#if _MSC_VER > 1000
|
|
Toshihiro Shimizu |
890ddd |
#pragma once
|
|
Toshihiro Shimizu |
890ddd |
#endif // _MSC_VER > 1000
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef WIN32
|
|
Toshihiro Shimizu |
890ddd |
#pragma warning(disable : 4996)
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
#include <streambuf></streambuf>
|
|
Toshihiro Shimizu |
890ddd |
#include <vector></vector>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <math.h></math.h>
|
|
Toshihiro Shimizu |
890ddd |
#include <memory.h></memory.h>
|
|
Toshihiro Shimizu |
890ddd |
#include "YOMBInputParam.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "STPic.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "SDef.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "CIL.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "SError.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
using namespace std;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class p=""></class>
|
|
Toshihiro Shimizu |
890ddd |
class CSTColSelPic : public CSTPic
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *m_sel;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CSTColSelPic() : CSTPic(), m_sel(0){};
|
|
Toshihiro Shimizu |
890ddd |
virtual ~CSTColSelPic()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_sel) {
|
|
Toshihiro Shimizu |
890ddd |
delete[] m_sel, m_sel = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void nullSel()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_sel) {
|
|
Toshihiro Shimizu |
890ddd |
delete[] m_sel;
|
|
Toshihiro Shimizu |
890ddd |
m_sel = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void initSel() //throw(SMemAllocError)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
nullSel();
|
|
Toshihiro Shimizu |
890ddd |
if (CSTPic::m_lX > 0 && CSTPic ::m_lY > 0) {
|
|
Toshihiro Shimizu |
890ddd |
m_sel = new UCHAR[CSTPic::m_lX * CSTPic ::m_lY];
|
|
Toshihiro Shimizu |
890ddd |
if (!m_sel)
|
|
Toshihiro Shimizu |
890ddd |
throw SMemAllocError(" in initColorSelection");
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
char s[200];
|
|
Toshihiro Shimizu |
890ddd |
sprintf(s, " in initColorSelection lXY=(%d,%d)\n", CSTPic::m_lX, CSTPic ::m_lY);
|
|
Toshihiro Shimizu |
890ddd |
throw SMemAllocError(s);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void copySel(const UCHAR *sel)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
memcpy(m_sel, sel, CSTPic::m_lX * CSTPic ::m_lY * sizeof(UCHAR));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void copySel(const UCHAR sel)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
memset(m_sel, sel, CSTPic::m_lX * CSTPic ::m_lY * sizeof(UCHAR));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CSTColSelPic(const CSTColSelPic &csp) /*throw(SMemAllocError) */
|
|
Toshihiro Shimizu |
890ddd |
: CSTPic(csp)
|
|
Toshihiro Shimizu |
890ddd |
/* , m_sel(0) */
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
try {
|
|
Toshihiro Shimizu |
890ddd |
if ( csp.m_sel && m_lX>0 m_lY>0) {
|
|
Toshihiro Shimizu |
890ddd |
initSel();
|
|
Toshihiro Shimizu |
890ddd |
copySel(csp.m_sel);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
catch (SMemAllocError) {
|
|
Toshihiro Shimizu |
890ddd |
throw;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
const CSTColSelPic &operator=(const CSTColSelPic &sp) // throw(SMemAllocError)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
const CSTPic *spp;
|
|
Toshihiro Shimizu |
890ddd |
CSTPic *dpp;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
try {
|
|
Toshihiro Shimizu |
890ddd |
CSTPic::null();
|
|
Toshihiro Shimizu |
890ddd |
spp = static_cast<const cstpic<p=""> *>(&sp);</const>
|
|
Toshihiro Shimizu |
890ddd |
dpp = static_cast<cstpic<p> *>(this);</cstpic<p>
|
|
Toshihiro Shimizu |
890ddd |
*dpp = *spp;
|
|
Toshihiro Shimizu |
890ddd |
if (sp.m_sel && CSTPic::m_lX > 0 && CSTPic ::m_lY > 0) {
|
|
Toshihiro Shimizu |
890ddd |
initSel();
|
|
Toshihiro Shimizu |
890ddd |
copySel(sp.m_sel);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} catch (SMemAllocError) {
|
|
Toshihiro Shimizu |
890ddd |
throw;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return (*this);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int isInCIL(USHORT c, const COLOR_INDEX_LIST &cil)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < cil.nb; i++)
|
|
Toshihiro Shimizu |
890ddd |
if (cil.ci[i] == c)
|
|
Toshihiro Shimizu |
890ddd |
return i;
|
|
Toshihiro Shimizu |
890ddd |
return -1;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int makeSelectionCMAP32(const COLOR_INDEX_LIST &ink,
|
|
Toshihiro Shimizu |
890ddd |
const COLOR_INDEX_LIST &paint)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *pSel = m_sel;
|
|
Toshihiro Shimizu |
890ddd |
P *pic = CSTPic::m_pic;
|
|
Toshihiro Shimizu |
890ddd |
int xy = 0, nbSel = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (int y = 0; y < CSTPic::m_lY; y++)
|
|
Toshihiro Shimizu |
890ddd |
for (int x = 0; x < CSTPic::m_lX; x++, xy++, pSel++, pic++) {
|
|
Toshihiro Shimizu |
890ddd |
int xyRas = y * CSTPic::m_ras->wrap + x;
|
|
Toshihiro Shimizu |
890ddd |
UD44_CMAPINDEX32 ci32 = *((UD44_CMAPINDEX32 *)(CSTPic::m_ras->buffer) + xyRas);
|
|
Toshihiro Shimizu |
890ddd |
if ((ci32 & 0x000000ff) == 0xff) {
|
|
Toshihiro Shimizu |
890ddd |
// Paint color
|
|
Toshihiro Shimizu |
890ddd |
int p = isInCIL((int)((ci32 >> 8) & 0x00000fff), paint);
|
|
Toshihiro Shimizu |
890ddd |
if (p >= 0) {
|
|
Toshihiro Shimizu |
890ddd |
*pSel = 255 - p;
|
|
Toshihiro Shimizu |
890ddd |
nbSel++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} else if ((ci32 & 0x000000ff) == 0x0) {
|
|
Toshihiro Shimizu |
890ddd |
// Ink color
|
|
Toshihiro Shimizu |
890ddd |
int p = isInCIL((int)((ci32 >> 20) & 0x00000fff), ink);
|
|
Toshihiro Shimizu |
890ddd |
if (p >= 0) {
|
|
Toshihiro Shimizu |
890ddd |
//*pSel=paint.nb
|
|
Toshihiro Shimizu |
890ddd |
*pSel = 255 - p;
|
|
Toshihiro Shimizu |
890ddd |
nbSel++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
// Tone color
|
|
Toshihiro Shimizu |
890ddd |
int p = isInCIL((int)((ci32 >> 8) & 0x00000fff), paint);
|
|
Toshihiro Shimizu |
890ddd |
if (p >= 0)
|
|
Toshihiro Shimizu |
890ddd |
if (isInCIL((int)((ci32 >> 20) & 0x00000fff), ink) >= 0) {
|
|
Toshihiro Shimizu |
890ddd |
*pSel = 255 - p;
|
|
Toshihiro Shimizu |
890ddd |
nbSel++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return nbSel;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int makeSelectionCMAP(const COLOR_INDEX_LIST &ink,
|
|
Toshihiro Shimizu |
890ddd |
const COLOR_INDEX_LIST &paint)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
copySel((UCHAR)0);
|
|
Toshihiro Shimizu |
890ddd |
if (CSTPic::m_lX > 0 && CSTPic ::m_lY > 0 && m_sel && CSTPic ::m_pic && CSTPic ::m_ras) {
|
|
Toshihiro Shimizu |
890ddd |
if (CSTPic::m_ras->type == RAS_CM32)
|
|
Toshihiro Shimizu |
890ddd |
return makeSelectionCMAP32(ink, paint);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int makeSelectionCMAP(const CCIL &ink,
|
|
Toshihiro Shimizu |
890ddd |
const CCIL &paint)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
copySel((UCHAR)0);
|
|
Toshihiro Shimizu |
890ddd |
COLOR_INDEX_LIST hink, hpaint;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
hink.nb = ink.m_nb;
|
|
Toshihiro Shimizu |
890ddd |
int i;
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < ink.m_nb; i++)
|
|
Toshihiro Shimizu |
890ddd |
hink.ci[i] = (USHORT)ink.m_ci[i];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
hpaint.nb = paint.m_nb;
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < paint.m_nb; i++)
|
|
Toshihiro Shimizu |
890ddd |
hpaint.ci[i] = (USHORT)paint.m_ci[i];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (CSTPic::m_lX > 0 && CSTPic ::m_lY > 0 && m_sel && CSTPic ::m_pic && CSTPic ::m_ras) {
|
|
Toshihiro Shimizu |
890ddd |
if (CSTPic::m_ras->type == RAS_CM32)
|
|
Toshihiro Shimizu |
890ddd |
return makeSelectionCMAP32(hink, hpaint);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int makeSelectionRGB(const vector<i_pixel> &col,</i_pixel>
|
|
Toshihiro Shimizu |
890ddd |
const double dA, const double dAB)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int nbCol;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
copySel((UCHAR)0);
|
|
Toshihiro Shimizu |
890ddd |
nbCol = col.size();
|
|
Toshihiro Shimizu |
890ddd |
if (CSTPic::m_lX > 0 && CSTPic ::m_lY > 0 && m_sel && CSTPic ::m_pic) {
|
|
Toshihiro Shimizu |
890ddd |
switch (nbCol) {
|
|
Toshihiro Shimizu |
890ddd |
case 1:
|
|
Toshihiro Shimizu |
890ddd |
return makeSelectionRGB1(col, dA);
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case 2:
|
|
Toshihiro Shimizu |
890ddd |
return makeSelectionRGB2(col, dA, dAB);
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case 3:
|
|
Toshihiro Shimizu |
890ddd |
return makeSelectionRGB3(col, dA, dAB);
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
default:
|
|
Toshihiro Shimizu |
890ddd |
return makeSelectionRGBMore(col, dA, dAB);
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double distRGB2(const I_PIXEL &c1, const I_PIXEL &c2) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double q = (double)(c1.r - c2.r) * (double)(c1.r - c2.r);
|
|
Toshihiro Shimizu |
890ddd |
q += (double)(c1.g - c2.g) * (double)(c1.g - c2.g);
|
|
Toshihiro Shimizu |
890ddd |
q += (double)(c1.b - c2.b) * (double)(c1.b - c2.b);
|
|
Toshihiro Shimizu |
890ddd |
return q;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double distRGBM2(const I_PIXEL &c1, const I_PIXEL &c2) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double q = (double)(c1.r - c2.r) * (double)(c1.r - c2.r);
|
|
Toshihiro Shimizu |
890ddd |
q += (double)(c1.g - c2.g) * (double)(c1.g - c2.g);
|
|
Toshihiro Shimizu |
890ddd |
q += (double)(c1.b - c2.b) * (double)(c1.b - c2.b);
|
|
Toshihiro Shimizu |
890ddd |
q += (double)(c1.m - c2.m) * (double)(c1.m - c2.m);
|
|
Toshihiro Shimizu |
890ddd |
return q;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double distRGB(const I_PIXEL &c1, const I_PIXEL &c2) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int qd = (c1.r - c2.r) * (c1.r - c2.r) + (c1.g - c2.g) * (c1.g - c2.g) + (c1.b - c2.b) * (c1.b - c2.b);
|
|
Toshihiro Shimizu |
890ddd |
return sqrt((double)qd);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double distRGBM(const I_PIXEL &c1, const I_PIXEL &c2) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int qd = (c1.r - c2.r) * (c1.r - c2.r) + (c1.g - c2.g) * (c1.g - c2.g) +
|
|
Toshihiro Shimizu |
890ddd |
(c1.b - c2.b) * (c1.b - c2.b) * (c1.m - c2.m) * (c1.m - c2.m);
|
|
Toshihiro Shimizu |
890ddd |
return sqrt((double)qd);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline bool isSameColor(const I_PIXEL &c1, const I_PIXEL &c2) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return (c1.r == c2.r && c1.g == c2.g && c1.b == c2.b);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline void setIntPixel(I_PIXEL &dp, const P &sp) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
dp.r = (int)sp.r;
|
|
Toshihiro Shimizu |
890ddd |
dp.g = (int)sp.g;
|
|
Toshihiro Shimizu |
890ddd |
dp.b = (int)sp.b;
|
|
Toshihiro Shimizu |
890ddd |
dp.m = (int)sp.m;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline void setIntPixel(I_PIXEL &dp, const P *sp) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
dp.r = (int)sp->r;
|
|
Toshihiro Shimizu |
890ddd |
dp.g = (int)sp->g;
|
|
Toshihiro Shimizu |
890ddd |
dp.b = (int)sp->b;
|
|
Toshihiro Shimizu |
890ddd |
dp.m = (int)sp->m;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int makeSelectionRGB1(const vector<i_pixel> &col, const double dA)</i_pixel>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
P *pPic = CSTPic::m_pic;
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *pSel = m_sel;
|
|
Toshihiro Shimizu |
890ddd |
I_PIXEL ip;
|
|
Toshihiro Shimizu |
890ddd |
int xy, lxy = CSTPic::m_lX * CSTPic ::m_lY;
|
|
Toshihiro Shimizu |
890ddd |
int nbPixel = 0;
|
|
Toshihiro Shimizu |
890ddd |
double dA2 = dA * dA;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (xy = 0; xy < lxy; xy++, pPic++, pSel++) {
|
|
Toshihiro Shimizu |
890ddd |
// if ( pPic->m>0 ) {
|
|
Toshihiro Shimizu |
890ddd |
setIntPixel(ip, pPic);
|
|
Toshihiro Shimizu |
890ddd |
if (ip.m == col[0].m && distRGB2(ip, col[0]) <= dA2) {
|
|
Toshihiro Shimizu |
890ddd |
*pSel = 255;
|
|
Toshihiro Shimizu |
890ddd |
nbPixel++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
// }
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return nbPixel;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool isBetween(const I_PIXEL &a, const I_PIXEL &b, const I_PIXEL &c) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (c.r < min(a.r, b.r))
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
if (c.r > max(a.r, b.r))
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
if (c.g < min(a.g, b.g))
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
if (c.g > max(a.g, b.g))
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
if (c.b < min(a.b, b.b))
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
if (c.b > max(a.b, b.b))
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
if (c.m < min(a.m, b.m))
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
if (c.m > max(a.m, b.m))
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
//if ( c.m!=0 )
|
|
Toshihiro Shimizu |
890ddd |
// tmsg_info("A=(%d,%d,%d,%d) B=(%d,%d,%d,%d) C=(%d,%d,%d,%d)\n",a.r,a.g,a.b,a.m,b.r,b.g,b.b,b.m,c.r,c.g,c.b,c.m);
|
|
Toshihiro Shimizu |
890ddd |
if ( c.r
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
if ( c.r>a.r && c.r>b.r )
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
if ( c.g
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
if ( c.g>a.g && c.g>b.g )
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
if ( c.b
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
if ( c.b>a.b && c.b>b.b )
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
if ( c.m
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
if ( c.m>a.m && c.m>b.m )
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
//if ( c.m!=0 )
|
|
Toshihiro Shimizu |
890ddd |
//tmsg_info("IS_BETWEEN");
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool isLinComb(const I_PIXEL &a, const I_PIXEL &b, const I_PIXEL &c,
|
|
Toshihiro Shimizu |
890ddd |
const double dAB)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
// if ( isSameColor(a,b) && isSameColor(a,c) )
|
|
Toshihiro Shimizu |
890ddd |
// return true;
|
|
Toshihiro Shimizu |
890ddd |
if (!isBetween(a, b, c))
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
/* double dab=distRGBM(a,b);
|
|
Toshihiro Shimizu |
890ddd |
double dac=distRGBM(a,c);
|
|
Toshihiro Shimizu |
890ddd |
double dbc=distRGBM(b,c);
|
|
Toshihiro Shimizu |
890ddd |
double d= dab-(dac+dbc);
|
|
Toshihiro Shimizu |
890ddd |
d= d<0.0 ? -d : d;
|
|
Toshihiro Shimizu |
890ddd |
if ( d<=dAB )
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int makeSelectionRGB2(const vector<i_pixel> &col,</i_pixel>
|
|
Toshihiro Shimizu |
890ddd |
const double dA, const double dAB)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
P *pPic;
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *pSel;
|
|
Toshihiro Shimizu |
890ddd |
I_PIXEL ip;
|
|
Toshihiro Shimizu |
890ddd |
int xy, lxy, nbPixel;
|
|
Toshihiro Shimizu |
890ddd |
double dA2 = dA * dA;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
nbPixel = 0;
|
|
Toshihiro Shimizu |
890ddd |
pPic = CSTPic::m_pic;
|
|
Toshihiro Shimizu |
890ddd |
pSel = m_sel;
|
|
Toshihiro Shimizu |
890ddd |
lxy = CSTPic::m_lX * CSTPic ::m_lY;
|
|
Toshihiro Shimizu |
890ddd |
for (xy = 0; xy < lxy; xy++, pPic++, pSel++) {
|
|
Toshihiro Shimizu |
890ddd |
// if ( pPic->m>0 ) {
|
|
Toshihiro Shimizu |
890ddd |
setIntPixel(ip, pPic);
|
|
Toshihiro Shimizu |
890ddd |
if (ip.m == col[0].m && distRGB2(ip, col[0]) <= dA2) {
|
|
Toshihiro Shimizu |
890ddd |
*pSel = 255;
|
|
Toshihiro Shimizu |
890ddd |
nbPixel++;
|
|
Toshihiro Shimizu |
890ddd |
} else if (ip.m == col[1].m && distRGB2(ip, col[1]) <= dA2) {
|
|
Toshihiro Shimizu |
890ddd |
*pSel = (UCHAR)(255 - 1);
|
|
Toshihiro Shimizu |
890ddd |
nbPixel++;
|
|
Toshihiro Shimizu |
890ddd |
} else if (isLinComb(col[0], col[1], ip, dAB)) {
|
|
Toshihiro Shimizu |
890ddd |
// *pSel=(UCHAR)253;
|
|
Toshihiro Shimizu |
890ddd |
*pSel = distRGBM2(col[0], ip) < distRGBM2(col[1], ip) ? 255 : (UCHAR)(255 - 1);
|
|
Toshihiro Shimizu |
890ddd |
nbPixel++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// }
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return nbPixel;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int makeSelectionRGB3(const vector<i_pixel> &col,</i_pixel>
|
|
Toshihiro Shimizu |
890ddd |
const double dA, const double dAB)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
P *pPic = CSTPic::m_pic;
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *pSel = m_sel;
|
|
Toshihiro Shimizu |
890ddd |
I_PIXEL ip;
|
|
Toshihiro Shimizu |
890ddd |
int xy, nbPixel = 0;
|
|
Toshihiro Shimizu |
890ddd |
int lxy = CSTPic::m_lX * CSTPic ::m_lY;
|
|
Toshihiro Shimizu |
890ddd |
double dA2 = dA * dA;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (xy = 0; xy < lxy; xy++, pPic++, pSel++) {
|
|
Toshihiro Shimizu |
890ddd |
// if ( pPic->m>0 ) {
|
|
Toshihiro Shimizu |
890ddd |
setIntPixel(ip, pPic);
|
|
Toshihiro Shimizu |
890ddd |
if (ip.m == col[0].m && distRGB2(ip, col[0]) <= dA2) {
|
|
Toshihiro Shimizu |
890ddd |
*pSel = 255;
|
|
Toshihiro Shimizu |
890ddd |
nbPixel++;
|
|
Toshihiro Shimizu |
890ddd |
} else if (ip.m == col[1].m && distRGB2(ip, col[1]) <= dA2) {
|
|
Toshihiro Shimizu |
890ddd |
*pSel = (UCHAR)(255 - 1);
|
|
Toshihiro Shimizu |
890ddd |
nbPixel++;
|
|
Toshihiro Shimizu |
890ddd |
} else if (ip.m == col[2].m && distRGB2(ip, col[2]) <= dA2) {
|
|
Toshihiro Shimizu |
890ddd |
*pSel = (UCHAR)(255 - 2);
|
|
Toshihiro Shimizu |
890ddd |
nbPixel++;
|
|
Toshihiro Shimizu |
890ddd |
} else if (isLinComb(col[0], col[1], ip, dAB)) {
|
|
Toshihiro Shimizu |
890ddd |
*pSel = distRGBM2(col[0], ip) < distRGBM2(col[1], ip) ? 255 : 255 - 1;
|
|
Toshihiro Shimizu |
890ddd |
nbPixel++;
|
|
Toshihiro Shimizu |
890ddd |
} else if (isLinComb(col[0], col[2], ip, dAB)) {
|
|
Toshihiro Shimizu |
890ddd |
*pSel = distRGBM2(col[0], ip) < distRGBM2(col[2], ip) ? 255 : 255 - 2;
|
|
Toshihiro Shimizu |
890ddd |
nbPixel++;
|
|
Toshihiro Shimizu |
890ddd |
} else if (isLinComb(col[1], col[2], ip, dAB)) {
|
|
Toshihiro Shimizu |
890ddd |
*pSel = distRGBM2(col[1], ip) < distRGBM2(col[2], ip) ? 255 - 1 : 255 - 2;
|
|
Toshihiro Shimizu |
890ddd |
nbPixel++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
// }
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return nbPixel;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int makeSelectionRGBMore(const vector<i_pixel> &col,</i_pixel>
|
|
Toshihiro Shimizu |
890ddd |
const double dA, const double dAB)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int nbPixel = 0, i, j, k;
|
|
Toshihiro Shimizu |
890ddd |
int nbCol = col.size();
|
|
Toshihiro Shimizu |
890ddd |
for (i = 1, k = 0; i < nbCol; i++)
|
|
Toshihiro Shimizu |
890ddd |
for (j = 0; j < i; j++) {
|
|
Toshihiro Shimizu |
890ddd |
nbPixel += makeSelectionRGBMore(col, dA, dAB, i, j, k);
|
|
Toshihiro Shimizu |
890ddd |
k++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return nbPixel;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int makeSelectionRGBMore(const vector<i_pixel> &col,</i_pixel>
|
|
Toshihiro Shimizu |
890ddd |
const double dA, const double dAB,
|
|
Toshihiro Shimizu |
890ddd |
const int i, const int j, const int k)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
P *pPic = CSTPic::m_pic;
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *pSel = m_sel;
|
|
Toshihiro Shimizu |
890ddd |
I_PIXEL ip;
|
|
Toshihiro Shimizu |
890ddd |
int nbPixel = 0;
|
|
Toshihiro Shimizu |
890ddd |
double dA2 = dA * dA;
|
|
Toshihiro Shimizu |
890ddd |
int nbCol = col.size();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (int y = 0; y < CSTPic::m_lY; y++)
|
|
Toshihiro Shimizu |
890ddd |
for (int x = 0; x < CSTPic::m_lX; x++, pPic++, pSel++) {
|
|
Toshihiro Shimizu |
890ddd |
// if ( pPic->m>0 ) {
|
|
Toshihiro Shimizu |
890ddd |
setIntPixel(ip, pPic);
|
|
Toshihiro Shimizu |
890ddd |
if (ip.m == col[i].m && distRGB2(ip, col[i]) <= dA2) {
|
|
Toshihiro Shimizu |
890ddd |
*pSel = (UCHAR)(255 - i);
|
|
Toshihiro Shimizu |
890ddd |
nbPixel++;
|
|
Toshihiro Shimizu |
890ddd |
} else if (ip.m == col[j].m && distRGB2(ip, col[j]) <= dA2) {
|
|
Toshihiro Shimizu |
890ddd |
*pSel = (UCHAR)(255 - j);
|
|
Toshihiro Shimizu |
890ddd |
nbPixel++;
|
|
Toshihiro Shimizu |
890ddd |
} else if (isLinComb(col[i], col[j], ip, dAB)) {
|
|
Toshihiro Shimizu |
890ddd |
*pSel = distRGBM2(col[i], ip) < distRGBM2(col[j], ip) ? 255 - i : 255 - j;
|
|
Toshihiro Shimizu |
890ddd |
nbPixel++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
// }
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return nbPixel;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void setSel01()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int xy = CSTPic::m_lX * CSTPic ::m_lY;
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *p = m_sel;
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < xy; i++, p++)
|
|
Toshihiro Shimizu |
890ddd |
*p = *p > (UCHAR)0 ? (UCHAR)1 : (UCHAR)0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void showSelection()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
P *pPic;
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *pSel;
|
|
Toshihiro Shimizu |
890ddd |
int lxy, xy;
|
|
Toshihiro Shimizu |
890ddd |
int fcolor;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
lxy = CSTPic::m_lX * CSTPic ::m_lY;
|
|
Toshihiro Shimizu |
890ddd |
pSel = m_sel;
|
|
Toshihiro Shimizu |
890ddd |
pPic = CSTPic::m_pic;
|
|
Toshihiro Shimizu |
890ddd |
bool isRGBMType = CSTPic::getType() == ST_RGBM;
|
|
Toshihiro Shimizu |
890ddd |
fcolor = isRGBMType ? 255 : 65535;
|
|
Toshihiro Shimizu |
890ddd |
for (xy = 0; xy < lxy; xy++, pPic++, pSel++) {
|
|
Toshihiro Shimizu |
890ddd |
/* if (*pSel==(UCHAR)0) {
|
|
Toshihiro Shimizu |
890ddd |
pPic->r=fcolor/2;
|
|
Toshihiro Shimizu |
890ddd |
pPic->g=0;
|
|
Toshihiro Shimizu |
890ddd |
pPic->b=0;
|
|
Toshihiro Shimizu |
890ddd |
pPic->m=fcolor;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
if (*pSel > (UCHAR)0) {
|
|
Toshihiro Shimizu |
890ddd |
pPic->r = 255;
|
|
Toshihiro Shimizu |
890ddd |
pPic->g = 0;
|
|
Toshihiro Shimizu |
890ddd |
pPic->b = 0;
|
|
Toshihiro Shimizu |
890ddd |
pPic->m = fcolor;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/* if (*pSel==(UCHAR)2) {
|
|
Toshihiro Shimizu |
890ddd |
pPic->r=0;
|
|
Toshihiro Shimizu |
890ddd |
pPic->g=0;
|
|
Toshihiro Shimizu |
890ddd |
pPic->b=fcolor;
|
|
Toshihiro Shimizu |
890ddd |
pPic->m=fcolor;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (*pSel==(UCHAR)3) {
|
|
Toshihiro Shimizu |
890ddd |
pPic->r=fcolor;
|
|
Toshihiro Shimizu |
890ddd |
pPic->g=0;
|
|
Toshihiro Shimizu |
890ddd |
pPic->b=0;
|
|
Toshihiro Shimizu |
890ddd |
pPic->m=fcolor;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
/* if (*pSel==(UCHAR)255) {
|
|
Toshihiro Shimizu |
890ddd |
pPic->r=0;
|
|
Toshihiro Shimizu |
890ddd |
pPic->g=0;
|
|
Toshihiro Shimizu |
890ddd |
pPic->b=fcolor;
|
|
Toshihiro Shimizu |
890ddd |
pPic->m=fcolor;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (*pSel==(UCHAR)254) {
|
|
Toshihiro Shimizu |
890ddd |
pPic->r=fcolor;
|
|
Toshihiro Shimizu |
890ddd |
pPic->g=fcolor;
|
|
Toshihiro Shimizu |
890ddd |
pPic->b=0;
|
|
Toshihiro Shimizu |
890ddd |
pPic->m=fcolor;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (*pSel==(UCHAR)253) {
|
|
Toshihiro Shimizu |
890ddd |
pPic->r=fcolor;
|
|
Toshihiro Shimizu |
890ddd |
pPic->g=0;
|
|
Toshihiro Shimizu |
890ddd |
pPic->b=0;
|
|
Toshihiro Shimizu |
890ddd |
pPic->m=fcolor;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (*pSel==(UCHAR)251) {
|
|
Toshihiro Shimizu |
890ddd |
pPic->r=fcolor;
|
|
Toshihiro Shimizu |
890ddd |
pPic->g=0;
|
|
Toshihiro Shimizu |
890ddd |
pPic->b=fcolor;
|
|
Toshihiro Shimizu |
890ddd |
pPic->m=fcolor;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (*pSel==(UCHAR)250) {
|
|
Toshihiro Shimizu |
890ddd |
pPic->r=0;
|
|
Toshihiro Shimizu |
890ddd |
pPic->g=fcolor;
|
|
Toshihiro Shimizu |
890ddd |
pPic->b=fcolor;
|
|
Toshihiro Shimizu |
890ddd |
pPic->m=fcolor;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void selBox(SRECT &box)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
box.x0 = CSTPic::m_lX;
|
|
Toshihiro Shimizu |
890ddd |
box.x1 = -1;
|
|
Toshihiro Shimizu |
890ddd |
box.y0 = CSTPic::m_lY;
|
|
Toshihiro Shimizu |
890ddd |
box.y1 = -1;
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *pSel = m_sel;
|
|
Toshihiro Shimizu |
890ddd |
for (int y = 0; y < CSTPic::m_lY; y++)
|
|
Toshihiro Shimizu |
890ddd |
for (int x = 0; x < CSTPic::m_lX; x++, pSel++)
|
|
Toshihiro Shimizu |
890ddd |
if (*pSel > (UCHAR)0) {
|
|
Toshihiro Shimizu |
890ddd |
box.x0 = min(box.x0, x);
|
|
Toshihiro Shimizu |
890ddd |
box.x1 = max(box.x1, x);
|
|
Toshihiro Shimizu |
890ddd |
box.y0 = min(box.y0, y);
|
|
Toshihiro Shimizu |
890ddd |
box.y1 = max(box.y1, y);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void selRunLengthH(const SRECT &box, const int step, int &rl, int &nbRl)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
for (int y = box.y0; y <= (box.y1); y += step) {
|
|
Toshihiro Shimizu |
890ddd |
int l = 0;
|
|
Toshihiro Shimizu |
890ddd |
bool isIn = false;
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *pSel = m_sel + y * CSTPic::m_lX + box.x0;
|
|
Toshihiro Shimizu |
890ddd |
for (int x = box.x0; x <= box.x1; x++, pSel++) {
|
|
Toshihiro Shimizu |
890ddd |
if (isIn && *pSel == (UCHAR)0) {
|
|
Toshihiro Shimizu |
890ddd |
rl += l;
|
|
Toshihiro Shimizu |
890ddd |
nbRl++;
|
|
Toshihiro Shimizu |
890ddd |
l = 0;
|
|
Toshihiro Shimizu |
890ddd |
isIn = false;
|
|
Toshihiro Shimizu |
890ddd |
} else if (isIn && *pSel > (UCHAR)0) {
|
|
Toshihiro Shimizu |
890ddd |
l++;
|
|
Toshihiro Shimizu |
890ddd |
} else if (!isIn && *pSel > (UCHAR)0) {
|
|
Toshihiro Shimizu |
890ddd |
l = 1;
|
|
Toshihiro Shimizu |
890ddd |
isIn = true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (isIn) {
|
|
Toshihiro Shimizu |
890ddd |
rl += l;
|
|
Toshihiro Shimizu |
890ddd |
nbRl++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void selRunLengthV(const SRECT &box, const int step, int &rl, int &nbRl)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
for (int x = box.x0; x <= (box.x1); x += step) {
|
|
Toshihiro Shimizu |
890ddd |
int l = 0;
|
|
Toshihiro Shimizu |
890ddd |
bool isIn = false;
|
|
Toshihiro Shimizu |
890ddd |
for (int y = box.y0; y <= box.y1; y++) {
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *pSel = m_sel + y * CSTPic::m_lX + x;
|
|
Toshihiro Shimizu |
890ddd |
if (isIn && *pSel == (UCHAR)0) {
|
|
Toshihiro Shimizu |
890ddd |
rl += l;
|
|
Toshihiro Shimizu |
890ddd |
nbRl++;
|
|
Toshihiro Shimizu |
890ddd |
l = 0;
|
|
Toshihiro Shimizu |
890ddd |
isIn = false;
|
|
Toshihiro Shimizu |
890ddd |
} else if (isIn && *pSel > (UCHAR)0) {
|
|
Toshihiro Shimizu |
890ddd |
l++;
|
|
Toshihiro Shimizu |
890ddd |
} else if (!isIn && *pSel > (UCHAR)0) {
|
|
Toshihiro Shimizu |
890ddd |
l = 1;
|
|
Toshihiro Shimizu |
890ddd |
isIn = true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (isIn) {
|
|
Toshihiro Shimizu |
890ddd |
rl += l;
|
|
Toshihiro Shimizu |
890ddd |
nbRl++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int selRunLength(const int step)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int s = step < 1 ? 1 : step;
|
|
Toshihiro Shimizu |
890ddd |
SRECT box;
|
|
Toshihiro Shimizu |
890ddd |
selBox(box);
|
|
Toshihiro Shimizu |
890ddd |
int rl = 0;
|
|
Toshihiro Shimizu |
890ddd |
int nbRl = 0;
|
|
Toshihiro Shimizu |
890ddd |
selRunLengthH(box, s, rl, nbRl);
|
|
Toshihiro Shimizu |
890ddd |
selRunLengthV(box, s, rl, nbRl);
|
|
Toshihiro Shimizu |
890ddd |
if (nbRl > 0) {
|
|
Toshihiro Shimizu |
890ddd |
double d = (double)rl / (double)nbRl;
|
|
Toshihiro Shimizu |
890ddd |
return I_ROUNDP(d);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void hlsNoise(const double d)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int xy = CSTPic::m_lX * CSTPic ::m_lY;
|
|
Toshihiro Shimizu |
890ddd |
P *p = CSTPic::m_pic;
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *pSel = m_sel;
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < xy; i++, p++, pSel++)
|
|
Toshihiro Shimizu |
890ddd |
if (p->m > 0 && (*pSel) > (UCHAR)0) {
|
|
Toshihiro Shimizu |
890ddd |
double h, l, s, q;
|
|
Toshihiro Shimizu |
890ddd |
rgb2hls(p->r, p->g, p->b, &h, &l, &s);
|
|
Toshihiro Shimizu |
890ddd |
q = 1.0 - d * (double)((rand() % 201) - 100) / 100.0;
|
|
Toshihiro Shimizu |
890ddd |
l *= q;
|
|
Toshihiro Shimizu |
890ddd |
hls2rgb(h, l, s, &(p->r), &(p->g), &(p->b));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
void expand(const int border) throw(SMemAllocError)
|
|
Toshihiro Shimizu |
890ddd |
{ try {
|
|
Toshihiro Shimizu |
890ddd |
int olX=m_lX;
|
|
Toshihiro Shimizu |
890ddd |
int olY=m_lY;
|
|
Toshihiro Shimizu |
890ddd |
CSTPic::expand(border);
|
|
Toshihiro Shimizu |
890ddd |
UCHAR* nSel=new UCHAR[m_lX*m_lY];
|
|
Toshihiro Shimizu |
890ddd |
if ( !nSel )
|
|
Toshihiro Shimizu |
890ddd |
throw SMemAllocError("in expand");
|
|
Toshihiro Shimizu |
890ddd |
UCHAR* pNSel=nSel;
|
|
Toshihiro Shimizu |
890ddd |
for( int y=0; y
|
|
Toshihiro Shimizu |
890ddd |
for( int x=0; x
|
|
Toshihiro Shimizu |
890ddd |
int ox=x-border;
|
|
Toshihiro Shimizu |
890ddd |
int oy=y-border;
|
|
Toshihiro Shimizu |
890ddd |
if ( ox>=0 && ox<olx &&="" oy="">=0 && oy</olx>
|
|
Toshihiro Shimizu |
890ddd |
*pNSel=*(m_sel+oy*olX+ox);
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
*pNSel=(UCHAR)0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
delete [] m_sel;
|
|
Toshihiro Shimizu |
890ddd |
m_sel=nSel;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
catch (SMemAllocError) {
|
|
Toshihiro Shimizu |
890ddd |
throw;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif // !defined(AFX_STCOLSELPIC_H__80D708B0_FCA2_11D5_B949_0040F674BE6A__INCLUDED_)
|