Click here to Skip to main content
15,891,951 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: visual c++ change button code Pin
Hamid_RT11-May-06 5:36
Hamid_RT11-May-06 5:36 
AnswerRe: visual c++ change button code Pin
Cedric Moonen11-May-06 5:00
Cedric Moonen11-May-06 5:00 
GeneralRe: visual c++ change button code Pin
toxcct11-May-06 22:56
toxcct11-May-06 22:56 
GeneralRe: visual c++ change button code Pin
Cedric Moonen11-May-06 22:59
Cedric Moonen11-May-06 22:59 
QuestionDisplay Grayscale Image from a Firewire Camera Pin
surfman1911-May-06 4:19
surfman1911-May-06 4:19 
AnswerRe: Display Grayscale Image from a Firewire Camera Pin
Russell'11-May-06 5:00
Russell'11-May-06 5:00 
GeneralRe: Display Grayscale Image from a Firewire Camera Pin
surfman1911-May-06 7:49
surfman1911-May-06 7:49 
GeneralRe: Display Grayscale Image from a Firewire Camera Pin
Justin Tay11-May-06 15:18
Justin Tay11-May-06 15:18 
Your loop is already wrong. Img2 is an unsigned char *, so Img2[0] refers to byte 0, Img2[1] refers to byte 1, etc. And you should be creating your bitmap using CreateDIBitmap().

void CImageProcView::RGB2Gray(unsigned char *Img1, unsigned char *Img2, unsigned int ByteSize)
{
  for(int i = 0; i<ByteSize/4; i++)
  {
    Img2[i] = ((char)Img1[4*i] + (char)Img1[4*i+1] + (char)Img1[4*i+2]) / 3; // Incorrect
  }
}


If you find it difficult to think in terms of bytes, you can always cast it to RGBQUAD.
void CImageProcView::RGB2Gray(unsigned char *Img1, unsigned char *Img2, unsigned int ByteSize)
{
  RGBQUAD *pSource = static_cast<RGBQUAD*>(Img1);
  RGBQUAD *pDest = static_cast<RGBQUAD*>(Img2);

  for(int i = 0; i<ByteSize/sizeof(RGBQUAD); i++)
  {
    pDest[i].rgbRed = pDest[i].rgbGreen = pDest[i].rgbBlue = (pSource[i].rgbBlue + pSource[i].rgbGreen + pSource[i].rgbRed) / 3;
    pDest[i].rgbReserved = 0;
  }
}

GeneralRe: Display Grayscale Image from a Firewire Camera Pin
surfman1912-May-06 0:25
surfman1912-May-06 0:25 
GeneralRe: Display Grayscale Image from a Firewire Camera Pin
Justin Tay12-May-06 0:37
Justin Tay12-May-06 0:37 
GeneralRe: Display Grayscale Image from a Firewire Camera Pin
surfman1912-May-06 3:09
surfman1912-May-06 3:09 
QuestionCCombobox drawitem question Pin
Tarek Jabri11-May-06 4:17
Tarek Jabri11-May-06 4:17 
AnswerRe: CCombobox drawitem question Pin
Hamid_RT11-May-06 4:49
Hamid_RT11-May-06 4:49 
GeneralRe: CCombobox drawitem question Pin
Tarek Jabri11-May-06 6:02
Tarek Jabri11-May-06 6:02 
GeneralRe: CCombobox drawitem question Pin
Hamid_RT11-May-06 6:49
Hamid_RT11-May-06 6:49 
GeneralRe: CCombobox drawitem question Pin
Hamid_RT11-May-06 7:23
Hamid_RT11-May-06 7:23 
QuestionUDP/ TCP socket problem Pin
nahitan11-May-06 3:47
nahitan11-May-06 3:47 
AnswerRe: UDP/ TCP socket problem Pin
kk.tvm11-May-06 22:24
kk.tvm11-May-06 22:24 
Questionneeding help in algorithm Pin
V_shr11-May-06 3:46
V_shr11-May-06 3:46 
AnswerRe: needing help in algorithm Pin
toxcct11-May-06 3:51
toxcct11-May-06 3:51 
GeneralRe: needing help in algorithm Pin
V_shr11-May-06 3:57
V_shr11-May-06 3:57 
GeneralRe: needing help in algorithm Pin
toxcct11-May-06 4:03
toxcct11-May-06 4:03 
GeneralRe: needing help in algorithm Pin
V_shr11-May-06 4:13
V_shr11-May-06 4:13 
GeneralRe: needing help in algorithm Pin
toxcct11-May-06 4:14
toxcct11-May-06 4:14 
GeneralRe: needing help in algorithm Pin
Bob Flynn11-May-06 4:28
Bob Flynn11-May-06 4:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.