Added image library and threshold function. Moved pixel access defines from state to image class.
This commit is contained in:
@@ -5,6 +5,7 @@ set(AIGO_SRCS
|
||||
quickcam.cpp
|
||||
settings.cpp
|
||||
state.cpp
|
||||
image.cpp
|
||||
)
|
||||
|
||||
#find SDL and its related libraries
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#include "image.h"
|
||||
|
||||
namespace Image
|
||||
{
|
||||
void threshold(SDL_Surface *image, int lowerBound, int upperBound)
|
||||
{
|
||||
int x, y;
|
||||
for (int i = 0; i < image->w * image->h; ++i)
|
||||
{
|
||||
int gray = GRAY(((uint32_t*)image->pixels)[i]);
|
||||
if (gray > lowerBound && gray < upperBound)
|
||||
((uint32_t*)image->pixels)[i] = 0xffffffff;
|
||||
else
|
||||
((uint32_t*)image->pixels)[i] = 0xff000000;
|
||||
//gray | (gray << 8) | (gray << 16);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#ifndef _IMAGE_H_
|
||||
#define _IMAGE_H_
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
|
||||
// get pixel/something in array p of size w*h
|
||||
#define PX_(p, x, y, w, h) ((p)[(x)+(y)*(w)])
|
||||
// get pixel in SDL_Surface i
|
||||
#define PX(i,x,y) (PX_((uint32_t*)(i)->pixels, (x), (y), (i)->w, (i)->h))
|
||||
// get color components of pixel value. should probably be done in a nicer way
|
||||
#define PXR(px) ((px) & 0xff)
|
||||
#define PXG(px) (((px) & 0xff00) >> 8)
|
||||
#define PXB(px) (((px) & 0xff0000) >> 16)
|
||||
|
||||
//get the grayscale value of the pixel
|
||||
#define GRAY(px) ((PXR(px) + PXG(px) + PXB(px)) / 3)
|
||||
|
||||
// iterate over SDL_Surface s with variables x, y
|
||||
#define iter_pixels(s,x,y) for (x = 0; x < s->w; x++) for (y = 0; y < s->h; y++)
|
||||
|
||||
namespace Image
|
||||
{
|
||||
|
||||
void threshold(SDL_Surface *image, int lowerBound, int upperBound);
|
||||
|
||||
}
|
||||
|
||||
#endif /* ifndef _IMAGE_H_ */
|
||||
+1
-11
@@ -4,17 +4,7 @@
|
||||
#include "settings.h"
|
||||
#include <SDL/SDL.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// get pixel/something in array p of size w*h
|
||||
#define PX_(p, x, y, w, h) ((p)[(x)+(y)*(w)])
|
||||
// get pixel in SDL_Surface i
|
||||
#define PX(i,x,y) (PX_((uint32_t*)(i)->pixels, (x), (y), (i)->w, (i)->h))
|
||||
// get color components of pixel value. should probably be done in a nicer way
|
||||
#define PXR(px) ((px) & 0xff)
|
||||
#define PXG(px) (((px) & 0xff00) >> 8)
|
||||
#define PXB(px) (((px) & 0xff0000) >> 16)
|
||||
// iterate over SDL_Surface s with variables x, y
|
||||
#define iter_pixels(s,x,y) for (x = 0; x < s->w; x++) for (y = 0; y < s->h; y++)
|
||||
#include "image.h"
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user