|
Hello,
is it possible to grab the contents of the screen and write it to a file?
Does anyone have an example?
Regards,
Jeroen
|
|
|
|
|
// copy the screen to a HBITMAP
HDC hdcDesk = GetDC(HWND_DESKTOP);
int width = GetDeviceCaps(hdcDesk, HORZRES);
int height = GetDeviceCaps(hdcDesk, VERTRES);
HDC hdcCopy = CreateCompatibleDC(hdcDesk);
HBITMAP hBm = CreateCompatibleBitmap(hdcDesk, width, height);
SelectObject(hdcCopy, hBm);
BitBlt(hdcCopy, 0, 0, width, height, hdcDesk, 0, 0, SRCCOPY);
// create a CxImage from the screen grab
CxImage *image = new CxImage();
image->CreateFromHBITMAP(hBm);
// clean up the bitmap and dcs
ReleaseDC(hdcDesk);
DeleteDC(hdcCopy);
DeleteObject(hBm);
// now save the file
image->Save("screenshot.png", CXIMAGE_FORMAT_PNG);
// free the image object
delete image;
hope that helps
|
|
|
|
|
I user Gdiplus Bitmap object.
but Bitmap object should make file name and BITMAPINFO and bitmap Data.
how make gdiplus Bitmap Object.
Please! help me.
Thank for my attention.
|
|
|
|
|
default mask size is 2
and mask area is -1 <= (x,y) <= 1
but this library area is -1 <= (x,y) < 1
so erode ans dilate process has right shite
and right pixel has not erode ans dilate.
you must insert = at for loop
|
|
|
|
|
I have a buffer filled with the image pixels. I want to save it to disk as a jpeg image. I use these calls:
image.SetJpegQuality(100);
image.CreateFromArray(bufferImage, width, height, 24, width * 3, FALSE);
image.Save(filename, CXIMAGE_FORMAT_JPG);
but the image created appears smoothed!
If I save the image as a BMP the smoothing disappears. But I need to save the image as a JPG, not as BMP.
Please, help
|
|
|
|
|
First of all I want to say it is really great Library.
Second I have problem I am dealing with monochrome Images and CXImage successfuly load and process it.
But I want to know How 2 extact image pixels values in an array?
and wut Size should i use to create arrays for a monochrame case.
does each pixel is places in 1 bit or 1 byte?
it would be great if any one can write a sample code.
with array initilaization.
I need reply as fast as possible.
Thank you
|
|
|
|
|
I downloaded the full source files and tried to build.
I got an error, saying -
"Conversion of the source control binding for this project could not be completed because a .opt or .suo file is missing or corrupted. The Change Source Control dialog box will be displayed so that you can rebind this project to source control."
I clicked on the OK button and than it opened me the "Change Source Control" window. I cliked on the projects I wanted to bind, and than OK, but again an error message appeared saying:
"Cannot change source control bindings. Ensure that each project has a valid binding.
Alternatively, you can choose to work disconnected. In order to work disconnected, clear the connection check boxes for the projects with invalid source control bindings."
I need to handle only jpeg.
How can I include the "cxImage.h" - after adding the project to my solution, I should direct it to the other project (the cxImage project). I tried just to write #include "cxImage.h", but it wasn't compiled, because it is in another project.
What should I write?
Thank a lot
Inbar
|
|
|
|
|
Here is what they say :
To use CxImage in your project, you must edit these settings:
Project Settings
|- C/C++
| |- Code Generation
| | |- Use run-time library : Multithreaded DLL (must be the same for
| | | all the linked libraries)
| | |- Struct member alignment : must be the same for all the linked
| | | libraries
| |- Precompiled headers : not using precompiled headers
| |- Preprocessor
| |- Additional Include Directories: ..\cximage
|- Link
|- General
|- Object/library modules: ../png/Debug/png.lib
../jpeg/Debug/jpeg.lib
../zlib/Debug/zlib.lib
../tiff/Debug/tiff.lib
../cximage/Debug/cximage.lib ...
In my version I had to add the library include folders and libraries in
Linker | Input | Additional Dependencies : png.lib jpeg.lib zlib.lib tiff.lib cximage.lib
Dating Software : http://www.datetopia.com
|
|
|
|
|
I would like to load a jpeg to a secific rect, which is different from the jpeg size.
How can I do that? The loading itself and the rect handling.
Will it be distorted because the rect is different?
Thanks a lot,
Liat
Liat
|
|
|
|
|
How to create a pic's thumb with XImage
thanks.
|
|
|
|
|
PLEASE PAY ATTENTION WHEN USING THE PIXEL OPERATIONS.
I recently used CxImage in one of my projects. I have to say it's a great help.
However, when using some pixel operations such as GetPixelColor and DrawLine, I encountered some problem:
The Y-Coordinate in the pixel operations does not match standard image formatting! Thus Y=0 is at the BOTTOM of the image, Y=Max is at the top!
For using pixel operations the "normal" way just use code like this:
int maxY=image->GetHeight() - 1;
DrawLine(yourX,maxY-yourY,yourColor); //or other pixel operation
|
|
|
|
|
Yeah, area selection does too! If you get a selection rectangle the left and top coordinates area refer to left-bottom corner (i.e. DIB image coordinates space). Thus, if you use Width() method of rectangle you get a negative value. Normalize() method should be used in this case.
regards
The Ghost in the Mind Machine
|
|
|
|
|
http://www.imagemagick.org/
|
|
|
|
|
I don't agree.
I've just downloaded the latest stable version - with a 1-bit TIF image it's SOOOOOOO SLOOOOOOOOOW! Oooh. It's just stopped responding (and appears to have used up most of the resources on my machine after thrashing the hard drive for about 5 minutes).
|
|
|
|
|
It would be if it would work.I don't know how the other guy made it, but the project created by the configuration inutility is empty.Ihave tried and tried and tried:either it does not compile or it does not run(exceptions are fired).
|
|
|
|
|
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)
|
|
|
|
|