WM_ImgLib Functionality

Function Definitions:

The WM_ImgLib was originally designed with large images in mind. The limit is the address space of the OS.
Set the swap space to as large as possible value (2 GB on LINUX).

All bool functions return false on successful completion and true on ERROR.

Use Get_Last_Error() to get aditional indication of the failure.


char *Get_Version_String()
int Get_Version_Int()
char *Get_Copyright()
These functions obtain various Library Version info

char *Get_Last_Error()
Use PostError("") after Get_Last_Error() is processed to clear the Error stack;

Obtain the last Library execution ERROR.
Empty string is returned for no ERROR.

bool GetSingleColor(ImgClass *In,ImgClass *Out,int color)
Obtain a single color image in Out from a RGB color image In.The color is specified as:
Color = 0 Red
Color = 1 Green
Color = 2 Blue

bool YCCtoRGB(ImgClass *In)
Convert image In from YCC to RGB profile, no sub sampling is assumed.

bool RGBtoYCC(ImgClass *In)
Convert image In from RGB to YCC profile,, no sub-sampling

bool Make_Header(char *ImageFile,IMAGE_HDR_t *p_mHdr);
Obtain the header info and fill the IMAGE_HDR structure.



bool    Make_Local_Header(char *ImageFile,char *OutFile)
Create an image header file from a fully qualified image pointed to by ImageFile.
The header file be generated as OutFile.

It is recommended to keep a ".hdr" extension in OutFile.
The header file, contains a set of information associated with a particular image.
There may be a number of different *.hdr files for any particular Image.
The header file has historical roots and will be removed in the future. :-)
true is returned on ERRORand no file is generated.


bool    Make_Local_Tnl(int Quality, int Size, char *HdrFile,char *Outfile,double Gamma);
Generate a thumbnail from an image specified in the HdrFile.
The thumbnail name will be as specified by OutFile.

Quality
 = 0
LZW compressed tiff thumbnail is generated.
Quality in the range  from 1 to 100 ( useful values are between 20 and 90 )
JPEG thumbnail is generated.
Size            specifies the image size in pixels ( X direction ).
                   The number of lines ( Y direction ) is calculated from the aspect ratio of the original image.

HdrFile
       Should contain a fully qualified path to an existing header file or Image file

Outfile     A fully qualified path the the destination thumbnail image.
                 If the file exists it is not overwritten !!!
                It is the clients responsibility to assure that the file doesn't exist,
                before Make_Local_Tnl(...) is called.
Gamma    gamma of the output image

If OutFile is an empty string then the thumbnail is generated in the same directory, where the HdrFile exists. The output extension will be ".tnl".

bool    Make_Local_Tnl_Img(int Quality, int Size, ImgClass *In,ImgClass *Out, double Gamma)
If the image is memory resident as In then this is a quick way to generate the thumbnail.
The Out image may the be saved by any of the write functions.
!!!
Do not forget to set the Out->ImgStruct.File variable to a legal file name before the image is written out.
!!!

double Get_Aspect( char *HdrFile)
Get the Aspect ratio of an image.
The image is specified in the HdrFile.
    This just gets rid of parsing the HdrFile.

On ERROR the return value is 0.0

bool Get_Image_Dimension( char *HdrFile, int *Width, int *Height)
Obtain the X (pixels) and Y ( lines ) dimensions of the image specified by the HdrFile file.
HdrFile must a fully qualified header file name.
If the file does not exist true is returned.
    This just gets rid of parsing the HdrFile.

true is returned on ERROR.



bool Get_Image_Res( char *HdrFile,double *Xres, double *Yres, int *ResType)
Obtain the image res if specified in the image.
ResType is an image res type as per TIFF specification.

    This just gets rid of parsing the HdrFile.

true
is returned on ERROR.



bool    ReadImage1( bool RGBSwap,char *ImgFile, ImgClass *Img )

Read the entire Image into Memory and optionally swap the R and B channels if RGBSwap is set to true.
The ImgFile may be either a fully qualified pointer to the desired image file and the file must exist, or a pointer to a  ImageHeader file.

The image must be one of the following TIFF,JPEG,PGM,PPM,BMP,TARGA...

The list of available formats will grow in the future.


true is returned on ERROR.



bool    ReadImage( bool RGBSwap, ImgClass *Img)

Read the entire Image into memory and  optionally swap the R and B channels if RGBSwap is set to true.

Img->ImgStruct.File must be a valid image file name. and the file must exist.

See ReadImage( bool RGBSwap, char *HdrFile, ImgClass *Img for more info.

true is returned on ERROR.


bool ScaleImage(ImgClass *From, double XScale, double YScale, ImgClass *To)
Scale an image From to image To by XScale and YScale.
The scaling algorithm used is a slightly modified bi-cubic interpolation algorithm.

Both In  and Out must be valid ImgClass pointers.
YScale may be set to -1.0 which indicates that the aspect ratio of the resulting image should be preserved
if RGBSwap is true, the red and blue channels are swapped in the To image

bool SubsampleLocalImage(ImgClass *In, ImgClass *Out,int OutX,int OutY)

Resample image In to an image Out .
The Out image will have OutX  pixels and OutY lines.
OutY
may be set to -1, which the preserves the aspect ratio of the resulting image

true is returned on ERROR


bool WriteTIFF(bool compress, bool bgr,ImgClass * Out)
bool WriteJPEG( int Quality, ImgClass *Img)
bool Write_8BitPPM( ImgClass *Img)
bool Write_8BitPGM( ImgClass *Img)
bool Write_BMP( ImgClass *Img)
Write various output image formats.
ImgClass->ImgStruct.File must be a valid path /file_name.


bool GetImageRectangle(char *File, CRect Rct, ImgClass *Img)
Get a section of an image specified by Rect ( x,y,Width,Height )
Rct is assumed to be in Image coordinates. Image origin is at the top-left.
See Crect.h for class definition.


bool Convert_Image( char *In, char *Out, int Out_Type, int Quality)
Read image In ( fully qualified file image name) and write the image in different format.
In        Input image name
Out    Output image name
Out_Type
    0 TIFF
    1 JPEG
    2 PPM
    3 PGM
    4 BMP
Quality is used for JPEG output format only.
Default output is a BMP file.



bool Read_Hdr( char *ImgHdr, IMAGE_HDR *hdr)
Fill the IMAGE_HDR struct from a header file.
See ImgClass.h for specification.


bool Rotate_Image( char *In, char *Out, int Type, int Rotation)
Rotate an image In and write it to Out as type specified by Type
Rotation:
0    no action ( same as Convert_Image(...) )
1 90 deg CW ( 90 CW )
-1 90 deg CCW ( 90 CCW )
2 Flip Horizontal ( 180 CW )
-2 Flip Vertical and Flip Horizontal ( 180 CCW )
3 Flip Vertical

CRect CalcCropRect(bool *Frst,bool Rhb,CPoint Pt, CRect DispRct, double Zoom, int ImgWidth, int ImgHeight)
Calculate an crop rectangle, in image coordinates from an image described as 0,0,ImgWidth,ImgHeight
the rectangle is centered around Pt
Frst set to false
Rhb not used set to false
Pt point within the DispRct
DispRct rectangle describing the display area
Zoom zoom factor
!!!    Do not use, for internal use only    !!!

char *ZoomImageLocal
(
 int Xpos, int Ypos,
 int DispW, int DispH,
 CRect *Crop,
double Magnification,
int Quality,
ImgClass *Src, ImgClass *Dest
 )
ZoomImageLocal can perform different operations depending on the argument settings !!!
It simply calculates the the crop rectangle depending on Magnification and Xpos,Ypos. This Crop rectangle is extracted from the Src image and subsampled to fit to DispW,DispH rectangle.
Since the original Image is in memory, this operation is a quick one, mainly dependent on whether the Src image is cached or not.


1]    If Magnification is less then 0.0, the Library crop rectangle is reset and empty string is returned.
        Magnification has different function, dependent on the Crop rectangle;
2]    If Crop is an empty rectangle, Magnification as specified is assumed to be from within the entire
       image. Otherwise it is specified within the Crop rectangle.

3]    If the RED and BLUE channels should be swapped in the generated image,
       set Dest->ImgStruct.BGR to true.


The resulting image must be greater then 32 pixels or lines, or ERROR exit is taken.

Xpos,Ypos:
       represents a point within the DispW x DispH rectangle. It is used as the center of the crop rectangle.
DispW,DispH:
Represents the width and height of the rectangle on the clients screen!!!
Crop:
                    The actual image crop rectangle, use GetCrop(..) to get the crop rectangle from the library.
If Crop is not empty, Magnification is incremental and Xpos and Ypos are assumed to lie within Crop . Hence while you call ZoomImageLocal(...) with a non-empty Crop the Magnification should be set to a fixed value ( 1.5 to 2.0 seems reasonable ).
Use GetCrop(..) function to obtain the actual Crop rectangle as used by the library, after each successful call to ZoomImageLocal(...).

OutImage:
Is zoomed section of Image file subsampled to fit DispW, DispH rectangle.
 
Quality:
not used.
ZoomImageLocal returns hopefully unique file name or an empty string on ERROR

This is the slow version :-)


char *ZoomImageLocal
(
int Xpos, int Ypos,
int DispW int DisH,
CRect *Crop,
double Magnification,
int Quality,
char *HdrFile,
ImgClass *OutImg
);

Xpos, Ypos, DispW, DispH, Crop, Magnification and Quality are the same as above.
HdrFile    Fully qualified image header file name, the file must exist !!
OutImg    returned Zoomed image. OutImg may not be NULL.

The image is read into memory, cropped, subsampled and passed back as OutImage image.
The original image is discarded.

bool GenerateLocalCmd(CRect *CropRct, int ImgW, int ImgH, int Qual);
Donot use unless absolutely necessary :-)

bool    GetCrop( CRect *Crop)
Obtain the Library's crop Rectangle.
Do not try to calculate the Crop, just us this call.

bool PostError ( char *Str )
Place the Str on the Error stack
if Str is empty, the error stack is cleared.

char    *Get_File_Name ( char *Str)

Obtain the file name from a fully qualified path


char    *Make_Temp_FileName(char *FileName, char *Extention)
FileName:
File name is the original name.
Extension:
Optional output file extenuation. ( may be NULL)

bool    SlowScaleImage(bool Compress,char *From, char *To, double XSc, double YSc,double Res)
YSc may be set to -1.0 to preserve the aspect ratio.


Back to README