BfxALU Class Reference

Arithmetic and logic unit for bitmap effects. More...

#include <bfxalu.h>

Inheritance diagram for BfxALU:

CCObject SimpleCCObject List of all members.

Public Member Functions

 BfxALU ()
 Default constructor for ALU.
virtual ~BfxALU ()
 Default constructor for ALU.
virtual BOOL Init ()
 Initialises the bitmap effect subsystem.
virtual BOOL DeInit ()
 Initialises the bitmap effect subsystem.
virtual KernelBitmapNewBitmap (KernelBitmap *pBitmap, INT32 XAdjust=0, INT32 YAdjust=0, INT32 NewDepth=0, String_256 *pName=NULL, UINT32 ResID=0)
 General purpose call to claim a new kernel bitmap.
virtual BOOL SetA (KernelBitmap *pBitmap=NULL)
 GDraw needs a bitmap to plot to & from, this is the accumulator.
virtual BOOL SetB (KernelBitmap *pBitmap=NULL, INT32 XOffset=0, INT32 YOffset=0, const BYTE *pTable=NULL, DWORD Style=0)
 GDraw needs a bitmap to plot to & from, this is the accumulator.
virtual BOOL SetB (DWORD Colour)
 GDraw needs a bitmap to plot to & from, this is the accumulator.
virtual BOOL SetT (KernelBitmap *pBitmap=NULL, INT32 XOffset=0, INT32 YOffset=0, const BYTE *pTable=NULL, DWORD Style=0)
 GDraw needs a bitmap to plot to & from, this is the accumulator.
virtual BOOL SetT (DWORD Value)
 GDraw needs a bitmap to plot to & from, this is the accumulator.
virtual BOOL PlotB ()
 This routine sets up GDraw for A & B, and calls DoRect().
virtual BOOL PlotBLUT (BfxALULUT *LUT)
 This routine sets up GDraw for A & B, and calls DoRect().
virtual BOOL PartTAB ()
 Arithemtic operation to do the above.
virtual BOOL PartMulTAB ()
 Arithemtic operation to do the above.
virtual BOOL PartRevMulTAB ()
 Arithemtic operation to do the above.
virtual BOOL AddTAB ()
 Arithemtic operation to do the above.
virtual BOOL SubTAB ()
 Arithemtic operation to do the above.
virtual BOOL PartKAB (DWORD Value)
 Arithemtic operation to do the above.
virtual BOOL PartMulKAB (DWORD Value)
 Arithemtic operation to do the above.
virtual BOOL PartRevMulKAB (DWORD Value)
 Arithemtic operation to do the above.
virtual BOOL AddKAB (DWORD Value)
 Arithemtic operation to do the above.
virtual BOOL SubKAB (DWORD Value)
 Arithemtic operation to do the above.
virtual BOOL MarkThresholdError (INT32 Value, DWORD MarkValue, DWORD ClearValue)
 Arithemtic operation to do the above.
virtual BOOL MarkColourThresholdError (INT32 Value, DWORD Colour, DWORD MarkValue, DWORD ClearValue, double *pAError, double *pBError, INT32 *pTotalPixels, INT32 *pMarkedPixels)
 Arithemtic operation to do the above.
virtual BOOL MarkPositive (INT32 Value, DWORD MarkValue, DWORD ClearValue, double *pAError=NULL, double *pBError=NULL, INT32 *pTotalPixels=NULL, INT32 *pMarkedPixels=NULL)
 Arithemtic operation to do the above.
virtual BOOL MarkLargestArea (DWORD MarkValue, DWORD ClearValue, DWORD RegionValue, BOOL *FoundRegion, INT32 *InitialX, INT32 *InitialY, INT32 *Area)
 Arithemtic operation to do the above.
virtual BOOL MarkGivenArea (DWORD MarkValue, DWORD ClearValue, DWORD RegionValue, BOOL *FoundRegion, INT32 *InitialX, INT32 *InitialY, INT32 *Area)
 Arithemtic operation to do the above.
virtual BOOL GradFillPath (Path *ThePath, DWORD StartColour, DWORD EndColour, INT32 StartX, INT32 StartY, INT32 EndX, INT32 EndY, BOOL AntiAlias=FALSE, BOOL ColoursAreDWORDs=FALSE)
 Calls GDraw to fill a path.
virtual BOOL GetStatistics (Path *ThePath, KernelStatistics *pStats)
 Calls GDraw to statistically analyse the contents of a path.
virtual BOOL MarkBitByWord (DWORD BitMask, DWORD TheWord)
 Arithemtic operation to do the above.
virtual BOOL ClearBitByWord (DWORD BitMask, DWORD TheWord)
 Arithemtic operation to do the above.
virtual BOOL MarkWordByBit (DWORD BitMask, DWORD MarkValue, DWORD ClearValue)
 Arithemtic operation to do the above.
virtual BOOL BuildErrorRegionList (DWORD MarkValue, DWORD ClearValue, DWORD RegionValue, BfxErrorRegionList *pERL, INT32 MinimumArea)
 Arithemtic operation to do the above.
virtual BOOL ScanBit (DWORD BitMask, INT32 *X, INT32 *Y, INT32 *pPixel, BOOL *Found, BOOL CheckConnected=FALSE)
 Arithemtic operation to search A for the next pixel s.t. (A & BitMask) !=0.
virtual BOOL ScanThreshold (INT32 Value, INT32 *X, INT32 *Y, INT32 *pPixel, BOOL *Found, BOOL CheckConnected=FALSE)
 Arithemtic operation to search A for the next pixel s.t. (A & BitMask) !=0.
virtual BOOL GetSize (KernelBitmap *pBitmap, INT32 *pXSize=NULL, INT32 *pYSize=NULL, INT32 *pDepth=NULL)
 Convenient place to overcome the inadequacies of the KernelBitmapClass.
virtual BOOL ZeroA (DWORD FillValue=0)
 Zeros the accumulator.
virtual BOOL ByteCopyBA ()
 Copies B into the accumulator.
virtual void TestGD ()
virtual BOOL FlipX (KernelBitmap **ppOutput)
 A new bitmap is created which is the flipped version of the accumulator.
virtual BOOL FlipY (KernelBitmap **ppOutput)
 A new bitmap is created which is the flipped version of the accumulator.
virtual BOOL Rotate90 (KernelBitmap **ppOutput)
 A new bitmap is created which is the flipped version of the accumulator.
virtual BOOL Rotate180 (KernelBitmap **ppOutput)
 A new bitmap is created which is the flipped version of the accumulator.
virtual BOOL Rotate270 (KernelBitmap **ppOutput)
 A new bitmap is created which is the flipped version of the accumulator.
virtual BOOL Resize (KernelBitmap **ppOutput, INT32 Width, INT32 Height, BOOL LinearInterpolation)
 A new bitmap is created as per function name.
virtual BOOL BrightnessContrast (KernelBitmap **ppOutput, INT32 Brightness=0, INT32 Contrast=0, INT32 Colour=0)
 A new bitmap is created as per function name.
virtual BOOL BayerMono (KernelBitmap **ppOutput)
 A new bitmap is created as per function name.
virtual BOOL HalftoneMono (KernelBitmap **ppOutput)
 A new bitmap is created as per function name.
virtual BOOL DiffusionMono (KernelBitmap **ppOutput)
 A new bitmap is created as per function name.
virtual BOOL BayerColour (KernelBitmap **ppOutput)
 A new bitmap is created as per function name.
virtual BOOL DiffusionColour (KernelBitmap **ppOutput)
 A new bitmap is created as per function name.
virtual BOOL PopularityColour (KernelBitmap **ppOutput)
 A new bitmap is created as per function name.
virtual BOOL MakeGreyscale (KernelBitmap **ppOutput)
 A new bitmap is created as per function name.
virtual BOOL MakeGreyscale32to8 (KernelBitmap **ppOutput)
 A new bitmap is created as per function name.
virtual BOOL Octree (KernelBitmap **ppOutput)
 A new bitmap is created as per function name.
virtual BOOL SharpenBlur (KernelBitmap **ppOutput, INT32 Degree, INT32 Times)
 A new bitmap is created as per function name.
virtual BOOL RemoveDither (KernelBitmap **ppOutput, INT32 Thresh, INT32 QuantCols, TraceMethod Method)
virtual BOOL SpecialEffect (KernelBitmap **ppOutput, double *Matrix, BfxSpecialEffect Type)
 A new bitmap is created as per function name.

Static Public Member Functions

static BOOL IsGreyscaleBitmap (KernelBitmap *pKB)
 Determines whether or not a bitmap is 32bpp.
static BOOL IsGreyscaleBitmap (OILBitmap *pOilBmp)
 Determines whether or not a bitmap is 32bpp.

Protected Member Functions

virtual BOOL DoRect ()
 Calls GDraw to perform the desired ALU operation.
virtual BOOL UseBT (DWORD TransparencyStyle=0)
 This routine sets up GDraw for A & B, and calls DoRect().
virtual BOOL UseBK (DWORD TransparencyStyle, DWORD Value)
 This routine sets up GDraw for A & B, and calls DoRect().
virtual BOOL MarkRegions (DWORD MarkValue, DWORD ClearValue, BOOL *FoundRegion, INT32 *InitialX, INT32 *InitialY, INT32 *Area, INT32 *pSize, INT32 *pHighestChain, INT32 *pWidth, DWORD **ppA)
virtual BOOL MakeAccusoftHandle (INT32 *pHandle, BOOL DoBodge=FALSE)
 gets items from list A new accusoft bitmap handle is created for the B reg
virtual BOOL MakeKernelBitmap (INT32 Handle, KernelBitmap **ppOutput, BOOL Make32Bits=FALSE, String_256 *pName=NULL, UINT32 ResID=0, BOOL DoBodge=FALSE)
 A new accusoft bitmap handle is created for the accumulator.
virtual BOOL AdjustBrightnessContrastColour (LPBYTE Source, LPBYTE Dest, INT32 Size, INT32 Width, INT32 Height, INT32 Brightness, INT32 Contrast, INT32 Colour, BOOL SingleChannel)
 A new bitmap is created as per function name.
BOOL MAH_BodgeCopyBitmap (INT32 Width, INT32 Height, INT32 Depth, LPBYTE pSourceBits, LPBYTE pDestBits)
 To copy the bitmap across to the destination but instead of doing a straight copy we copy it to a bitmap which is three times the width and to the middle section of this. We then pad the left hand side with the first left pixel. We then pad the right hand side with the right hand pixel. Assumes: Destination bitmap is three times the width of the source but is the same in all other aspects.
BOOL MKB_BodgeCopyBitmap (INT32 Width, INT32 Height, INT32 Depth, LPBYTE pSourceBits, LPBYTE pDestBits)
 The reverse of the MAH_BodgeCopyBitmap version. This copies the bitmap across to the destination but instead of doing a straight copy we copy the middle section from the source bitmap which should be three times the width we want to the destination bitmap which should be a third of the width we want. Assumes: Source bitmap is three times the width of the destination but is the same in all other aspects.
void ConvertScanLineToDWORD (KernelBitmap *pBitmap, INT32 Line, DWORD *pBuffer)
 Converts a scanline in the bitmap to a 32 bit scanline.
void ConvertScanLineFromDWORD (KernelBitmap *pBitmap, INT32 Line, DWORD *pBuffer)
 Converts 32 bit scanline to a scanline in the bitmap.
void SlowRemoveDither (BYTE *ByteLine[5], INT32 NoiseMatrix[5][5], BYTE *OutputLine, INT32 Width, INT32 Thresh, BOOL Mono)
 Removes dither (slowly).

Protected Attributes

KernelBitmapA
KernelBitmapB
KernelBitmapT
POINT BPoints [3]
POINT TPoints [3]
COLORREF BColour
DWORD TValue
const BYTE * BpTable
const BYTE * TpTable
DWORD BStyle
DWORD TStyle
GDrawContextGC
GMATRIX identity
BOOL ResetAccusoftDibsToRuns

Private Member Functions

 CC_DECLARE_DYNCREATE (BfxALU)

Detailed Description

Arithmetic and logic unit for bitmap effects.

Author:
Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/10/1994
This class implements the Bitmap Effect ALU (Arithmetic and logic unit). You can think of this as the Kernel i/f for GDraw when using bitmap effects, but that would be a bit of a narrow view. The class is there to perform fast arithmetic and logical operations on bitmaps, and at the moment, we reckon the fastest way to do that is to use GDraw.

The ALU works very like a processor ALU, except each register holds a bitmap (actually a pointer to a bitmap which can cause some complications), and each operand (like Add) adds two bitmaps, rather than two integers. In fact, some registers may be set to 'pseudo bitmaps' like solid colour and linear fills, which are usefully expanded by the ALU at plot time without occupying memory.

The ALU has the following registers: Name Purpose ==== ======= A (Accumulator) The accumulator is the destination register for all operands, and is the source register for many. The accumulator can be 32 bit or 8 bpp grey but at the moment only 32 bpp is supported. The T channel of the accumulator is always zero (well, that's how the plot operations leave it anyway). B (Bitmap) A general purpose bitmap, normally used as a secondary source operand. T (Bitmap) And 8 bit bitmap used for weigthing values on some calls.

Here are some example arithmetic operands:

AddpAqB A <- pA+qB AddApB A <- A+pB SubApB A <- A-pB InvA A <- 255-A

Here are some example load & store operations

SetA(bitmap) SetB(bitmap) SetB(linear fill parameters)

Definition at line 265 of file bfxalu.h.


Constructor & Destructor Documentation

BfxALU::BfxALU  ) 
 

Default constructor for ALU.

Author:
Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/10/94
Parameters:
None [INPUTS]
Constructs object [OUTPUTS]
Returns:
Nothing

Errors: None yet

See also:
-
This constructs the ALU - most of the work is done in the Init function

Definition at line 299 of file bfxalu.cpp.

00300 {
00301 #ifndef EXCLUDE_FROM_RALPH
00302     GC = NULL;
00303     ResetAccusoftDibsToRuns = FALSE;
00304 #endif
00305 }

BfxALU::~BfxALU  )  [virtual]
 

Default constructor for ALU.

Author:
Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/10/94
Parameters:
None [INPUTS]
Constructs object [OUTPUTS]
Returns:
Nothing

Errors: Error3 if DeInit hasn't been called.

See also:
-
This destructs the ALU - most of the work should be done in the Init function

Definition at line 324 of file bfxalu.cpp.

00325 {
00326 #ifndef EXCLUDE_FROM_RALPH
00327     // has to be a level 3 check - we can't return an error code
00328     ERROR3IF( (GC!=NULL), "Someone hasn't called the BfxALU deinit function!");
00329 #endif
00330 }


Member Function Documentation

BOOL BfxALU::AddKAB DWORD  Value  )  [virtual]
 

Arithemtic operation to do the above.

Author:
Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/10/94
Parameters:
None [INPUTS]
A <- A + Value.B [OUTPUTS]
Returns:
TRUE if succeeded, FALSE & error set if not

Errors: Error 2 & 3 from called routines Scope: Public

See also:
-

Definition at line 1270 of file bfxalu.cpp.

01271 {
01272     return UseBK(ALUC_ADD, Value);  
01273 }

BOOL BfxALU::AddTAB  )  [virtual]
 

Arithemtic operation to do the above.

Author:
Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/10/94
Parameters:
None [INPUTS]
A <- A + TB [OUTPUTS]
Returns:
TRUE if succeeded, FALSE & error set if not

Errors: Error 2 & 3 from called routines Scope: Public

See also:
-

Definition at line 1165 of file bfxalu.cpp.

01166 {
01167     return UseBT(ALUC_ADD); 
01168 }

BOOL BfxALU::AdjustBrightnessContrastColour LPBYTE  Source,
LPBYTE  Dest,
INT32  Size,
INT32  Width,
INT32  Height,
INT32  Brightness,
INT32  Contrast,
INT32  Colour,
BOOL  SingleChannel
[protected, virtual]
 

A new bitmap is created as per function name.

Author:
Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/01/95
Parameters:
Source = pointer to source bytes [INPUTS] Size = size of entries Brightness, Contast, Colour (-127 to +127) SingleChannel set if just to do a .. urm ... single channel.
Dest bytes filled in [OUTPUTS]
Returns:
TRUE if succeeded, FALSE & error set if not

Errors: Error 2 if init hasn't been called or GDraw fails Error 3 if windows and some other Oil layer are stangely mixed... Scope: Public

See also:
-

Definition at line 5205 of file bfxalu.cpp.

05207 {
05208     // We make a LUT which is Output = LUT[gun, sumofguns]
05209 
05210     double dBrightness = (Brightness*1.0)/127.0   *0.75; // *0.75 is the 'Charles' factor.
05211     double dContrast = pow(2.0,3.0*(Contrast*1.0)/127.0);
05212     double dColour = pow(2.0,3.0*(Colour*1.0)/127.0);
05213 
05214     // GunOut = dBrightness + dContrast * ((GunSum/3) + dColour * (GunIn- GunSum/3)) + (1-dContrast)*0.5;
05215     //        = (dBrightness + ((1-dContrast)*0.5)) + GunSum * (dContrast/3.0 * (1-dColour)) + GunIn * (dContrast*dColour)
05216 
05217     double PropA = dContrast * dColour;
05218     double PropB = dContrast / 3.0 * (1.0-dColour);
05219     double Offset = dBrightness + (1.0-dContrast)*0.5;
05220 
05221     INT32 pa=(INT32)(PropA*(1<<15));
05222     INT32 pb=(INT32)(PropB*(1<<15));
05223     INT32 po=(INT32)(Offset*((1<<15)*255)+/* for rounding */(1<<14));
05224 
05225     BYTE * Data = (BYTE *) CCMalloc(3*256*256);
05226     if (!Data) return FALSE; // error already set
05227 
05228     // Please note how we're *NOT* using doubles in the loop as that's
05229     // sooooo sloooooow on 486SX. We use 17.15 arithmetic throughout
05230 
05231 #ifndef FASTLINEARABK
05232     INT32 a;
05233     INT32 b;
05234     INT32 r;
05235     for (a=0; a<256; a++) for (b=0; b<256*3; b++)
05236     {
05237         r=(a*pa+b*pb+po)>>15; /* we did the rounding in the offset calc */
05238         LUTBYTE(a,b)=(r<0)?0:((r>255)?255:(BYTE)(INT32)(r));
05239     }
05240 #else
05241     FastLinearABK(Data, pa, pb, po, 256*3);
05242 #endif
05243     
05244     DWORD Sum;
05245 
05246     if (!SingleChannel)
05247     {
05248         for (INT32 y = 0 ;y<Height; y++)
05249         {
05250             for (INT32 x = 0; x<Width; x++)
05251             {
05252                 Sum=((DWORD)Source[0])+((DWORD)Source[1])+((DWORD)Source[2]);
05253                 Dest[0]=LUTBYTE(Source[0], Sum);
05254                 Dest[1]=LUTBYTE(Source[1], Sum);
05255                 Dest[2]=LUTBYTE(Source[2], Sum);
05256                 Source+=Size;
05257                 Dest+=Size;
05258             }
05259             Source = (LPBYTE)(void *)((((UINT_PTR)(void *)Source) +3)&(~3));
05260             Dest = (LPBYTE)(void *)((((UINT_PTR)(void *)Dest) +3)&(~3));
05261         }
05262     }
05263     else
05264     {
05265         for (INT32 y = 0 ;y<Height; y++)
05266         {
05267             for (INT32 x = 0; x<Width; x++)
05268             {
05269                 *Dest=LUTBYTE((*Source), (*Source));
05270                 Source+=Size;
05271                 Dest+=Size;
05272             }
05273             Source = (LPBYTE)(void *)((((UINT_PTR)(void *)Source) +3)&(~3));
05274             Dest = (LPBYTE)(void *)((((UINT_PTR)(void *)Dest) +3)&(~3));
05275         }
05276     }
05277 
05278     CCFree(Data);   
05279     return TRUE;
05280 }

BOOL BfxALU::BayerColour KernelBitmap **  ppOutput  )  [virtual]
 

A new bitmap is created as per function name.

Author:
Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/01/95
Parameters:
None [INPUTS]
*ppOutput = a pointer to the output bitmap [OUTPUTS]
Returns:
TRUE if succeeded, FALSE & error set if not

Errors: Error 2 if init hasn't been called or GDraw fails Error 3 if windows and some other Oil layer are stangely mixed... Scope: Public

See also:
-

Definition at line 4019 of file bfxalu.cpp.

04020 {
04021     ERROR2IF((!ppOutput),FALSE, "BfxALU output parameter must be non-null");
04022     INT32 AccusoftHandle = -1;
04023     if (!MakeAccusoftHandle(&AccusoftHandle)) return FALSE;
04024     if ( (((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiHeader).biBitCount <8 )
04025     {
04026         INT32 result = AccusoftFilters::pfnIMG_promote_8(AccusoftHandle);
04027         if (result < 0)
04028         {
04029             AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
04030             ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
04031         }
04032     }
04033     INT32 result = AccusoftFilters::pfnIMG_bayer_color(AccusoftHandle);
04034     if (result < 0)
04035     {
04036         AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
04037         ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
04038     }
04039         return MakeKernelBitmap(AccusoftHandle, ppOutput, FALSE, &(B->ActualBitmap->GetName()), _R(IDS_BFX_BAYERCOLOUR));
04040 }

BOOL BfxALU::BayerMono KernelBitmap **  ppOutput  )  [virtual]
 

A new bitmap is created as per function name.

Author:
Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/01/95
Parameters:
None [INPUTS]
*ppOutput = a pointer to the output bitmap [OUTPUTS]
Returns:
TRUE if succeeded, FALSE & error set if not

Errors: Error 2 if init hasn't been called or GDraw fails Error 3 if windows and some other Oil layer are stangely mixed... Scope: Public

See also:
-

Definition at line 3877 of file bfxalu.cpp.

03878 {
03879     ERROR2IF((!ppOutput),FALSE, "BfxALU output parameter must be non-null");
03880     INT32 AccusoftHandle = -1;
03881     if (!MakeAccusoftHandle(&AccusoftHandle)) return FALSE;
03882     if ( (((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiHeader).biBitCount <8 )
03883     {
03884         INT32 result = AccusoftFilters::pfnIMG_promote_8(AccusoftHandle);
03885         if (result < 0)
03886         {
03887             AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
03888             ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
03889         }
03890     }
03891     INT32 result = AccusoftFilters::pfnIMG_bayer_mono(AccusoftHandle);
03892     if (result < 0)
03893     {
03894         AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
03895         ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
03896     }
03897     
03898     //AccusoftFilters::pfnIMG_runs_to_dib (AccusoftHandle);
03899     ResetAccusoftDibsToRuns = TRUE;
03900     
03901     return MakeKernelBitmap(AccusoftHandle, ppOutput, FALSE, &(B->ActualBitmap->GetName()), _R(IDS_BFX_BAYERMONO));
03902 }

BOOL BfxALU::BrightnessContrast KernelBitmap **  ppOutput,
INT32  Brightness = 0,
INT32  Contrast = 0,
INT32  Colour = 0
[virtual]
 

A new bitmap is created as per function name.

Author:
Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/01/95
Parameters:
Brightness & Contast (-127 to +127) [INPUTS]
*ppOutput = a pointer to the output bitmap [OUTPUTS]
Returns:
TRUE if succeeded, FALSE & error set if not

Errors: Error 2 if init hasn't been called or GDraw fails Error 3 if windows and some other Oil layer are stangely mixed... Scope: Public

See also:
-

Definition at line 3778 of file bfxalu.cpp.

03779 {
03780     ERROR2IF((!ppOutput),FALSE, "BfxALU output parameter must be non-null");
03781 #if 0
03782     INT32 AccusoftHandle = -1;
03783     if (!MakeAccusoftHandle(&AccusoftHandle)) return FALSE;
03784     INT32 result = AccusoftFilters::pfnIMG_set_lut(AccusoftHandle, (INT32) Brightness, (INT32) Contrast);
03785     if (result < 0)
03786     {
03787         AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
03788         ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
03789     }
03790         return MakeKernelBitmap(AccusoftHandle, ppOutput, FALSE, &(B->ActualBitmap->GetName()), _R(IDS_BFX_BRIGHTCONT));
03791 #endif
03792     
03793     *ppOutput = NewBitmap(B,0,0,0,NULL, _R(IDS_BFX_BRIGHTCONT));
03794     if (!ppOutput) return FALSE;
03795     
03796     BITMAPINFOHEADER * pBBMI=&(((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiHeader);
03797     BITMAPINFOHEADER * pABMI=&(((CWxBitmap *)((*ppOutput)->ActualBitmap))->BMInfo->bmiHeader);
03798 
03799     DWORD PaletteUsed = pBBMI->biClrUsed;
03800     
03801     ERROR2IF ((pBBMI->biSizeImage == 0) || (pBBMI->biCompression != BI_RGB) || (pBBMI->biHeight<0), FALSE, 
03802                 "A naughty DIB format has been used internally");
03803     pABMI->biXPelsPerMeter = pBBMI->biXPelsPerMeter;
03804     pABMI->biYPelsPerMeter = pBBMI->biYPelsPerMeter;
03805     ERROR2IF ((pBBMI->biSizeImage != pABMI->biSizeImage), FALSE, "BfxALU brightness & constrast size upset");
03806     
03807     DWORD Width;
03808     DWORD Height;
03809     DWORD Size;
03810     LPBYTE Source;
03811     LPBYTE Dest;
03812     LPBYTE pSBits = (((CWxBitmap *)(B->ActualBitmap))->BMBytes);
03813     LPBYTE pDBits = (((CWxBitmap *)((*ppOutput)->ActualBitmap))->BMBytes);
03814     
03815     // We modify the image itself in the case of greyscale images
03816     BOOL SingleChannel=IsGreyscaleBitmap(B);
03817 
03818     // Handle wierd palette stuff
03819     if ((SingleChannel) || pBBMI->biBitCount>8)
03820     {
03821         if (SingleChannel && PaletteUsed)
03822         {
03823             // Copy the palette
03824             memcpy(((LPBYTE)(pABMI + 1/*ptr arith*/)) /*dest*/, ((LPBYTE)(pBBMI + 1/*ptr arith*/)) /*source*/,
03825                     PaletteUsed * sizeof(DWORD));
03826         }
03827         else
03828         {
03829             PaletteUsed = 0;
03830         }
03831         Width = pBBMI->biWidth;
03832         Height = pBBMI->biHeight;
03833         Size = (pBBMI->biBitCount / 8);
03834         Source = pSBits;
03835         Dest = pDBits;
03836     }
03837     else
03838     {
03839         // 0 is MS for maximum
03840         if (PaletteUsed == 0) PaletteUsed = 1<<pBBMI->biBitCount;
03841         Width = PaletteUsed;
03842         Height = 1;
03843         Size = 4;
03844         // This points to palette
03845         Source = ((LPBYTE)(pBBMI + 1/*ptr arith*/));
03846         Dest = ((LPBYTE)(pABMI + 1/*ptr arith*/));
03847         // Copy the image
03848         memcpy(pDBits /*dest*/, pSBits /*source*/, pBBMI->biSizeImage);
03849     } 
03850 
03851     if (!AdjustBrightnessContrastColour(Source, Dest, Size, Width, Height, Brightness, Contrast, Colour, SingleChannel))
03852     {
03853         delete *ppOutput;
03854         *ppOutput=NULL;
03855         return FALSE;
03856     }
03857     return TRUE;
03858 }

BOOL BfxALU::BuildErrorRegionList DWORD  MarkValue,
DWORD  ClearValue,
DWORD  RegionValue,
BfxErrorRegionList pERL,
INT32  MinimumArea
[virtual]
 

Arithemtic operation to do the above.

Author:
Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/10/94
Parameters:
MarkValue = the value marked pixel have [INPUTS] ClearValue = the value cleared pixels have pERL = error region list to alter MinimumArea = min area to consider
A = RegionValue if pixel is in region, otherwise a different number [OUTPUTS] ClearValue if pixel is not marked pERL altered
Returns:
TRUE if succeeded, FALSE & error set if not

Errors: Error 2 & 3 from called routines Scope: Public

See also:
TraceControl::FindInitialPoint, BfxALU::MarkRegions, BfxALU::BuildErrorRegionList
This is used by the tracer routines work out the area to mark.

Definition at line 2014 of file bfxalu.cpp.

02016 {
02017     INT32 Pixel;
02018     INT32 Size;
02019     INT32 Width;
02020     DWORD * pA;
02021     BOOL FoundRegion=FALSE;
02022     
02023     ERROR2IF(!pERL, FALSE, "OK, Where's the error region list then?");
02024     
02025     // Empty the region list
02026     if (!pERL->Empty()) return FALSE;
02027 
02028 //  INT32 ListSize=pERL->GetSize();
02029 
02030     // Most of our error checking done in MarkRegions
02031     if (!MarkRegions(MarkValue, ClearValue, &FoundRegion, NULL, NULL, NULL,
02032                      &Size, NULL, &Width, &pA)) return FALSE;
02033 
02034     INT32 Area;
02035     
02036     if (FoundRegion)
02037     {
02038         Pixel = 0;
02039         do
02040         {
02041 
02042 #ifdef FASTBUILDERRORREGIONLIST
02043             FastBuildErrorRegionList(pA, Size, RegionValue, ClearValue, MinimumArea, &Pixel, &Area);
02044 #else
02045             do
02046             {
02047                 if ((DWORD) (Area=(INT32)(pA[Pixel])) != ClearValue) pA[Pixel]=RegionValue;
02048                 // We evilly use bit 30 to check for clearvalue
02049             } while ( (((DWORD)Area & 0xC0000000)!=0x80000000) && (Pixel++<Size));
02050 #endif
02051     
02052             if (Pixel<Size)
02053             {
02054                 if ((DWORD)(Area-0x80000000) >= (DWORD)MinimumArea)
02055                 {
02056 //                  TRACEUSER( "Alex", _T("Found region at %d,%d Area %d\n"),Pixel % Width, Pixel / Width, Area-0x80000000);
02057                     if (pERL->IsSpace()) pERL->Insert(Pixel % Width, Pixel / Width, Area-0x80000000);
02058                 }
02059 
02060             }
02061         } while (Pixel<Size);
02062 
02063     }
02064     if (!pERL->IsSpace()) TRACEUSER( "Alex", _T("[[BuildErrorRegionList ran out of space]]\n"));
02065 
02066     return (pERL->Sort() && pERL->ResetRead());
02067 }

BOOL BfxALU::ByteCopyBA  )  [virtual]
 

Copies B into the accumulator.

Author:
Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/01/95
Parameters:
None [INPUTS]
Accumulator altered [OUTPUTS]
Returns:
TRUE if succeeded, FALSE & error set if not

Errors: Error 2 if init hasn't been called or GDraw fails Error 3 if windows and some other Oil layer are stangely mixed... Scope: Protected

See also:
-
The bitmaps must be identical in dimension and depth - this is a bytewise copy.

Definition at line 2683 of file bfxalu.cpp.

02684 {
02685     ERROR2IF((GC==NULL),FALSE,"BfxALU::Init not called / failed");
02686     ERROR2IF( ((!A) || (A->ActualBitmap==NULL)) ,FALSE,"BfxALU can't find OIL bitmap");
02687     ERROR3IF( (!(A->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
02688     ERROR2IF( ((!B) || (B->ActualBitmap==NULL)) ,FALSE,"BfxALU can't find OIL bitmap");
02689     ERROR3IF( (!(B->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
02690 
02691     BITMAPINFOHEADER * pABMI=&(((CWxBitmap *)(A->ActualBitmap))->BMInfo->bmiHeader);
02692     BITMAPINFOHEADER * pBBMI=&(((CWxBitmap *)(A->ActualBitmap))->BMInfo->bmiHeader);
02693 
02694     ERROR2IF((pABMI->biBitCount != pBBMI->biBitCount), FALSE,"Bad BfxALU A/B reg");
02695     ERROR2IF( (pABMI->biSizeImage != pBBMI->biSizeImage), FALSE,
02696               "Incompatible bitmaps for ByteCopyBA()");
02697     
02698     void * pA = (void *)(((CWxBitmap *)(A->ActualBitmap))->BMBytes);
02699     void * pB = (void *)(((CWxBitmap *)(B->ActualBitmap))->BMBytes);
02700 
02701     memcpy(pA, pB, pABMI->biSizeImage);
02702 
02703     return TRUE;
02704 }

BfxALU::CC_DECLARE_DYNCREATE BfxALU   )  [private]
 

BOOL BfxALU::ClearBitByWord DWORD  BitMask,
DWORD  TheWord
[virtual]
 

Arithemtic operation to do the above.

Author:
Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/10/94
Parameters:
TheWord = value to look for to mark [INPUTS]
A &= ~BitMask if B=TheWord else intact [OUTPUTS]
Returns:
TRUE if succeeded, FALSE & error set if not

Errors: Error 2 & 3 from called routines Scope: Public

See also:
BfxALU::MarkWordByBit, TraceControl::FindInitialArea

Definition at line 1633 of file bfxalu.cpp.

01634 {
01635     ERROR2IF((GC==NULL),FALSE,"BfxALU::Init not called / failed");
01636     ERROR2IF( ((!A) || (A->ActualBitmap==NULL)) ,FALSE,"BfxALU can't find OIL bitmap");
01637     ERROR3IF( (!(A->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
01638     ERROR2IF( ((!B) || (B->ActualBitmap==NULL)) ,FALSE,"BfxALU can't find OIL bitmap");
01639     ERROR3IF( (!(B->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
01640 
01641     BITMAPINFOHEADER * pABMI=&(((CWxBitmap *)(A->ActualBitmap))->BMInfo->bmiHeader);
01642     BITMAPINFOHEADER * pBBMI=&(((CWxBitmap *)(A->ActualBitmap))->BMInfo->bmiHeader);
01643 
01644     ERROR2IF((pABMI->biBitCount !=32), FALSE,"Bad BfxALU A reg");
01645     ERROR2IF((pBBMI->biBitCount !=32), FALSE,"Bad BfxALU B reg");
01646 
01647     ERROR2IF( (pABMI->biSizeImage != pBBMI->biSizeImage), FALSE, "Incompatible bitmaps for MarkBitByWord");
01648     
01649     DWORD * pA = (DWORD *)(void *)(((CWxBitmap *)(A->ActualBitmap))->BMBytes);
01650     DWORD * pB = (DWORD *)(void *)(((CWxBitmap *)(B->ActualBitmap))->BMBytes);
01651 
01652     ERROR3IF((sizeof(DWORD) != sizeof(AluPix32)), "OK who's broken AluPix32 not to be 32 bits");
01653 
01654     INT32 Size = (pABMI->biSizeImage)>>2;
01655 
01656 #ifdef FASTCLEARBITBYWORD
01657     FastClearBitByWord(pB, pA, Size, BitMask, TheWord);
01658 #else
01659     for (INT32 Pixel = 0; Pixel < Size; Pixel ++) if (pB[Pixel]==TheWord) pA[Pixel]&=~BitMask;
01660 #endif
01661 
01662     return TRUE;
01663 }

void BfxALU::ConvertScanLineFromDWORD KernelBitmap pBitmap,
INT32  Line,
DWORD pBuffer
[protected]
 

Converts 32 bit scanline to a scanline in the bitmap.

Author:
Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/01/95
Parameters:
pBitmap pointer to bitmap [INPUTS] Line = line number pBuffer = buffer
None [OUTPUTS]
Returns:
None

Errors: None Scope: Protected

See also:
-
THIS FUNCTION HAS NO ERROR CHECKING. How does it smell? TERRIBLE

(i.e. you are expected to do your own.). This is because it must be **FAST**

Definition at line 5402 of file bfxalu.cpp.

05403 {
05404     return;
05405 }

void BfxALU::ConvertScanLineToDWORD KernelBitmap pBitmap,
INT32  Line,
DWORD pBuffer
[protected]
 

Converts a scanline in the bitmap to a 32 bit scanline.

Author:
Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/01/95
Parameters:
pBitmap pointer to bitmap [INPUTS] Line = line number pBuffer = buffer
None [OUTPUTS]
Returns:
None

Errors: None Scope: Protected

See also:
-
THIS FUNCTION HAS NO ERROR CHECKING. How does it smell? TERRIBLE

(i.e. you are expected to do your own.). This is because it must be **FAST**

Definition at line 5304 of file bfxalu.cpp.

05305 {
05306     BITMAPINFOHEADER * pBMI=&(((CWxBitmap *)(pBitmap->ActualBitmap))->BMInfo->bmiHeader);
05307     RGBQUAD * pPal=(((CWxBitmap *)(pBitmap->ActualBitmap))->BMInfo->bmiColors);
05308     void * VImage = (((CWxBitmap *)(pBitmap->ActualBitmap))->BMBytes);
05309     INT32 Width=pBMI->biWidth;
05310     switch (pBMI->biBitCount)
05311     {
05312         case 32:
05313         {
05314             DWORD * Source = &(((DWORD *) VImage)[Width*Line]);
05315             for (INT32 w=0; w<Width; w++) pBuffer[w]=Source[w] & 0x00ffffff;
05316             return;
05317         }
05318         break; // not really needed
05319         case 24:
05320         {
05321             BYTE * Source = &(((BYTE *) VImage)[(((Width*3)+3)&~3)*Line]);
05322             INT32 b=0;
05323             for (INT32 w=0; w<Width; w++)
05324             {   
05325                 pBuffer[w]=(((INT32)(Source[b])))|(((INT32)(Source[b+1]))<<8)|(((INT32)(Source[b+2]))<<16);
05326                 b+=3; // Grrr MS bug prevents us from doing this efficiently
05327             }
05328             return;
05329         }
05330         break; // not really needed
05331         case 8:
05332         {
05333             BYTE * Source = &(((BYTE *) VImage)[((Width+3)&~3)*Line]);
05334             for (INT32 w=0; w<Width; w++)
05335             {
05336                 pBuffer[w]=0x00ffffff & *((DWORD *)(&pPal[Source[w]]));
05337             }
05338             return;
05339         }
05340         break; // not really needed
05341         case 4:
05342         {
05343             BYTE * Source = &(((BYTE *) VImage)[(((Width+7)&~7)>>1)*Line]);
05344             for (INT32 w=0; w<Width; w++)
05345             {
05346                 pBuffer[w]=0x00ffffff & *((DWORD *)(&pPal[ (Source[w>>1]>>( (1-(w&1)) <<2) )&0xf]));
05347             }
05348             return;
05349         }
05350         break; // not really needed
05351         case 2:
05352         {
05353             BYTE * Source = &(((BYTE *) VImage)[(((Width+15)&~15)>>2)*Line]);
05354             for (INT32 w=0; w<Width; w++)
05355             {
05356                 pBuffer[w]=0x00ffffff & *((DWORD *)(&pPal[ (Source[w>>2]>>( (3-(w&3)) <<1) )&0x3]));
05357             }
05358             return;
05359         }
05360         break; // not really needed
05361         case 1:
05362         {
05363             BYTE * Source = &(((BYTE *) VImage)[(((Width+31)&~31)>>3)*Line]);
05364             for (INT32 w=0; w<Width; w++)
05365             {
05366                 pBuffer[w]=0x00ffffff & *((DWORD *)(&pPal[ (Source[w>>3]>>( (7-(w&7)) /*<<0*/) )&0x1]));
05367             }
05368             return;
05369         }
05370         break; // not really needed
05371         default:
05372         {
05373             ERROR3("BPP not supported");
05374         }
05375         break; // not really needed
05376     }
05377     return; // not really needed
05378 }

BOOL BfxALU::DeInit void   )  [virtual]
 

Initialises the bitmap effect subsystem.

Author:
Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/10/94
Parameters:
None [INPUTS]
DeInitialises subsystem [OUTPUTS]
Returns:
TRUE if succeeded, FALSE & error set if not

Errors: None from this one as yet

See also:
-
This call's primary purposes is to deinitialise the BfxALU, releasing a GDraw context etc.

Definition at line 400 of file bfxalu.cpp.

00401 {
00402     if (GC)
00403     {
00404         delete GC; 
00405         GC=NULL;
00406     }
00407     return TRUE;
00408 }

BOOL BfxALU::DiffusionColour KernelBitmap **  ppOutput  )  [virtual]
 

A new bitmap is created as per function name.

Author:
Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/01/95
Parameters:
None [INPUTS]
*ppOutput = a pointer to the output bitmap [OUTPUTS]
Returns:
TRUE if succeeded, FALSE & error set if not

Errors: Error 2 if init hasn't been called or GDraw fails Error 3 if windows and some other Oil layer are stangely mixed... Scope: Public

See also:
-

Definition at line 4099 of file bfxalu.cpp.

04100 {
04101 
04102 //ERROR2(FALSE, "The Accusoft boys have chosen to make this function rampantly crash");
04103 
04104     ERROR2IF((!ppOutput),FALSE, "BfxALU output parameter must be non-null");
04105     INT32 AccusoftHandle = -1;
04106     if (!MakeAccusoftHandle(&AccusoftHandle)) return FALSE;
04107     if ( (((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiHeader).biBitCount <8 )
04108     {
04109         INT32 result = AccusoftFilters::pfnIMG_promote_8(AccusoftHandle);
04110         if (result < 0)
04111         {
04112             AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
04113             ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
04114         }
04115     }
04116     INT32 result = AccusoftFilters::pfnIMG_diffusion_color(AccusoftHandle);
04117     if (result < 0)
04118     {
04119         AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
04120         ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
04121     }
04122         return MakeKernelBitmap(AccusoftHandle, ppOutput, FALSE, &(B->ActualBitmap->GetName()), _R(IDS_BFX_DIFFUSIONCOLOUR));
04123 }

BOOL BfxALU::DiffusionMono KernelBitmap **  ppOutput  )  [virtual]
 

A new bitmap is created as per function name.

Author:
Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/01/95
Parameters:</