-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpaint.asm
454 lines (396 loc) · 12 KB
/
paint.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
.386
.model flat, stdcall
option casemap:none
include windows.inc
include gdi32.inc
include user32.inc
include kernel32.inc
include msimg32.inc
include paint.inc
include util.inc
include main.inc
include rclist.inc
.data
BitmapbufferCnt DWORD 0
.data
stageWidth DWORD 0
stageHeight DWORD 0
.data?
blendFunction BLENDFUNCTION <?>
BitmapBuffer HBITMAP MAXBITMAP DUP(?)
.code
ReleaseAllBitmap PROC uses ebx edi esi
lea edi, BitmapBuffer
mov ecx, MIN_BITMAP_ID
mov eax, sizeof HBITMAP
mul ecx
add edi, eax
.WHILE ecx <= MAX_BITMAP_ID
push ecx
mov ebx, DWORD ptr [edi]
invoke DeleteObject, ebx
add edi, sizeof HBITMAP
pop ecx
inc ecx
.ENDW
ret
ReleaseAllBitmap ENDP
LoadAllBitmap PROC uses ebx edi esi
lea edi, BitmapBuffer
mov ecx, MIN_BITMAP_ID
mov eax, sizeof HBITMAP
mul ecx
add edi, eax
.WHILE ecx <= MAX_BITMAP_ID
; invoke dPrint, ecx
push ecx
invoke LoadBitmap, hInstance, ecx
mov DWORD ptr [edi], eax
add edi, sizeof HBITMAP
pop ecx
inc ecx
.ENDW
ret
LoadAllBitmap ENDP
LoadBitmapFromBuffer PROC uses ebx edi esi BitmapID:DWORD
lea edi, BitmapBuffer
mov eax, sizeof HBITMAP
mul BitmapID
add edi, eax
mov eax, DWORD PTR [edi]
ret
LoadBitmapFromBuffer ENDP
InitPaint PROC uses ebx edi esi
mov al, AC_SRC_OVER
mov blendFunction.BlendOp, al
mov al, 0
mov blendFunction.BlendFlags, al
mov al, 255
mov blendFunction.BlendFlags, al
mov al, AC_SRC_ALPHA
mov blendFunction.BlendFlags, al
ret
InitPaint ENDP
GetCircleRect PROC uses ebx ecx edx lpCircle: ptr CIRCLEDATA, lpRect: ptr RECT
mov edx, lpRect
assume edx: ptr RECT
mov ebx, lpCircle
assume ebx: ptr CIRCLEDATA
mov eax, [ebx].r
mov ecx, [ebx].centerX
sub ecx, eax
mov [edx].left, ecx
shl eax, 1
add ecx, eax
mov [edx].right, ecx
mov ecx, [ebx].centerY
shr eax, 1
sub ecx, eax
mov [edx].top, ecx
shl eax, 1
add ecx, eax
mov [edx].bottom, ecx
xor eax, eax
ret
GetCircleRect ENDP
PaintCircle PROC hDc:DWORD, lpCircle: ptr CIRCLEDATA
local @stRect:RECT
invoke GetCircleRect, lpCircle, addr @stRect
invoke Ellipse, hDc, @stRect.left, @stRect.top, @stRect.right, @stRect.bottom
ret
PaintCircle ENDP
PaintCircleCR PROC hDc:DWORD, centerX:DWORD, centerY:DWORD, r:DWORD
local @stCircle:CIRCLEDATA
mov eax, centerX
mov @stCircle.centerX, eax
mov eax, centerY
mov @stCircle.centerY, eax
mov eax, r
mov @stCircle.r, eax
invoke PaintCircle, hDc, addr @stCircle
ret
PaintCircleCR ENDP
PrepareBitmapPaint PROC uses edi ebx hDc:DWORD, bitmapID:DWORD, lpBitmapData:ptr BITMAPDATA
local @hDcBitmap
local @hBitmap, @bitmap[32]:byte
local @w, @h
mov edi, lpBitmapData
assume edi: ptr BITMAPDATA
invoke CreateCompatibleDC, hDc
mov @hDcBitmap, eax
mov [edi].hDcBitmap, eax
invoke LoadBitmapFromBuffer, bitmapID
mov @hBitmap, eax
mov [edi].hBitmap, eax
invoke SelectObject, @hDcBitmap, @hBitmap
invoke GetObject, @hBitmap, 32, addr @bitmap
lea eax, @bitmap
mov ebx, [eax+4]
mov [edi].w, ebx
mov ebx, [eax+8]
mov [edi].h, ebx
xor eax, eax
ret
PrepareBitmapPaint ENDP
GetBitmapSize PROC uses edi ebx bitmapID:DWORD, pPoint:ptr D_POINT
local @hBitmap:DWORD, @bitmap[32]:byte
invoke LoadBitmapFromBuffer, bitmapID
mov @hBitmap, eax
invoke GetObject, @hBitmap, 32, addr @bitmap
lea eax, @bitmap
mov edi, pPoint
assume edi: ptr D_POINT
mov ebx, [eax+4]
mov [edi].x, ebx
mov ebx, [eax+8]
mov [edi].y, ebx
xor eax, eax
ret
GetBitmapSize ENDP
ReleaseBitmapData PROC uses edi lpBitmapData: ptr BITMAPDATA
mov edi, lpBitmapData
assume edi: ptr BITMAPDATA
invoke DeleteDC, [edi].hDcBitmap
xor eax, eax
ret
ReleaseBitmapData ENDP
PaintBitmap PROC uses edi hDc:DWORD, bitmapID:DWORD, posX:DWORD, posY:DWORD
local @stBitmapData:BITMAPDATA
invoke PrepareBitmapPaint, hDc, bitmapID, addr @stBitmapData
invoke BitBlt, hDc, posX, posY, @stBitmapData.w, @stBitmapData.h, @stBitmapData.hDcBitmap, 0, 0, SRCCOPY
invoke ReleaseBitmapData, addr @stBitmapData
ret
PaintBitmap ENDP
PaintBitmapTrans PROC uses edi hDc:DWORD, bitmapID:DWORD, posX:DWORD, posY:DWORD
local @stBitmapData:BITMAPDATA
invoke PrepareBitmapPaint, hDc, bitmapID, addr @stBitmapData
invoke TransparentBlt, hDc, posX, posY, @stBitmapData.w, @stBitmapData.h, @stBitmapData.hDcBitmap, 0, 0, @stBitmapData.w, @stBitmapData.h, 0
invoke ReleaseBitmapData, addr @stBitmapData
ret
PaintBitmapTrans ENDP
PaintBitmapTransEx PROC uses edi ebx hDc:DWORD, bitmapID:DWORD, lpRect:ptr RECT, optionCode:DWORD
local @stBitmapData:BITMAPDATA
local @areaW, @areaH
local @srcW, @srcH, @tarW, @tarH; source width&height and target width&height
local @posX, @posY; target left-top corner
mov edi,lpRect
assume edi: ptr RECT
mov eax, [edi].right
mov ebx, [edi].left
mov @posX, ebx
sub eax, ebx
mov @areaW, eax
mov @tarW, eax
mov eax, [edi].bottom
mov ebx, [edi].top
mov @posY, ebx
sub eax, ebx
mov @areaH, eax
mov @tarH, eax
invoke PrepareBitmapPaint, hDc, bitmapID, addr @stBitmapData
mov eax, @stBitmapData.w
mov ebx, @stBitmapData.h
mov @srcW, eax
mov @srcH, ebx
mov eax, optionCode
and eax, STRETCH_X
.IF eax == 0
mov eax, @srcW
mov @tarW, eax
.ENDIF
mov eax, optionCode
and eax, STRETCH_Y
.IF eax == 0
mov eax, @srcH
mov @tarH, eax
.ENDIF
mov eax, optionCode
and eax, CENTER_MASK
.IF eax == CENTER_XY
mov eax, @tarW
mov ebx, @areaW
sub ebx, eax
sar ebx, 1
mov eax, @posX
add eax, ebx
mov @posX, eax
mov eax, @tarH
mov ebx, @areaH
sub ebx, eax
sar ebx, 1
mov eax, @posY
add eax, ebx
mov @posY, eax
.ENDIF
invoke SetStretchBltMode, hDc, HALFTONE
invoke TransparentBlt, hDc, @posX, @posY, @tarW, @tarH, \
@stBitmapData.hDcBitmap, 0, 0, @srcW, @srcH, \
0
invoke ReleaseBitmapData, addr @stBitmapData
ret
PaintBitmapTransEx ENDP
PaintBitmapEx PROC uses edi ebx hDc:DWORD, bitmapID:DWORD, lpRect:ptr RECT, optionCode:DWORD
local @stBitmapData:BITMAPDATA
local @areaW, @areaH
local @srcW, @srcH, @tarW, @tarH; source width&height and target width&height
local @posX, @posY; target left-top corner
mov edi,lpRect
assume edi: ptr RECT
mov eax, [edi].right
mov ebx, [edi].left
mov @posX, ebx
sub eax, ebx
mov @areaW, eax
mov @tarW, eax
mov eax, [edi].bottom
mov ebx, [edi].top
mov @posY, ebx
sub eax, ebx
mov @areaH, eax
mov @tarH, eax
invoke PrepareBitmapPaint, hDc, bitmapID, addr @stBitmapData
mov eax, @stBitmapData.w
mov ebx, @stBitmapData.h
mov @srcW, eax
mov @srcH, ebx
mov eax, optionCode
and eax, STRETCH_X
.IF eax == 0
mov eax, @srcW
mov @tarW, eax
.ENDIF
mov eax, optionCode
and eax, STRETCH_Y
.IF eax == 0
mov eax, @srcH
mov @tarH, eax
.ENDIF
mov eax, optionCode
and eax, CENTER_MASK
.IF eax == CENTER_XY
mov eax, @tarW
mov ebx, @areaW
sub ebx, eax
sar ebx, 1
mov eax, @posX
add eax, ebx
mov @posX, eax
mov eax, @tarH
mov ebx, @areaH
sub ebx, eax
sar ebx, 1
mov eax, @posY
add eax, ebx
mov @posY, eax
.ENDIF
invoke SetStretchBltMode, hDc, HALFTONE
invoke StretchBlt, hDc, @posX, @posY, @tarW, @tarH, \
@stBitmapData.hDcBitmap, 0, 0, @srcW, @srcH, \
SRCCOPY
invoke ReleaseBitmapData, addr @stBitmapData
ret
PaintBitmapEx ENDP
PaintRect proc uses edi hDc:DWORD, lpRect:ptr RECT
mov edi, lpRect
assume edi: ptr RECT
invoke Rectangle, hDc, [edi].left, [edi].top, [edi].right, [edi].bottom
ret
PaintRect ENDP
PaintRoundRect proc hDc:DWORD, lpRect:ptr RECT, r:DWORD
mov edi, lpRect
assume edi: ptr RECT
invoke RoundRect, hDc, [edi].left, [edi].top, [edi].right, [edi].bottom, r, r
ret
PaintRoundRect ENDP
RotateDC PROC uses ebx esi edi hdc:DWORD, Angle:DWORD, x:DWORD, y:DWORD
local @nGraphicsMode:DWORD, @fangle:REAL4, @ftmp:REAL4
local @xform:XFORM
lea edi, @xform
assume edi: PTR XFORM
invoke SetGraphicsMode, hdc, GM_ADVANCED
.IF Angle != 0
mov eax, Angle
mov @fangle, eax
fld DWORD ptr @fangle
fcos
fstp DWORD ptr @ftmp
mov eax, @ftmp
mov [edi].eM11, eax
mov [edi].eM22, eax
fld DWORD ptr @fangle
fsin
fstp DWORD ptr @ftmp
mov eax, @ftmp
mov [edi].eM12, eax
xor eax, 80000000h
mov [edi].eM21, eax
fild DWORD ptr x
fld DWORD ptr @fangle
fcos
fild DWORD ptr x
fmul
fsub
fld DWORD ptr @fangle
fsin
fild DWORD ptr y
fmul
fadd
fstp DWORD ptr @ftmp
mov eax, @ftmp
mov [edi].ex, eax
fild DWORD ptr y
fld DWORD ptr @fangle
fcos
fild DWORD ptr y
fmul
fsub
fld DWORD ptr @fangle
fsin
fild DWORD ptr x
fmul
fsub
fstp DWORD ptr @ftmp
mov eax, @ftmp
mov [edi].ey, eax
invoke SetWorldTransform, hdc, edi
.ENDIF
mov eax, @nGraphicsMode
ret
RotateDC ENDP
RotateDCi PROC uses ebx esi edi hdc:DWORD, iAngle:DWORD, x:DWORD, y:DWORD
local @fangle:REAL4
local @f180: DWORD
fild DWORD ptr iAngle
mov @f180, 180
fidiv @f180
fmul PI
fstp DWORD ptr @fangle
invoke RotateDC, hdc, @fangle, x, y
ret
RotateDCi ENDP
ClearDCRotate PROC uses ebx esi edi hdc:DWORD
local @xform:XFORM, @tmp:DWORD
lea edi, @xform
assume edi: PTR XFORM
invoke SetGraphicsMode, hdc, GM_ADVANCED
mov eax, 0
mov [edi].ey, eax
mov [edi].ex, eax
mov [edi].eM12, eax
mov [edi].eM21, eax
mov eax, 1
mov @tmp, eax
fild DWORD ptr @tmp
fstp DWORD ptr @tmp
mov eax, @tmp
mov [edi].eM11, eax
mov [edi].eM22, eax
invoke SetWorldTransform, hdc, edi
ret
ClearDCRotate ENDP
SetPen PROC uses ebx edi esi hdc:DWORD, fnPenStyle:DWORD, nWidth:DWORD, crColor:DWORD
invoke CreatePen, fnPenStyle, nWidth, crColor
invoke SelectObject, hdc, eax
ret
SetPen ENDP
end