2

this is my first question here; hope I'll be clear enough...

I've got this struct available

typedef struct COLORTRIPLE
{
  byte blue;
  byte green;
  byte red;
}

which is contained in another struct like that:

struct color_temp
{ 
  COLORTRIPLE color;
  int temp;
};

And (EDIT)

#define PIXEL(image, row, column)  \
    image.pixel [(row) * image.width + (column)]

is a macro.

So there will be PIXEL(bmpin,row,column).red, PIXEL(bmpin,row,column).green and PIXEL(bmpin,row,column).blue.

I need to scan a bitmap file pixel by pixel and check if the current pixel is equal to one color of the color_temp struct.

I tried something like:

if ((PIXEL(bmpin,row,column))==(map[n].color))
{...}

where

struct color_temp map[]

is a vector of color_temp.

But cygwin gcc says:

error:request for member 'color' in something not a struct or a union

Any suggestions?

Thanks

Mark

Stephen
  • 6,027
  • 4
  • 37
  • 55
Madrac
  • 23
  • 3
  • Is it C or C++? There is a difference you know. – Björn Pollex Sep 23 '10 at 10:18
  • 1
    Welcome to Stackoverflow. Next time please format your code using the `101010` button above the edit box, as Naveen meanwhile has done for you. Also, if this is a homework question, please add the `homework` tag. (It prompts people to post answers that help you learning instead of snippets you can turn in as your own.) Then, decide whether your code and question is C or C++. Besides some syntactical similarities, these two have very little in common. And if you reply to comments, don't forget to properly @address people, so the replies show up in their "Aswers" tab. And please read the FAQ. – sbi Sep 23 '10 at 10:20
  • If `PIXEL(...)` is a pointer, then `PIXEL(...).red` is bad code. What is `PIXEL`, a macro? – Marcelo Cantos Sep 23 '10 at 10:25
  • What exactly do you mean by, "doesn't work"? Does it not compile (What's the error?), fall over at runtime, or something else? – Marcelo Cantos Sep 23 '10 at 10:26
  • thanks for the replies and sorry for the mistakes, now I'll edit the message – Madrac Sep 23 '10 at 10:45
  • @Williham Totland: I tried that before posting my question and the compiler gives me the same error – Madrac Sep 23 '10 at 11:05

2 Answers2

2

Try this:

int is_pixels_equal (COLORTRIPLE a, COLORTRIPLE b) {
  return (a.red == b.red && a.green == b.green && a.blue == b.blue);
}
Williham Totland
  • 28,471
  • 6
  • 52
  • 68
0

You can't directly compare structs in C, it doesn't define such an operator. Therefore you have to implement it yourself, as Williham Totland suggested. For more discussion, see for instance this question.

Community
  • 1
  • 1
unwind
  • 391,730
  • 64
  • 469
  • 606