![]() |
wxIScan
|
Go to the source code of this file.
Functions | |
| wxImage | Image2Mono (const wxImage &oSrcImage, int nMonoThreshold=128) |
| Convert an image to monochrome (black and white). | |
| wxImage | Image2Grey (const wxImage &oSrcImage) |
| Convert an image to greyscale. | |
| wxImage | CropImage (wxImage oImage, int x, int y, int w, int h) |
| Crop an image to the given size. | |
| wxImage | EnhenceColours (const wxImage &oSrcImage, int nBrightness=0, int nContrast=0, int nGamma=100, int nRed=0, int nGreen=0, int nBlue=0) |
| Modify brightness, contrast, gamma value, red, green and blue channel of an image. | |
| wxImage | RotateImage (const wxImage &oSrcImage, double nAngleRadian) |
| Fine rotate an image by its centre. | |
| wxImage | ResizeImage (const wxImage &oSrcImage, int nDestWidth, int nDestHeight) |
| Resize an image to the given size. | |
| bool | CopyText2Clipboard (const wxString &strText) |
| Copy the given text to the sytem clipboard. | |
| bool | CopyImage2Clipboard (const wxImage &oImage) |
| Copy the given image to the sytem clipboard. | |
| wxString | GetTextFromFile (const wxString &strFilename) |
| Load the content of a text file into memory. | |
| bool CopyImage2Clipboard | ( | const wxImage & | oImage | ) |
Copy the given image to the sytem clipboard.
| oImage | the image to copy to the clipboard |
Definition at line 199 of file wxiscanglobals.cpp.
Referenced by wxIScanFrame::OnEditCopy().
{
// Create a image data object for the clipboard.
wxBitmapDataObject *poBitmapData=new wxBitmapDataObject;
if( !poBitmapData )
{
wxLogError( wxString( wxT( "wxIScanFrame::CopyImage2Clipboard -- " ) )
+ _( "Failed to create clipboard image data object." ) );
return false;
}
// Copy the image to the image data object for the clipboard.
poBitmapData->SetBitmap( oImage );
// Open the clipboard and copy the image to the clipboard.
bool bRetC= wxTheClipboard->Open() && wxTheClipboard->SetData( poBitmapData );
// Close the clipboard (and release it).
wxTheClipboard->Close();
// Log errors.
if( !bRetC )
{
wxLogError( wxString( wxT( "wxIScanFrame::CopyImage2Clipboard -- " ) )
+ _( "Failed to copy image to clipboard." ) );
}
// Return the error state.
return bRetC;
}
| bool CopyText2Clipboard | ( | const wxString & | strText | ) |
Copy the given text to the sytem clipboard.
| strText | the text to copy to the clipboard |
Definition at line 165 of file wxiscanglobals.cpp.
Referenced by wxIScanFrame::OnDocumentCopyText().
{
// Create a text data object for the clipboard.
wxTextDataObject *poTextData=new wxTextDataObject;
if( !poTextData )
{
wxLogError( wxString( wxT( "wxIScanFrame::CopyText2Clipboard -- " ) )
+ _( "Failed to create clipboard text data object." ) );
return false;
}
// Copy the text to the text data object for the clipboard.
poTextData->SetText( strText );
// Open the clipboard and copy the text to the clipboard.
bool bRetC= wxTheClipboard->Open() && wxTheClipboard->SetData( poTextData );
// Close the clipboard (and release it).
wxTheClipboard->Close();
// Log errors.
if( !bRetC )
{
wxLogError( wxString( wxT( "wxIScanFrame::CopyText2Clipboard -- " ) )
+ _( "Failed to copy text to clipboard." ) );
}
// Return the error state.
return bRetC;
}
| wxImage CropImage | ( | wxImage | oImage, |
| int | x, | ||
| int | y, | ||
| int | w, | ||
| int | h | ||
| ) | [inline] |
Crop an image to the given size.
| oSrcImage | the image to transformed |
| x | x-coordinate in pixels of the upper left corner of the cropping region. |
| y | y-coordinate in pixels of the upper left corner of the cropping region. |
| w | Width of the cropping region in pixels. |
| h | Height of the cropping region in pixels. |
NOTE: The returned object is the transformed image.
Definition at line 52 of file wxiscanglobals.h.
Referenced by wxIScanFrame::ApplyProfile().
{
oImage.Resize( wxSize( w + x, h + y ), wxPoint( 0, 0 ), 255, 255, 255 );
return oImage.GetSubImage( wxRect( x, y, w, h ) );
}
| wxImage EnhenceColours | ( | const wxImage & | oSrcImage, |
| int | nBrightness = 0, |
||
| int | nContrast = 0, |
||
| int | nGamma = 100, |
||
| int | nRed = 0, |
||
| int | nGreen = 0, |
||
| int | nBlue = 0 |
||
| ) |
Modify brightness, contrast, gamma value, red, green and blue channel of an image.
| oSrcImage | the image to be transformed |
| nBrightness | adjustment value for brightness |
| nContrast | adjustment value for constrast |
| nGamma | adjustment value for gamma value * 100 |
| nRed | adjustment value for red value |
| nGreen | adjustment value for green value |
| nBlue | adjustment value for blue value |
NOTE: The returned object is the transformed image. The original image is left intact.
Definition at line 99 of file wxiscanglobals.cpp.
References Limit255(), and x_exp_y().
{
wxImage oImage= oSrcImage;
// ...
int nCount= oImage.GetWidth() * oImage.GetHeight() * 3;
unsigned char *pImageDataSrc= oImage.GetData();
unsigned char *pImageDataDest= (unsigned char *)malloc( nCount * sizeof( unsigned char ) );
if( !pImageDataDest )
{
wxLogError( wxString( wxT( "EnhenceColours - " ) )
+ _( "Cannot allocate memory for destination image." ) );
return oImage;
}
// ...
int nIncRed= nRed + nBrightness;
int nIncGreen= nGreen + nBrightness;
int nIncBlue= nBlue + nBrightness;
double nContrastFactor= exp( (double)nContrast / 75.0 );
double nInvGamma= 100.0 / (double)nGamma;
// Recalculate the image as a whole. That is calculate brightness,
// contrast, gamma and color correction all at once.
//
// NOTE: We use floating point (double) calculation for not to cut off
// values as early as 8 bit integer calculation would do (for
// numeric stability). The disadvantage is that the transformation
// of one image of about 8 Mega pixels (e. g. an A4 page) even on
// a 1.6 GHertz machine lasts for more than 5s.
//
unsigned char *pIndex= pImageDataDest;
for( int i= 0; i < nCount; i += 3 )
{
// Red.
(*pIndex)= Limit255( (int)( x_exp_y( ( (double)( (*pImageDataSrc) + nIncRed ) * nContrastFactor ) / 255.0,
nInvGamma ) * 255.0 ) );
pImageDataSrc++;
pIndex++;
// Green.
(*pIndex)= Limit255( (int)( x_exp_y( ( (double)( (*pImageDataSrc) + nIncGreen ) * nContrastFactor ) / 255.0,
nInvGamma ) * 255.0 ) );
pImageDataSrc++;
pIndex++;
// Blue.
(*pIndex)= Limit255( (int)( x_exp_y( ( (double)( (*pImageDataSrc) + nIncBlue ) * nContrastFactor ) / 255.0,
nInvGamma ) * 255.0 ) );
pImageDataSrc++;
pIndex++;
}
oImage.SetData( pImageDataDest );
return oImage;
}
| wxString GetTextFromFile | ( | const wxString & | strFilename | ) |
Load the content of a text file into memory.
| strFilename | the name of the text file |
Definition at line 237 of file wxiscanglobals.cpp.
Referenced by wxIScanFrame::AddPdfPage(), wxIScanLuaScript::OCR(), wxIScanFrame::OnDocumentCopyText(), and wxIScanFrame::StartScript().
{
// Open a textfile, ...
wxFile oFile( strFilename );
if( !oFile.IsOpened() )
{
// Return an empty string on failure.
return wxEmptyString;
}
// ... create a temporary buffer of file size, ...
wxFileOffset nLength= oFile.Length();
char *pcBuffer= new char[nLength];
if( !pcBuffer )
{
// Return an empty string on failure.
return wxEmptyString;
}
// ... read the file's content into the buffer, ...
oFile.Read( pcBuffer, nLength );
// ... convert it to a wxString object (from UTF8), ...
wxString strText= wxString::FromUTF8( pcBuffer, nLength );
// ... delete the (temporary) buffer, ...
delete[] pcBuffer;
// ... and return the text.
return strText;
}
| wxImage Image2Grey | ( | const wxImage & | oSrcImage | ) | [inline] |
Convert an image to greyscale.
| oSrcImage | the image to transformed |
NOTE: The returned object is the transformed image. The original image is left intact.
Definition at line 36 of file wxiscanglobals.h.
Referenced by wxIScanFrame::ApplyProfile().
{
return oSrcImage.ConvertToGreyscale();
}
| wxImage Image2Mono | ( | const wxImage & | oSrcImage, |
| int | nMonoThreshold = 128 |
||
| ) |
Convert an image to monochrome (black and white).
| oSrcImage | the image to transformed |
| nMonoThreshold | value for deciding if a point is black or white |
NOTE: The returned object is the transformed image. The original image is left intact.
Definition at line 27 of file wxiscanglobals.cpp.
Referenced by wxIScanFrame::ApplyProfile(), and wxIScanFrame::OCR().
{
wxImage oImage= oSrcImage.ConvertToGreyscale();
int nCount= oImage.GetWidth() * oImage.GetHeight() * 3;
unsigned char *pImageDataSrc= oImage.GetData();
unsigned char *pImageDataDest= (unsigned char *)malloc( nCount * sizeof( unsigned char ) );
if( !pImageDataDest )
{
wxLogError( wxString( wxT( "Image2Mono - " ) )
+ _( "Cannot allocate memory for destination image." ) );
return oImage;
}
// ...
unsigned char *pIndex= pImageDataDest;
for( int i= 0; i < nCount; i += 3 )
{
unsigned char nValue= ( (*pImageDataSrc) < nMonoThreshold ) ? 0 : 255;
// Red.
(*pIndex)= nValue;
pImageDataSrc++;
pIndex++;
// Green.
(*pIndex)= nValue;
pImageDataSrc++;
pIndex++;
// Blue.
(*pIndex)= nValue;
pImageDataSrc++;
pIndex++;
}
oImage.SetData( pImageDataDest );
return oImage;
}
| wxImage ResizeImage | ( | const wxImage & | oSrcImage, |
| int | nDestWidth, | ||
| int | nDestHeight | ||
| ) | [inline] |
Resize an image to the given size.
| oSrcImage | the image to be transformed |
| nDestWidth | the desired width of the destination image |
| nDestHeight | the desired height of the destination image |
NOTE: The returned object is the transformed image. The original image is left intact.
Definition at line 101 of file wxiscanglobals.h.
{
return oSrcImage.Scale( nDestWidth, nDestHeight, wxIMAGE_QUALITY_HIGH );
}
| wxImage RotateImage | ( | const wxImage & | oSrcImage, |
| double | nAngleRadian | ||
| ) | [inline] |
Fine rotate an image by its centre.
| oSrcImage | the image to be transformed |
| nAngleRadian | the angle in radian |
NOTE: The returned object is the transformed image. The original image is left intact.
Definition at line 86 of file wxiscanglobals.h.
Referenced by wxIScanFrame::OnCanvasSelected().
{
return oSrcImage.Rotate( nAngleRadian, wxPoint( oSrcImage.GetWidth() / 2, oSrcImage.GetHeight() / 2 ), true, NULL );
}