Code: Select all
lea rdi, BitmapData
mov rax, BitmapWidth
mov rcx, BitmapHeight
mul rcx
mov rcx, rax
mov rax, FillColor
rep stosd
Code: Select all
lea rdi, BitmapData
mov rax, BitmapWidth
mov rcx, BitmapHeight
mul rcx
mov rcx, rax
mov rax, FillColor
rep stosd
Code: Select all
EnableExplicit
Procedure.i BitmapFillColor(*Bits,Width.i,Height.i,Color.i,Depth.i = 32)
If *Bits And Width And Height
If Depth = 24
!mov rdi,[p.p_Bits]
!mov eax,dword[p.v_Color]
!mov rcx,[p.v_Width]
!imul rcx,0x3
!imul rcx,[p.v_Height]
!rep stosb
ProcedureReturn #True
ElseIf Depth = 32
!mov rdi,[p.p_Bits]
!mov eax,dword[p.v_Color]
!mov rcx,[p.v_Width]
!imul rcx,[p.v_Height]
!rep stosd
ProcedureReturn #True
EndIf
EndIf
ProcedureReturn #False
EndProcedure
Procedure.i Main()
Protected *bits
Protected w.i
Protected h.i
Protected s.i
If OpenConsole("")
w = 128
h = 64
PrintN("PRESS ANY KEY - 24 Bit Test!")
Input()
s = (w * 3) * h
*bits = AllocateMemory(s)
If *bits
BitmapFillColor(*bits,w,h,$FFFFFF,24)
ShowMemoryViewer(*bits,s)
FreeMemory(*bits)
EndIf
PrintN("PRESS ANY KEY - 32 Bit Test!")
Input()
s = (w * 4) * h
*bits = AllocateMemory(s)
If *bits
BitmapFillColor(*bits,w,h,$FFFFFFFF,32)
ShowMemoryViewer(*bits,s)
FreeMemory(*bits)
EndIf
Input()
CloseConsole()
EndIf
ProcedureReturn
EndProcedure
Main()
End
This only works for 32 bit.Mijikai wrote:Example fills a bitmap with a 24 or 32-bit Color:
Ups, since its a byte transfer...wilbert wrote:This only works for 32 bit.Mijikai wrote:Example fills a bitmap with a 24 or 32-bit Color:
For 24 bit images you can only set a gray value from 0 - 255 but not a color.
Code: Select all
...
!cld ;increment the index register
!stosd
I only need 32-bit images, so the 24-bit stuff is not a problem.wilbert wrote:Mijikai wrote:Example fills a bitmap with a 24 or 32-bit Color:
This only works for 32 bit.
For 24 bit images you can only set a gray value from 0 - 255 but not a color.
[/size]Isn't the DF cleared on function entry anyways? It seems always set to 0.Helle wrote:For instructions like STOSD it´s a good idea set/clear explicit the Direction Flag before. In this caseCode: Select all
... !cld ;increment the index register !stosd
Code: Select all
Procedure BitmapFillColor(Width.l, Height.l, ARGB.l=$FF000000)
Protected img.l, bmi.BITMAPINFO
bmi\bmiHeader\biSize = SizeOf(BITMAPINFOHEADER)
bmi\bmiHeader\biWidth = Width
bmi\bmiHeader\biHeight = -Height
bmi\bmiHeader\biPlanes = 1
bmi\bmiHeader\biBitCount = 32
img = CreateDIBSection_(0, @bmi, #DIB_RGB_COLORS, @*bits, 0, 0)
!mov edi,[p.p_bits]
!mov ecx,[p.v_Width]
!imul ecx,[p.v_Height]
!mov eax,[p.v_ARGB]
!cld
!rep stosd
ProcedureReturn img
EndProcedure
img.l = BitmapFillColor(300, 180, $FF00FF00)
OpenWindow(0, 0, 0, 320, 200, "", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ImageGadget(0, 10, 10, 0, 0, img)
DeleteObject_(img)
While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend
Code: Select all
EnableExplicit
Procedure.i BitmapFillColor(*Bits,Width.i,Height.i,Color.i,Depth.i = 32)
If *Bits And Width And Height
If Depth = 32
!mov rdi,[p.p_Bits]
!mov eax,dword[p.v_Color]
!mov rcx,[p.v_Width]
!imul rcx,[p.v_Height]
!cld
!rep stosd
ProcedureReturn #True
ElseIf Depth > 7
!lea r8,[p.v_Color]
!mov r9,[p.p_Bits]
!mov rdx,[p.v_Depth]
!shr rdx,0x3
!mov rax,[p.v_Width]
!imul rax,[p.v_Height]
!cld
!@@:
!mov rsi,r8
!mov rdi,r9
!mov rcx,rdx
!rep movsb
!add r9,rdx
!dec rax
!test rax,rax
!jne @b
ProcedureReturn #True
EndIf
EndIf
ProcedureReturn #False
EndProcedure
Procedure.i Main()
Protected *bits
Protected w.i
Protected h.i
Protected s.i
If OpenConsole("")
w = 128
h = 64
PrintN("PRESS ANY KEY - 24 Bit Test!")
Input()
s = (w * 3) * h
*bits = AllocateMemory(s)
If *bits
BitmapFillColor(*bits,w,h,$332211,24)
ShowMemoryViewer(*bits,s)
FreeMemory(*bits)
EndIf
PrintN("PRESS ANY KEY - 32 Bit Test!")
Input()
s = (w * 4) * h
*bits = AllocateMemory(s)
If *bits
BitmapFillColor(*bits,w,h,$44332211,32)
ShowMemoryViewer(*bits,s)
FreeMemory(*bits)
EndIf
Input()
CloseConsole()
EndIf
ProcedureReturn
EndProcedure
Main()
End
Code: Select all
Procedure BitmapFillColor(Width.l, Height.l, ARGB.l=$FF000000)
Protected img.l, bmi.BITMAPINFO
bmi\bmiHeader\biSize = SizeOf(BITMAPINFOHEADER)
bmi\bmiHeader\biWidth = Width
bmi\bmiHeader\biHeight = -Height
bmi\bmiHeader\biPlanes = 1
bmi\bmiHeader\biBitCount = 32
img = CreateDIBSection_(0, @bmi, #DIB_RGB_COLORS, @*bits, 0, 0)
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
!mov edi,[p.p_bits]
!mov ecx,[p.v_Width]
!imul ecx,[p.v_Height]
!mov eax,[p.v_ARGB]
;!cld
!rep stosd
CompilerElse
!mov rdi,[p.p_bits]
!mov rcx,[p.v_Width]
!imul rcx,[p.v_Height]
!mov rax,[p.v_ARGB]
;!cld
!rep stosd
CompilerEndIf
ProcedureReturn img
EndProcedure
;...
!std ;e.g. from another part of your program (und du suchst dich dumm und dämlich :-) )
;...
img = BitmapFillColor(300, 180, $FF00FF00)
OpenWindow(0, 0, 0, 320, 200, "", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ImageGadget(0, 10, 10, 0, 0, img)
While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend
DeleteObject_(img)
Code: Select all
!mov eax,dword[p.v_Color]
Code: Select all
!mov rax,[p.v_Color]
It results in smaller code.chi wrote: @Mijikai: Is there a reason why you use[/size] instead ofCode: Select all
!mov eax,dword[p.v_Color]
[/size]Something I should be aware of?Code: Select all
!mov rax,[p.v_Color]
Actually I "learned" that a few month ago, but I already forgot . Thanks for the reminder ^^Mijikai wrote:It results in smaller code.
Code: Select all
Box(x, y, w, h, c)
Code: Select all
! Rep ScaSD ; search a RGBA color
Its useable if you can accept all the limitations that come with it.Olli wrote:All this could be considered useless !Box() is as fast and short !Code: Select all
Box(x, y, w, h, c)