使用C ++和opengl进行图像处理,试图理解代码 [英] Image processing with C++ and opengl, trying to understand a code
问题描述
我正在学习使用C ++和OpenGL进行图像处理。
我遇到了这个部分,
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
{...
}
条件中* p == 0是什么意思?检查指向图像的指针为0?
这是否意味着检查图像是否已加载?
我尝试过:
我理解完整代码的其余部分,除了* p == 0部分。
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.
推荐答案
在您的示例*
中是解除引用运算符 - 维基百科 [ ^ ]。因为p
的类型为unsigned char *
,它将访问unsigned char
指向p
。它类似于使用p [0]
和*(p + 1)
类似于p [1]
。
In your example*
is the Dereference operator - Wikipedia[^]. Becausep
is of typeunsigned char *
it will access theunsigned char
to whichp
is pointing. It is similar to usingp[0]
and*(p+1)
is similar top[1]
.
加载检查是
if(image == NULL) exit(0); //if loaded image fail
您的代码检查内存是否为p并且p + 1指向为0.这是两个字节,因此它是一个16位值或WORD。通常是解释内存到某些格式信息。这取决于图像的数据格式。为此你必须阅读SOIL_load_image的规格细节。
这种代码模式通常用于识别颜色的某些区域并对其进行操作。
缺少一些重要的代码,即改变p。
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.
这篇关于使用C ++和opengl进行图像处理,试图理解代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!