Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Change pixel color
#3
Is it a typo at line #5 in #sub TimerProc v?
If I comment it out or remove that line, I could run your sample.

Macro Macro129
Code:
Copy      Help
#sub TimerProc v
function hDlg
;KillTimer hDlg 1

;PF
;get dialog DC and rectangle. Erase.
__Hdc dc.Init(hDlg)
RECT r; GetClientRect hDlg &r
FillRect dc &r GetSysColorBrush(COLOR_BTNFACE)

;copy screen image under dialog to a memory DC. Slow, but there are no faster ways.
MapWindowPoints hDlg 0 +&r 2
int cx(r.right-r.left) cy(r.bottom-r.top)
__MemBmp m.Create(cx cy 1 r.left r.top)

;get color bits
ARRAY(int) a.create(cx cy)
int* b=&a[0 0]
BITMAPINFO bi; int _1 _2
BITMAPINFOHEADER& h=bi.bmiHeader
h.biSize=sizeof(h)
h.biBitCount=32; h.biWidth=cx; h.biHeight=-cy; h.biPlanes=1
if(GetDIBits(m.dc m.bm 0 cy b +&h DIB_RGB_COLORS)!=cy) ret

;replace color. Compile to C by default. Would be too slow in QM.
int n(cx*cy) alpha=b[0]&0xff000000
color1|alpha; color2|alpha
#if DRCPC_USE_TCC
__Tcc+ __tcc_drspc
if(!__tcc_drspc.f) out 1; __tcc_drspc.Compile("" "ReplaceColor")
call __tcc_drspc.f b n color1 color2
#else
int i
for i 0 n
,if(b[i]=color1) b[i]=color2
#endif

;draw the modified color bits on dialog
if(!SetDIBitsToDevice(dc 0 0 cx cy 0 0 0 cy b &bi DIB_RGB_COLORS)) ret


#ret
void ReplaceColor(int* b, int n, int color1, int color2)
{
int* be=b+n;
for(; b<be; b++) if(*b==color1) *b=color2;
}


Messages In This Thread

Forum Jump:


Users browsing this thread: 4 Guest(s)