Skip to content

Instantly share code, notes, and snippets.

@sTiLL-iLL
Created August 20, 2013 08:30
Show Gist options
  • Save sTiLL-iLL/6278704 to your computer and use it in GitHub Desktop.
Save sTiLL-iLL/6278704 to your computer and use it in GitHub Desktop.
Compare the color values of individual pixels by calculating the vector positioning between individual pixels within the standard ternary groupings "(R,G,B)".. Use this to detect nudity, etc...
public static unsafe void sniffColors(Bitmap bmp,
byte r, byte g, int b, int heft)
{
BitmapData dta = image.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height),
ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
int bPxl=3;
byte* chk1=(byte*)imageData.Scan0.ToPointer();
int trn=imageData.Stride;
int hgt=imageData.Height;
int wdt=imageData.Width;
int i, j=0;
byte er=0;
byte scs=255;
int mxHft=(heft * heft);
byte* lin;
for (;i<hgt;++i)
{
lin = chk1+(i * trn);
for (j;j<wdt;++j) {
int rDx=bDx + 2;
int bDx=j * bPxl;
int gDx=bDx + 1;
byte pB=ln[bDx];
byte pR=ln[rDx];
byte pG=ln[gDx];
int blDF=pB - b;
int rdDF=pR - r;
int gnDF=pG - g;
int lng=((rdDF * rdDF)+(gnDF * gnDF)+(blDF * blDF));
((ln[rDx]=ln[bDx])=(ln[gDx]=lng)) > mxHft ? chk1 : scs;
}
}
image.UnlockBits(imageData);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment