请问这个代码应该怎么修改???

shiter
领域专家: 人工智能技术领域
2014-04-19 08:20:08




/* use imRef to access image data. */
#define imRef(im, x, y) (((uchar *)(im->data+y*im->w))[x])


static image<rgb> *imageGRAYtoRGB(image<uchar> *input)
{
int width = input->width();
int height = input->height();
image<rgb> *output = new image<rgb>(width, height, false);

for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
imRef(output, x, y).r = imRef(input, x, y);//这里报错
//imRef(output, x, y).g = imRef(input, x, y);
//imRef(output, x, y).b = imRef(input, x, y);
}
}


报错:


error C2228: “.r”的左边必须有类/结构/联合
...全文
156 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
mujiok2003 2014-04-22
  • 打赏
  • 举报
回复
引用
#define imRef(im, x, y) (((uchar *)(im->data+y*im->w))[x])
换成内联函数函数吧,让你的日子好过点。
赵4老师 2014-04-22
  • 打赏
  • 举报
回复
试试看,不保证对:
for (int y = 0; y < height; y++)
  {
    for (int x = 0; x < width; x++)
    {
     ((rgb *)imPtr(output, x, y))->r = imRef(input, x, y);
     ((rgb *)imPtr(output, x, y))->g = imRef(input, x, y);
     ((rgb *)imPtr(output, x, y))->b = imRef(input, x, y);
    }
  }
shiter 2014-04-22
  • 打赏
  • 举报
回复
引用 4 楼 zhao4zhong1 的回复:
rgb的定义在哪里?
typedef unsigned char uchar;


typedef unsigned char uchar;
typedef struct 
{ 
	uchar r, g, b;
} rgb;
求指导!!!
shiter 2014-04-22
  • 打赏
  • 举报
回复
引用 9 楼 mujiok2003 的回复:
引用
#define imRef(im, x, y) (((uchar *)(im->data+y*im->w))[x])
换成内联函数函数吧,让你的日子好过点。
请问一下怎么改呢,谢谢大牛
千树之影 2014-04-21
  • 打赏
  • 举报
回复
#define imRef(im, x, y) (((uchar *)(im->data+y*im->w))[x]) ---->#define imRef(im, x, y) (((rgb *)(im->data+y*im->w))[x])
赵4老师 2014-04-21
  • 打赏
  • 举报
回复
编译选项加/EP /P,重新编译,查看宏展开后对应的.i文件。gcc加-E
赵4老师 2014-04-21
  • 打赏
  • 举报
回复
rgb的定义在哪里?
shiter 2014-04-21
  • 打赏
  • 举报
回复
求指导啊,各位大牛。。。
shiter 2014-04-19
  • 打赏
  • 举报
回复
shiter 2014-04-19
  • 打赏
  • 举报
回复
template <class T>
class image
{
 public:
 /* create an image */
 image(const int width, const int height, const bool init = true);
 /* delete an image */
 ~image();
  /* init an image */
  void init(const T &val);
 /* copy an image */
  image<T> *copy() const;

//  /* get the width of an image. */
  int width() const { return w; }
  
//  /* get the height of an image. */
int height() const { return h; }
//  
 /* image data. */
  T *data;
//  
//  /* row pointers. */
  T **access;
//  
  public:
  int w, h;
};

/* use imRef to access image data. */
#define imRef(im, x, y) (((uchar *)(im->data+y*im->w))[x])
  
/* use imPtr to get pointer to image data. */
#define imPtr(im, x, y) &(((uchar *)(im->data+y*im->w))[x])

template <class T>
image<T>::image(const int width, const int height, const bool init)
{
 w = width;
 h = height;
 data = new T[w * h];  // allocate space for image data
 access = new T*[h];   // allocate space for row pointers

// initialize row pointers
 for (int i = 0; i < h; i++)
  access[i] = data + (i * w);  

  if (init)
    memset(data, 0, w * h * sizeof(T));
}


template <class T>
image<T>::~image()
{
  delete [] data; 
delete [] access;
}
template <class T>
void image<T>::init(const T &val) 
{
  T *ptr = imPtr(this, 0, 0);
  T *end = imPtr(this, w-1, h-1);
  while (ptr <= end)
    *ptr++ = val;
}
template <class T>
image<T> *image<T>::copy() const
{
  image<T> *im = new image<T>(w, h, false);
  memcpy(im->data, data, w * h * sizeof(T));
  return im;
}

65,208

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧