C++openGL-获取和设置像素的函数
C++ openGL - get and set functions of pixels
我们得到了一些赋值代码。我在确定get在.h文件中而set在.cpp文件中的原因时遇到了一些问题。当我在纹理类中调用theTexMap.GetRgbPixel(x, y, r, g, b);
时,它无法在.h文件中找到GetRgbPixel函数(显然)。可能需要将get添加到RgbImage.cpp中?有人有时间解释吗?看起来这一切都是为getter完全内置在.h中的,所以我不确定为什么要添加这个函数。当很多GetRgbPixel函数已经在.h中时,我需要在多大程度上添加它?
/*********************************************************************
* SetRgbPixel routines allow changing the contents of the RgbImage. *
*********************************************************************/
void RgbImage::SetRgbPixelf( long row, long col, double red, double green, double blue )
{
SetRgbPixelc( row, col, doubleToUnsignedChar(red),
doubleToUnsignedChar(green),
doubleToUnsignedChar(blue) );
}
void RgbImage::SetRgbPixelc( long row, long col,
unsigned char red, unsigned char green, unsigned char blue )
{
assert ( row<NumRows && col<NumCols );
unsigned char* thePixel = GetRgbPixel( row, col );
*(thePixel++) = red;
*(thePixel++) = green;
*(thePixel) = blue;
}
RbgImage.h文件代码。
// Returned value points to three "unsigned char" values for R,G,B
inline const unsigned char* RgbImage::GetRgbPixel( long row, long col ) const
{
assert ( row<NumRows && col<NumCols );
const unsigned char* ret = ImagePtr;
long i = row*GetNumBytesPerRow() + 3*col;
ret += i;
return ret;
}
inline unsigned char* RgbImage::GetRgbPixel( long row, long col )
{
assert ( row<NumRows && col<NumCols );
unsigned char* ret = ImagePtr;
long i = row*GetNumBytesPerRow() + 3*col;
ret += i;
return ret;
}
inline void RgbImage::GetRgbPixel( long row, long col, float* red, float* green, float* blue ) const
{
assert ( row<NumRows && col<NumCols );
const unsigned char* thePixel = GetRgbPixel( row, col );
const float f = 1.0f/255.0f;
*red = f*(float)(*(thePixel++));
*green = f*(float)(*(thePixel++));
*blue = f*(float)(*thePixel);
}
inline void RgbImage::GetRgbPixel( long row, long col, double* red, double* green, double* blue ) const
{
assert ( row<NumRows && col<NumCols );
const unsigned char* thePixel = GetRgbPixel( row, col );
const double f = 1.0/255.0;
*red = f*(double)(*(thePixel++));
*green = f*(double)(*(thePixel++));
*blue = f*(double)(*thePixel);
}
内联函数应该在头中定义,这样就不是问题了。inline
告诉编译器,无论函数在哪里被调用,它都会用函数中的实际代码替换对函数的调用。它可以用作速度优化,但inline
实际上只是编译器的一个提示。最终由编译器来决定它要做什么
您的问题可能是GetRgbPixel
接受red
、green
和blue
参数的指针,因为这是它返回值的地方。
你会想做这样的事情:
float r, g, b;
theTexMap.GetRgbPixel(x, y, &r, &g, &b);
&
运算符获取变量的地址,该地址将变量转换为指针,并允许GetRgbPixel
函数将值返回给这些参数。
相关文章:
- 如何在不产生任何垃圾的情况下获得C中的像素
- 在C++中使用GDAL可以将图像的像素坐标转换为lat,long吗
- 如何在24位SDL_Surface上设置像素的颜色
- 如何从SDL_Surface获取特定像素的颜色
- 如何将CMSampleBufferRef/CIImage/UIImage转换为像素,例如uint8_t[]
- 在C++中查找像素 RGB 数据的最快方法是什么?
- 是否可以从 OpenGL 缓冲区获取原始大小的像素?
- 选择基于另一个垫子的非零像素的cv::Mat的一部分?
- 如何使用 sdl2 快速绘制像素网格?
- 如何在C++中进行像素操作? - Linux
- 每像素字节数,每行字节数-如何在tess二的tessbaseapi.cpp中使用函数nativeSetImageByte
- C/C++嵌入python模块PIL,python函数想返回所有像素数据,但我为什么不能?
- 如何在C程序中直接更改视频内存映射来绘制像素(无库函数)
- 如何在mousepressEvent()函数中显示像素坐标,然后如何在每次单击鼠标时在paintGL()函数中将其使用
- C++openGL-获取和设置像素的函数
- 如何沿数学函数获取像素
- 设置像素函数 [C++]
- C++ OpenCV 函数"mat.at<Vec3b>(Point(j, i))"无法生成正确的像素值并崩溃
- 我如何在'opencv'函数,当我构建隐藏窗口(在后台运行)时获得像素的颜色
- 在使用cuda_gl_interop函数进行设置时,是否可以检索像素缓冲区