📄 image.cpp
字号:
/*
*
* All Contents Copyright 2000 by Jared Samet. All Rights Reserved.
*
*/
#include <stdafx.h>
#include "Image.h"
#include "Sequence.h"
int CImage::m_iGapPenalty;
int CImage::m_iMatchThree;
int CImage::m_iMatchTwo;
int CImage::m_iMatchOne;
int CImage::m_iMatchZero;
CImage::CImage()
: m_pRGBArray(NULL), m_iHeight(0), m_iWidth(0)
{
}
CImage::~CImage()
{
if (NULL != m_pRGBArray)
{
delete [] m_pRGBArray;
}
}
unsigned int CImage::cRows(void)
{
return m_iHeight;
}
unsigned int CImage::cCols(void)
{
return m_iWidth;
}
CSequence* CImage::getRow(unsigned int iRow)
{
ASSERT(iRow < m_iHeight);
CSequence* pSeq = new CSequence(NULL, m_iWidth);
C3D_RGB* pRGB = m_pRGBArray + (iRow * m_iWidth);
for (unsigned int i=0; i < m_iWidth; i++)
{
pSeq->LetterAt(i) = RGBToInt(*pRGB++);
}
return pSeq;
}
int CImage::GapPenalty(unsigned int)
{
return m_iGapPenalty;
}
void CImage::RGBtoHSL(CImage::C3D_RGB rgb, double *H, double *S, double *L)
{
double delta;
double r = (double) (rgb.Red)/255.0;
double g = (double) (rgb.Green)/255.0;
double b = (double) (rgb.Blue)/255.0;
double cmax = max(r,max(g,b));
double cmin = min(r,min(g,b));
*L=(cmax+cmin)/2.0;
if(cmax==cmin)
{
*S = 0;
*H = 0; // it's really undefined
}
else
{
if(*L < 0.5)
{
*S = (cmax-cmin)/(cmax+cmin);
}
else
{
*S = (cmax-cmin)/(2.0-cmax-cmin);
}
delta = cmax - cmin;
if (r==cmax)
{
*H = (g-b)/delta;
}
else
{
if (g==cmax)
{
*H = 2.0 +(b-r)/delta;
}
else
{
*H=4.0+(r-g)/delta;
}
}
*H /= 6.0;
if (*H < 0.0)
{
*H += 1;
}
}
}
int CImage::MatchScore(unsigned int left, unsigned int right)
{
// double hLeft, hRight, sLeft, sRight, lLeft, lRight;
C3D_RGB rgbLeft = IntToRGB(left), rgbRight = IntToRGB(right);
// RGBtoHSL(rgbLeft, &hLeft, &sLeft, &lLeft);
// RGBtoHSL(rgbRight, &hRight, &sRight, &lRight);
int iQuadratic = m_iMatchThree - (rgbLeft.Blue - rgbRight.Blue)*(rgbLeft.Blue - rgbRight.Blue);
return max(iQuadratic, 2 * (m_iGapPenalty - 1));
}
CImage::C3D_RGB CImage::IntToRGB(unsigned int i)
{
C3D_RGB rgb;
rgb.Red = (unsigned char) ((i & 0x00FF0000) >> 16);
rgb.Green = (unsigned char) ((i & 0x0000FF00) >> 8);
rgb.Blue = (unsigned char) (i & 0x000000FF);
return rgb;
}
unsigned int CImage::RGBToInt(C3D_RGB rgb)
{
return (rgb.Red << 16) | (rgb.Green << 8) | (rgb.Blue);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -