Access RGB of each pixels in bitmap using C Win32 -


i have demo program written in plain c win32. program using framegrabber grab images camera , store them in main memory buffer (images 8bit/pixel grayscale). demo can show grabbed images on computer screen. , save them on hard disk.

now want add function program, read raw data buffer each frame , lets show each pixel color (rgb) on console, can use them analysing.

i have following information far in code :

lpstr createbmp( hwnd happwnd, int nimagetype ) {           void            * pwingbits = null; int             i; z_bitmapinfo    zwingheader;    //  bitmapinfo cerating dib //  create dc bitmap. hdcbits = createcompatibledc( ghdcmain );  switch ( nimagetype ) {     case bayer_filter:      break;      case color32:     break;      case color24:     break;      case color3x16:     break;      case bw1x10:     break;      default:     case bw8:     //  create bitmap-infoheader.     zwingheader.bmiheader.bisize        = sizeof( bitmapinfoheader );     zwingheader.bmiheader.biplanes      = 1;     zwingheader.bmiheader.bibitcount    = 8;     zwingheader.bmiheader.bicompression = bi_rgb;     zwingheader.bmiheader.bisizeimage   = 0;             zwingheader.bmiheader.biclrused     = (1<<8);            zwingheader.bmiheader.biclrimportant= 0;     zwingheader.bmiheader.biheight      = -lysize;     zwingheader.bmiheader.biwidth       = lxsize;     //  create colortable fot bitmap (grayvalues).     (i = 0; < 256; i++)      {         zwingheader.bmicolors[i].rgbgreen   = i;                 zwingheader.bmicolors[i].rgbblue    = i;         zwingheader.bmicolors[i].rgbred     = i;                     zwingheader.bmicolors[i].rgbreserved = 0;                }     break; }  //  cerate identity palette  hpal = createidentitypalette( zwingheader.bmicolors );  //  new palette dc , map physical palette register. holdpal = selectpalette( ghdcmain, hpal, false);     realizepalette( ghdcmain );  //  cerate dib-section f黵 direct access of image-data. hbitmap = createdibsection(     hdcbits,                        //  handle of device context     (bitmapinfo *)&zwingheader,     //  address of structure containing                                     //  bitmap size, format , color data     dib_rgb_colors,                 //  color data type indicator: rgb values                                     //  or palette indices     &pwingbits,                     //  pointer variable receive pointer                                     //  bitmap's bit values     null,                           //  optional handle file mapping object     0                               //  offset bitmap bit values within                                     //  file mapping object );       //  bitmap dc . holdbitmap = (hbitmap)selectobject( hdcbits, hbitmap );  return pwingbits;           //  return pointer dib  } 

also here code saving bitmap on disk :

bool savetofile(hbitmap hbitmap3, lpctstr lpszfilename) {    hdc = createdc("display", null, null, null); ibits = getdevicecaps(hdc, bitspixel) * getdevicecaps(hdc, planes); deletedc(hdc); if (ibits <= 1)     wbitcount = 1; else if (ibits <= 4)     wbitcount = 4; else if (ibits <= 8)     wbitcount = 8; else     wbitcount = 24;  getobject(hbitmap3, sizeof(bitmap0), (lpstr)&bitmap0); bi.bisize = sizeof(bitmapinfoheader); bi.biwidth = bitmap0.bmwidth; bi.biheight =-bitmap0.bmheight; bi.biplanes = 1; bi.bibitcount = wbitcount; bi.bicompression = bi_rgb; bi.bisizeimage = 0; bi.bixpelspermeter = 0; bi.biypelspermeter = 0; bi.biclrimportant = 0; bi.biclrused = 256; dwbmbitssize = ((bitmap0.bmwidth * wbitcount +31) & ~31) /8 * bitmap0.bmheight;  hdib = globalalloc(ghnd,dwbmbitssize + dwpalettesize + sizeof(bitmapinfoheader)); lpbi = (lpbitmapinfoheader)globallock(hdib); *lpbi = bi;  hpal = getstockobject(default_palette); if (hpal) {      hdc = getdc(null);     holdpal2 = selectpalette(hdc, (hpalette)hpal, false);     realizepalette(hdc); }   getdibits(hdc, hbitmap3, 0, (uint) bitmap0.bmheight, (lpstr)lpbi + sizeof(bitmapinfoheader)  +dwpalettesize, (bitmapinfo *)lpbi, dib_rgb_colors);  if (holdpal2) {     selectpalette(hdc, (hpalette)holdpal2, true);     realizepalette(hdc);     releasedc(null, hdc); } //create file , save on disk }  

here palette function :

hpalette createidentitypalette( rgbquad* argb ) { int i; int nstaticcolors; struct {     word version;     word numberofentries;     paletteentry aentries[256]; } palette = {     0x300,     256 };  hdc hdc = getdc( null );  //  read 20 static colors of systempalette . nstaticcolors = getdevicecaps ( hdc, numcolors ); getsystempaletteentries ( hdc, 0, 256, palette.aentries );  //  release palettenregister in order insert our colors in desired //  order hardware-register setsystempaletteuse( hdc, syspal_nostatic ); setsystempaletteuse( hdc, syspal_static );  //  reset 'peflags' of lower static colors 0 (i=0; < 10; i++)         palette.aentries[i].peflags = 0;  //  insert colors of given colortable (i=10; < 246; i++) {     palette.aentries[i].pered   = argb[i].rgbred;     palette.aentries[i].pegreen = argb[i].rgbgreen;     palette.aentries[i].peblue  = argb[i].rgbblue;      palette.aentries[i].peflags = pc_nocollapse; }  //  reset 'peflags' of upper static colors 0 (i=246; i<256; i++)         palette.aentries[i].peflags = 0;  //  release dc releasedc (null, hdc);  //  return palette return createpalette( (logpalette *)&palette ); } 

can please hare idea how can usde functions , information have value rgb of each pixel 1 one, , hold in array ?


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -