// xImaDsp.cpp : DSP functions
/* 07/08/2001 v1.00 - Davide Pizzolato - www.xdp.it
* CxImage version 7.0.2 07/Feb/2011
*/
#include "ximage.h"
#include "ximaiter.h"
#if CXIMAGE_SUPPORT_DSP
////////////////////////////////////////////////////////////////////////////////
/**
* Converts the image to B&W.
* The OptimalThreshold() function can be used for calculating the optimal threshold.
* \param level: the lightness threshold.
* \return true if everything is ok
*/
bool CxImage::Threshold(uint8_t level)
{
if (!pDib) return false;
if (head.biBitCount == 1) return true;
GrayScale();
CxImage tmp(head.biWidth,head.biHeight,1);
if (!tmp.IsValid()){
strcpy(info.szLastError,tmp.GetLastError());
return false;
}
for (int32_t y=0;y<head.biHeight;y++){
info.nProgress = (int32_t)(100*y/head.biHeight);
if (info.nEscape) break;
for (int32_t x=0;x<head.biWidth;x++){
if (BlindGetPixelIndex(x,y)>level)
tmp.BlindSetPixelIndex(x,y,1);
else
tmp.BlindSetPixelIndex(x,y,0);
}
}
tmp.SetPaletteColor(0,0,0,0);
tmp.SetPaletteColor(1,255,255,255);
Transfer(tmp);
return true;
}
////////////////////////////////////////////////////////////////////////////////
/**
* Converts the image to B&W, using a threshold mask
* \param pThresholdMask: the lightness threshold mask.
* the pThresholdMask image must be grayscale with same with and height of the current image
* \return true if everything is ok
*/
bool CxImage::Threshold(CxImage* pThresholdMask)
{
if (!pDib) return false;
if (head.biBitCount == 1) return true;
if (!pThresholdMask) return false;
if (!pThresholdMask->IsValid() ||
!pThresholdMask->IsGrayScale() ||
pThresholdMask->GetWidth() != GetWidth() ||
pThresholdMask->GetHeight() != GetHeight()){
strcpy(info.szLastError,"invalid ThresholdMask");
return false;
}
GrayScale();
CxImage tmp(head.biWidth,head.biHeight,1);
if (!tmp.IsValid()){
strcpy(info.szLastError,tmp.GetLastError());
return false;
}
for (int32_t y=0;y<head.biHeight;y++){
info.nProgress = (int32_t)(100*y/head.biHeight);
if (info.nEscape) break;
for (int32_t x=0;x<head.biWidth;x++){
if (BlindGetPixelIndex(x,y)>pThresholdMask->BlindGetPixelIndex(x,y))
tmp.BlindSetPixelIndex(x,y,1);
else
tmp.BlindSetPixelIndex(x,y,0);
}
}
tmp.SetPaletteColor(0,0,0,0);
tmp.SetPaletteColor(1,255,255,255);
Transfer(tmp);
return true;
}
////////////////////////////////////////////////////////////////////////////////
/**
* Filters only the pixels with a lightness less (or more) than the threshold level,
* and preserves the colors for the unfiltered pixels.
* \param level = the lightness threshold.
* \param bDirection = false: filter dark pixels, true: filter light pixels
* \param nBkgndColor = filtered pixels are set to nBkgndColor color
* \param bSetAlpha = if true, sets also the alpha component for the filtered pixels, with nBkgndColor.rgbReserved
* \return true if everything is ok
* \author [DP], [wangsongtao]
*/
////////////////////////////////////////////////////////////////////////////////
bool CxImage::Threshold2(uint8_t level, bool bDirection, RGBQUAD nBkgndColor, bool bSetAlpha)
{
if (!pDib) return false;
if (head.biBitCount == 1) return true;
CxImage tmp(*this, true, false, false);
if (!tmp.IsValid()){
strcpy(info.szLastError,tmp.GetLastError());
return false;
}
tmp.GrayScale();
int32_t xmin,xmax,ymin,ymax;
if (pSelection){
xmin = info.rSelectionBox.left; xmax = info.rSelectionBox.right;
ymin = info.rSelectionBox.bottom; ymax = info.rSelectionBox.top;
} else {
xmin = ymin = 0;
xmax = head.biWidth; ymax=head.biHeight;
}
for(int32_t y=ymin; y<ymax; y++){
info.nProgress = (int32_t)(100*y/head.biHeight);
if (info.nEscape) break;
for(int32_t x=xmin; x<xmax; x++){
#if CXIMAGE_SUPPORT_SELECTION
if (BlindSelectionIsInside(x,y))
#endif //CXIMAGE_SUPPORT_SELECTION
{
uint8_t i = tmp.BlindGetPixelIndex(x,y);
if (!bDirection && i<level) BlindSetPixelColor(x,y,nBkgndColor,bSetAlpha);
if (bDirection && i>=level) BlindSetPixelColor(x,y,nBkgndColor,bSetAlpha);
}
}
}
return true;
}
////////////////////////////////////////////////////////////////////////////////
/**
* Extract RGB channels from the image. Each channel is an 8 bit grayscale image.
* \param r,g,b: pointers to CxImage objects, to store the splited channels
* \return true if everything is ok
*/
bool CxImage::SplitRGB(CxImage* r,CxImage* g,CxImage* b)
{
if (!pDib) return false;
if (r==NULL && g==NULL && b==NULL) return false;
CxImage tmpr(head.biWidth,head.biHeight,8);
CxImage tmpg(head.biWidth,head.biHeight,8);
CxImage tmpb(head.biWidth,head.biHeight,8);
RGBQUAD color;
for(int32_t y=0; y<head.biHeight; y++){
for(int32_t x=0; x<head.biWidth; x++){
color = BlindGetPixelColor(x,y);
if (r) tmpr.BlindSetPixelIndex(x,y,color.rgbRed);
if (g) tmpg.BlindSetPixelIndex(x,y,color.rgbGreen);
if (b) tmpb.BlindSetPixelIndex(x,y,color.rgbBlue);
}
}
if (r) tmpr.SetGrayPalette();
if (g) tmpg.SetGrayPalette();
if (b) tmpb.SetGrayPalette();
/*for(int32_t j=0; j<256; j++){
uint8_t i=(uint8_t)j;
if (r) tmpr.SetPaletteColor(i,i,0,0);
if (g) tmpg.SetPaletteColor(i,0,i,0);
if (b) tmpb.SetPaletteColor(i,0,0,i);
}*/
if (r) r->Transfer(tmpr);
if (g) g->Transfer(tmpg);
if (b) b->Transfer(tmpb);
return true;
}
////////////////////////////////////////////////////////////////////////////////
/**
* Extract CMYK channels from the image. Each channel is an 8 bit grayscale image.
* \param c,m,y,k: pointers to CxImage objects, to store the splited channels
* \return true if everything is ok
*/
bool CxImage::SplitCMYK(CxImage* c,CxImage* m,CxImage* y,CxImage* k)
{
if (!pDib) return false;
if (c==NULL && m==NULL && y==NULL && k==NULL) return false;
CxImage tmpc(head.biWidth,head.biHeight,8);
CxImage tmpm(head.biWidth,head.biHeight,8);
CxImage tmpy(head.biWidth,head.biHeight,8);
CxImage tmpk(head.biWidth,head.biHeight,8);
RGBQUAD color;
for(int32_t yy=0; yy<head.biHeight; yy++){
for(int32_t xx=0; xx<head.biWidth; xx++){
color = BlindGetPixelColor(xx,yy);
if (c) tmpc.BlindSetPixelIndex(xx,yy,(uint8_t)(255-color.rgbRed));
if (m) tmpm.BlindSetPixelIndex(xx,yy,(uint8_t)(255-color.rgbGreen));
if (y) tmpy.BlindSetPixelIndex(xx,yy,(uint8_t)(255-color.rgbBlue));
if (k) tmpk.BlindSetPixelIndex(xx,yy,(uint8_t)RGB2GRAY(color.rgbRed,color.rgbGreen,color.rgbBlue));
}
}
if (c) tmpc.SetGrayPalette();
if (m) tmpm.SetGrayPalette();
if (y) tmpy.SetGrayPalette();
if (k) tmpk.SetGrayPalette();
if (c) c->Transfer(tmpc);
if (m) m->Transfer(tmpm);
if (y) y->Transfer(tmpy);
if (k) k->Transfer(tmpk);
return true;
}
////////////////////////////////////////////////////////////////////////////////
/**
* Extract YUV channels from the image. Each channel is an 8 bit grayscale image.
* \param y,u,v: pointers to CxImage objects, to store the splited channels
* \return true if everything is ok
*/
bool CxImage::SplitYUV(CxImage* y,CxImage* u,CxImage* v)
{
if (!pDib) return false;
if (y==NULL && u==NULL && v==NULL) return false;
CxImage tmpy(head.biWidth,head.biHeight,8);
CxImage tmpu(head.biWidth,head.biHeight,8);
CxImage tmpv(head.biWidth,head.biHeight,8);
RGBQUAD color;
for(int32_t yy=0; yy<head.biHeight; yy++){
for(int32_t x=0; x<head.biWidth; x++){
color = RGBtoYUV(BlindGetPixelColor(x,yy));
if (y) tmpy.BlindSetPixelIndex(x,yy,color.rgbRed);
if (u) tmpu.BlindSetPixelIndex(x,yy,color.rgbGreen);
if (v) tmpv.BlindSetPixelIndex(x,yy,color.rgbBlue);
}
}
if (y) tmpy.SetGrayPalette();
if (u) tmpu.SetGrayPalette();
if (v) tmpv.SetGrayPalette();
if (y) y->Transfer(tmpy);
if (u) u->Transfer(tmpu);
if (v) v-
没有合适的资源?快使用搜索试试~ 我知道了~
cximage_vs2010已编译好的库
共83个文件
cpp:32个
h:25个
lib:24个
5星 · 超过95%的资源 需积分: 32 234 下载量 91 浏览量
2014-04-08
21:42:18
上传
评论 3
收藏 9.48MB ZIP 举报
温馨提示
cximage_vs2010已编译好的库,inlcude文件夹下是头文件,lib文件夹下是静态库文件,dll文件夹下是dll文件和对应的lib文件,根据自己的需要直接使用动态库或者静态库即可,具体使用方法,参考:http://blog.csdn.net/tuling_research/article/details/23203291
资源推荐
资源详情
资源评论
收起资源包目录
cximage_vs2010已编译好的库.zip (83个子文件)
cximage
dll
debug
cximaged.lib 195KB
cximaged.dll 3.18MB
release
cximage.dll 1.47MB
cximage.lib 194KB
include
ximawbmp.h 1KB
ximapsd.cpp 42KB
xmemfile.h 1KB
stdint.h 8KB
ximaico.cpp 14KB
ximamng.h 2KB
ximath.h 802B
xmemfile.cpp 5KB
ximalpha.cpp 10KB
ximage.h 31KB
ximawmf.cpp 15KB
ximacfg.h 2KB
ximatif.cpp 30KB
ximainfo.cpp 27KB
ximatif.h 2KB
ximaenc.cpp 31KB
ximage.cpp 16KB
ximagif.cpp 49KB
ximawnd.cpp 61KB
tif_xfile.cpp 5KB
ximawmf.h 5KB
ximaexif.cpp 31KB
ximaska.h 1KB
ximapcx.cpp 15KB
ximapng.cpp 17KB
ximajas.h 3KB
ximapcx.h 2KB
ximadef.h 4KB
ximaiter.h 7KB
ximajas.cpp 9KB
xfile.h 3KB
ximalyr.cpp 3KB
ximaraw.cpp 9KB
ximapal.cpp 30KB
ximatga.cpp 10KB
ximagif.h 8KB
ximath.cpp 2KB
ximabmp.cpp 14KB
ximapng.h 3KB
ximaint.cpp 39KB
ximajpg.cpp 19KB
ximaraw.h 3KB
ximaska.cpp 4KB
ximajbg.h 1KB
ximabmp.h 3KB
ximatran.cpp 88KB
ximahist.cpp 17KB
xiofile.h 3KB
ximapsd.h 3KB
ximatga.h 2KB
ximajbg.cpp 4KB
ximajpg.h 9KB
ximawbmp.cpp 4KB
ximaico.h 2KB
ximasel.cpp 22KB
ximamng.cpp 14KB
ximadsp.cpp 110KB
lib
Release
libdcr.lib 694KB
libpsd.lib 1.13MB
demodll.lib 47KB
zlib.lib 303KB
tiff.lib 1.41MB
jasper.lib 2.85MB
demo.lib 46KB
cximage.lib 4.79MB
jpeg.lib 1.25MB
jbig.lib 160KB
png.lib 1.3MB
mng.lib 1.72MB
Debug
libdcr.lib 636KB
libpsd.lib 1.19MB
zlib.lib 221KB
tiff.lib 1.42MB
jasper.lib 2.12MB
cximage.lib 2.43MB
jpeg.lib 1021KB
jbig.lib 104KB
png.lib 979KB
mng.lib 1.54MB
共 83 条
- 1
tuling56
- 粉丝: 37
- 资源: 44
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页