Need faster bitmap compare method



Hello,

Sorry if this is a double post. I dont think my first one went through.

I am trying to improve my current code with hopefully a more optimized
way. Hope someone can help.

I am taking two bitmaps and comparing them, region by region, and
returning the regions that dont match, cloning them then saving them. The
region size im scanning is 128x96 on a 1024x768 bitmap. It works, just too
slow.

The code below is the current method im using. this is unsafe code


//Begin of Code

public void ScanForChanges()

{


//RectW is the screen Width

//RectH is the screen Height;

//capW is how wide do we want to scan at a time

//capH is how high do we want to scan at a time

//xtimes is how many times we have to go across to get to the end

//ytimes is how many times we have to go down to get to the end

int curx = 0;

int cury = 0;

int halfW = capW/2;

int halfH = capH/2;

int ytimes = RectW/capW;//on 1024x768 should be 8 or 9

int xtimes = RectH/capH;

for(int col = 0; col<ytimes;col++)

{

cury = col * capH;//Should set the Y position (i.e. first is 0(zero), then
92, 184,276...)


for(int row = 0; row<xtimes;row++)

{

curx = row * capW;//should set the X position(i.e first is 0(zero), then
128, 256, 384...)

if(curx < RectW)

{
//this checks the current region we are at
//to see if its the same

bool same = CheckDiff(curx,cury);


if(same==false)

{

//Clone region

CollectRegionChanges(curx, cury); //if its not the same we clone this region


}

}

}


}

}





//This code actually does the comparing

//I need to find a quicker way to scan that region

//right now I scan 5 pixels, if they dont match clone it..but thats 5 pixels
out of 128x96 region

private bool CheckDiff(int locx, int locy)

{


int newx = locx;

int newy = locy;

bool same = true;





try

{


for(int yo = 0; yo<=5;yo++)

{


CheckX = FastRandomX(minX, maxX);//gets random number used for pixel
position(i.e what pixels to check)
CheckY = FastRandomY(minY, maxY);//ditto here

newx = CheckX;

newy = CheckY;

string cx = RectH;

string cy = RectW;

if(CheckX > RectH)

{

CheckX = cx;

}


if(CheckY > RectW)

{

CheckY = cy;

}

yo+=1;

Pixel* pPixel = PixelAt(CheckX, CheckY);

Pixel* pPixel2 = PixelAt2(CheckX, CheckY);


if((pPixel2->green==pPixel->green)&&(pPixel2->red==pPixel->red)&&(pPixel2->blue==pPixel->blue))

{


int xr = pPixel2->red;

int xb = pPixel2->blue;

int xg = pPixel2->green;


int yr = pPixel->red;

int yb = pPixel->blue;

int yg = pPixel->green;


}

else

{

//Pixels are Different


#region Pixel Change found - Copy Bitmap Section and send

same = false;


break;

#endregion



}


}





Console.Write("X:" + CheckX + ", Y: " + CheckY + " Same: " + same + "\r\n");


if(same == false)

{

return false;

}

else

{

return true;

}

}

catch(Exception ex)

{

//UnlockBitmap2();

//UnlockBitmap();

return false;

}



}

//END of CODE



What this code is suppose to do is start at position 0,0 with the rectangle
of 128x96 and compare that area with the other bitmap

Then it moves on to the next region, which should be 128x96 (instead of
0,0) and so on and so forth. Not happening here, it seems like its

skipping regions for some reason.

Can someone provide a better way of doing this please?

Thanks for the time.

Steve.



.



Relevant Pages

  • Patch 5/23 - Bitmaps, Cpumasks and Nodemasks
    ... P5.bitmap_extensions - Optimize and extend bitmap. ... -int bitmap_empty ... -void bitmap_complement(unsigned long *dst, const unsigned long *src, int bits); ... +static inline void bitmap_clear ...
    (Linux-Kernel)
  • [Patch 5 of 17] cpumask v4 - Optimize and extend bitmap.
    ... mask5-bitmap-extensions - Optimize and extend bitmap. ... -int bitmap_empty ... -void bitmap_complement(unsigned long *dst, const unsigned long *src, int bits); ... +static inline void bitmap_clear ...
    (Linux-Kernel)
  • Re: Getting header info of a BMP file
    ... int infoSize; ... Specifies the number of bytes required by the structure. ... Specifies the width of the bitmap, ... specify the red, green, and blue components of each pixel. ...
    (comp.lang.java.programmer)
  • [PATCH] cpumask 3/10 bitmap inlining and optimizations
    ... -int bitmap_empty(const unsigned long *bitmap, ... -void bitmap_complement(unsigned long *dst, const unsigned long *src, int bits); ... +static inline void bitmap_zero ...
    (Linux-Kernel)
  • [UPDATE][15/21]e2fsprogs add new functions with 64-bit blk64_t
    ... bitmap, leaving existing functions as they are. ... mark_block_used(ctx, blk); ... * Mark block used for the inode bitmap ... static int delete_file_block(ext2_filsys fs, ...
    (Linux-Kernel)

Quantcast