Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm learning image processing using C++ and OpenGL.
I encountered this part,

int main(int argc, char *argv[])
{
  unsigned char* image; 
    image = SOIL_load_image("Images/image.png", &width, &height, 0, SOIL_LOAD_RGBA);
    if(image == NULL) exit(0); //if loaded image fail
  }

static void createImages(void)
{
    unsigned char *p;

    p = image;
    for(int i = 0; i < height*width; i++) {     
        if(*p == 0 && *(p+1) == 0) { //(p+1)==0-->Green pixel =0, what is *p==0 ?
         //some commands to replace pixels value
     {...

}
what does *p == 0 in condition mean ? checking pointer to the image as 0 ?
Does that mean checking if the image is loaded ?

What I have tried:

I understand the rest of the full code except for the *p==0 part.
Posted
Updated 18-Sep-18 0:06am

In your example * is the Dereference operator - Wikipedia[^]. Because p is of type unsigned char * it will access the unsigned char to which p is pointing. It is similar to using p[0] and *(p+1) is similar to p[1].
 
Share this answer
 
Comments
lock&_lock 17-Sep-18 12:47pm    
Thanks ! I understand the pointer part, if p is pointing to another memory.
I also undertsand (p+1) is similar to p[1] in this case is Green pixel.
I just don't understand the condition part, what is that condition checking ?
condition if(*p == 0 && *(p+1) == 0) is to check if green pixel value (p+1) equals 0 and *p==0, what is this *p==0 ?
lock&_lock 17-Sep-18 12:51pm    
Oh. my bad. I got it now. Thanks a lot !
The load check is your
C++
if(image == NULL) exit(0); //if loaded image fail
Your code checks whether the memory to which p and p+1 is pointing is 0. This are two bytes, so it is a 16-bit value or WORD. Normally is that done to interpret memory to some format information. That is depending on the data format of your image. For that you must read the specifications details of SOIL_load_image.

Such code pattern is often used to identify some areas of a color and manipulate it.

Some important code is missing which is about changing p.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900