|
Hello,
i have some problems (I think it is a problem) with reading in TIF Files. I get everytime two errors:
Error1: unknown field tag 700 (xxx)ignored
Error2: unknown field tag 34665 (xxx) ignored
Anyone knows how to kill this errors or to hide the messageboxes?
Ingo
|
|
|
|
|
I also have this problems when reading TIF files.
Please help me!
|
|
|
|
|
Yes, me too. I encountered the same problem. Please Help! Thanks a lot!
ZHANG
|
|
|
|
|
|
this happens only in debug builds. In release buils these messages are not shown
|
|
|
|
|
This occurs with version 5.99. With version 5.56, everything was OK. Any hints?
|
|
|
|
|
Seems that the problem is the following:
Since 5.80 CxImage tries to find a transparent color when an icon is loaded. If one is found, the color of the appropriate pixels is changed. The Explorer seems to have a problem if the transparent color isn't a pure color - but this is only a guess. However, if I comment out the section in the source that sets the transparent color, everything works fine.
|
|
|
|
|
Does anyone develope more formats for CxImage, such as RAW, DICOM? Can you share them with us? By the way, I am trying to add more functions for CxImage to open RAW, DICOM formats. Can anyone tell me how to add those formats into CXImage?
thanks!
uranus
contact mail: linchunshu@yahoo.com
welcome to write to me.
|
|
|
|
|
In order to add new format to CxImage, you should change some files and create others.
For example, to create a new format: CHIBA format, with the appropriate extentions: *.xyz, *.ktu, *.rgb do as follow:
For the new class,
1. Create file cximage\ximachiba.cpp
2. Create file cximage\ximachiba.h
To register into cximage class
3. Change cximage\cximaenc.cpp
4. Change cximage\cximage.h
For the MFC demo
5. Change demo\demo.cpp
6. Change demo\demoDoc.cpp
For the console demo
7. Change demo2\console.cpp
For your own format file, compare the modified files with the original files to find changes.
//===================================================
// cximage\ximachiba.cpp
//===================================================
#include "ximachiba.h"
#if CXIMAGE_SUPPORT_CHIBA
#include "ximaiter.h"
#define CHIBA_BUFSIZE 8192
////////////////////////////////////////////////////////////////////////////////
/*===========================================
===========================================*/
bool CxImageCHIBA::Encode(CxFile *hFile)
{
if (EncodeSafeCheck(hFile)) return false;
char buffer[200];
sprintf(buffer, "%i\t%i\n", head.biWidth, head.biHeight );
hFile->Write(buffer, strlen(buffer), 1);
RGBQUAD color;
for(long y=0; y<head.biheight; y++){
="" for(long="" x="0;" x<head.biwidth;="" x++){
="" color="GetPixelColor(x,y);
" sprintf(buffer,="" "%i\t%i\t%i\n",="" color.rgbred,="" color.rgbgreen,="" color.rgbblue);
="" hfile-="">Write(buffer, strlen(buffer), 1);
}
}
return true;
}
////////////////////////////////////////////////////////////////////////////////
bool CxImageCHIBA::Decode(CxFile *hFile)
{
return true;
}
////////////////////////////////////////////////////////////////////////////////
#endif // CXIMAGE_SUPPORT_CHIBA
|
|
|
|
|
//===================================================
// cximage\ximachiba.h
//===================================================
#if !defined(__ximaCHIBA_h)
#define __ximaCHIBA_h
#include "ximage.h"
#if CXIMAGE_SUPPORT_CHIBA
/* Define structures and constants here */
typedef struct tag_chibaRGB{
BYTE transpcolflag:1;
BYTE userinputflag:1;
BYTE dispmeth:3;
BYTE res:3;
WORD delaytime;
BYTE transpcolindex;
} struct_gifaagce;
class CxImageCHIBA: public CxImage
{
public:
CxImageCHIBA(): CxImage(CXIMAGE_FORMAT_CHIBA) {}
bool Decode(CxFile * hFile);
bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); }
#if CXIMAGE_SUPPORT_ENCODE
bool Encode(CxFile * hFile);
bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); }
#endif // CXIMAGE_SUPPORT_ENCODE
};
#endif
#endif
//===================================================
// cximage\cximaenc.cpp
//===================================================
#include "ximage.h"
#if CXIMAGE_SUPPORT_JPG
#include "ximajpg.h"
#endif
#if CXIMAGE_SUPPORT_GIF
#include "ximagif.h"
#endif
#if CXIMAGE_SUPPORT_PNG
#include "ximapng.h"
#endif
#if CXIMAGE_SUPPORT_MNG
#include "ximamng.h"
#endif
#if CXIMAGE_SUPPORT_BMP
#include "ximabmp.h"
#endif
#if CXIMAGE_SUPPORT_ICO
#include "ximaico.h"
#endif
#if CXIMAGE_SUPPORT_TIF
#include "ximatif.h"
#endif
#if CXIMAGE_SUPPORT_TGA
#include "ximatga.h"
#endif
#if CXIMAGE_SUPPORT_PCX
#include "ximapcx.h"
#endif
#if CXIMAGE_SUPPORT_WBMP
#include "ximawbmp.h"
#endif
#if CXIMAGE_SUPPORT_WMF
#include "ximawmf.h" // <vho> - WMF/EMF support
#endif
#if CXIMAGE_SUPPORT_J2K
#include "ximaj2k.h"
#endif
#if CXIMAGE_SUPPORT_JBG
#include "ximajbg.h"
#endif
#if CXIMAGE_SUPPORT_JASPER
#include "ximajas.h"
#endif
//ThanhDK=================================
#if CXIMAGE_SUPPORT_CHIBA
#include "ximachiba.h"
#endif
//========================================
////////////////////////////////////////////////////////////////////////////////
#if CXIMAGE_SUPPORT_ENCODE
////////////////////////////////////////////////////////////////////////////////
bool CxImage::EncodeSafeCheck(CxFile *hFile)
{
if (hFile==NULL) {
strcpy(info.szLastError,CXIMAGE_ERR_NOFILE);
return true;
}
if (pDib==NULL){
strcpy(info.szLastError,CXIMAGE_ERR_NOIMAGE);
return true;
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
//#ifdef WIN32
//bool CxImage::Save(LPCWSTR filename, DWORD imagetype)
//{
// FILE* hFile; //file handle to write the image
// if ((hFile=_wfopen(filename,L"wb"))==NULL) return false;
// bool bOK = Encode(hFile,imagetype);
// fclose(hFile);
// return bOK;
//}
//#endif //WIN32
////////////////////////////////////////////////////////////////////////////////
// For UNICODE support: char -> TCHAR
bool CxImage::Save(const TCHAR * filename, DWORD imagetype)
{
FILE* hFile; //file handle to write the image
if ((hFile=_tfopen(filename,_T("wb")))==NULL) return false; // For UNICODE support
//if ((hFile=fopen(filename,"wb"))==NULL) return false;
bool bOK = Encode(hFile,imagetype);
fclose(hFile);
return bOK;
}
////////////////////////////////////////////////////////////////////////////////
bool CxImage::Encode(FILE *hFile, DWORD imagetype)
{
CxIOFile file(hFile);
return Encode(&file,imagetype);
}
////////////////////////////////////////////////////////////////////////////////
bool CxImage::Encode(BYTE * &buffer, long &size, DWORD imagetype)
{
if (buffer!=NULL) return false; //the buffer must be empty
CxMemFile file;
file.Open();
if(Encode(&file,imagetype)){
buffer=file.GetBuffer();
size=file.Size();
return true;
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
bool CxImage::Encode(CxFile *hFile, DWORD imagetype)
{
#if CXIMAGE_SUPPORT_BMP
if (imagetype==CXIMAGE_FORMAT_BMP){
CxImageBMP newima;
newima.Ghost(this);
if (newima.Encode(hFile)){
return true;
} else {
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
#if CXIMAGE_SUPPORT_ICO
if (imagetype==CXIMAGE_FORMAT_ICO){
CxImageICO newima;
newima.Ghost(this);
if (newima.Encode(hFile)){
return true;
} else {
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
#if CXIMAGE_SUPPORT_TIF
if (imagetype==CXIMAGE_FORMAT_TIF){
CxImageTIF newima;
newima.Ghost(this);
if (newima.Encode(hFile)){
return true;
} else {
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
#if CXIMAGE_SUPPORT_JPG
if (imagetype==CXIMAGE_FORMAT_JPG){
CxImageJPG newima;
newima.Ghost(this);
if (newima.Encode(hFile)){
return true;
} else {
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
#if CXIMAGE_SUPPORT_GIF
if (imagetype==CXIMAGE_FORMAT_GIF){
CxImageGIF newima;
newima.Ghost(this);
if (newima.Encode(hFile)){
return true;
} else {
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
#if CXIMAGE_SUPPORT_PNG
if (imagetype==CXIMAGE_FORMAT_PNG){
CxImagePNG newima;
newima.Ghost(this);
if (newima.Encode(hFile)){
return true;
} else {
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
#if CXIMAGE_SUPPORT_MNG
if (imagetype==CXIMAGE_FORMAT_MNG){
CxImageMNG newima;
newima.Ghost(this);
if (newima.Encode(hFile)){
return true;
} else {
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
#if CXIMAGE_SUPPORT_TGA
if (imagetype==CXIMAGE_FORMAT_TGA){
CxImageTGA newima;
newima.Ghost(this);
if (newima.Encode(hFile)){
return true;
} else {
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
#if CXIMAGE_SUPPORT_PCX
if (imagetype==CXIMAGE_FORMAT_PCX){
CxImagePCX newima;
newima.Ghost(this);
if (newima.Encode(hFile)){
return true;
} else {
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
#if CXIMAGE_SUPPORT_WBMP
if (imagetype==CXIMAGE_FORMAT_WBMP){
CxImageWBMP newima;
newima.Ghost(this);
if (newima.Encode(hFile)){
return true;
} else {
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
#if CXIMAGE_SUPPORT_WMF && CXIMAGE_SUPPORT_WINDOWS // <vho> - WMF/EMF support
if (imagetype==CXIMAGE_FORMAT_WMF){
CxImageWMF newima;
newima.Ghost(this);
if (newima.Encode(hFile)){
return true;
} else {
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
#if CXIMAGE_SUPPORT_J2K
if (imagetype==CXIMAGE_FORMAT_J2K){
CxImageJ2K newima;
newima.Ghost(this);
if (newima.Encode(hFile)){
return true;
} else {
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
#if CXIMAGE_SUPPORT_JBG
if (imagetype==CXIMAGE_FORMAT_JBG){
CxImageJBG newima;
newima.Ghost(this);
if (newima.Encode(hFile)){
return true;
} else {
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
//ThanhDK=====================================
#if CXIMAGE_SUPPORT_CHIBA
if (imagetype==CXIMAGE_FORMAT_CHIBA){
CxImageCHIBA newima;
newima.Ghost(this);
if (newima.Encode(hFile)){
return true;
} else {
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
//============================================
#if CXIMAGE_SUPPORT_JASPER
if (
#if CXIMAGE_SUPPORT_JP2
imagetype==CXIMAGE_FORMAT_JP2 ||
#endif
#if CXIMAGE_SUPPORT_JPC
imagetype==CXIMAGE_FORMAT_JPC ||
#endif
#if CXIMAGE_SUPPORT_PGX
imagetype==CXIMAGE_FORMAT_PGX ||
#endif
#if CXIMAGE_SUPPORT_PNM
imagetype==CXIMAGE_FORMAT_PNM ||
#endif
#if CXIMAGE_SUPPORT_RAS
imagetype==CXIMAGE_FORMAT_RAS ||
#endif
false ){
CxImageJAS newima;
newima.Ghost(this);
if (newima.Encode(hFile,imagetype)){
return true;
} else {
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
strcpy(info.szLastError,"Encode: Unknown format");
return false;
}
////////////////////////////////////////////////////////////////////////////////
bool CxImage::Encode(FILE * hFile, CxImage ** pImages, int pagecount, DWORD imagetype)
{
CxIOFile file(hFile);
return Encode(&file, pImages, pagecount,imagetype);
}
////////////////////////////////////////////////////////////////////////////////
bool CxImage::Encode(CxFile * hFile, CxImage ** pImages, int pagecount, DWORD imagetype)
{
#if CXIMAGE_SUPPORT_TIF
if (imagetype==CXIMAGE_FORMAT_TIF){
CxImageTIF newima;
newima.Ghost(this);
if (newima.Encode(hFile,pImages,pagecount)){
return true;
} else {
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
#if CXIMAGE_SUPPORT_GIF
if (imagetype==CXIMAGE_FORMAT_GIF){
CxImageGIF newima;
newima.Ghost(this);
if (newima.Encode(hFile,pImages,pagecount)){
return true;
} else {
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
strcpy(info.szLastError,"Multipage Encode, Unsupported operation for this format");
return false;
}
////////////////////////////////////////////////////////////////////////////////
#endif //CXIMAGE_SUPPORT_ENCODE
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
#if CXIMAGE_SUPPORT_DECODE
////////////////////////////////////////////////////////////////////////////////
// For UNICODE support: char -> TCHAR
bool CxImage::Load(const TCHAR * filename, DWORD imagetype)
//bool CxImage::Load(const char * filename, DWORD imagetype)
{
/*FILE* hFile; //file handle to read the image
if ((hFile=fopen(filename,"rb"))==NULL) return false;
bool bOK = Decode(hFile,imagetype);
fclose(hFile);*/
/* automatic file type recognition */
bool bOK = false;
if ( imagetype > 0 && imagetype < CMAX_IMAGE_FORMATS ){
FILE* hFile; //file handle to read the image
if ((hFile=_tfopen(filename,_T("rb")))==NULL) return false; // For UNICODE support
//if ((hFile=fopen(filename,"rb"))==NULL) return false;
bOK = Decode(hFile,imagetype);
fclose(hFile);
if (bOK) return bOK;
}
char szError[256];
strcpy(szError,info.szLastError); //save the first error
// if failed, try automatic recognition of the file...
FILE* hFile;
if ((hFile=_tfopen(filename,_T("rb")))==NULL) return false; // For UNICODE support
//if ((hFile=fopen(filename,"rb"))==NULL) return false;
bOK = Decode(hFile,CXIMAGE_FORMAT_UNKNOWN);
fclose(hFile);
if (!bOK && imagetype > 0) strcpy(info.szLastError,szError); //restore the first error
return bOK;
}
////////////////////////////////////////////////////////////////////////////////
#ifdef WIN32
//bool CxImage::Load(LPCWSTR filename, DWORD imagetype)
//{
// /*FILE* hFile; //file handle to read the image
// if ((hFile=_wfopen(filename, L"rb"))==NULL) return false;
// bool bOK = Decode(hFile,imagetype);
// fclose(hFile);*/
//
// /* automatic file type recognition */
// bool bOK = false;
// if ( imagetype > 0 && imagetype < CMAX_IMAGE_FORMATS ){
// FILE* hFile; //file handle to read the image
// if ((hFile=_wfopen(filename,L"rb"))==NULL) return false;
// bOK = Decode(hFile,imagetype);
// fclose(hFile);
// if (bOK) return bOK;
// }
//
// char szError[256];
// strcpy(szError,info.szLastError); //save the first error
//
// // if failed, try automatic recognition of the file...
// FILE* hFile; //file handle to read the image
// if ((hFile=_wfopen(filename,L"rb"))==NULL) return false;
// bOK = Decode(hFile,CXIMAGE_FORMAT_UNKNOWN);
// fclose(hFile);
//
// if (!bOK && imagetype > 0) strcpy(info.szLastError,szError); //restore the first error
//
// return bOK;
//}
////////////////////////////////////////////////////////////////////////////////
bool CxImage::LoadResource(HRSRC hRes, DWORD imagetype, HMODULE hModule)
{
DWORD rsize=SizeofResource(hModule,hRes);
HGLOBAL hMem=::LoadResource(hModule,hRes);
if (hMem){
char* lpVoid=(char*)LockResource(hMem);
if (lpVoid){
// FILE* fTmp=tmpfile(); doesn't work with network
/*char tmpPath[MAX_PATH] = {0};
char tmpFile[MAX_PATH] = {0};
GetTempPath(MAX_PATH,tmpPath);
GetTempFileName(tmpPath,"IMG",0,tmpFile);
FILE* fTmp=fopen(tmpFile,"w+b");
if (fTmp){
fwrite(lpVoid,rsize,1,fTmp);
fseek(fTmp,0,SEEK_SET);
bool bOK = Decode(fTmp,imagetype);
fclose(fTmp);
DeleteFile(tmpFile);
return bOK;
}*/
CxMemFile fTmp((BYTE*)lpVoid,rsize);
return Decode(&fTmp,imagetype);
}
} else strcpy(info.szLastError,"Unable to load resource!");
return false;
}
#endif //WIN32
////////////////////////////////////////////////////////////////////////////////
// File name constructor
// > filename: file name
// > imagetype: specify the image format (CXIMAGE_FORMAT_BMP,...)
// For UNICODE support: char -> TCHAR
CxImage::CxImage(const TCHAR * filename, DWORD imagetype)
//CxImage::CxImage(const char * filename, DWORD imagetype)
{
Startup(imagetype);
Load(filename,imagetype);
}
////////////////////////////////////////////////////////////////////////////////
// Stream constructor
// § the file is always closed by the constructor.
// > stream: file with "rb" access
// > imagetype: specify the image format (CXIMAGE_FORMAT_BMP,...)
CxImage::CxImage(FILE * stream, DWORD imagetype)
{
Startup(imagetype);
Decode(stream,imagetype);
}
////////////////////////////////////////////////////////////////////////////////
CxImage::CxImage(CxFile * stream, DWORD imagetype)
{
Startup(imagetype);
Decode(stream,imagetype);
}
////////////////////////////////////////////////////////////////////////////////
CxImage::CxImage(BYTE * buffer, DWORD size, DWORD imagetype)
{
Startup(imagetype);
CxMemFile stream(buffer,size);
Decode(&stream,imagetype);
}
////////////////////////////////////////////////////////////////////////////////
bool CxImage::Decode(BYTE * buffer, DWORD size, DWORD imagetype)
{
CxMemFile file(buffer,size);
return Decode(&file,imagetype);
}
////////////////////////////////////////////////////////////////////////////////
bool CxImage::Decode(FILE *hFile, DWORD imagetype)
{
CxIOFile file(hFile);
return Decode(&file,imagetype);
}
////////////////////////////////////////////////////////////////////////////////
bool CxImage::Decode(CxFile *hFile, DWORD imagetype)
{
if (imagetype==CXIMAGE_FORMAT_UNKNOWN){
DWORD pos = hFile->Tell();
#if CXIMAGE_SUPPORT_BMP
{ CxImageBMP newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); }
#endif
#if CXIMAGE_SUPPORT_JPG
{ CxImageJPG newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); }
#endif
#if CXIMAGE_SUPPORT_ICO
{ CxImageICO newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); }
#endif
#if CXIMAGE_SUPPORT_GIF
{ CxImageGIF newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); }
#endif
#if CXIMAGE_SUPPORT_PNG
{ CxImagePNG newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); }
#endif
#if CXIMAGE_SUPPORT_TIF
{ CxImageTIF newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); }
#endif
#if CXIMAGE_SUPPORT_MNG
{ CxImageMNG newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); }
#endif
#if CXIMAGE_SUPPORT_TGA
{ CxImageTGA newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); }
#endif
#if CXIMAGE_SUPPORT_PCX
{ CxImagePCX newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); }
#endif
#if CXIMAGE_SUPPORT_WBMP
{ CxImageWBMP newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); }
#endif
#if CXIMAGE_SUPPORT_WMF && CXIMAGE_SUPPORT_WINDOWS
{ CxImageWMF newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); }
#endif
#if CXIMAGE_SUPPORT_J2K
{ CxImageJ2K newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); }
#endif
#if CXIMAGE_SUPPORT_JBG
{ CxImageJBG newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); }
#endif
#if CXIMAGE_SUPPORT_JASPER
{ CxImageJAS newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); }
#endif
}
#if CXIMAGE_SUPPORT_BMP
if (imagetype==CXIMAGE_FORMAT_BMP){
CxImageBMP newima;
newima.CopyInfo(*this);
if (newima.Decode(hFile)){
Transfer(newima);
return true;
} else {
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
#if CXIMAGE_SUPPORT_JPG
if (imagetype==CXIMAGE_FORMAT_JPG){
CxImageJPG newima;
newima.CopyInfo(*this); // <ignacio>
if (newima.Decode(hFile)){
Transfer(newima);
return true;
} else {
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
#if CXIMAGE_SUPPORT_ICO
if (imagetype==CXIMAGE_FORMAT_ICO){
CxImageICO newima;
newima.CopyInfo(*this);
if (newima.Decode(hFile)){
Transfer(newima);
return true;
} else {
info.nNumFrames = newima.info.nNumFrames;
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
#if CXIMAGE_SUPPORT_GIF
if (imagetype==CXIMAGE_FORMAT_GIF){
CxImageGIF newima;
newima.CopyInfo(*this);
if (newima.Decode(hFile)){
Transfer(newima);
return true;
} else {
info.nNumFrames = newima.info.nNumFrames;
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
#if CXIMAGE_SUPPORT_PNG
if (imagetype==CXIMAGE_FORMAT_PNG){
CxImagePNG newima;
newima.CopyInfo(*this);
if (newima.Decode(hFile)){
Transfer(newima);
return true;
} else {
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
#if CXIMAGE_SUPPORT_TIF
if (imagetype==CXIMAGE_FORMAT_TIF){
CxImageTIF newima;
newima.CopyInfo(*this);
if (newima.Decode(hFile)){
Transfer(newima);
return true;
} else {
info.nNumFrames = newima.info.nNumFrames;
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
#if CXIMAGE_SUPPORT_MNG
if (imagetype==CXIMAGE_FORMAT_MNG){
CxImageMNG newima;
newima.CopyInfo(*this);
if (newima.Decode(hFile)){
Transfer(newima);
return true;
} else {
info.nNumFrames = newima.info.nNumFrames;
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
#if CXIMAGE_SUPPORT_TGA
if (imagetype==CXIMAGE_FORMAT_TGA){
CxImageTGA newima;
newima.CopyInfo(*this);
if (newima.Decode(hFile)){
Transfer(newima);
return true;
} else {
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
#if CXIMAGE_SUPPORT_PCX
if (imagetype==CXIMAGE_FORMAT_PCX){
CxImagePCX newima;
newima.CopyInfo(*this);
if (newima.Decode(hFile)){
Transfer(newima);
return true;
} else {
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
#if CXIMAGE_SUPPORT_WBMP
if (imagetype==CXIMAGE_FORMAT_WBMP){
CxImageWBMP newima;
newima.CopyInfo(*this);
if (newima.Decode(hFile)){
Transfer(newima);
return true;
} else {
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
#if CXIMAGE_SUPPORT_WMF && CXIMAGE_SUPPORT_WINDOWS // vho - WMF support
if (imagetype == CXIMAGE_FORMAT_WMF){
CxImageWMF newima;
newima.CopyInfo(*this);
if (newima.Decode(hFile)){
Transfer(newima);
return true;
} else {
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
#if CXIMAGE_SUPPORT_J2K
if (imagetype==CXIMAGE_FORMAT_J2K){
CxImageJ2K newima;
newima.CopyInfo(*this);
if (newima.Decode(hFile)){
Transfer(newima);
return true;
} else {
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
#if CXIMAGE_SUPPORT_JBG
if (imagetype==CXIMAGE_FORMAT_JBG){
CxImageJBG newima;
newima.CopyInfo(*this);
if (newima.Decode(hFile)){
Transfer(newima);
return true;
} else {
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
#if CXIMAGE_SUPPORT_JASPER
if (
#if CXIMAGE_SUPPORT_JP2
imagetype==CXIMAGE_FORMAT_JP2 ||
#endif
#if CXIMAGE_SUPPORT_JPC
imagetype==CXIMAGE_FORMAT_JPC ||
#endif
#if CXIMAGE_SUPPORT_PGX
imagetype==CXIMAGE_FORMAT_PGX ||
#endif
#if CXIMAGE_SUPPORT_PNM
imagetype==CXIMAGE_FORMAT_PNM ||
#endif
#if CXIMAGE_SUPPORT_RAS
imagetype==CXIMAGE_FORMAT_RAS ||
#endif
false ){
CxImageJAS newima;
newima.CopyInfo(*this);
if (newima.Decode(hFile,imagetype)){
Transfer(newima);
return true;
} else {
strcpy(info.szLastError,newima.GetLastError());
return false;
}
}
#endif
strcpy(info.szLastError,"Decode: Unknown or wrong format");
return false;
}
////////////////////////////////////////////////////////////////////////////////
#endif //CXIMAGE_SUPPORT_DECODE
////////////////////////////////////////////////////////////////////////////////
//===================================================
// cximage\cximage.h
//===================================================
#if !defined(__CXIMAGE_H)
#define __CXIMAGE_H
#if _MSC_VER > 1000
#pragma once
#endif
/////////////////////////////////////////////////////////////////////////////
// CxImage supported features
#define CXIMAGE_SUPPORT_ALPHA 1
#define CXIMAGE_SUPPORT_SELECTION 1
#define CXIMAGE_SUPPORT_TRANSFORMATION 1
#define CXIMAGE_SUPPORT_DSP 1
#define CXIMAGE_SUPPORT_LAYERS 1
#define CXIMAGE_SUPPORT_DECODE 1
#define CXIMAGE_SUPPORT_ENCODE 1 //<vho><t.peck>
#define CXIMAGE_SUPPORT_WINDOWS 1
#define CXIMAGE_SUPPORT_WINCE 0 //<t.peck>
/////////////////////////////////////////////////////////////////////////////
// CxImage supported formats
#define CXIMAGE_SUPPORT_BMP 1
#define CXIMAGE_SUPPORT_GIF 1
#define CXIMAGE_SUPPORT_JPG 1
#define CXIMAGE_SUPPORT_PNG 1
#define CXIMAGE_SUPPORT_MNG 0
#define CXIMAGE_SUPPORT_ICO 1
#define CXIMAGE_SUPPORT_TIF 1
#define CXIMAGE_SUPPORT_TGA 1
#define CXIMAGE_SUPPORT_PCX 1
#define CXIMAGE_SUPPORT_WBMP 1
#define CXIMAGE_SUPPORT_WMF 1
#define CXIMAGE_SUPPORT_J2K 0 // Beta, use JP2
#define CXIMAGE_SUPPORT_JBG 0 // GPL'd see ../jbig/copying.txt & ../jbig/patents.htm
#define CXIMAGE_SUPPORT_JP2 1
#define CXIMAGE_SUPPORT_JPC 1
#define CXIMAGE_SUPPORT_PGX 1
#define CXIMAGE_SUPPORT_PNM 1
#define CXIMAGE_SUPPORT_RAS 1
#define CXIMAGE_SUPPORT_CHIBA 1
/////////////////////////////////////////////////////////////////////////////
#include <tchar.h> // For UNICODE support
#include "xfile.h"
#include "xiofile.h"
#include "xmemfile.h"
#include "ximadefs.h" //<vho> adjust some #define
/////////////////////////////////////////////////////////////////////////////
// CxImage formats enumerator
enum ENUM_CXIMAGE_FORMATS{
CXIMAGE_FORMAT_UNKNOWN,
#if CXIMAGE_SUPPORT_BMP
CXIMAGE_FORMAT_BMP,
#endif
#if CXIMAGE_SUPPORT_GIF
CXIMAGE_FORMAT_GIF,
#endif
#if CXIMAGE_SUPPORT_JPG
CXIMAGE_FORMAT_JPG,
#endif
#if CXIMAGE_SUPPORT_PNG
CXIMAGE_FORMAT_PNG,
#endif
#if CXIMAGE_SUPPORT_MNG
CXIMAGE_FORMAT_MNG,
#endif
#if CXIMAGE_SUPPORT_ICO
CXIMAGE_FORMAT_ICO,
#endif
#if CXIMAGE_SUPPORT_TIF
CXIMAGE_FORMAT_TIF,
#endif
#if CXIMAGE_SUPPORT_TGA
CXIMAGE_FORMAT_TGA,
#endif
#if CXIMAGE_SUPPORT_PCX
CXIMAGE_FORMAT_PCX,
#endif
#if CXIMAGE_SUPPORT_WBMP
CXIMAGE_FORMAT_WBMP,
#endif
#if CXIMAGE_SUPPORT_WMF
CXIMAGE_FORMAT_WMF,
#endif
#if CXIMAGE_SUPPORT_J2K
CXIMAGE_FORMAT_J2K,
#endif
#if CXIMAGE_SUPPORT_JBG
CXIMAGE_FORMAT_JBG,
#endif
#if CXIMAGE_SUPPORT_JP2
CXIMAGE_FORMAT_JP2,
#endif
#if CXIMAGE_SUPPORT_JPC
CXIMAGE_FORMAT_JPC,
#endif
#if CXIMAGE_SUPPORT_PGX
CXIMAGE_FORMAT_PGX,
#endif
#if CXIMAGE_SUPPORT_PNM
CXIMAGE_FORMAT_PNM,
#endif
#if CXIMAGE_SUPPORT_RAS
CXIMAGE_FORMAT_RAS,
#endif
#if CXIMAGE_SUPPORT_CHIBA
CXIMAGE_FORMAT_CHIBA,
#endif
CMAX_IMAGE_FORMATS
};
//color to grey mapping <h. muelner=""> <jurgene>
//#define RGB2GRAY(r,g,b) (((b)*114 + (g)*587 + (r)*299)/1000)
#define RGB2GRAY(r,g,b) (((b)*117 + (g)*601 + (r)*306) >> 10)
struct rgb_color { BYTE r,g,b; };
// <vati> text placement data
// members must be initialized with the InitTextInfo(&this) function.
typedef struct DLL_EXP tagCxTextInfo
{
char text[4096]; // text
LOGFONT lfont; // font and codepage data
COLORREF fcolor; // foreground color
long align; // DT_CENTER, DT_RIGHT, DT_LEFT aligment for multiline text
BYTE opaque; // text has background or hasn't. Default is true.
// data for background (ignored if .opaque==FALSE)
COLORREF bcolor; // background color
float b_opacity; // opacity value for background between 0.0-1.0 Default is 0. (opaque)
BYTE b_outline; // outline width for background (zero: no outline)
BYTE b_round; // rounding radius for background rectangle. % of the height, between 0-50. Default is 10.
// (backgr. always has a frame: width = 3 pixel + 10% of height by default.)
} CXTEXTINFO;
/////////////////////////////////////////////////////////////////////////////
// CxImage class
/////////////////////////////////////////////////////////////////////////////
class DLL_EXP CxImage
{
//extensible information collector
typedef struct tagCxImageInfo {
DWORD dwEffWidth; //DWORD aligned scan line width
BYTE* pImage; //THE IMAGE BITS
CxImage* pGhost; //if this is a ghost, pGhost points to the body
CxImage* pParent; //if this is a layer, pParent points to the body
DWORD dwType; //original image format
char szLastError[256]; //debugging
long nProgress; //monitor
long nEscape; //escape
long nBkgndIndex; //used for GIF, PNG, MNG
RGBQUAD nBkgndColor; //used for RGB transparency
BYTE nQuality; //used for JPEG
BYTE nScale; //used for JPEG <ignacio>
long nFrame; //used for TIF, GIF, MNG : actual frame
long nNumFrames; //used for TIF, GIF, MNG : total number of frames
DWORD dwFrameDelay; //used for GIF, MNG
long xDPI; //horizontal resolution
long yDPI; //vertical resolution
RECT rSelectionBox; //bounding rectangle
BYTE nAlphaMax; //max opacity (fade)
bool bAlphaPaletteEnabled; //true if alpha values in the palette are enabled.
bool bEnabled; //enables the painting functions
long xOffset;
long yOffset;
DWORD dwCodecOption; //for GIF, TIF : 0=def.1=unc,2=fax3,3=fax4,4=pack,5=jpg
RGBQUAD last_c; //for GetNearestIndex optimization
BYTE last_c_index;
bool last_c_isvalid;
long nNumLayers;
DWORD dwFlags; // 0x??00000 = reserved, 0x00??0000 = blend mode, 0x0000???? = layer id - user flags
} CXIMAGEINFO;
public:
//constructors
CxImage(DWORD imagetype = 0);
CxImage(DWORD dwWidth, DWORD dwHeight, DWORD wBpp, DWORD imagetype = 0);
CxImage(const CxImage &src, bool copypixels = true, bool copyselection = true, bool copyalpha = true);
CxImage(const TCHAR * filename, DWORD imagetype); // For UNICODE support: char -> TCHAR
// CxImage(const char * filename, DWORD imagetype);
CxImage(FILE * stream, DWORD imagetype);
CxImage(CxFile * stream, DWORD imagetype);
CxImage(BYTE * buffer, DWORD size, DWORD imagetype);
virtual ~CxImage() { Destroy(); };
CxImage& operator = (const CxImage&);
//initializzation
void* Create(DWORD dwWidth, DWORD dwHeight, DWORD wBpp, DWORD imagetype = 0);
bool Destroy();
void Clear(BYTE bval=0);
void Copy(const CxImage &src, bool copypixels = true, bool copyselection = true, bool copyalpha = true);
bool Transfer(CxImage &from);
bool CreateFromArray(BYTE* pArray,DWORD dwWidth,DWORD dwHeight,DWORD dwBitsperpixel, DWORD dwBytesperline, bool bFlipImage);
bool CreateFromMatrix(BYTE** ppMatrix,DWORD dwWidth,DWORD dwHeight,DWORD dwBitsperpixel, DWORD dwBytesperline, bool bFlipImage);
//Attributes
long GetSize();
BYTE* GetBits(DWORD row = 0);
BYTE GetColorType();
void* GetDIB() const {return pDib;}
DWORD GetHeight() const {return head.biHeight;}
DWORD GetWidth() const {return head.biWidth;}
DWORD GetEffWidth() const {return info.dwEffWidth;}
DWORD GetNumColors() const {return head.biClrUsed;}
WORD GetBpp() const {return head.biBitCount;}
DWORD GetType() const {return info.dwType;}
char* GetLastError() {return info.szLastError;}
const TCHAR* GetVersion();
DWORD GetFrameDelay() const {return info.dwFrameDelay;}
void SetFrameDelay(DWORD d) {info.dwFrameDelay=d;}
void GetOffset(long *x,long *y) {*x=info.xOffset; *y=info.yOffset;}
void SetOffset(long x,long y) {info.xOffset=x; info.yOffset=y;}
BYTE GetJpegQuality() const {return info.nQuality;}
void SetJpegQuality(BYTE q) {info.nQuality = q;}
//<ignacio> used for scaling down during JPEG decoding valid numbers are 1, 2, 4, 8
BYTE GetJpegScale() const {return info.nScale;}
void SetJpegScale(BYTE q) {info.nScale = q;}
long GetXDPI() const {return info.xDPI;}
long GetYDPI() const {return info.yDPI;}
void SetXDPI(long dpi);
void SetYDPI(long dpi);
DWORD GetClrImportant() const {return head.biClrImportant;}
void SetClrImportant(DWORD ncolors = 0);
long GetProgress() const {return info.nProgress;}
long GetEscape() const {return info.nEscape;}
void SetProgress(long p) {info.nProgress = p;}
void SetEscape(long i) {info.nEscape = i;}
long GetTransIndex() const {return info.nBkgndIndex;}
RGBQUAD GetTransColor();
void SetTransIndex(long idx) {info.nBkgndIndex = idx;}
void SetTransColor(RGBQUAD rgb) {rgb.rgbReserved=0; info.nBkgndColor = rgb;}
bool IsTransparent() const {return info.nBkgndIndex>=0;} // <vho>
DWORD GetCodecOption() const {return info.dwCodecOption;}
void SetCodecOption(DWORD opt) {info.dwCodecOption = opt;}
DWORD GetFlags() const {return info.dwFlags;}
void SetFlags(DWORD flags, bool bLockReservedFlags = true);
//void* GetUserData() const {return info.pUserData;}
//void SetUserData(void* pUserData) {info.pUserData = pUserData;}
//palette operations
bool IsGrayScale();
bool IsIndexed() {return head.biClrUsed!=0;}
DWORD GetPaletteSize();
RGBQUAD* GetPalette() const;
RGBQUAD GetPaletteColor(BYTE idx);
bool GetPaletteColor(BYTE i, BYTE* r, BYTE* g, BYTE* b);
BYTE GetNearestIndex(RGBQUAD c);
void BlendPalette(COLORREF cr,long perc);
void SetGrayPalette();
void SetPalette(DWORD n, BYTE *r, BYTE *g, BYTE *b);
void SetPalette(RGBQUAD* pPal,DWORD nColors=256);
void SetPalette(rgb_color *rgb,DWORD nColors=256);
void SetPaletteColor(BYTE idx, BYTE r, BYTE g, BYTE b, BYTE alpha=0);
void SetPaletteColor(BYTE idx, RGBQUAD c);
void SetPaletteColor(BYTE idx, COLORREF cr);
void SwapIndex(BYTE idx1, BYTE idx2);
void SetStdPalette();
//pixel operations
bool IsInside(long x, long y);
bool IsTransparent(long x,long y);
RGBQUAD GetPixelColor(long x,long y, bool bGetAlpha = true);
BYTE GetPixelIndex(long x,long y);
BYTE GetPixelGray(long x, long y);
void SetPixelColor(long x,long y,RGBQUAD c, bool bSetAlpha = false);
void SetPixelColor(long x,long y,COLORREF cr);
void SetPixelIndex(long x,long y,BYTE i);
void DrawLine(int StartX, int EndX, int StartY, int EndY, RGBQUAD color, bool bSetAlpha=false);
void DrawLine(int StartX, int EndX, int StartY, int EndY, COLORREF cr);
//painting operations
#if CXIMAGE_SUPPORT_WINCE
long Blt(HDC pDC, long x=0, long y=0);
#endif
#if CXIMAGE_SUPPORT_WINDOWS
HBITMAP MakeBitmap(HDC hdc = NULL);
HANDLE CopyToHandle();
bool CreateFromHANDLE(HANDLE hMem); //Windows objects (clipboard)
bool CreateFromHBITMAP(HBITMAP hbmp, HPALETTE hpal=0); //Windows resource
bool CreateFromHICON(HICON hico);
long Draw(HDC hdc, long x=0, long y=0, long cx = -1, long cy = -1, RECT* pClipRect = 0);
long Draw(HDC hdc, const RECT& rect, RECT* pClipRect=NULL) { return Draw(hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, pClipRect); }
long Stretch(HDC hdc, long xoffset, long yoffset, long xsize, long ysize, DWORD dwRop = SRCCOPY);
long Stretch(HDC hdc, const RECT& rect, DWORD dwRop = SRCCOPY) { return Stretch(hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, dwRop); }
long Tile(HDC hdc, RECT *rc);
long Draw2(HDC hdc, long x=0, long y=0, long cx = -1, long cy = -1);
long Draw2(HDC hdc, const RECT& rect) { return Draw2(hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); }
//long DrawString(HDC hdc, long x, long y, const char* text, RGBQUAD color, const char* font, long lSize=0, long lWeight=400, BYTE bItalic=0, BYTE bUnderline=0, bool bSetAlpha=false);
long DrawString(HDC hdc, long x, long y, const TCHAR* text, RGBQUAD color, const TCHAR* font, long lSize=0, long lWeight=400, BYTE bItalic=0, BYTE bUnderline=0, bool bSetAlpha=false);
// <vati> extensions
long DrawStringEx(HDC hdc, long x, long y, CXTEXTINFO *pTextType, bool bSetAlpha=false );
void InitTextInfo( CXTEXTINFO *txt );
#endif //CXIMAGE_SUPPORT_WINDOWS
// file operations
#if CXIMAGE_SUPPORT_DECODE
#ifdef WIN32
//bool Load(LPCWSTR filename, DWORD imagetype=0);
bool LoadResource(HRSRC hRes, DWORD imagetype, HMODULE hModule=NULL);
#endif
// For UNICODE support: char -> TCHAR
bool Load(const TCHAR* filename, DWORD imagetype=0);
//bool Load(const char * filename, DWORD imagetype=0);
bool Decode(FILE * hFile, DWORD imagetype);
bool Decode(CxFile * hFile, DWORD imagetype);
bool Decode(BYTE * buffer, DWORD size, DWORD imagetype);
#endif //CXIMAGE_SUPPORT_DECODE
#if CXIMAGE_SUPPORT_ENCODE
protected:
bool EncodeSafeCheck(CxFile *hFile);
public:
#ifdef WIN32
//bool Save(LPCWSTR filename, DWORD imagetype=0);
#endif
// For UNICODE support: char -> TCHAR
bool Save(const TCHAR* filename, DWORD imagetype=0);
//bool Save(const char * filename, DWORD imagetype=0);
bool Encode(FILE * hFile, DWORD imagetype);
bool Encode(CxFile * hFile, DWORD imagetype);
bool Encode(CxFile * hFile, CxImage ** pImages, int pagecount, DWORD imagetype);
bool Encode(FILE *hFile, CxImage ** pImages, int pagecount, DWORD imagetype);
bool Encode(BYTE * &buffer, long &size, DWORD imagetype);
#endif //CXIMAGE_SUPPORT_ENCODE
//misc.
bool IsValid() const {return pDib!=0;}
bool IsEnabled() const {return info.bEnabled;}
void Enable(bool enable=true){info.bEnabled=enable;}
// frame operations
long GetNumFrames() const {return info.nNumFrames;}
long GetFrame() const {return info.nFrame;}
void SetFrame(long nFrame) {info.nFrame=nFrame;}
#if CXIMAGE_SUPPORT_BASICTRANSFORMATIONS
bool GrayScale();
bool Flip();
bool Mirror();
bool Negative();
bool RotateLeft(CxImage* iDst = NULL);
bool RotateRight(CxImage* iDst = NULL);
#endif //CXIMAGE_SUPPORT_BASICTRANSFORMATIONS
#if CXIMAGE_SUPPORT_TRANSFORMATION
// image operations
bool Rotate(float angle, CxImage* iDst = NULL);
bool Rotate180(CxImage* iDst = NULL);
bool Resample(long newx, long newy, int mode = 1, CxImage* iDst = NULL);
bool DecreaseBpp(DWORD nbit, bool errordiffusion, RGBQUAD* ppal = 0, DWORD clrimportant = 0);
bool IncreaseBpp(DWORD nbit);
bool Dither(long method = 0);
bool Crop(long left, long top, long right, long bottom, CxImage* iDst = NULL);
bool Crop(const RECT& rect, CxImage* iDst = NULL) { return Crop(rect.left, rect.top, rect.right, rect.bottom, iDst); }
bool CropRotatedRectangle( long topx, long topy, long width, long height, float angle, CxImage* iDst = NULL);
bool Skew(float xgain, float ygain, long xpivot=0, long ypivot=0);
bool Expand(long left, long top, long right, long bottom, RGBQUAD canvascolor, CxImage* iDst = 0);
bool Expand(long newx, long newy, RGBQUAD canvascolor, CxImage* iDst = 0);
bool Thumbnail(long newx, long newy, RGBQUAD canvascolor, CxImage* iDst = 0);
bool CircleTransform(int type,long rmax=0,float Koeff=1.0f);
protected:
float b3spline(float x);
public:
#endif //CXIMAGE_SUPPORT_TRANSFORMATION
#if CXIMAGE_SUPPORT_DSP
bool Contour();
bool HistogramStretch(long method = 0);
bool HistogramEqualize();
bool HistogramNormalize();
bool HistogramRoot();
bool HistogramLog();
long Histogram(long* red, long* green = 0, long* blue = 0, long* gray = 0, long colorspace = 0);
bool Jitter(long radius=2);
bool Repair(float radius = 0.25f, long niterations = 1, long colorspace = 0);
bool Combine(CxImage* r,CxImage* g,CxImage* b,CxImage* a, long colorspace = 0);
bool FFT2(CxImage* srcReal, CxImage* srcImag, CxImage* dstReal, CxImage* dstImag, long direction = 1, bool bForceFFT = true, bool bMagnitude = true);
bool Noise(long level);
bool Median(long Ksize=3);
bool Gamma(float gamma);
bool ShiftRGB(long r, long g, long b);
bool Threshold(BYTE level);
bool Colorize(BYTE hue, BYTE sat);
bool Light(long brightness, long contrast = 0);
float Mean();
bool Filter(long* kernel, long Ksize, long Kfactor, long Koffset);
bool Erode(long Ksize=2);
bool Dilate(long Ksize=2);
void HuePalette(float correction=1);
enum ImageOpType { OpAdd, OpAnd, OpXor, OpOr, OpMask, OpSrcCopy, OpDstCopy, OpSub, OpSrcBlend };
void Mix(CxImage & imgsrc2, ImageOpType op, long lXOffset = 0, long lYOffset = 0);
void MixFrom(CxImage & imagesrc2, long lXOffset, long lYOffset);
bool UnsharpMask(float radius = 5.0, float amount = 0.5, int threshold = 0);
bool Lut(BYTE* pLut);
bool Lut(BYTE* pLutR, BYTE* pLutG, BYTE* pLutB, BYTE* pLutA = 0);
protected:
bool IsPowerof2(long x);
bool FFT(int dir,int m,double *x,double *y);
bool DFT(int dir,long m,double *x1,double *y1,double *x2,double *y2);
bool RepairChannel(CxImage *ch, float radius);
// <nipper>
int gen_convolve_matrix (float radius, float **cmatrix_p);
float* gen_lookup_table (float *cmatrix, int cmatrix_length);
void blur_line (float *ctable, float *cmatrix, int cmatrix_length, BYTE* cur_col, BYTE* dest_col, int y, long bytes);
public:
//color conversion utilities
bool SplitRGB(CxImage* r,CxImage* g,CxImage* b);
bool SplitYUV(CxImage* y,CxImage* u,CxImage* v);
bool SplitHSL(CxImage* h,CxImage* s,CxImage* l);
bool SplitYIQ(CxImage* y,CxImage* i,CxImage* q);
bool SplitXYZ(CxImage* x,CxImage* y,CxImage* z);
bool SplitCMYK(CxImage* c,CxImage* m,CxImage* y,CxImage* k);
RGBQUAD HSLtoRGB(COLORREF cHSLColor);
RGBQUAD RGBtoHSL(RGBQUAD lRGBColor);
RGBQUAD HSLtoRGB(RGBQUAD lHSLColor);
RGBQUAD YUVtoRGB(RGBQUAD lYUVColor);
RGBQUAD RGBtoYUV(RGBQUAD lRGBColor);
RGBQUAD YIQtoRGB(RGBQUAD lYIQColor);
RGBQUAD RGBtoYIQ(RGBQUAD lRGBColor);
RGBQUAD XYZtoRGB(RGBQUAD lXYZColor);
RGBQUAD RGBtoXYZ(RGBQUAD lRGBColor);
#endif //CXIMAGE_SUPPORT_DSP
RGBQUAD RGBtoRGBQUAD(COLORREF cr);
COLORREF RGBQUADtoRGB (RGBQUAD c);
#if CXIMAGE_SUPPORT_SELECTION
//selection
bool SelectionClear();
bool SelectionCreate();
bool SelectionDelete();
bool SelectionInvert();
bool SelectionAddRect(RECT r);
bool SelectionAddEllipse(RECT r);
bool SelectionAddPolygon(POINT *points, long npoints);
bool SelectionAddColor(RGBQUAD c);
bool SelectionAddPixel(int x, int y);
bool SelectionCopy(CxImage &from);
bool SelectionIsInside(long x, long y);
bool SelectionIsValid(){return pSelection!=0;}
void SelectionGetBox(RECT& r){memcpy(&r,&info.rSelectionBox,sizeof(RECT));}
bool SelectionToHRGN(HRGN& region);
#endif //CXIMAGE_SUPPORT_SELECTION
#if CXIMAGE_SUPPORT_ALPHA
//Alpha
void AlphaClear();
void AlphaCreate();
void AlphaDelete();
void AlphaInvert();
bool AlphaMirror();
bool AlphaFlip();
bool AlphaCopy(CxImage &from);
bool AlphaSplit(CxImage *dest);
void AlphaStrip();
void AlphaSet(BYTE level);
bool AlphaSet(CxImage &from);
void AlphaSet(long x,long y,BYTE level);
BYTE AlphaGet(long x,long y);
BYTE AlphaGetMax() const {return info.nAlphaMax;}
void AlphaSetMax(BYTE nAlphaMax) {info.nAlphaMax=nAlphaMax;}
bool AlphaIsValid(){return pAlpha!=0;}
BYTE* AlphaGetBits() const {return pAlpha;}
void AlphaPaletteClear();
void AlphaPaletteEnable(bool enable=true){info.bAlphaPaletteEnabled=enable;}
bool AlphaPaletteIsEnabled(){return info.bAlphaPaletteEnabled;}
bool AlphaPaletteIsValid();
bool AlphaPaletteSplit(CxImage *dest);
#endif //CXIMAGE_SUPPORT_ALPHA
#if CXIMAGE_SUPPORT_LAYERS
bool LayerCreate(long position = -1);
bool LayerDelete(long position = -1);
void LayerDeleteAll();
CxImage* GetLayer(long position);
CxImage* GetParent() const {return info.pParent;}
long GetNumLayers() const {return info.nNumLayers;}
#endif //CXIMAGE_SUPPORT_LAYERS
protected:
void Startup(DWORD imagetype = 0);
void CopyInfo(const CxImage &src);
void Ghost(CxImage *src);
void RGBtoBGR(BYTE *buffer, int length);
float HueToRGB(float n1,float n2, float hue);
void Bitfield2RGB(BYTE *src, WORD redmask, WORD greenmask, WORD bluemask, BYTE bpp);
static int CompareColors(const void *elem1, const void *elem2);
void* pDib; //contains the header, the palette, the pixels
BITMAPINFOHEADER head; //standard header
CXIMAGEINFO info; //extended information
BYTE* pSelection; //selected region
BYTE* pAlpha; //alpha channel
CxImage** pLayers; //generic layers
};
////////////////////////////////////////////////////////////////////////////
#define CXIMAGE_MAX_MEMORY 256000000
#define CXIMAGE_ERR_NOFILE "null file handler"
#define CXIMAGE_ERR_NOIMAGE "null image!!!"
////////////////////////////////////////////////////////////////////////////
#endif // !defined(__CXIMAGE_H)
|
|
|
|
|
//===================================================
// demo\demo.cpp
//===================================================
// demo.cpp : Defines the class behaviors for the application.
#include "stdafx.h"
#include "demo.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#include "demoDoc.h"
#include "demoView.h"
#include "xTargetButton.h"
#include "DlgURL.h"
#include "ximage.h"
#include "ximagif.h"
#include "ximatif.h"
#include "xfile.h"
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
DocType doctypes[CMAX_IMAGE_FORMATS] =
{
{ -1, TRUE, TRUE, "Supported files", "*.bmp;*.gif;*.jpg;*.jpeg;*.png;*.ico;*.tif;*.tiff;*.tga;*.pcx;*.wbmp;*.wmf;*.emf;*.j2k;*.jp2;*.jbg;*.j2c;*.jpc;*.pgx;*.pnm;*.pgm;*.ppm;*.ras" },
//ThanhDK========================================
#if CXIMAGE_SUPPORT_CHIBA
{ CXIMAGE_SUPPORT_CHIBA, TRUE, TRUE, "CHIBA files", "*.xyz, *.rgb, *.ktu" },
#endif
//===============================================
#if CXIMAGE_SUPPORT_BMP
{ CXIMAGE_FORMAT_BMP, TRUE, TRUE, "BMP files", "*.bmp" },
#endif
#if CXIMAGE_SUPPORT_GIF
{ CXIMAGE_FORMAT_GIF, TRUE, TRUE, "GIF files", "*.gif" },
#endif
#if CXIMAGE_SUPPORT_JPG
{ CXIMAGE_FORMAT_JPG, TRUE, TRUE, "JPG files", "*.jpg;*.jpeg" },
#endif
#if CXIMAGE_SUPPORT_PNG
{ CXIMAGE_FORMAT_PNG, TRUE, TRUE, "PNG files", "*.png" },
#endif
#if CXIMAGE_SUPPORT_MNG
{ CXIMAGE_FORMAT_MNG, TRUE, TRUE, "MNG files", "*.mng;*.jng;*.png" },
#endif
#if CXIMAGE_SUPPORT_ICO
{ CXIMAGE_FORMAT_ICO, TRUE, TRUE, "ICO CUR files", "*.ico;*.cur" },
#endif
#if CXIMAGE_SUPPORT_TIF
{ CXIMAGE_FORMAT_TIF, TRUE, TRUE, "TIF files", "*.tif;*.tiff" },
#endif
#if CXIMAGE_SUPPORT_TGA
{ CXIMAGE_FORMAT_TGA, TRUE, TRUE, "TGA files", "*.tga" },
#endif
#if CXIMAGE_SUPPORT_PCX
{ CXIMAGE_FORMAT_PCX, TRUE, TRUE, "PCX files", "*.pcx" },
#endif
#if CXIMAGE_SUPPORT_WBMP
{ CXIMAGE_FORMAT_WBMP, TRUE, TRUE, "WBMP files", "*.wbmp" },
#endif
#if CXIMAGE_SUPPORT_WMF
{ CXIMAGE_FORMAT_WMF, TRUE, FALSE, "WMF EMF files", "*.wmf;*.emf" },
#endif
#if CXIMAGE_SUPPORT_J2K
{ CXIMAGE_FORMAT_J2K, TRUE, TRUE, "J2K files", "*.j2k;*.jp2" },
#endif
#if CXIMAGE_SUPPORT_JBG
{ CXIMAGE_FORMAT_JBG, TRUE, TRUE, "JBG files", "*.jbg" },
#endif
#if CXIMAGE_SUPPORT_JP2
{ CXIMAGE_FORMAT_JP2, TRUE, TRUE, "JP2 files", "*.j2k;*.jp2" },
#endif
#if CXIMAGE_SUPPORT_JPC
{ CXIMAGE_FORMAT_JPC, TRUE, TRUE, "JPC files", "*.j2c;*.jpc" },
#endif
#if CXIMAGE_SUPPORT_PGX
{ CXIMAGE_FORMAT_PGX, TRUE, TRUE, "PGX files", "*.pgx" },
#endif
#if CXIMAGE_SUPPORT_RAS
{ CXIMAGE_FORMAT_RAS, TRUE, TRUE, "RAS files", "*.ras" },
#endif
#if CXIMAGE_SUPPORT_PNM
{ CXIMAGE_FORMAT_PNM, TRUE, TRUE, "PNM files", "*.pnm;*.pgm;*.ppm" }
#endif
};
//////////////////////////////////////////////////////////////////////////////
// CDemoApp
BEGIN_MESSAGE_MAP(CDemoApp, CWinApp)
//{{AFX_MSG_MAP(CDemoApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_IMAGE_FROM_BITMAP, OnImageFromBitmap)
ON_COMMAND(ID_CXIMAGE_LOADJPEGRESOURCE, OnCximageLoadjpegresource)
ON_COMMAND(ID_CXIMAGE_LOADICONRESOURCE, OnCximageLoadiconresource)
ON_COMMAND(ID_CXIMAGE_LOADGIFRESOURCE, OnCximageLoadgifresource)
ON_COMMAND(ID_CXIMAGE_LOADPNGRESOURCE, OnCximageLoadpngresource)
ON_COMMAND(ID_CXIMAGE_LOADTIFRESOURCE, OnCximageLoadtifresource)
ON_COMMAND(ID_WINDOW_CLOSEALL, OnWindowCloseall)
ON_COMMAND(ID_CXIMAGE_DEMOSAVEMULTIPAGETIFF, OnCximageDemosavemultipagetiff)
ON_COMMAND(ID_CXIMAGE_DEMOSAVEANIMATEDGIF, OnCximageDemosaveanimatedgif)
ON_COMMAND(ID_CXIMAGE_DOWNLOADFROMURL, OnCximageDownloadfromurl)
ON_COMMAND(ID_CXIMAGE_DEMOCREATEFROMARRAY, OnCximageDemocreatefromarray)
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CDemoApp::OnFileOpen)
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
//////////////////////////////////////////////////////////////////////////////
// CDemoApp construction
CDemoApp::CDemoApp()
{
m_nDocCount=1; //counter for documents
}
//////////////////////////////////////////////////////////////////////////////
// The one and only CDemoApp object
CDemoApp theApp;
//////////////////////////////////////////////////////////////////////////////
// CDemoApp initialization
BOOL CDemoApp::InitInstance()
{
// <dave> dump memory leaks
#ifdef _DEBUG
_CrtDumpMemoryLeaks();
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
// Standard initialization
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
LoadStdProfileSettings(9); // Load standard INI file options (including MRU)
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(
IDR_DEMOTYPE,
RUNTIME_CLASS(CDemoDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CDemoView));
demoTemplate = pDocTemplate;
AddDocTemplate(pDocTemplate);
// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE;
m_pMainWnd = pMainFrame;
// This code replaces the MFC created menus with
// the Ownerdrawn versions
pDocTemplate->m_hMenuShared=pMainFrame->NewMenu();
pMainFrame->m_hMenuDefault=pMainFrame->NewDefaultMenu();
// This simulates a window being opened if you don't have
// a default window displayed at startup
pMainFrame->OnUpdateFrameMenu(pMainFrame->m_hMenuDefault);
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
// Alter behaviour to not open window immediately
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo)) return FALSE;
#ifdef VATI_EXTENSIONS
// init m_text by a temporary CxImage
CxImage *ima = new CxImage;
ima->InitTextInfo( &m_text );
delete ima;
//recall last used font data for Text tool
sprintf( m_text.lfont.lfFaceName, GetProfileString ( "TextTool", "lfFaceName", "Arial") );
m_text.lfont.lfCharSet = GetProfileInt ( "TextTool", "lfCharSet", EASTEUROPE_CHARSET ) ;
m_text.lfont.lfWeight = GetProfileInt ( "TextTool", "lfWeight", 0 );
m_text.lfont.lfItalic = GetProfileInt ( "TextTool", "lfItalic", 0 );
m_text.lfont.lfUnderline = GetProfileInt ( "TextTool", "lfUnderline", 0 );
m_text.fcolor = GetProfileInt ( "TextTool", "fcolor", RGB( 255,255,160 ));
m_text.bcolor = GetProfileInt ( "TextTool", "bcolor", RGB( 32, 96, 0 ));
m_text.opaque = GetProfileInt ( "TextTool", "opaque", 1);
m_text.b_opacity = (float)(GetProfileInt( "TextTool", "opacity", 0 ))/(float)100.;
m_text.b_round = GetProfileInt ( "TextTool", "roundradius", 25 );
m_optJpegQuality = GetProfileInt("Options","JpegQuality",90);
// recall if main window was maximized on last exit
if ( GetProfileInt ( "Screen", "maximized", 0 ))
m_nCmdShow|=SW_MAXIMIZE;
#endif;
// The main window has been initialized, so show and update it.
pMainFrame -> ShowWindow ( m_nCmdShow ) ;
pMainFrame->UpdateWindow();
// Enable drag/drop open
m_pMainWnd->DragAcceptFiles();
// Enable open from command line
if (*m_lpCmdLine != 0)
OpenDocumentFile(m_lpCmdLine);
return TRUE;
}
//////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
CxTargetButton m_ok;
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
virtual BOOL OnInitDialog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//////////////////////////////////////////////////////////////////////////////
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
//////////////////////////////////////////////////////////////////////////////
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(DlgCapture)
DDX_Control(pDX, IDOK, m_ok);
//}}AFX_DATA_MAP
}
//////////////////////////////////////////////////////////////////////////////
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//////////////////////////////////////////////////////////////////////////////
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_ok.SetIcon(IDI_G,BS_LEFT);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
//////////////////////////////////////////////////////////////////////////////
// App command to run the dialog
void CDemoApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
//////////////////////////////////////////////////////////////////////////////
void CDemoApp::OnFileOpen()
{
// prompt the user (with all document templates)
CString newName;
int nDocType = -1;
if (!PromptForFileName(newName, AFX_IDS_OPENFILE,
OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, TRUE, &nDocType))
return; // open cancelled
OpenDocumentFile(newName);
}
//////////////////////////////////////////////////////////////////////////////
// prompt for file name - used for open and save as
// static function called from app
BOOL CDemoApp::PromptForFileName(CString& fileName, UINT nIDSTitle,
DWORD dwFlags, BOOL bOpenFileDialog, int* pType)
{
CFileDialog dlgFile(bOpenFileDialog);
CString title;
if (bOpenFileDialog) title="Open image file"; else title="Save image file";
dlgFile.m_ofn.Flags |= dwFlags;
int nDocType = (pType != NULL) ? *pType : CXIMAGE_FORMAT_BMP;
if (nDocType==0) nDocType=1;
int nIndex = GetIndexFromType(nDocType, bOpenFileDialog);
if (nIndex == -1) nIndex = 0;
dlgFile.m_ofn.nFilterIndex = nIndex +1;
// strDefExt is necessary to hold onto the memory from GetExtFromType
CString strDefExt = GetExtFromType(nDocType).Mid(2,3);
dlgFile.m_ofn.lpstrDefExt = strDefExt;
CString strFilter = GetFileTypes(bOpenFileDialog);
dlgFile.m_ofn.lpstrFilter = strFilter;
dlgFile.m_ofn.lpstrTitle = title;
dlgFile.m_ofn.lpstrFile = fileName.GetBuffer(_MAX_PATH);
BOOL bRet = (dlgFile.DoModal() == IDOK) ? TRUE : FALSE;
fileName.ReleaseBuffer();
if (bRet){
if (pType != NULL){
int nIndex = (int)dlgFile.m_ofn.nFilterIndex - 1;
ASSERT(nIndex >= 0);
*pType = GetTypeFromIndex(nIndex, bOpenFileDialog);
}
}
return bRet;
}
//////////////////////////////////////////////////////////////////////////////
int CDemoApp::GetIndexFromType(int nDocType, BOOL bOpenFileDialog)
{
int nCnt = 0;
for (int i=0;i<cmax_image_formats;i++){
if="" (bopenfiledialog="" ?="" doctypes[i].bread="" :="" doctypes[i].bwrite){
="" (doctypes[i].nid="=" ndoctype)="" return="" ncnt;
="" ncnt++;
="" }
="" -1;
}
=""
int="" cdemoapp::gettypefromindex(int="" nindex,="" bool="" bopenfiledialog)
{
="" int="" ncnt="0;
" for="" (int="" i="0;i<CMAX_IMAGE_FORMATS;i++){
" (ncnt="=" nindex)
="" i;="" pjo="" -="" buglet="" ?
="" doctypes[i].nid;
="" assert(false);
=""
cstring="" cdemoapp::getextfromtype(int="" ndoctype)
{
="" ndoctype)
="" doctypes[i].ext;
="" cstring("");
}
="" cdemoapp::getdescfromtype(int="" doctypes[i].description;
=""
bool="" cdemoapp::getwritabletype(int="" ndoctype){
="" doctypes[i].bwrite;
="" false;
}
="" cdemoapp::getfiletypes(bool="" cstring="" str;
="" &&="" doctypes[i].bread){
="" str="" +="doctypes[i].description;
" }="" else="" (!bopenfiledialog="" doctypes[i].bwrite)="" {
="" str;
}
=""
="" cdemoapp="" commands
void="" cdemoapp::onimagefrombitmap()=""
{
="" *="" hbitmap="" bitmap;
="" (!(bitmap="::LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BITMAP1)))){
" afxmessagebox("could="" not="" load="" bitmap="" from="" resource");
="" return;
="" }*=""
="" cximage*="" newimage="new" cximage();
="" (!newimage-="">LoadResource(FindResource(NULL,MAKEINTRESOURCE(IDB_BITMAP1),RT_BITMAP),CXIMAGE_FORMAT_BMP)){
AfxMessageBox(newImage->GetLastError());
delete newImage;
newImage =NULL;
return;
}
CDemoDoc *doc = (CDemoDoc *)demoTemplate->OpenDocumentFile(NULL);
if (doc){
doc->image = newImage;
CString s;
s.Format("BITMAP Resource Image %d",m_nDocCount++);
doc->SetTitle(s);
doc->UpdateAllViews(0);
doc->UpdateStatusBar();
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoApp::OnCximageLoadjpegresource()
{
CxImage* newImage = new CxImage();
if (!newImage->LoadResource(FindResource(NULL,"IDR_JPG2","JPG"),CXIMAGE_FORMAT_JPG)){
AfxMessageBox(newImage->GetLastError());
delete newImage;
newImage =NULL;
return;
}
CDemoDoc *doc = (CDemoDoc *)demoTemplate->OpenDocumentFile(NULL);
if (doc){
doc->image = newImage;
CString s;
s.Format("JPEG Resource Image %d",m_nDocCount++);
doc->SetTitle(s);
doc->UpdateAllViews(0);
doc->UpdateStatusBar();
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoApp::OnCximageLoadiconresource()
{
CxImage* newImage = new CxImage();
if (!newImage->LoadResource(FindResource(NULL,MAKEINTRESOURCE(IDR_ICO1),"ICO"),CXIMAGE_FORMAT_ICO)){
AfxMessageBox(newImage->GetLastError());
delete newImage;
newImage =NULL;
return;
}
// HICON my_Icon = (HICON)::LoadImage(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDI_G),IMAGE_ICON,0, 0, 0);
// CxImage my_image;
// my_image.CreateFromHICON(my_Icon);
// DestroyIcon(my_Icon);
CDemoDoc *doc = (CDemoDoc *)demoTemplate->OpenDocumentFile(NULL);
if (doc){
doc->image = newImage;
CString s;
s.Format("Icon Resource Image %d",m_nDocCount++);
doc->SetTitle(s);
doc->UpdateAllViews(0);
doc->UpdateStatusBar();
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoApp::OnCximageLoadgifresource()
{
CxImage* newImage = new CxImage();
if (!newImage->LoadResource(FindResource(NULL,MAKEINTRESOURCE(IDR_GIF1),"GIF"),CXIMAGE_FORMAT_GIF)){
AfxMessageBox(newImage->GetLastError());
delete newImage;
newImage =NULL;
return;
}
CDemoDoc *doc = (CDemoDoc *)demoTemplate->OpenDocumentFile(NULL);
if (doc){
doc->image = newImage;
CString s;
s.Format("GIF Resource Image %d",m_nDocCount++);
doc->SetTitle(s);
doc->UpdateAllViews(0);
doc->UpdateStatusBar();
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoApp::OnCximageLoadpngresource()
{
CxImage* newImage = new CxImage();
if (!newImage->LoadResource(FindResource(NULL,MAKEINTRESOURCE(IDR_PNG1),"PNG"),CXIMAGE_FORMAT_PNG)){
AfxMessageBox(newImage->GetLastError());
delete newImage;
newImage =NULL;
return;
}
CDemoDoc *doc = (CDemoDoc *)demoTemplate->OpenDocumentFile(NULL);
if (doc){
doc->image = newImage;
CString s;
s.Format("PNG Resource Image %d",m_nDocCount++);
doc->SetTitle(s);
doc->UpdateAllViews(0);
doc->UpdateStatusBar();
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoApp::OnCximageLoadtifresource()
{
CxImage* newImage = new CxImage();
if (!newImage->LoadResource(FindResource(NULL,MAKEINTRESOURCE(IDR_TIF1),"TIF"),CXIMAGE_FORMAT_TIF)){
AfxMessageBox(newImage->GetLastError());
delete newImage;
newImage =NULL;
return;
}
CDemoDoc *doc = (CDemoDoc *)demoTemplate->OpenDocumentFile(NULL);
if (doc){
doc->image = newImage;
CString s;
s.Format("TIF Resource Image %d",m_nDocCount++);
doc->SetTitle(s);
doc->UpdateAllViews(0);
doc->UpdateStatusBar();
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoApp::OnWindowCloseall()
{
POSITION pos = AfxGetApp()->GetFirstDocTemplatePosition();
while(pos) {
CDocTemplate* pTemplate = AfxGetApp()->GetNextDocTemplate(pos);
POSITION pos2 = pTemplate->GetFirstDocPosition();
while(pos2) {
CDocument* pDocument;
if ((pDocument=pTemplate->GetNextDoc(pos2)) != NULL)
pDocument->OnCloseDocument();
}
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoApp::OnCximageDemosavemultipagetiff()
{
CxImage* newImage1 = new CxImage();
if (!newImage1->LoadResource(FindResource(NULL,MAKEINTRESOURCE(IDR_TIF1),"TIF"),CXIMAGE_FORMAT_TIF)){
AfxMessageBox(newImage1->GetLastError());
delete newImage1;
newImage1 =NULL;
}
CxImage* newImage2 = new CxImage();
if (!newImage2->LoadResource(FindResource(NULL,MAKEINTRESOURCE(IDR_GIF1),"GIF"),CXIMAGE_FORMAT_GIF)){
AfxMessageBox(newImage2->GetLastError());
delete newImage2;
newImage2 =NULL;
}
CxImage* newImage3 = new CxImage();
if (!newImage3->LoadResource(FindResource(NULL,"IDR_JPG2","JPG"),CXIMAGE_FORMAT_JPG)){
AfxMessageBox(newImage3->GetLastError());
delete newImage3;
newImage3 =NULL;
}
newImage3->DecreaseBpp(8,true);
CxImage *pimage[3];
pimage[0]=newImage1;
pimage[1]=newImage2;
pimage[2]=newImage3;
FILE* hFile;
hFile = fopen("multipage.tif","w+b");
CxImage multiimage;
multiimage.Encode(hFile,pimage,3,CXIMAGE_FORMAT_TIF);
fclose(hFile);
delete newImage1;
delete newImage2;
delete newImage3;
/*{
FILE* hFile;
hFile = fopen("c:\\multi.tif","w+b");
CxImageTIF image;
image.Load("c:\\1.tif",CXIMAGE_FORMAT_TIF);
image.Encode(hFile,true);
image.Load("c:\\2.bmp",CXIMAGE_FORMAT_BMP);
image.Encode(hFile,true);
image.Load("c:\\3.png",CXIMAGE_FORMAT_PNG);
image.Encode(hFile);
fclose(hFile);
}*/
AfxMessageBox("file ""mulipage.tif"" saved to disk",MB_OK);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoApp::OnCximageDemosaveanimatedgif()
{
CxImage* newImage = new CxImage();
if (!newImage->LoadResource(FindResource(NULL,MAKEINTRESOURCE(IDR_GIF1),"GIF"),CXIMAGE_FORMAT_GIF)){
AfxMessageBox(newImage->GetLastError());
delete newImage;
newImage =NULL;
}
newImage->IncreaseBpp(24);
CxImage ima1,ima2,ima3;
ima1.Copy(*newImage);
ima1.Light(22);
ima2.Copy(*newImage);
ima2.Light(44);
ima3.Copy(*newImage);
ima3.Light(66);
newImage->DecreaseBpp(8,0,0);
ima1.DecreaseBpp(8,0,0);
ima2.DecreaseBpp(8,0,0);
ima3.DecreaseBpp(8,0,0);
newImage->SetTransIndex(newImage->GetPixelIndex(0,0));
ima1.SetTransIndex(ima1.GetPixelIndex(0,0));
ima2.SetTransIndex(ima2.GetPixelIndex(0,0));
ima3.SetTransIndex(ima3.GetPixelIndex(0,0));
newImage->SetFrameDelay(22);
ima1.SetFrameDelay(22);
ima2.SetFrameDelay(22);
ima3.SetFrameDelay(44);
CxImage *pimage[7];
pimage[0]=newImage;
pimage[1]=&ima1;
pimage[2]=&ima2;
pimage[3]=&ima3;
pimage[4]=&ima2;
pimage[5]=&ima1;
pimage[6]=newImage;
FILE* hFile;
hFile = fopen("ani.gif","wb");
CxImageGIF multiimage;
multiimage.SetComment("CxImage demo");
multiimage.SetLoops(3);
multiimage.SetDisposalMethod(2);
multiimage.Encode(hFile,pimage,7);
fclose(hFile);
delete newImage;
AfxMessageBox("file ""ani.gif"" saved to disk",MB_OK);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoApp::OnCximageDownloadfromurl()
{
DlgURL dlg;
if (dlg.DoModal()==IDOK){
long size = dlg.m_size;
if (size){
CxMemFile memfile((BYTE*)dlg.m_data.GetBuffer(0),size);
CDemoDoc *doc = (CDemoDoc *)demoTemplate->OpenDocumentFile(NULL);
if (doc){
CString ext(doc->FindExtension(dlg.m_url));
ext.MakeLower();
if (ext == "") return;
int type = doc->FindType(ext);
CxImage* ima = new CxImage();
ima->Decode(&memfile,type);
doc->image = ima;
doc->SetTitle(dlg.m_url);
doc->UpdateAllViews(0);
doc->UpdateStatusBar();
if (ima->GetNumFrames()>1){
CString s;
s.Format("File with %d images. Read all?",ima->GetNumFrames());
if (AfxMessageBox(s,MB_OKCANCEL)==IDOK){
int j; // points to the document name
for(j=strlen(dlg.m_url)-1;j>=0;j--){
if (dlg.m_url[j]=='\\'){ j++; break; }
}
// create the documents for the other images
for(int i=1;i<ima->GetNumFrames();i++){
CDemoDoc *NewDoc=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL);
if (NewDoc) {
CxImage *newImage = new CxImage();
newImage->SetFrame(i);
memfile.Seek(0,SEEK_SET);
newImage->Decode(&memfile,type);
NewDoc->image = newImage;
CString s;
s.Format("%s (%d)",dlg.m_url.Mid(j),i+1);
NewDoc->SetTitle(s);
NewDoc->UpdateAllViews(NULL,WM_USER_NEWIMAGE);
}
}
}
}
}
}
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoApp::OnCximageDemocreatefromarray()
{
CxImage* newImage = new CxImage();
long w = 256;
long h = 256;
BYTE c = 4;
BYTE* pArray = (BYTE*)malloc(w*h*c);
int n,d,e;
int a=w/2;
for(int i = 0; i < h; i++) {
for(int j = 0; j < w; j++) {
n=c*(j+w*i);
d=(BYTE)((a*i)/h+(a*(w-j))/w);
e=(BYTE)((a*(h-i))/h+(a*(w-j))/w);
if (c==4) pArray[n+3]=(BYTE)(d);
pArray[n+2]=(BYTE)(e);
pArray[n+1]=(BYTE)(255-d);
pArray[n]=(BYTE)(255-e);
}
}
newImage->CreateFromArray(pArray,w,h,8*c,c*w,0);
free(pArray);
if (!newImage->IsValid()){
AfxMessageBox(newImage->GetLastError());
delete newImage;
newImage =NULL;
return;
}
CDemoDoc *doc = (CDemoDoc *)demoTemplate->OpenDocumentFile(NULL);
if (doc){
doc->image = newImage;
CString s;
s.Format("CreateFromArray Image %d",m_nDocCount++);
doc->SetTitle(s);
doc->UpdateAllViews(0);
doc->UpdateStatusBar();
}
}
//////////////////////////////////////////////////////////////////////////////
//===================================================
// demo\demoDoc.cpp
//===================================================
// demoDoc.cpp : implementation of the CDemoDoc class
//
#include "stdafx.h"
#include "demo.h"
#include "MainFrm.h"
#include "demoDoc.h"
#include "demoView.h"
#include "DlgRotate.h"
#include "DlgResample.h"
#include "DlgDecBpp.h"
#include "DlgIncBpp.h"
#include "DlgOptions.h"
#include "DlgDither.h"
#include "DlgThreshold.h"
#include "DlgColorize.h"
#include "Quantize.h"
#include "DlgOpacity.h"
#include "DlgGamma.h"
#include "DlgPalette.h"
#include "DlgCombine.h"
#include "DlgFFT.h"
#include "DlgRepair.h"
#include "DlgText.h"
#include "DlgMix.h"
#include "ximage.h"
#include <math.h>
#include <process.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//////////////////////////////////////////////////////////////////////////////
// CDemoDoc
IMPLEMENT_DYNCREATE(CDemoDoc, CDocument)
BEGIN_MESSAGE_MAP(CDemoDoc, CDocument)
//{{AFX_MSG_MAP(CDemoDoc)
ON_UPDATE_COMMAND_UI(ID_FILE_SAVE_AS, OnUpdateFileSaveAs)
ON_UPDATE_COMMAND_UI(ID_FILE_SAVE, OnUpdateFileSave)
ON_COMMAND(ID_STRETCH_MODE, OnStretchMode)
ON_UPDATE_COMMAND_UI(ID_STRETCH_MODE, OnUpdateStretchMode)
ON_COMMAND(ID_TRANSFORM_ELLIPSE, OnTransformEllipse)
ON_COMMAND(ID_WINDOW_DUPLICATE, OnWindowDuplicate)
ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
ON_COMMAND(ID_CXIMAGE_FLIP, OnCximageFlip)
ON_COMMAND(ID_CXIMAGE_MIRROR, OnCximageMirror)
ON_COMMAND(ID_CXIMAGE_NEGATIVE, OnCximageNegative)
ON_COMMAND(ID_CXIMAGE_GRAYSCALE, OnCximageGrayscale)
ON_COMMAND(ID_CXIMAGE_ROTATE, OnCximageRotate)
ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateEditUndo)
ON_COMMAND(ID_EDIT_REDO, OnEditRedo)
ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
ON_UPDATE_COMMAND_UI(ID_EDIT_REDO, OnUpdateEditRedo)
ON_COMMAND(ID_VIEW_ZOOMIN, OnViewZoomin)
ON_COMMAND(ID_VIEW_ZOOMOUT, OnViewZoomout)
ON_UPDATE_COMMAND_UI(ID_VIEW_ZOOMIN, OnUpdateViewZoomin)
ON_UPDATE_COMMAND_UI(ID_VIEW_ZOOMOUT, OnUpdateViewZoomout)
ON_COMMAND(ID_VIEW_NORMALVIEWING11, OnViewNormalviewing11)
ON_UPDATE_COMMAND_UI(ID_VIEW_NORMALVIEWING11, OnUpdateViewNormalviewing11)
ON_COMMAND(ID_CXIMAGE_SETTRANSPARENCY, OnCximageSettransparency)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_SETTRANSPARENCY, OnUpdateCximageSettransparency)
ON_COMMAND(ID_CXIMAGE_REMOVETRANSPARENCY, OnCximageRemovetransparency)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_REMOVETRANSPARENCY, OnUpdateCximageRemovetransparency)
ON_COMMAND(ID_CXIMAGE_RESAMPLE, OnCximageResample)
ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopy)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_FLIP, OnUpdateCximageFlip)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_GRAYSCALE, OnUpdateCximageGrayscale)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_MIRROR, OnUpdateCximageMirror)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_NEGATIVE, OnUpdateCximageNegative)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_RESAMPLE, OnUpdateCximageResample)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_ROTATE, OnUpdateCximageRotate)
ON_UPDATE_COMMAND_UI(ID_TRANSFORM_ELLIPSE, OnUpdateTransformEllipse)
ON_COMMAND(ID_CXIMAGE_DECREASEBPP, OnCximageDecreasebpp)
ON_COMMAND(ID_CXIMAGE_INCREASEBPP, OnCximageIncreasebpp)
ON_COMMAND(ID_CXIMAGE_OPTIONS, OnCximageOptions)
ON_COMMAND(ID_CXIMAGE_DITHER, OnCximageDither)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_DITHER, OnUpdateCximageDither)
ON_COMMAND(ID_CXIMAGE_THRESHOLD, OnCximageThreshold)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_THRESHOLD, OnUpdateCximageThreshold)
ON_COMMAND(ID_CXIMAGE_SPLITRGB, OnCximageSplitrgb)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_SPLITRGB, OnUpdateCximageSplitrgb)
ON_COMMAND(ID_CXIMAGE_SPLITYUV, OnCximageSplityuv)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_SPLITYUV, OnUpdateCximageSplityuv)
ON_COMMAND(ID_CXIMAGE_SPLITHSL, OnCximageSplithsl)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_SPLITHSL, OnUpdateCximageSplithsl)
ON_COMMAND(ID_CXIMAGE_PSEUDOCOLORS, OnCximagePseudocolors)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_PSEUDOCOLORS, OnUpdateCximagePseudocolors)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_COLORIZE, OnUpdateCximageFiltersColorize)
ON_COMMAND(ID_CXIMAGE_COLORIZE, OnCximageFiltersColorize)
ON_COMMAND(ID_CXIMAGE_DARKEN, OnCximageDarken)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_DARKEN, OnUpdateCximageDarken)
ON_COMMAND(ID_CXIMAGE_LIGHTEN, OnCximageLighten)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_LIGHTEN, OnUpdateCximageLighten)
ON_COMMAND(ID_CXIMAGE_CONTRAST, OnCximageContrast)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_CONTRAST, OnUpdateCximageContrast)
ON_COMMAND(ID_CXIMAGE_EMBOSS, OnCximageEmboss)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_EMBOSS, OnUpdateCximageEmboss)
ON_COMMAND(ID_CXIMAGE_BLUR, OnCximageBlur)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_BLUR, OnUpdateCximageBlur)
ON_COMMAND(ID_CXIMAGE_DILATE, OnCximageDilate)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_DILATE, OnUpdateCximageDilate)
ON_COMMAND(ID_CXIMAGE_EDGE, OnCximageEdge)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_EDGE, OnUpdateCximageEdge)
ON_COMMAND(ID_CXIMAGE_ERODE, OnCximageErode)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_ERODE, OnUpdateCximageErode)
ON_COMMAND(ID_CXIMAGE_SHARPEN, OnCximageSharpen)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_SHARPEN, OnUpdateCximageSharpen)
ON_COMMAND(ID_CXIMAGE_SOFTEN, OnCximageSoften)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_SOFTEN, OnUpdateCximageSoften)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_CROP, OnUpdateCximageCrop)
ON_COMMAND(ID_CXIMAGE_CROP, OnCximageCrop)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_REMOVEALPHACHANNEL, OnUpdateCximageRemovealphachannel)
ON_COMMAND(ID_CXIMAGE_REMOVEALPHACHANNEL, OnCximageRemovealphachannel)
ON_COMMAND(ID_CXIMAGE_OPACITY, OnCximageOpacity)
ON_COMMAND(ID_CXIMAGE_INVETALPHA, OnCximageInvetalpha)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_INVETALPHA, OnUpdateCximageInvetalpha)
ON_COMMAND(ID_CXIMAGE_ALPHAPALETTETOGGLE, OnCximageAlphapalettetoggle)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_ALPHAPALETTETOGGLE, OnUpdateCximageAlphapalettetoggle)
ON_COMMAND(ID_CXIMAGE_ALPHASTRIP, OnCximageAlphastrip)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_ALPHASTRIP, OnUpdateCximageAlphastrip)
ON_COMMAND(ID_CXIMAGE_ROTATEL, OnCximageRotatel)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_ROTATEL, OnUpdateCximageRotatel)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_ROTATER, OnUpdateCximageRotater)
ON_COMMAND(ID_CXIMAGE_ROTATER, OnCximageRotater)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_GAMMA, OnUpdateCximageGamma)
ON_COMMAND(ID_CXIMAGE_GAMMA, OnCximageGamma)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_MEDIAN, OnUpdateCximageMedian)
ON_COMMAND(ID_CXIMAGE_MEDIAN, OnCximageMedian)
ON_COMMAND(ID_CXIMAGE_ADDNOISE, OnCximageAddnoise)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_ADDNOISE, OnUpdateCximageAddnoise)
ON_UPDATE_COMMAND_UI(ID_VIEW_TOOLS_MOVE, OnUpdateViewToolsMove)
ON_COMMAND(ID_VIEW_TOOLS_MOVE, OnViewToolsMove)
ON_COMMAND(ID_VIEW_TOOLS_SELECT, OnViewToolsSelect)
ON_UPDATE_COMMAND_UI(ID_VIEW_TOOLS_SELECT, OnUpdateViewToolsSelect)
ON_COMMAND(ID_VIEW_TOOLS_ZOOM, OnViewToolsZoom)
ON_UPDATE_COMMAND_UI(ID_VIEW_TOOLS_ZOOM, OnUpdateViewToolsZoom)
ON_UPDATE_COMMAND_UI(ID_VIEW_PALETTE, OnUpdateViewPalette)
ON_COMMAND(ID_VIEW_PALETTE, OnViewPalette)
ON_COMMAND(ID_CXIMAGE_COMBINE, OnCximageCombine)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_COMBINE, OnUpdateCximageCombine)
ON_COMMAND(ID_CXIMAGE_FFT, OnCximageFft)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_FFT, OnUpdateCximageFft)
ON_COMMAND(ID_CXIMAGE_SPLITYIQ, OnCximageSplityiq)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_SPLITYIQ, OnUpdateCximageSplityiq)
ON_COMMAND(ID_CXIMAGE_SPLITXYZ, OnCximageSplitxyz)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_SPLITXYZ, OnUpdateCximageSplitxyz)
ON_COMMAND(ID_CXIMAGE_REPAIR, OnCximageRepair)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_REPAIR, OnUpdateCximageRepair)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_ALPHACHANNEL_SPLIT, OnUpdateCximageAlphachannelSplit)
ON_COMMAND(ID_CXIMAGE_ALPHACHANNEL_SPLIT, OnCximageAlphachannelSplit)
ON_COMMAND(ID_VIEW_TOOLS_TEXT, OnViewToolsText)
ON_UPDATE_COMMAND_UI(ID_VIEW_TOOLS_TEXT, OnUpdateViewToolsText)
ON_COMMAND(ID_CXIMAGE_SPLITCMYK, OnCximageSplitcmyk)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_SPLITCMYK, OnUpdateCximageSplitcmyk)
ON_COMMAND(ID_CXIMAGE_ALPHACREATE, OnCximageAlphaCreate)
ON_COMMAND(ID_CXIMAGE_HISTOGRAM_LOG, OnCximageFiltersLog)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_HISTOGRAM_LOG, OnUpdateCximageFiltersLog)
ON_COMMAND(ID_CXIMAGE_HISTOGRAM_ROOT, OnCximageFiltersRoot)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_HISTOGRAM_ROOT, OnUpdateCximageFiltersRoot)
ON_COMMAND(ID_CXIMAGE_HISTOGRAM_EQUALIZE, OnCximageHistogramEqualize)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_HISTOGRAM_EQUALIZE, OnUpdateCximageHistogramEqualize)
ON_COMMAND(ID_CXIMAGE_HISTOGRAM_NORMALIZE, OnCximageHistogramNormalize)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_HISTOGRAM_NORMALIZE, OnUpdateCximageHistogramNormalize)
ON_COMMAND(ID_CXIMAGE_HISTOGRAM_STRETCH, OnCximageHistogramStretch)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_HISTOGRAM_STRETCH, OnUpdateCximageHistogramStretch)
ON_COMMAND(ID_CXIMAGE_GAUSSIAN3X3, OnCximageGaussian3x3)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_GAUSSIAN3X3, OnUpdateCximageGaussian3x3)
ON_COMMAND(ID_CXIMAGE_GAUSSIAN5X5, OnCximageGaussian5x5)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_GAUSSIAN5X5, OnUpdateCximageGaussian5x5)
ON_COMMAND(ID_CXIMAGE_CONTOUR, OnCximageContour)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_CONTOUR, OnUpdateCximageContour)
ON_COMMAND(ID_CXIMAGE_LESSCONTRAST, OnCximageLesscontrast)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_LESSCONTRAST, OnUpdateCximageLesscontrast)
ON_COMMAND(ID_CXIMAGE_JITTER, OnCximageJitter)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_JITTER, OnUpdateCximageJitter)
ON_UPDATE_COMMAND_UI(ID_WINDOW_DUPLICATE, OnUpdateWindowDuplicate)
ON_UPDATE_COMMAND_UI(ID_FILTERS_MIX, OnUpdateFiltersMix)
ON_COMMAND(ID_FILTERS_MIX, OnFiltersMix)
ON_COMMAND(ID_CXIMAGE_CIRCLETRANSFORM_CYLINDER, OnCximageCircletransformCylinder)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_CIRCLETRANSFORM_CYLINDER, OnUpdateCximageCircletransformCylinder)
ON_COMMAND(ID_CXIMAGE_CIRCLETRANSFORM_PINCH, OnCximageCircletransformPinch)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_CIRCLETRANSFORM_PINCH, OnUpdateCximageCircletransformPinch)
ON_COMMAND(ID_CXIMAGE_CIRCLETRANSFORM_PUNCH, OnCximageCircletransformPunch)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_CIRCLETRANSFORM_PUNCH, OnUpdateCximageCircletransformPunch)
ON_COMMAND(ID_CXIMAGE_CIRCLETRANSFORM_SWIRL, OnCximageCircletransformSwirl)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_CIRCLETRANSFORM_SWIRL, OnUpdateCximageCircletransformSwirl)
ON_COMMAND(ID_CXIMAGE_CIRCLETRANSFORM_BATHROOM, OnCximageCircletransformBathroom)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_CIRCLETRANSFORM_BATHROOM, OnUpdateCximageCircletransformBathroom)
ON_COMMAND(ID_CXIMAGE_HISTOGRAM_STRETCH1, OnCximageHistogramStretch1)
ON_COMMAND(ID_CXIMAGE_HISTOGRAM_STRETCH2, OnCximageHistogramStretch2)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_HISTOGRAM_STRETCH1, OnUpdateCximageHistogramStretch1)
ON_UPDATE_COMMAND_UI(ID_CXIMAGE_HISTOGRAM_STRETCH2, OnUpdateCximageHistogramStretch2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//////////////////////////////////////////////////////////////////////////////
// CDemoDoc construction/destruction
CDemoDoc::CDemoDoc()
{
image = NULL;
m_WaitingClick = stretchMode = FALSE;
for (int i=0;i<max_undo_levels;i++) imageundo[i]="NULL;
" m_undolevel="0;
" m_zoomfactor="1;
" queryperformancefrequency(&m_swfreq);
="" m_etime="0.0;
" hthread="hProgress=0;
" m_numsel="0;
" m_tool="0;
" m_hmax="0;
#ifndef" vati_extensions
="" memset(&m_font,0,sizeof(m_font));
="" m_color="0;
" m_text="text" ;
#endif
}
=""
cdemodoc::~cdemodoc()
{
="" stop="" the="" elaborations
="" if="" (image)="" image-="">SetEscape(1);
// stop the progress bar
if (hProgress){
ResumeThread(hProgress); //wake up!
WaitForSingleObject(hProgress,INFINITE);
CloseHandle(hProgress);
}
if (hThread){
WaitForSingleObject(hThread,INFINITE);
CloseHandle(hThread);
}
// free objects
delete image;
for (int i=0;i<max_undo_levels;i++) delete="" imageundo[i];
}
=""
bool="" cdemodoc::onnewdocument()
{
="" if="" (!cdocument::onnewdocument())="" return="" false;
="" todo:="" add="" reinitialization="" code="" here
="" (sdi="" documents="" will="" reuse="" this="" document)
="" image="NULL;
" true;
}
=""
="" cdemodoc="" serialization
void="" cdemodoc::serialize(carchive&="" ar)
{
="" (ar.isstoring())="" {="" }="" else="" }
}
="" diagnostics
#ifdef="" _debug
void="" cdemodoc::assertvalid()="" const
{
="" cdocument::assertvalid();
}
=""
void="" cdemodoc::dump(cdumpcontext&="" dc)="" cdocument::dump(dc);
}
#endif="" _debug
="" commands
cstring="" cdemodoc::findextension(const="" cstring&="" name)
{
="" int="" len="name.GetLength();
" i;
="" for="" (i="len-1;" i="">= 0; i--){
if (name[i] == '.'){
return name.Mid(i+1);
}
}
return CString("");
}
//////////////////////////////////////////////////////////////////////////////
int CDemoDoc::FindType(const CString& ext)
{
int type = 0;
if (ext == "bmp") type = CXIMAGE_FORMAT_BMP;
//ThanhDK====================================
#if CXIMAGE_SUPPORT_CHIBA
else if (ext=="txt"||ext=="xyz"||ext=="xyY"||ext=="ktu") type = CXIMAGE_FORMAT_CHIBA;
#endif
//===========================================
#if CXIMAGE_SUPPORT_JPG
else if (ext=="jpg"||ext=="jpeg") type = CXIMAGE_FORMAT_JPG;
#endif
#if CXIMAGE_SUPPORT_GIF
else if (ext == "gif") type = CXIMAGE_FORMAT_GIF;
#endif
#if CXIMAGE_SUPPORT_PNG
else if (ext == "png") type = CXIMAGE_FORMAT_PNG;
#endif
#if CXIMAGE_SUPPORT_MNG
else if (ext=="mng"||ext=="jng") type = CXIMAGE_FORMAT_MNG;
#endif
#if CXIMAGE_SUPPORT_ICO
else if (ext == "ico") type = CXIMAGE_FORMAT_ICO;
#endif
#if CXIMAGE_SUPPORT_TIF
else if (ext=="tiff"||ext=="tif") type = CXIMAGE_FORMAT_TIF;
#endif
#if CXIMAGE_SUPPORT_TGA
else if (ext=="tga") type = CXIMAGE_FORMAT_TGA;
#endif
#if CXIMAGE_SUPPORT_PCX
else if (ext=="pcx") type = CXIMAGE_FORMAT_PCX;
#endif
#if CXIMAGE_SUPPORT_WBMP
else if (ext=="wbmp") type = CXIMAGE_FORMAT_WBMP;
#endif
#if CXIMAGE_SUPPORT_WMF
else if (ext=="wmf"||ext=="emf") type = CXIMAGE_FORMAT_WMF;
#endif
#if CXIMAGE_SUPPORT_J2K
else if (ext=="j2k"||ext=="jp2") type = CXIMAGE_FORMAT_J2K;
#endif
#if CXIMAGE_SUPPORT_JBG
else if (ext=="jbg") type = CXIMAGE_FORMAT_JBG;
#endif
#if CXIMAGE_SUPPORT_JP2
else if (ext=="jp2"||ext=="j2k") type = CXIMAGE_FORMAT_JP2;
#endif
#if CXIMAGE_SUPPORT_JPC
else if (ext=="jpc"||ext=="j2c") type = CXIMAGE_FORMAT_JPC;
#endif
#if CXIMAGE_SUPPORT_PGX
else if (ext=="pgx") type = CXIMAGE_FORMAT_PGX;
#endif
#if CXIMAGE_SUPPORT_RAS
else if (ext=="ras") type = CXIMAGE_FORMAT_RAS;
#endif
#if CXIMAGE_SUPPORT_PNM
else if (ext=="pnm"||ext=="pgm"||ext=="ppm") type = CXIMAGE_FORMAT_PNM;
#endif
else type = CXIMAGE_FORMAT_UNKNOWN;
return type;
}
//////////////////////////////////////////////////////////////////////////////
BOOL CDemoDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
CString filename(lpszPathName);
CString ext(FindExtension(filename));
ext.MakeLower();
if (ext == "") return FALSE;
int type = FindType(ext);
/*CxImage canvas;
canvas.SetEscape(-1);
CxIOFile file;
file.Open(filename,"rb");
canvas.Decode(&file, type);*/
Stopwatch(0);
image = new CxImage(filename, type);
Stopwatch(1);
if (!image->IsValid()){
AfxMessageBox(image->GetLastError());
delete image;
image = NULL;
return FALSE;
}
UpdateStatusBar();
UpdateAllViews(NULL,WM_USER_NEWIMAGE);
//multiple images (TIFF/ICO)
if (image->GetNumFrames()>1){
CString s;
s.Format("File with %d images. Read all?",image->GetNumFrames());
if (AfxMessageBox(s,MB_OKCANCEL)==IDOK){
int j; // points to the document name
for(j=strlen(filename)-1;j>=0;j--){
if (filename[j]=='\\'){ j++; break; }
}
// create the documents for the other images
for(int i=1;i<image->GetNumFrames();i++){
CDemoDoc *NewDoc=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL);
if (NewDoc) {
CxImage *newImage = new CxImage();
newImage->SetFrame(i);
newImage->Load(filename,type);
NewDoc->image = newImage;
CString s;
s.Format("%s (%d)",filename.Mid(j),i+1);
NewDoc->SetTitle(s);
NewDoc->UpdateAllViews(NULL,WM_USER_NEWIMAGE);
}
}
}
}
// EXIF jpegs
if (image->GetType() == CXIMAGE_FORMAT_JPG){
FILE* hfile = fopen(filename,"rb");
m_exif.DecodeExif(hfile);
fclose(hfile);
}
return TRUE;
}
//////////////////////////////////////////////////////////////////////////////
BOOL CDemoDoc::OnSaveDocument(LPCTSTR lpszPathName)
{
CString filename(lpszPathName);
CString ext(FindExtension(filename));
ext.MakeLower();
if (ext == "") return FALSE;
int type = FindType(ext);
if (type == CXIMAGE_FORMAT_UNKNOWN) return FALSE;
bool retval;
Stopwatch(0);
retval = image->Save(filename, type);
Stopwatch(1);
UpdateStatusBar();
if (retval) return TRUE;
AfxMessageBox(image->GetLastError());
return FALSE;
}
//////////////////////////////////////////////////////////////////////////////
BOOL CDemoDoc::DoSave(LPCTSTR pszPathName, BOOL bReplace /*=TRUE*/)
{
if (!image) return FALSE;
CString newName = pszPathName;
BOOL bModified = IsModified();
BOOL bSaveAs = FALSE;
if (newName.IsEmpty()) bSaveAs = TRUE;
else if (!theApp.GetWritableType(image->GetType())) bSaveAs = TRUE;
if (bSaveAs){
newName = m_strPathName;
if (bReplace && newName.IsEmpty()){
newName = m_strTitle;
int iBad = newName.FindOneOf(_T("#%;/\\")); // dubious filename
if (iBad != -1) //newName.ReleaseBuffer(iBad);
newName = "UntitledImage";
// append the default suffix if there is one
if (image->GetType()) newName += theApp.GetExtFromType(image->GetType()).Mid(1,4);
}
int nDocType = image->GetType();
if (!theApp.PromptForFileName(newName,
bReplace ? AFX_IDS_SAVEFILE : AFX_IDS_SAVEFILECOPY,
OFN_HIDEREADONLY | OFN_PATHMUSTEXIST, FALSE, &nDocType))
{
return FALSE; // don't even try to save
}
}
BeginWaitCursor();
if (!OnSaveDocument(newName)){
if (pszPathName == NULL){
// be sure to delete the file
TRY
{
CFile::Remove(newName);
}
CATCH_ALL(e)
{
TRACE0("Warning: failed to delete file after failed SaveAs\n");
}
END_CATCH_ALL
}
EndWaitCursor();
return FALSE;
}
EndWaitCursor();
if (bReplace) {
// Reset the title and change the document name
SetPathName(newName, TRUE);
ASSERT(m_strPathName == newName); // must be set
}
else // SaveCopyAs
{
SetModifiedFlag(bModified);
}
return TRUE; // success
}
//////////////////////////////////////////////////////////////////////////////
#define EPSILON (0.0000001)
int CDemoDoc::ComputePixel(float x, float y, float &x1, float &y1)
{
double r, nn;
if (x==0 && y==0) {
x1 = x;
y1 = y;
return 1;
}
nn = sqrt(x*x + y*y);
r = (fabs(x) > fabs(y)) ? fabs(nn/x): fabs(nn/y);
x1 = (float)(r*x);
y1 = (float)(r*y);
return 1;
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnUpdateFileSaveAs(CCmdUI* pCmdUI)
{
pCmdUI->Enable(!(image==0 || hThread));
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnUpdateFileSave(CCmdUI* pCmdUI)
{
pCmdUI->Enable(0);
// pCmdUI->Enable((image != NULL)); //&& theApp.GetWritableType(image->GetType()));
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnStretchMode()
{
stretchMode = !stretchMode;
UpdateAllViews(NULL);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnUpdateStretchMode(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(stretchMode);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnUpdateCximageFlip(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageGrayscale(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageMirror(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageNegative(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageResample(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageRotate(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageRotater(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageRotatel(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageDither(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageThreshold(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageSplityuv(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageSplitrgb(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageSplithsl(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageSplityiq(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageSplitxyz(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageSplitcmyk(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximagePseudocolors(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageFiltersColorize(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageLighten(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageDarken(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageContrast(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageEmboss(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageBlur(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageDilate(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageEdge(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageErode(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageSharpen(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageSoften(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageCrop(CCmdUI* pCmdUI)
{ if(image==0 || hThread || !image->SelectionIsValid()) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageRemovealphachannel(CCmdUI* pCmdUI)
{ if(image==0 || hThread || !image->AlphaIsValid()) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageInvetalpha(CCmdUI* pCmdUI)
{ if(image==0 || hThread || !image->AlphaIsValid()) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageAlphapalettetoggle(CCmdUI* pCmdUI)
{ if(image==0 || hThread || !image->AlphaPaletteIsValid()) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageAlphastrip(CCmdUI* pCmdUI)
{ if(image==0 || hThread || (!image->AlphaIsValid() && !image->AlphaPaletteIsValid())) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageRemovetransparency(CCmdUI* pCmdUI)
{ if(image==0 || hThread || image->GetTransIndex()<0) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageGamma(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageMedian(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageAddnoise(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageCombine(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageFft(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageRepair(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageAlphachannelSplit(CCmdUI* pCmdUI)
{ if(image==0 || hThread || !image->AlphaIsValid()) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageFiltersLog(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageFiltersRoot(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageHistogramEqualize(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageHistogramNormalize(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageHistogramStretch(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageGaussian3x3(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageGaussian5x5(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageContour(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageLesscontrast(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageJitter(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateWindowDuplicate(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateFiltersMix(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageCircletransformCylinder(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageCircletransformPinch(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageCircletransformPunch(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageCircletransformSwirl(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageCircletransformBathroom(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageHistogramStretch1(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
void CDemoDoc::OnUpdateCximageHistogramStretch2(CCmdUI* pCmdUI)
{ if(image==0 || hThread) pCmdUI->Enable(0);}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnUpdateTransformEllipse(CCmdUI* pCmdUI)
{
if (image==NULL) pCmdUI->Enable(0);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnTransformEllipse()
{
SubmitUndo();
DWORD x, y, x1, y1;
float fx, fy, xmid, ymid, ar;
CxImage *image2 = new CxImage(*image,false,false,true);
xmid = (float) (image->GetWidth()/2.0);
ymid = (float) (image->GetHeight()/2.0);
ar = (float)(image->GetHeight())/(float)(image->GetWidth());
for (y=0; y<image->GetHeight(); y++) {
for (x=0; x<image->GetWidth(); x++) {
ComputePixel(ar*(x-xmid), y-ymid, fx, fy);
x1 = (int)(xmid+fx/ar);
y1 = (int)(ymid+fy);
image2->SetPixelColor(x, y, image->GetPixelColor(x1, y1));
}
}
delete image;
image = image2;
UpdateAllViews(NULL);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnWindowDuplicate()
{
CDemoDoc *NewDoc=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL);
if (NewDoc) {
CxImage *newImage = new CxImage(*image);
NewDoc->image = newImage;
CString s;
s.Format("Copy %d of %s",((CDemoApp*)AfxGetApp())->m_nDocCount++,GetTitle());
NewDoc->SetTitle(s);
NewDoc->UpdateAllViews(0,WM_USER_NEWIMAGE);
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnUpdateEditCopy(CCmdUI* pCmdUI)
{
if (image==NULL) pCmdUI->Enable(0);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnEditCopy()
{
HANDLE hDIB=image->CopyToHandle();
if (::OpenClipboard(AfxGetApp()->m_pMainWnd->GetSafeHwnd())) {
if(::EmptyClipboard()) {
if (::SetClipboardData(CF_DIB,hDIB) == NULL ) {
AfxMessageBox( "Unable to set Clipboard data" );
}
}
}
CloseClipboard();
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnUpdateEditUndo(CCmdUI* pCmdUI)
{
if(image==0 || hThread) pCmdUI->Enable(0);
else pCmdUI->Enable(m_UndoLevel>0);
CString s;
s.Format("Undo (%d)\tCtrl+Z",m_UndoLevel);
pCmdUI->SetText(s);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnUpdateEditRedo(CCmdUI* pCmdUI)
{
if(image==0 || hThread) pCmdUI->Enable(0);
else pCmdUI->Enable((m_UndoLevel<(MAX_UNDO_LEVELS))&&
(imageUndo[m_UndoLevel]!=0));
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnEditUndo()
{
m_UndoLevel--;
CxImage* tmp = image;
image=imageUndo[m_UndoLevel];
imageUndo[m_UndoLevel]=tmp;
UpdateAllViews(0,WM_USER_NEWIMAGE);
UpdateStatusBar();
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnEditRedo()
{
CxImage* tmp = image;
image=imageUndo[m_UndoLevel];
imageUndo[m_UndoLevel]=tmp;
m_UndoLevel++;
UpdateAllViews(0,WM_USER_NEWIMAGE);
UpdateStatusBar();
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::SubmitUndo()
{
if (m_UndoLevel>=MAX_UNDO_LEVELS){ // Max Undo reached
delete imageUndo[0]; // discard the early undo
for(int i=1;i<max_undo_levels;i++){
imageundo[i-1]="imageUndo[i];" shift="" the="" history
="" }
="" imageundo[max_undo_levels-1]="0;" clear="" undo="" slot
="" m_undolevel="MAX_UNDO_LEVELS-1;" reposition="" at="" last="" level
="" we="" must="" "redo"="" history="" when="" a="" new="" action="" is="" performed
="" for="" (int="" i="m_UndoLevel;i<MAX_UNDO_LEVELS;i++){
" if="" (imageundo[i]){
="" delete="" imageundo[i];
="" imageundo[i]="0;
" save="" actual="" image="" in="" (image-="">IsValid()){
imageUndo[m_UndoLevel] = new CxImage();
imageUndo[m_UndoLevel]->Copy(*image);
m_UndoLevel++;
}
}
//////////////////////////////////////////////////////////////////////////////
void /*unsigned long _stdcall*/ RunProgressThread(void *lpParam)
{
CDemoDoc *pDoc = (CDemoDoc *)lpParam;
long n;
POSITION pos;
CView *pView;
while((n=pDoc->image->GetProgress())<100){
Sleep(333);
if(pDoc->image->GetEscape()) break;
pos = pDoc->GetFirstViewPosition();
pView = pDoc->GetNextView(pos);
if (pView) SendMessage(pView->m_hWnd, WM_USER_PROGRESS,n,0);
}
pos = pDoc->GetFirstViewPosition();
pView = pDoc->GetNextView(pos);
if (pView) SendMessage(pView->m_hWnd, WM_USER_PROGRESS,100,0);
Sleep(111);
pos = pDoc->GetFirstViewPosition();
pView = pDoc->GetNextView(pos);
if (pView) SendMessage(pView->m_hWnd, WM_USER_NEWIMAGE,0,0);
pDoc->hProgress = 0;
_endthread();
return;
}
//////////////////////////////////////////////////////////////////////////////
void /*unsigned long _stdcall*/ RunCxImageThread(void *lpParam)
{
CDemoDoc *pDoc = (CDemoDoc *)lpParam;
if (pDoc==NULL) return;
if (pDoc->image==NULL) return;
//prepare for elaboration
pDoc->image->SetProgress(0);
pDoc->image->SetEscape(0);
pDoc->SubmitUndo();
// auxilary thread for progress bar
pDoc->hProgress = (HANDLE)_beginthread(RunProgressThread,0,pDoc);
pDoc->Stopwatch(0);
switch (pDoc->m_MenuCommand)
{
// case ID_FILE_OPEN:
// pDoc->image->ReadFile(*(CString*)pDoc->m_fp[0],(int)pDoc->m_fp[1]);
// break;
case ID_CXIMAGE_FLIP:
pDoc->image->Flip();
break;
case ID_CXIMAGE_MIRROR:
pDoc->image->Mirror();
break;
case ID_CXIMAGE_NEGATIVE:
pDoc->image->Negative();
break;
case ID_CXIMAGE_GRAYSCALE:
pDoc->image->GrayScale();
break;
case ID_CXIMAGE_DITHER:
pDoc->image->Dither((long)pDoc->m_fp[0]);
break;
case ID_CXIMAGE_THRESHOLD:
pDoc->image->Threshold((BYTE)pDoc->m_fp[0]);
break;
case ID_CXIMAGE_COLORIZE:
if ((BYTE)pDoc->m_fp[0]){
pDoc->image->Colorize((BYTE)pDoc->m_fp[1],(BYTE)pDoc->m_fp[2]);
} else {
pDoc->image->ShiftRGB((BYTE)pDoc->m_fp[1],(BYTE)pDoc->m_fp[2],(BYTE)pDoc->m_fp[3]);
}
break;
case ID_CXIMAGE_LIGHTEN:
pDoc->image->Light(20);
break;
case ID_CXIMAGE_DARKEN:
pDoc->image->Light(-20);
break;
case ID_CXIMAGE_CONTRAST:
pDoc->image->Light((long)pDoc->m_fp[0],25);
break;
case ID_CXIMAGE_LESSCONTRAST:
pDoc->image->Light((long)pDoc->m_fp[0],-25);
break;
case ID_CXIMAGE_DILATE:
pDoc->image->Dilate();
break;
case ID_CXIMAGE_ERODE:
pDoc->image->Erode();
break;
case ID_CXIMAGE_CONTOUR:
pDoc->image->Contour();
break;
case ID_CXIMAGE_ADDNOISE:
pDoc->image->Noise(50);
break;
case ID_CXIMAGE_JITTER:
pDoc->image->Jitter();
break;
case ID_CXIMAGE_CIRCLETRANSFORM_CYLINDER:
pDoc->image->CircleTransform(3,0,100);
break;
case ID_CXIMAGE_CIRCLETRANSFORM_PINCH:
pDoc->image->CircleTransform(1,0,100);
break;
case ID_CXIMAGE_CIRCLETRANSFORM_PUNCH:
pDoc->image->CircleTransform(0,0,100);
break;
case ID_CXIMAGE_CIRCLETRANSFORM_SWIRL:
pDoc->image->CircleTransform(2,0,100);
break;
case ID_CXIMAGE_CIRCLETRANSFORM_BATHROOM:
pDoc->image->CircleTransform(4);
break;
case ID_CXIMAGE_EMBOSS:
{
long kernel[]={0,0,-1,0,0,0,1,0,0};
pDoc->image->Filter(kernel,3,0,127);
break;
}
case ID_CXIMAGE_BLUR:
{
long kernel[]={1,1,1,1,1,1,1,1,1};
pDoc->image->Filter(kernel,3,9,0);
break;
}
case ID_CXIMAGE_GAUSSIAN3X3:
{
long kernel[]={1,2,1,2,4,2,1,2,1};
pDoc->image->Filter(kernel,3,16,0);
break;
}
case ID_CXIMAGE_GAUSSIAN5X5:
{
long kernel[]={0,1,2,1,0,1,3,4,3,1,2,4,8,4,2,1,3,4,3,1,0,1,2,1,0};
pDoc->image->Filter(kernel,5,52,0);
break;
}
case ID_CXIMAGE_SOFTEN:
{
long kernel[]={1,1,1,1,8,1,1,1,1};
pDoc->image->Filter(kernel,3,16,0);
break;
}
case ID_CXIMAGE_SHARPEN:
{
long kernel[]={-1,-1,-1,-1,15,-1,-1,-1,-1};
pDoc->image->Filter(kernel,3,7,0);
break;
}
case ID_CXIMAGE_EDGE:
{
long kernel[]={-1,-1,-1,-1,8,-1,-1,-1,-1};
pDoc->image->Filter(kernel,3,-1,255);
break;
}
case ID_CXIMAGE_MEDIAN:
pDoc->image->Median(3);
break;
case ID_CXIMAGE_GAMMA:
pDoc->image->Gamma((float)(long)pDoc->m_fp[0]/1000);
break;
case ID_CXIMAGE_HISTOGRAM_LOG:
pDoc->image->HistogramLog();
break;
case ID_CXIMAGE_HISTOGRAM_ROOT:
pDoc->image->HistogramRoot();
break;
case ID_CXIMAGE_HISTOGRAM_EQUALIZE:
pDoc->image->HistogramEqualize();
break;
case ID_CXIMAGE_HISTOGRAM_NORMALIZE:
pDoc->image->HistogramNormalize();
break;
case ID_CXIMAGE_HISTOGRAM_STRETCH:
pDoc->image->HistogramStretch();
break;
case ID_CXIMAGE_HISTOGRAM_STRETCH1:
pDoc->image->HistogramStretch(1);
break;
case ID_CXIMAGE_HISTOGRAM_STRETCH2:
pDoc->image->HistogramStretch(2);
break;
case ID_CXIMAGE_ROTATE:
pDoc->image->Rotate((float)(long)pDoc->m_fp[0]/1000);
break;
case ID_CXIMAGE_ROTATEL:
pDoc->image->RotateLeft();
break;
case ID_CXIMAGE_ROTATER:
pDoc->image->RotateRight();
break;
case ID_CXIMAGE_RESAMPLE:
pDoc->image->Resample((long)pDoc->m_fp[0],(long)pDoc->m_fp[1],(long)pDoc->m_fp[2]);
break;
case ID_CXIMAGE_INCREASEBPP:
pDoc->image->IncreaseBpp((long)pDoc->m_fp[0]);
break;
case ID_CXIMAGE_DECREASEBPP:
{
long bit=(long)pDoc->m_fp[0];
long method=(long)pDoc->m_fp[1];
bool errordiffusion=((long)pDoc->m_fp[2])!=0;
long colors=(long)pDoc->m_fp[3];
//pDoc->image->IncreaseBpp(24);
RGBQUAD* ppal = NULL;
if (method==1){
switch (bit){
/*case 1:
{
CQuantizer q(2,8);
q.ProcessImage(pDoc->image->GetDIB());
ppal=(RGBQUAD*)calloc(2*sizeof(RGBQUAD),1);
q.SetColorTable(ppal);
break;
}*/
case 4:
{
CQuantizer q(colors,8);
q.ProcessImage(pDoc->image->GetDIB());
ppal=(RGBQUAD*)calloc(16*sizeof(RGBQUAD),1);
q.SetColorTable(ppal);
break;
}
case 8:
{
CQuantizer q(colors,(colors>16?7:8));
q.ProcessImage(pDoc->image->GetDIB());
ppal=(RGBQUAD*)calloc(256*sizeof(RGBQUAD),1);
q.SetColorTable(ppal);
}
}
pDoc->image->DecreaseBpp(bit,errordiffusion,ppal,colors);
} else pDoc->image->DecreaseBpp(bit,errordiffusion,0);
if (!pDoc->image->AlphaPaletteIsValid()) pDoc->image->AlphaPaletteEnable(0);
if (ppal) free(ppal);
break;
}
}
pDoc->Stopwatch(1);
pDoc->image->SetProgress(100);
pDoc->hThread=0;
_endthread();
return ;
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageFlip()
{
m_MenuCommand=ID_CXIMAGE_FLIP;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageMirror()
{
m_MenuCommand=ID_CXIMAGE_MIRROR;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageNegative()
{
m_MenuCommand=ID_CXIMAGE_NEGATIVE;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageGrayscale()
{
m_MenuCommand=ID_CXIMAGE_GRAYSCALE;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageDecreasebpp()
{
if (image==NULL) return;
DlgDecBpp dlg;
dlg.m_bit=4;
dlg.m_maxcolors = 256;
if (dlg.DoModal()==IDOK){
m_MenuCommand=ID_CXIMAGE_DECREASEBPP;
m_fp[0]=(void *)dlg.m_bit;
m_fp[1]=(void *)dlg.m_method;
m_fp[2]=(void *)dlg.m_errordiffusion;
m_fp[3]=(void *)dlg.m_maxcolors;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageIncreasebpp()
{
if (image==NULL) return;
DlgIncBpp dlg;
dlg.m_bit=24;
if (dlg.DoModal()==IDOK){
m_MenuCommand=ID_CXIMAGE_INCREASEBPP;
m_fp[0]=(void *)dlg.m_bit;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageRotatel()
{
m_MenuCommand=ID_CXIMAGE_ROTATEL;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageRotater()
{
m_MenuCommand=ID_CXIMAGE_ROTATER;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageRotate()
{
if (image==NULL) return;
DlgRotate dlg;
dlg.m_angle=(float)12.345;
if (dlg.DoModal()==IDOK){
m_MenuCommand=ID_CXIMAGE_ROTATE;
m_fp[0]=(void *)(long)(dlg.m_angle*1000);
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageResample()
{
if (image==NULL) return;
DlgResample dlg;
dlg.m_factor=(float)2;
if (dlg.DoModal()==IDOK){
m_MenuCommand=ID_CXIMAGE_RESAMPLE;
m_fp[0]=(void *)(long)(image->GetWidth() * dlg.m_factor);
m_fp[1]=(void *)(long)(image->GetHeight() * dlg.m_factor);
m_fp[2]=(void *)(long)dlg.m_mode;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::UpdateStatusBar()
{
if (image){
CStatusBar& statusBar = ((CMainFrame *)(AfxGetApp()->m_pMainWnd))->GetStatusBar();
CString s,t;
t = theApp.GetDescFromType(image->GetType());
s.Format("(%dx%dx%d)",image->GetWidth(),image->GetHeight(),image->GetBpp());
statusBar.SetPaneText(4, s);
statusBar.SetPaneText(3,t.Mid(0,3));
s.Format("Time (s): %.3f",m_etime);
statusBar.SetPaneText(2, s);
// ((CMainFrame *)(AfxGetApp()->m_pMainWnd))->GetProgressBar().SetPos(0);
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnViewZoomin()
{
if (m_ZoomFactor>=16) return;
m_ZoomFactor*=2;
UpdateAllViews(NULL,WM_USER_NEWIMAGE);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnViewZoomout()
{
if (m_ZoomFactor<=0.0625) return;
m_ZoomFactor/=2;
UpdateAllViews(NULL,WM_USER_NEWIMAGE);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnUpdateViewZoomin(CCmdUI* pCmdUI)
{
if (stretchMode) pCmdUI->Enable(0);
if (m_ZoomFactor>=16) pCmdUI->Enable(0);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnUpdateViewZoomout(CCmdUI* pCmdUI)
{
if (stretchMode) pCmdUI->Enable(0);
if (m_ZoomFactor<=0.125) pCmdUI->Enable(0);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnViewNormalviewing11()
{
m_ZoomFactor=1;
UpdateAllViews(NULL,WM_USER_NEWIMAGE);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnUpdateViewNormalviewing11(CCmdUI* pCmdUI)
{
if (stretchMode) pCmdUI->Enable(0);
if (m_ZoomFactor==1) pCmdUI->Enable(0);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnUpdateCximageSettransparency(CCmdUI* pCmdUI)
{
if (image && hThread==0) pCmdUI->Enable(1);
else pCmdUI->Enable(0);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageRemovetransparency()
{
SubmitUndo();
if (image) image->SetTransIndex(-1);
UpdateAllViews(NULL);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageSettransparency()
{
m_WaitingClick=TRUE;
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::Stopwatch(int start0stop1)
{
if (start0stop1==0) QueryPerformanceCounter(&m_swStart);
else {
QueryPerformanceCounter(&m_swStop);
if (m_swFreq.LowPart==0 && m_swFreq.HighPart==0) m_etime = -1;
else {
m_etime = (float)(m_swStop.LowPart - m_swStart.LowPart);
if (m_etime < 0) m_etime += 2^32;
m_etime /= (m_swFreq.LowPart+m_swFreq.HighPart * 2^32);
}
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageOptions()
{
if (image==NULL) return;
DlgOptions dlg;
dlg.m_quality = image->GetJpegQuality();
dlg.m_xres = image->GetXDPI();
dlg.m_yres = image->GetYDPI();
dlg.m_EncodeOption = image->GetCodecOption();
dlg.m_exif = &m_exif;
if (dlg.DoModal()==IDOK){
image->SetJpegQuality(dlg.m_quality);
image->SetXDPI(dlg.m_xres);
image->SetYDPI(dlg.m_yres);
image->SetCodecOption(dlg.m_EncodeOption);
#ifdef VATI_EXTENSIONS
theApp.m_optJpegQuality = dlg.m_quality;
#endif
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageDither()
{
if (image==NULL) return;
DlgDither dlg;
if (dlg.DoModal()==IDOK){
m_MenuCommand=ID_CXIMAGE_DITHER;
m_fp[0]=(void*)dlg.m_method;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageThreshold()
{
if (image==NULL) return;
DlgThreshold dlg;
dlg.m_level=(BYTE)image->Mean();
if (dlg.DoModal()==IDOK){
m_MenuCommand=ID_CXIMAGE_THRESHOLD;
m_fp[0]=(void *)(BYTE)(dlg.m_level);
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageSplitrgb()
{
if (image==NULL) return;
CxImage *newr = new CxImage();
CxImage *newg = new CxImage();
CxImage *newb = new CxImage();
Stopwatch(0);
image->SplitRGB(newr,newg,newb);
Stopwatch(1);
UpdateStatusBar();
((CDemoApp*)AfxGetApp())->m_nDocCount++;
CDemoDoc *NewDocr=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL);
if (NewDocr) {
NewDocr->image = newr;
CString s;
s.Format("Red Channel %d from %s",((CDemoApp*)AfxGetApp())->m_nDocCount,GetTitle());
NewDocr->SetTitle(s);
NewDocr->UpdateAllViews(0,WM_USER_NEWIMAGE);
}
CDemoDoc *NewDocg=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL);
if (NewDocg) {
NewDocg->image = newg;
CString s;
s.Format("Green Channel %d from %s",((CDemoApp*)AfxGetApp())->m_nDocCount,GetTitle());
NewDocg->SetTitle(s);
NewDocg->UpdateAllViews(0,WM_USER_NEWIMAGE);
}
CDemoDoc *NewDocb=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL);
if (NewDocb) {
NewDocb->image = newb;
CString s;
s.Format("Blue Channel %d from %s",((CDemoApp*)AfxGetApp())->m_nDocCount,GetTitle());
NewDocb->SetTitle(s);
NewDocb->UpdateAllViews(0,WM_USER_NEWIMAGE);
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageSplityuv()
{
if (image==NULL) return;
CxImage *newr = new CxImage();
CxImage *newg = new CxImage();
CxImage *newb = new CxImage();
Stopwatch(0);
image->SplitYUV(newr,newg,newb);
Stopwatch(1);
UpdateStatusBar();
((CDemoApp*)AfxGetApp())->m_nDocCount++;
CDemoDoc *NewDocr=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL);
if (NewDocr) {
NewDocr->image = newr;
CString s;
s.Format("Y Channel %d from %s",((CDemoApp*)AfxGetApp())->m_nDocCount,GetTitle());
NewDocr->SetTitle(s);
NewDocr->UpdateAllViews(0,WM_USER_NEWIMAGE);
}
CDemoDoc *NewDocg=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL);
if (NewDocg) {
NewDocg->image = newg;
CString s;
s.Format("U Channel %d from %s",((CDemoApp*)AfxGetApp())->m_nDocCount,GetTitle());
NewDocg->SetTitle(s);
NewDocg->UpdateAllViews(0,WM_USER_NEWIMAGE);
}
CDemoDoc *NewDocb=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL);
if (NewDocb) {
NewDocb->image = newb;
CString s;
s.Format("V Channel %d from %s",((CDemoApp*)AfxGetApp())->m_nDocCount,GetTitle());
NewDocb->SetTitle(s);
NewDocb->UpdateAllViews(0,WM_USER_NEWIMAGE);
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageSplithsl()
{
if (image==NULL) return;
CxImage *newr = new CxImage();
CxImage *newg = new CxImage();
CxImage *newb = new CxImage();
Stopwatch(0);
image->SplitHSL(newr,newg,newb);
Stopwatch(1);
UpdateStatusBar();
((CDemoApp*)AfxGetApp())->m_nDocCount++;
CDemoDoc *NewDocr=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL);
if (NewDocr) {
NewDocr->image = newr;
CString s;
s.Format("Hue Channel %d from %s",((CDemoApp*)AfxGetApp())->m_nDocCount,GetTitle());
NewDocr->SetTitle(s);
NewDocr->UpdateAllViews(0,WM_USER_NEWIMAGE);
}
CDemoDoc *NewDocg=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL);
if (NewDocg) {
NewDocg->image = newg;
CString s;
s.Format("Saturation Channel %d from %s",((CDemoApp*)AfxGetApp())->m_nDocCount,GetTitle());
NewDocg->SetTitle(s);
NewDocg->UpdateAllViews(0,WM_USER_NEWIMAGE);
}
CDemoDoc *NewDocb=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL);
if (NewDocb) {
NewDocb->image = newb;
CString s;
s.Format("Lightness Channel %d from %s",((CDemoApp*)AfxGetApp())->m_nDocCount,GetTitle());
NewDocb->SetTitle(s);
NewDocb->UpdateAllViews(0,WM_USER_NEWIMAGE);
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageSplitcmyk()
{
if (image==NULL) return;
CxImage *newc = new CxImage();
CxImage *newm = new CxImage();
CxImage *newy = new CxImage();
CxImage *newk = new CxImage();
Stopwatch(0);
image->SplitCMYK(newc,newm,newy,newk);
Stopwatch(1);
UpdateStatusBar();
((CDemoApp*)AfxGetApp())->m_nDocCount++;
CDemoDoc *NewDocr=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL);
if (NewDocr) {
NewDocr->image = newc;
CString s;
s.Format("C Channel %d from %s",((CDemoApp*)AfxGetApp())->m_nDocCount,GetTitle());
NewDocr->SetTitle(s);
NewDocr->UpdateAllViews(0,WM_USER_NEWIMAGE);
}
CDemoDoc *NewDocg=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL);
if (NewDocg) {
NewDocg->image = newm;
CString s;
s.Format("M Channel %d from %s",((CDemoApp*)AfxGetApp())->m_nDocCount,GetTitle());
NewDocg->SetTitle(s);
NewDocg->UpdateAllViews(0,WM_USER_NEWIMAGE);
}
CDemoDoc *NewDocb=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL);
if (NewDocb) {
NewDocb->image = newy;
CString s;
s.Format("Y Channel %d from %s",((CDemoApp*)AfxGetApp())->m_nDocCount,GetTitle());
NewDocb->SetTitle(s);
NewDocb->UpdateAllViews(0,WM_USER_NEWIMAGE);
}
CDemoDoc *NewDock=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL);
if (NewDock) {
NewDock->image = newk;
CString s;
s.Format("K Channel %d from %s",((CDemoApp*)AfxGetApp())->m_nDocCount,GetTitle());
NewDock->SetTitle(s);
NewDock->UpdateAllViews(0,WM_USER_NEWIMAGE);
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximagePseudocolors()
{
if (image==NULL) return;
SubmitUndo();
if (!image->IsGrayScale()) image->GrayScale();
image->HuePalette();
/* POSITION pos = GetFirstViewPosition();
CDemoView* pView = (CDemoView*)GetNextView(pos);
HDC srcDC = ::GetDC(pView->GetSafeHwnd());
HDC memDC = ::CreateCompatibleDC(srcDC);
// copy the screen to the bitmap
CSize sz(image->GetWidth(), image->GetHeight());
int xshift = 0, yshift = 0;
HBITMAP bm =::CreateCompatibleBitmap(srcDC, sz.cx, sz.cy);
HBITMAP oldbm = (HBITMAP)::SelectObject(memDC,bm);
::BitBlt(memDC, 0, 0, sz.cx, sz.cy, srcDC, xshift, yshift, SRCCOPY);
// image->SetTransIndex(-1);
// image->Draw(memDC);
::TextOut(memDC,10,10,"test",4);
CxImage newima;
newima.CreateFromHBITMAP(bm);
image->Transfer(newima);
// free objects
SelectObject(memDC,oldbm);
DeleteObject(memDC);*/
UpdateAllViews(NULL,WM_USER_NEWIMAGE);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageFiltersColorize()
{
if (image==NULL) return;
DlgColorize dlg;
dlg.m_sat=50;
dlg.m_hue=12;
dlg.m_r=50;
dlg.m_g=0;
dlg.m_b=-50;
if (dlg.DoModal()==IDOK){
m_MenuCommand=ID_CXIMAGE_COLORIZE;
if (dlg.m_bHSL){
m_fp[0]=(void *)(BYTE)(dlg.m_bHSL);
m_fp[1]=(void *)(BYTE)(dlg.m_hue);
m_fp[2]=(void *)(BYTE)(dlg.m_sat);
} else {
m_fp[0]=(void *)(BYTE)(dlg.m_bHSL);
m_fp[1]=(void *)(BYTE)(dlg.m_r);
m_fp[2]=(void *)(BYTE)(dlg.m_g);
m_fp[3]=(void *)(BYTE)(dlg.m_b);
}
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageDarken()
{
m_MenuCommand=ID_CXIMAGE_DARKEN;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageLighten()
{
m_MenuCommand=ID_CXIMAGE_LIGHTEN;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageContrast()
{
m_MenuCommand=ID_CXIMAGE_CONTRAST;
// m_fp[0]=(void *)(long)((128-image->Mean())/4);
m_fp[0]=(void *)(long)(0);
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageEmboss()
{
m_MenuCommand=ID_CXIMAGE_EMBOSS;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageBlur()
{
m_MenuCommand=ID_CXIMAGE_BLUR;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageDilate()
{
m_MenuCommand=ID_CXIMAGE_DILATE;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageEdge()
{
m_MenuCommand=ID_CXIMAGE_EDGE;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageErode()
{
m_MenuCommand=ID_CXIMAGE_ERODE;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageSharpen()
{
m_MenuCommand=ID_CXIMAGE_SHARPEN;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageSoften()
{
m_MenuCommand=ID_CXIMAGE_SOFTEN;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageCrop()
{
SubmitUndo();
RECT r;
#ifdef VATI_EXTENSIONS
// if there is a valid rectangle selection, then call the CropRotatedRectangle instead original Crop
if (m_isRectSel && m_NumSel==5 )
{
CPoint top;
long height, width;
float angle;
int topcorner = -1;
// get upperleft corner
top.x = 999999;
top.y = 999999;
for(int i=0; i<4; i++)
{
if ( top.y >= m_Sel[i].y )
{
if ( top.y == m_Sel[i].y && top.x < m_Sel[i].x )
continue;
top.x = m_Sel[i].x;
top.y = m_Sel[i].y;
topcorner = i;
}
}
// get side lengths (-1st and +1st indexes points to 2 sides)
if ( topcorner > 0 && topcorner < 4 )
height = (long)LEN2D( top.x - m_Sel[topcorner-1].x, top.y - m_Sel[topcorner-1].y );
else if ( topcorner == 0 )
height = (long)LEN2D( top.x - m_Sel[3].x, top.y - m_Sel[3].y );
else
return; // fatal prog error
width = (long)LEN2D( top.x - m_Sel[topcorner+1].x, top.y - m_Sel[topcorner+1].y );
angle = (float)atan2( (float)(m_Sel[topcorner+1].y - top.y), (float)(m_Sel[topcorner+1].x - top.x) );
image->CropRotatedRectangle( top.x, top.y, width, height, angle );
}
else // freehand selection
{
image->SelectionGetBox(r);
r.bottom = image->GetHeight() - 1 -r.bottom;
r.top = image->GetHeight() - 1 -r.top;
image->Crop(r);
}
#else
image->SelectionGetBox(r);
r.bottom = image->GetHeight() - 1 -r.bottom;
r.top = image->GetHeight() - 1 -r.top;
image->Crop(r);
#endif
UpdateStatusBar(); // VAti - to refresh image size in the status bar
UpdateAllViews(NULL,WM_USER_NEWIMAGE);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageRemovealphachannel()
{
SubmitUndo();
image->AlphaDelete();
image->AlphaSetMax(255);
UpdateAllViews(NULL);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageOpacity()
{
if (image==NULL) return;
DlgOpacity dlg;
dlg.m_level=image->AlphaGetMax();
if (dlg.DoModal()==IDOK){
SubmitUndo();
if (!image->AlphaIsValid()){
image->AlphaCreate();
}
image->AlphaSetMax(dlg.m_level);
}
UpdateAllViews(NULL);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageInvetalpha()
{
SubmitUndo();
image->AlphaInvert();
UpdateAllViews(NULL);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageAlphapalettetoggle()
{
SubmitUndo();
image->AlphaPaletteEnable(!image->AlphaPaletteIsEnabled());
UpdateAllViews(NULL);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageAlphastrip()
{
SubmitUndo();
RGBQUAD c={255,255,255,0};
image->SetTransColor(c);
image->AlphaStrip();
UpdateAllViews(NULL,WM_USER_NEWIMAGE);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageGamma()
{
if (image==NULL) return;
DlgGamma dlg;
dlg.m_gamma=(float)1.23;
if (dlg.DoModal()==IDOK){
m_MenuCommand=ID_CXIMAGE_GAMMA;
m_fp[0]=(void *)(long)(dlg.m_gamma*1000);
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageMedian()
{
m_MenuCommand=ID_CXIMAGE_MEDIAN;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageAddnoise()
{
m_MenuCommand=ID_CXIMAGE_ADDNOISE;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnViewToolsMove()
{
m_tool=0;
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnUpdateViewToolsMove(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_tool==0);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnViewToolsSelect()
{
m_tool=1;
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnUpdateViewToolsSelect(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_tool==1);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnViewToolsZoom()
{
m_tool=2;
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnUpdateViewToolsZoom(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_tool==2);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnViewToolsText()
{
if (image==NULL) return;
DlgText dlg;
#ifndef VATI_EXTENSIONS
memcpy(&(dlg.m_font),&m_font,sizeof(m_font));
dlg.m_text=m_text;
dlg.m_color=m_color;
if (dlg.DoModal()==IDOK){
m_text=dlg.m_text;
m_color=dlg.m_color;
memcpy(&m_font,&(dlg.m_font),sizeof(m_font));
m_tool=3;
}
#else
//pass all data about text
memcpy( &(dlg.m_textdata), &theApp.m_text, sizeof(CXTEXTINFO) );
if (dlg.DoModal()==IDOK)
{
//retrieve all data about text
memcpy( &theApp.m_text, &(dlg.m_textdata), sizeof(CXTEXTINFO) );
m_tool=3;
}
#endif
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnUpdateViewToolsText(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_tool==3);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnUpdateViewPalette(CCmdUI* pCmdUI)
{
if(image==0 || hThread || image->GetNumColors()==0) pCmdUI->Enable(0);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnViewPalette()
{
if (image==NULL) return;
DlgPalette dlg;
dlg.m_numcolors=image->GetNumColors();
memcpy(dlg.m_pal,image->GetPalette(),dlg.m_numcolors*sizeof(RGBQUAD));
if (dlg.DoModal()==IDOK){
if (dlg.m_changed){
SubmitUndo();
switch (dlg.m_replace){
case 1:
{
image->SetPalette(dlg.m_pal,dlg.m_numcolors);
break;
}
case 2:
{
int bpp=image->GetBpp();
image->IncreaseBpp(24);
image->DecreaseBpp(bpp,false,dlg.m_pal);
break;
}
case 3:
{
int bpp=image->GetBpp();
image->IncreaseBpp(24);
image->DecreaseBpp(bpp,true,dlg.m_pal);
break;
}
}
UpdateAllViews(NULL,WM_USER_NEWIMAGE);
}
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageCombine()
{
if (image==NULL) return;
DlgCombine dlg;
if (dlg.DoModal()==IDOK){
SetCursor(LoadCursor(0,IDC_WAIT));
Stopwatch(0);
CxImage *newr,*newg,*newb,*newa;
newr=newg=newb=newa=NULL;
newr = new CxImage();
switch(dlg.pChR){
case 0:
newr->Copy(*(dlg.pDocR->GetImage()),1,0,0);
newr->GrayScale();
break;
case 1:
dlg.pDocR->GetImage()->SplitRGB(newr,0,0);
break;
case 2:
dlg.pDocR->GetImage()->SplitRGB(0,newr,0);
break;
case 3:
dlg.pDocR->GetImage()->SplitRGB(0,0,newr);
break;
}
newg = new CxImage();
switch(dlg.pChG){
case 0:
newg->Copy(*(dlg.pDocG->GetImage()),1,0,0);
newg->GrayScale();
break;
case 1:
dlg.pDocG->GetImage()->SplitRGB(newg,0,0);
break;
case 2:
dlg.pDocG->GetImage()->SplitRGB(0,newg,0);
break;
case 3:
dlg.pDocG->GetImage()->SplitRGB(0,0,newg);
break;
}
newb = new CxImage();
switch(dlg.pChB){
case 0:
newb->Copy(*(dlg.pDocB->GetImage()),1,0,0);
newb->GrayScale();
break;
case 1:
dlg.pDocB->GetImage()->SplitRGB(newb,0,0);
break;
case 2:
dlg.pDocB->GetImage()->SplitRGB(0,newb,0);
break;
case 3:
dlg.pDocB->GetImage()->SplitRGB(0,0,newb);
break;
}
if (dlg.pDocA){
newa = new CxImage();
switch(dlg.pChA){
case 0:
newa->Copy(*(dlg.pDocA->GetImage()),1,0,0);
newa->GrayScale();
break;
case 1:
dlg.pDocA->GetImage()->SplitRGB(newa,0,0);
break;
case 2:
dlg.pDocA->GetImage()->SplitRGB(0,newa,0);
break;
case 3:
dlg.pDocA->GetImage()->SplitRGB(0,0,newa);
break;
}
}
CxImage *mix = new CxImage();
mix->Combine(newr,newg,newb,newa,dlg.pChS);
CDemoDoc *NewDocr=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL);
if (NewDocr) {
NewDocr->image = mix;
CString s;
s.Format("NewImage%d",((CDemoApp*)AfxGetApp())->m_nDocCount++);
NewDocr->SetTitle(s);
NewDocr->UpdateAllViews(0,WM_USER_NEWIMAGE);
}
delete newr;
delete newg;
delete newb;
delete newa;
Stopwatch(1);
UpdateStatusBar();
SetCursor(LoadCursor(0,IDC_ARROW));
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageFft()
{
if (image==NULL) return;
DlgFFT dlg;
if (dlg.DoModal()==IDOK){
SetCursor(LoadCursor(0,IDC_WAIT));
Stopwatch(0);
CxImage *srcr,*srci,*dstr,*dsti,tmp;
srcr = (dlg.pDocReal) ? dlg.pDocReal->GetImage() : 0;
srci = (dlg.pDocImag) ? dlg.pDocImag->GetImage() : 0;
if (srcr==0 && srci==0) return;
if (srcr) dstr = new CxImage(*srcr,true,false,false); else dstr=0;
if (srci) dsti = new CxImage(*srci,true,false,false); else dsti=0;
if (dstr==0){
dstr = new CxImage(dsti->GetWidth(),dsti->GetHeight(),8);
dstr->Clear(0);
dstr->SetGrayPalette();
}
if (dsti==0){
dsti = new CxImage(dstr->GetWidth(),dstr->GetHeight(),8);
dsti->Clear(0);
dsti->SetGrayPalette();
}
tmp.FFT2(dstr,dsti,0,0,dlg.bInverse,dlg.bForceFFT!=0,dlg.bMagnitude!=0);
((CDemoApp*)AfxGetApp())->m_nDocCount++;
CDemoDoc *NewDoci=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL);
if (NewDoci) {
NewDoci->image = dsti;
CString s;
if (dlg.bMagnitude){
s.Format("FFT Phase %d",((CDemoApp*)AfxGetApp())->m_nDocCount);
} else {
s.Format("FFT Imag %d",((CDemoApp*)AfxGetApp())->m_nDocCount);
}
NewDoci->SetTitle(s);
NewDoci->UpdateAllViews(0,WM_USER_NEWIMAGE);
}
CDemoDoc *NewDocr=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL);
if (NewDocr) {
NewDocr->image = dstr;
CString s;
if (dlg.bMagnitude){
s.Format("FFT Magnitude %d",((CDemoApp*)AfxGetApp())->m_nDocCount);
} else {
s.Format("FFT Real %d",((CDemoApp*)AfxGetApp())->m_nDocCount);
}
NewDocr->SetTitle(s);
NewDocr->UpdateAllViews(0,WM_USER_NEWIMAGE);
}
Stopwatch(1);
UpdateStatusBar();
SetCursor(LoadCursor(0,IDC_ARROW));
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageSplityiq()
{
if (image==NULL) return;
CxImage *newr = new CxImage();
CxImage *newg = new CxImage();
CxImage *newb = new CxImage();
Stopwatch(0);
image->SplitYIQ(newr,newg,newb);
Stopwatch(1);
UpdateStatusBar();
((CDemoApp*)AfxGetApp())->m_nDocCount++;
CDemoDoc *NewDocr=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL);
if (NewDocr) {
NewDocr->image = newr;
CString s;
s.Format("Y Channel %d from %s",((CDemoApp*)AfxGetApp())->m_nDocCount,GetTitle());
NewDocr->SetTitle(s);
NewDocr->UpdateAllViews(0,WM_USER_NEWIMAGE);
}
CDemoDoc *NewDocg=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL);
if (NewDocg) {
NewDocg->image = newg;
CString s;
s.Format("I Channel %d from %s",((CDemoApp*)AfxGetApp())->m_nDocCount,GetTitle());
NewDocg->SetTitle(s);
NewDocg->UpdateAllViews(0,WM_USER_NEWIMAGE);
}
CDemoDoc *NewDocb=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL);
if (NewDocb) {
NewDocb->image = newb;
CString s;
s.Format("Q Channel %d from %s",((CDemoApp*)AfxGetApp())->m_nDocCount,GetTitle());
NewDocb->SetTitle(s);
NewDocb->UpdateAllViews(0,WM_USER_NEWIMAGE);
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageSplitxyz()
{
if (image==NULL) return;
CxImage *newr = new CxImage();
CxImage *newg = new CxImage();
CxImage *newb = new CxImage();
Stopwatch(0);
image->SplitXYZ(newr,newg,newb);
Stopwatch(1);
UpdateStatusBar();
((CDemoApp*)AfxGetApp())->m_nDocCount++;
CDemoDoc *NewDocr=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL);
if (NewDocr) {
NewDocr->image = newr;
CString s;
s.Format("X Channel %d from %s",((CDemoApp*)AfxGetApp())->m_nDocCount,GetTitle());
NewDocr->SetTitle(s);
NewDocr->UpdateAllViews(0,WM_USER_NEWIMAGE);
}
CDemoDoc *NewDocg=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL);
if (NewDocg) {
NewDocg->image = newg;
CString s;
s.Format("Y Channel %d from %s",((CDemoApp*)AfxGetApp())->m_nDocCount,GetTitle());
NewDocg->SetTitle(s);
NewDocg->UpdateAllViews(0,WM_USER_NEWIMAGE);
}
CDemoDoc *NewDocb=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL);
if (NewDocb) {
NewDocb->image = newb;
CString s;
s.Format("Z Channel %d from %s",((CDemoApp*)AfxGetApp())->m_nDocCount,GetTitle());
NewDocb->SetTitle(s);
NewDocb->UpdateAllViews(0,WM_USER_NEWIMAGE);
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageRepair()
{
if (image==NULL) return;
DlgRepair dlg;
dlg.m_iterations = 2;
dlg.m_radius = (float)0.25;
if (dlg.DoModal()==IDOK){
SubmitUndo();
SetCursor(LoadCursor(0,IDC_WAIT));
Stopwatch(0);
image->Repair(dlg.m_radius,dlg.m_iterations,dlg.m_ncs);
Stopwatch(1);
UpdateAllViews(NULL);
UpdateStatusBar();
SetCursor(LoadCursor(0,IDC_ARROW));
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageAlphachannelSplit()
{
if (image==NULL) return;
CxImage *newa = new CxImage();
Stopwatch(0);
image->AlphaSplit(newa);
Stopwatch(1);
UpdateStatusBar();
((CDemoApp*)AfxGetApp())->m_nDocCount++;
CDemoDoc *NewDocr=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL);
if (NewDocr) {
NewDocr->image = newa;
CString s;
s.Format("Alpha Channel %d from %s",((CDemoApp*)AfxGetApp())->m_nDocCount,GetTitle());
NewDocr->SetTitle(s);
NewDocr->UpdateAllViews(0,WM_USER_NEWIMAGE);
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageAlphaCreate()
{
if (image==NULL) return;
CxImage gray(*image,true,false,false);
gray.IncreaseBpp(8);
gray.Negative();
gray.GrayScale();
image->AlphaSet(gray);
UpdateAllViews(NULL);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageFiltersLog()
{
m_MenuCommand=ID_CXIMAGE_HISTOGRAM_LOG;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageFiltersRoot()
{
m_MenuCommand=ID_CXIMAGE_HISTOGRAM_ROOT;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageHistogramEqualize()
{
m_MenuCommand=ID_CXIMAGE_HISTOGRAM_EQUALIZE;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageHistogramNormalize()
{
m_MenuCommand=ID_CXIMAGE_HISTOGRAM_NORMALIZE;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageHistogramStretch()
{
m_MenuCommand=ID_CXIMAGE_HISTOGRAM_STRETCH;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageGaussian3x3()
{
m_MenuCommand=ID_CXIMAGE_GAUSSIAN3X3;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageGaussian5x5()
{
m_MenuCommand=ID_CXIMAGE_GAUSSIAN5X5;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageContour()
{
m_MenuCommand=ID_CXIMAGE_CONTOUR;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageLesscontrast()
{
m_MenuCommand=ID_CXIMAGE_LESSCONTRAST;
m_fp[0]=(void *)(long)(0);
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageJitter()
{
m_MenuCommand=ID_CXIMAGE_JITTER;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnFiltersMix()
{
if (image==NULL) return;
DlgMix dlg;
if (dlg.DoModal()==IDOK){
SetCursor(LoadCursor(0,IDC_WAIT));
Stopwatch(0);
CxImage *src, *dst, *tmp;
src = (dlg.pDocSrc) ? dlg.pDocSrc->GetImage() : 0;
dst = (dlg.pDocDst) ? dlg.pDocDst->GetImage() : 0;
if (src==0 && dst==0) return;
tmp = new CxImage(*dst);
tmp->Mix(*src,(CxImage::ImageOpType)dlg.OpType,dlg.m_xoffset,dlg.m_yoffset);
((CDemoApp*)AfxGetApp())->m_nDocCount++;
CDemoDoc *NewDoci=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL);
if (NewDoci) {
NewDoci->image = tmp;
CString s;
s.Format("Mix %d",((CDemoApp*)AfxGetApp())->m_nDocCount);
NewDoci->SetTitle(s);
NewDoci->UpdateAllViews(0,WM_USER_NEWIMAGE);
}
Stopwatch(1);
UpdateStatusBar();
SetCursor(LoadCursor(0,IDC_ARROW));
}
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageCircletransformCylinder()
{
m_MenuCommand=ID_CXIMAGE_CIRCLETRANSFORM_CYLINDER;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageCircletransformPinch()
{
m_MenuCommand=ID_CXIMAGE_CIRCLETRANSFORM_PINCH;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageCircletransformPunch()
{
m_MenuCommand=ID_CXIMAGE_CIRCLETRANSFORM_PUNCH;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageCircletransformSwirl()
{
m_MenuCommand=ID_CXIMAGE_CIRCLETRANSFORM_SWIRL;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageCircletransformBathroom()
{
m_MenuCommand=ID_CXIMAGE_CIRCLETRANSFORM_BATHROOM;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageHistogramStretch1()
{
m_MenuCommand=ID_CXIMAGE_HISTOGRAM_STRETCH1;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
void CDemoDoc::OnCximageHistogramStretch2()
{
m_MenuCommand=ID_CXIMAGE_HISTOGRAM_STRETCH2;
hThread=(HANDLE)_beginthread(RunCxImageThread,0,this);
}
//////////////////////////////////////////////////////////////////////////////
//===================================================
// demo2\console.cpp
//===================================================
// Console.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "ximage.h"
CString FindExtension(const CString& name)
{
int len = name.GetLength();
int i;
for (i = len-1; i >= 0; i--){
if (name[i] == '.'){
return name.Mid(i+1);
}
}
return CString("");
}
int FindFormat(const CString& ext)
{
int type = 0;
if (ext == "bmp") type = CXIMAGE_FORMAT_BMP;
#if CXIMAGE_SUPPORT_CHIBA
else if (ext=="xyz"||ext=="rgb"||ext=="ktu") type = CXIMAGE_FORMAT_CHIBA;
#endif
#if CXIMAGE_SUPPORT_JPG
else if (ext=="jpg"||ext=="jpeg") type = CXIMAGE_FORMAT_JPG;
#endif
#if CXIMAGE_SUPPORT_GIF
else if (ext == "gif") type = CXIMAGE_FORMAT_GIF;
#endif
#if CXIMAGE_SUPPORT_PNG
else if (ext == "png") type = CXIMAGE_FORMAT_PNG;
#endif
#if CXIMAGE_SUPPORT_MNG
else if (ext=="mng"||ext=="jng") type = CXIMAGE_FORMAT_MNG;
#endif
#if CXIMAGE_SUPPORT_ICO
else if (ext == "ico") type = CXIMAGE_FORMAT_ICO;
#endif
#if CXIMAGE_SUPPORT_TIF
else if (ext=="tiff"||ext=="tif") type = CXIMAGE_FORMAT_TIF;
#endif
#if CXIMAGE_SUPPORT_TGA
else if (ext=="tga") type = CXIMAGE_FORMAT_TGA;
#endif
#if CXIMAGE_SUPPORT_PCX
else if (ext=="pcx") type = CXIMAGE_FORMAT_PCX;
#endif
#if CXIMAGE_SUPPORT_WBMP
else if (ext=="wbmp") type = CXIMAGE_FORMAT_WBMP;
#endif
#if CXIMAGE_SUPPORT_WMF
else if (ext=="wmf"||ext=="emf") type = CXIMAGE_FORMAT_WMF;
#endif
#if CXIMAGE_SUPPORT_J2K
else if (ext=="j2k"||ext=="jp2") type = CXIMAGE_FORMAT_J2K;
#endif
#if CXIMAGE_SUPPORT_JBG
else if (ext=="jbg") type = CXIMAGE_FORMAT_JBG;
#endif
#if CXIMAGE_SUPPORT_JP2
else if (ext=="jp2"||ext=="j2k") type = CXIMAGE_FORMAT_JP2;
#endif
#if CXIMAGE_SUPPORT_JPC
else if (ext=="jpc"||ext=="j2c") type = CXIMAGE_FORMAT_JPC;
#endif
#if CXIMAGE_SUPPORT_PGX
else if (ext=="pgx") type = CXIMAGE_FORMAT_PGX;
#endif
#if CXIMAGE_SUPPORT_RAS
else if (ext=="ras") type = CXIMAGE_FORMAT_RAS;
#endif
#if CXIMAGE_SUPPORT_PNM
else if (ext=="pnm"||ext=="pgm"||ext=="ppm") type = CXIMAGE_FORMAT_PNM;
#endif
else type = CXIMAGE_FORMAT_UNKNOWN;
return type;
}
int main(int argc, char* argv[])
{
CxImage image;
if (argc<3) {
fprintf(stderr, image.GetVersion());
fprintf(stderr, "\nConsole demo\n");
fprintf(stderr, "usage: %s input-file output-file\n", argv[0]);
return 1;
}
CString filein(argv[1]);
CString extin(FindExtension(filein));
extin.MakeLower();
int typein = FindFormat(extin);
if (typein == CXIMAGE_FORMAT_UNKNOWN) {
fprintf(stderr, "unknown extension for %s\n", argv[1]);
return 1;
}
CString fileout(argv[2]);
CString extout(FindExtension(fileout));
extout.MakeLower();
int typeout = FindFormat(extout);
if (typeout == CXIMAGE_FORMAT_UNKNOWN) {
fprintf(stderr, "unknown extension for %s\n", argv[2]);
return 1;
}
if (!image.Load(argv[1],typein)){
fprintf(stderr, "%s\n", image.GetLastError());
fprintf(stderr, "error loading %s\n", argv[1]);
return 1;
}
if (!image.Save(argv[2],typeout)){
fprintf(stderr, "%s\n", image.GetLastError());
fprintf(stderr, "error saving %s\n", argv[2]);
return 1;
}
printf("Done!\n");
return 0;
}
ThanhDK
|
|
|
|
|
hi, ThanhDk:
thanks for your usefull info. I did input .Raw files into CxImage, but I have to convert .Raw to .Bmp first. Then I make use of Bmp class of CxImage.
I would try your formal way of adding new format.
By the way, how can we add more functions into CxImage, such as deformation function, registration function etc??
thx!
uranus
contact mail: linchunshu@yahoo.com
welcome to write to me.
|
|
|
|
|
I'm trying to use this library in a VC++.NET 2002 project.
In section "Using CxImage in your projects" is said that we must specify Multi-threaded DLL in our project settings. But I've specified Single-threaded and all works fine (obviusly I've compiled and linked the projects I need of this library with single-threaded).
Can I have any problem using this library as a single-threaded?
Thanks.
PD: wonderful library
|
|
|
|
|
I also run it with single threaded...and it works fine )
|
|
|
|
|
Dear all,
What do GetSize() function return??
It is not like the real size.
How can I calculate the real size?
Pls reply me it is urgent.
|
|
|
|
|
dear,
I would like to speed up the reading operation of GIF file.
I read some old post from this group. Someone asked me that replacing "Decode" with "Load". However, I really don't know to to use it to read GIF file.
This is my original code.
Cximage image;
image.Load("C:\\test.gif",CXIMAGE_FORMAT_GIF);
for(int i=1;i
|
|
|
|
|
A five stars for you!
I use your code in one of my project, which merges some gif files to one.But when i open a gif, the Frames at the end will dirty Mixed With previous frame, what is the problem? I use your DEMO.EXE to decode all the frames, it do dirty mixed ,too. But it works fine at ACDSEE or other gif viewers . If i have your mail_box, I will mail you the gif file.
Thanx!
|
|
|
|
|
Using CxImage, I'm loading a PNG from a dll. The png has some transparent parts. When I display the image on the screen, the transparency seems to be ignored. I've looked thru the code but just can't seem to find what I am looking for. Can someone provide a sample or point me in the right direction.
Snip-it of my code from my ::OnPaint() handler (error checking has been removed):
CxImage *image = new CxImage();
HRSRC hres;
hres = FindResource( dll->getModuleHandle(), "#5099"; , "PNG");
image->LoadResource( hres, CXIMAGE_FORMAT_PNG, dll->getModuleHandle());
image->Draw2( dc, 10, 10, 247, 52);
I get the image but the transparent parts are not transparent.
Thanks,
Randy
|
|
|
|
|
Hello,
Using cxImage, It able to open 16bit tiff file. but if u make changes and re save as tiff, it converts 16 bit to 8 bit.
Is their any fix for this?
Please let me know.
Thanks,
|
|
|
|
|
CxImage does not handle 16 bit tiff images.
I had a similar problem awhile back. You will have to work with the libtiff library directly to read and display images as 16 bit.
Hope this helps
" Why oh why didn't I take the blue pill ? "
|
|
|
|
|
Thanks for u reply.
Do u have fix for it?
if so please can u share with me.
Thanks again,
|
|
|
|
|
As a matter of fact I did write an application that would read and display 16 bit grayscale tiff images. I'm planning on making this my first article once I can make sure it works.
But there are many kinds of tiff images ( multi page , different header bits etc). Mine only works for one kind of image. I'm trying to generalize it.
" Why oh why didn't I take the blue pill ? "
|
|
|
|
|
You can create a bmp by photoshop or other tools.
I found that CxImage can not use a bmp with such formats:Format:32bit A8R8GB8,or 16bit R5G6B5,or 16bit A4R4G4B4.
Did you find this?And will the CxImage be improved next?
|
|
|
|
|
Anyone know how to load a dib and dibsection from memory into CxImage ?
Need to import images directly from another libary
Thanks
Bob
|
|
|
|
|
Is there planned to be a cximage download version 5.99a for cbuilder6 ?
|
|
|
|
|