Hey guys I'm trying to do an image filtering program using SDL library. The problem is, I'm able to extract out every pixels and the RGB to form the image. I tried to sharpen it however it doesn't change anything.
Supposingly, by using these matrix, it will sharpen the image. int sharpen[3][3] = { {0,-1,0}, {-1, 5,-1}, {0,-1,0}};
int rsum = 0;
int gsum = 0;
int bsum = 0;
int psum = 0;
// Need to lock the surface before playing with the content
SDL_LockSurface(source);
for (int i = 0; i < img_size; i++) {
// Get the content of the pixel
// source -> pixel hold the address of the 1st pixel
// *(source -> pixels) get the content of the pixel
pixel = *((Uint32*) source -> pixels + i);
// Get Red component
temp = pixel & fmt->Rmask; /* Isolate red component */
temp = temp >> fmt->Rshift; /* Shift it down to 8-bit */
temp = temp << fmt->Rloss; /* Expand to a full 8-bit number */
R[i] = (Uint8) temp;
// Get Green component
temp = pixel & fmt->Gmask; /* Isolate green component */
temp = temp >> fmt->Gshift; /* Shift it down to 8-bit */
temp = temp << fmt->Gloss; /* Expand to a full 8-bit number */
G[i] = (Uint8) temp;
// Get Blue component */
temp = pixel & fmt->Bmask; /* Isolate blue component */
temp = temp >> fmt->Bshift; /* Shift it down to 8-bit */
temp = temp << fmt->Bloss; /* Expand to a full 8-bit number */
B[i] = (Uint8) temp;
for (int x = 0; x < img_height; x++)
{
for (int y = 0; y < img_width; y++)
{
for (int row = -1; row <= 1; row++)
{
for (int col = -1; col <= 1; col++)
{
rsum += filter[row + 1][col + 1] * R[i]; // Red
gsum += filter[row + 1][col + 1] * G[i]; // Green
bsum += filter[row + 1][col + 1] * B[i]; // Blue
}
}
}
}
}
SDL_UnlockSurface(source);
So what I did is to loop every single pixels then try to multiply it. It suppose to sharpen the image. But it didn't do anything. Any solution to this?
I don't understand what you mean by "sharpen the image". Is filter the same as sharpen? You never write anything back to the pixel data so that's why the image doesn't change.