Code: Alles auswählen
; Testumgebung CustomFilterCallback - so wie sie jetzt ist. - Auf eigene Gefahr. - experimental
UseJPEGImageDecoder()
UsePNGImageEncoder()
Structure bit64 : LowPart.l : HighPart.l : EndStructure
Structure CPUZeitTyp : StructureUnion : Ticks.bit64 : q.q : EndStructureUnion :EndStructure
Structure RGBATyp : StructureUnion : l.l : a4.a[4] : EndStructureUnion : EndStructure
Structure mixTyp : StructureUnion : a.a : u.u : l.l : q.q : EndStructureUnion : EndStructure
Macro setBits(ptr,BitFeldIndex,Wert) ; Wert kleiner $100 Vari BitOffset, Bitptr, *p
BitOffset=BitFeldIndex&$7
Bitptr=BitFeldIndex>>3
*p=ptr+Bitptr
*p\u=*p\u | ((Wert)<<BitOffset)
EndMacro
Macro getBits(ptr,BitFeldIndex,Anzahl,Ziel) ;Anzahl <=8 Vari BitOffset, Bitptr, *p
BitOffset=BitFeldIndex&$7
Bitptr=BitFeldIndex>>3
*p=ptr+Bitptr
Ziel=(*p\u & (($ff>>(8-Anzahl))<<Bitoffset))>>Bitoffset
EndMacro
Global *mem.mixTyp,*p.mixTyp,BitOfsset,Bitptr,Bfi=0
DisableDebugger
Procedure ScaleGrayCallback(x, y, SourceColor, TargetColor)
Protected light
light = ((Red(TargetColor) * 30 + Green(TargetColor) * 59 + Blue(TargetColor) * 11) / 100)
light = light & $E0 ; letzte 5 bit löschen.
ProcedureReturn RGBA(light, light, light, 255)
; ProcedureReturn $FF000000
EndProcedure
; Win64 pbcompiler --commented Ausgabe:
; ; Procedure ScaleGrayCallback(x, y, SourceColor, TargetColor)
; _Procedure0:
; MOV qword [rsp+8],rcx
; MOV qword [rsp+16],rdx
; MOV qword [rsp+24],r8
; MOV qword [rsp+32],r9
; PUSH r15
; PUSH r14
; PS0=80
; XOr rax,rax
; PUSH rax
; PUSH rax
; SUB rsp,40
; ; Protected light
; ; light = ((Red(TargetColor) * 30 + Green(TargetColor) * 59 + Blue(TargetColor) * 11) / 100)
; PUSH qword [rsp+PS0+24]
; POP rcx
; CALL PB_Red
; MOV r15,rax
; IMUL r15,30
; PUSH qword [rsp+PS0+24]
; POP rcx
; CALL PB_Green
; MOV r14,rax
; IMUL r14,59
; ADD r15,r14
; PUSH qword [rsp+PS0+24]
; POP rcx
; CALL PB_Blue
; MOV r14,rax
; IMUL r14,11
; ADD r15,r14
; MOV rax,r15
; MOV rcx,100
; CQO
; IDIV rcx
; MOV r15,rax
; MOV qword [rsp+40],r15
; ; ProcedureReturn RGBA(light, light, light, 255)
; PUSH qword 255
; PUSH qword [rsp+48]
; PUSH qword [rsp+56]
; PUSH qword [rsp+64]
; POP rcx
; POP rdx
; POP r8
; POP r9
; CALL PB_RGBA
; JMP _EndProcedure1
; ;
; ; EndProcedure
; _EndProcedureZero1:
; XOr rax,rax
; _EndProcedure1:
; ADD rsp,56
; POP r14
; POP r15
; RET
Procedure myScaleGrayCallback(x, y, SourceColor, TargetColor) ; Ist nötig für jede RGBA-Kombination
Protected *TargetFarbe.RGBATyp=@TargetColor
Protected light.a,retwert
Protected *p_rot.Ascii=?roteFarbe+*TargetFarbe\a4[0]
Protected *p_gruen.Ascii=?grueneFarbe+*TargetFarbe\a4[1]
Protected *p_blau.Ascii=?blaueFarbe+*TargetFarbe\a4[2]
light=(*p_rot\a+*p_gruen\a+*p_blau\a) & $E0 ; nur die ersten 3 Bits
; offen Bits in Speicher schreiben
retwert=$ff000000+light*$10101
setBits(*mem,Bfi,light>>5) : Bfi+3
ProcedureReturn retwert
EndProcedure
; Win64 pbcompiler --commented Ausgabe:
; Procedure myScaleGrayCallback(x, y, SourceColor, TargetColor)
; _Procedure2:
; MOV qword [rsp+8],rcx
; MOV qword [rsp+16],rdx
; MOV qword [rsp+24],r8
; MOV qword [rsp+32],r9
; PUSH rbp
; PUSH r15
; PUSH r14
; PS2=128
; MOV rax,7
; .ClearLoop:
; SUB rsp,8
; MOV qword [rsp],0
; DEC rax
; JNZ .ClearLoop
; SUB rsp,40
; ; Protected *TargetFarbe.RGBATyp=@TargetColor
; LEA rax,[rsp+PS2+24]
; MOV rax,rax
; PUSH rax
; POP rax
; MOV qword [rsp+40],rax
; ; Protected light.a,retwert
; ; Protected *p_rot.Ascii=?roteFarbe+*TargetFarbe\a4[0]
; MOV rbp,ll_myscalegraycallback_rotefarbe
; MOV r15,rbp
; MOV rbp,qword [rsp+40]
; PUSH rbp
; POP rbp
; MOVZX rax,byte [rbp]
; ADD r15,rax
; MOV qword [rsp+64],r15
; ; Protected *p_gruen.Ascii=?grueneFarbe+*TargetFarbe\a4[1]
; MOV rbp,ll_myscalegraycallback_gruenefarbe
; MOV r15,rbp
; MOV rbp,qword [rsp+40]
; PUSH rbp
; POP rbp
; MOVZX rax,byte [rbp+1]
; ADD r15,rax
; MOV qword [rsp+72],r15
; ; Protected *p_blau.Ascii=?blaueFarbe+*TargetFarbe\a4[2]
; MOV rbp,ll_myscalegraycallback_blauefarbe
; MOV r15,rbp
; MOV rbp,qword [rsp+40]
; PUSH rbp
; POP rbp
; MOVZX rax,byte [rbp+2]
; ADD r15,rax
; MOV qword [rsp+80],r15
; ; light=(*p_rot\a+*p_gruen\a+*p_blau\a) & $E0
; MOV rbp,qword [rsp+64]
; MOVZX r15,byte [rbp]
; MOV rbp,qword [rsp+72]
; MOVZX rax,byte [rbp]
; ADD r15,rax
; MOV rbp,qword [rsp+80]
; MOVZX rax,byte [rbp]
; ADD r15,rax
; And r15,224
; MOV rax,r15
; PUSH rax
; POP rax
; MOV byte [rsp+48],al
; ;
; ; retwert=$ff000000+light*$10101
; MOVZX r15,byte [rsp+48]
; IMUL r15,65793
; MOV rax,4278190080
; ADD r15,rax
; MOV qword [rsp+56],r15
; ; setBits(*mem,Bfi,light>>5) : Bfi+3
; MOV r15,qword [v_Bfi]
; And r15,7
; MOV qword [rsp+88],r15
; MOV r15,qword [v_Bfi]
; SAR r15,3
; MOV qword [v_Bitptr],r15
; MOV r15,qword [p_mem]
; ADD r15,qword [v_Bitptr]
; MOV qword [p_p],r15
; MOV rbp,qword [p_p]
; MOVZX r15,word [rbp]
; MOVZX r14,byte [rsp+48]
; SAR r14,5
; MOV rcx,qword [rsp+88]
; SAL r14,cl
; Or r15,r14
; MOV rax,r15
; PUSH rax
; MOV rbp,qword [p_p]
; POP rax
; MOV word [rbp],ax
; MOV r15,qword [v_Bfi]
; ADD r15,3
; MOV qword [v_Bfi],r15
; ; ProcedureReturn retwert
; MOV rax,qword [rsp+56]
; JMP _EndProcedure3
; ; EndProcedure
; _EndProcedureZero3:
; XOr rax,rax
; _EndProcedure3:
; ADD rsp,96
; POP r14
; POP r15
; POP rbp
; RET
EnableDebugger
Procedure Mainneu()
Protected x, y, image, myimage, tiefe,T0.CPUZeitTyp,T1.CPUZeitTyp,RegRDX,Start
CompilerIf #PB_OS_Windows =#PB_Compiler_OS
Protected vm=VirtualAlloc_(#Null,4096,#MEM_COMMIT,#PAGE_EXECUTE_READWRITE)
Protected *p.Ascii=vm
*p\a=$C3
CompilerEndIf
Dateiname.s="R:\tiger.jpg"
If FileSize(Dateiname)<=0 : Dateiname=OpenFileRequester("Bild","*.jpg","JPG *.jpg|*.jpg",0) : EndIf
image=LoadImage(#PB_Any,Dateiname)
x=ImageWidth(image)
y=ImageHeight(image)
tiefe= ImageDepth(image)
*mem=AllocateMemory(x*y*3/8+2)
myimage=CreateImage(#PB_Any,x,y,tiefe)
myRGBA.RGBATyp\l=RGBA(0,1,2,3)
Start=ElapsedMilliseconds()
EnableASM : DisableDebugger
RDTSC
MOV T0\Ticks\LowPart,eax
MOV T0\Ticks\HighPart,edx
If StartDrawing(ImageOutput(myimage))
DrawImage(ImageID(image), 0, 0)
DrawingMode(#PB_2DDrawing_CustomFilter)
;CustomFilterCallback(@ScaleGrayCallback())
; CustomFilterCallback(vm)
If $3020100=myRGBA\l
CustomFilterCallback(@myScaleGrayCallback())
Else
CustomFilterCallback(@ScaleGrayCallback())
Debug myRGBA\l
EndIf
Box(0, 0, x, y)
StopDrawing()
Else
EnableDebugger: Debug x : Debug y: Debug myimage
MessageRequester("FATAL","Fehler StartDrawing")
End
EndIf
DisableDebugger
RDTSC
MOV T1\Ticks\LowPart,eax
MOV T1\Ticks\HighPart,edx
EnableDebugger
Debug "Dauer: "+Str(T1\q-T0\q) +" "+Str(ElapsedMilliseconds()-Start)+" ms" ;6980419767
ShowMemoryViewer(*mem,1000)
Dateiname=ReplaceString(Dateiname,".jpg","grau.png")
SaveImage(myimage,Dateiname,#PB_ImagePlugin_PNG)
EndProcedure
Mainneu()
; Procedure.a rotwert(Farbe.l) : ProcedureReturn Int((Pow(Red (Farbe)/255.0,2.2)*0.2126)*255.5) : EndProcedure
; Procedure.a gruenwert(Farbe.l) : ProcedureReturn Int((Pow(Green(Farbe)/255.0,2.2)*0.7152)*255.5) : EndProcedure
; Procedure.a blauwert(Farbe.l) : ProcedureReturn Int((Pow(Blue (Farbe)/255.0,2.2)*0.0722)*255.5) : EndProcedure
DataSection : roteFarbe:
Data.a $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,
$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,
$01,$01,$01,$01,$01,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$03,$03,$03,$03,$03,$03,$03,$03,$03,$04,
$04,$04,$04,$04,$04,$04,$04,$04,$05,$05,$05,$05,$05,$05,$05,$06,$06,$06,$06,$06,$06,$06,$07,$07,$07,$07,$07,
$07,$08,$08,$08,$08,$08,$08,$09,$09,$09,$09,$09,$09,$0A,$0A,$0A,$0A,$0A,$0B,$0B,$0B,$0B,$0B,$0C,$0C,$0C,$0C,
$0C,$0D,$0D,$0D,$0D,$0E,$0E,$0E,$0E,$0E,$0F,$0F,$0F,$0F,$10,$10,$10,$10,$11,$11,$11,$11,$12,$12,$12,$12,$13,
$13,$13,$14,$14,$14,$14,$15,$15,$15,$15,$16,$16,$16,$17,$17,$17,$18,$18,$18,$18,$19,$19,$19,$1A,$1A,$1A,$1B,
$1B,$1B,$1C,$1C,$1C,$1D,$1D,$1D,$1E,$1E,$1E,$1F,$1F,$1F,$20,$20,$20,$21,$21,$21,$22,$22,$23,$23,$23,$24,$24,
$24,$25,$25,$26,$26,$26,$27,$27,$28,$28,$28,$29,$29,$2A,$2A,$2A,$2B,$2B,$2C,$2C,$2C,$2D,$2D,$2E,$2E,$2F,$2F,
$2F,$30,$30,$31,$31,$32,$32,$33,$33,$34,$34,$34,$35,$35,$36
grueneFarbe:
Data.a $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$01,
$01,$01,$01,$01,$01,$01,$01,$01,$02,$02,$02,$02,$02,$02,$02,$03,$03,$03,$03,$03,$04,$04,$04,$04,$04,$05,$05,
$05,$05,$06,$06,$06,$06,$07,$07,$07,$07,$08,$08,$08,$09,$09,$09,$09,$0A,$0A,$0A,$0B,$0B,$0C,$0C,$0C,$0D,$0D,
$0D,$0E,$0E,$0F,$0F,$0F,$10,$10,$11,$11,$12,$12,$12,$13,$13,$14,$14,$15,$15,$16,$16,$17,$17,$18,$18,$19,$19,
$1A,$1B,$1B,$1C,$1C,$1D,$1D,$1E,$1F,$1F,$20,$20,$21,$22,$22,$23,$24,$24,$25,$26,$26,$27,$28,$28,$29,$2A,$2A,
$2B,$2C,$2D,$2D,$2E,$2F,$30,$30,$31,$32,$33,$33,$34,$35,$36,$37,$38,$38,$39,$3A,$3B,$3C,$3D,$3D,$3E,$3F,$40,
$41,$42,$43,$44,$45,$46,$47,$48,$48,$49,$4A,$4B,$4C,$4D,$4E,$4F,$50,$51,$52,$53,$54,$55,$57,$58,$59,$5A,$5B,
$5C,$5D,$5E,$5F,$60,$61,$63,$64,$65,$66,$67,$68,$69,$6B,$6C,$6D,$6E,$6F,$71,$72,$73,$74,$75,$77,$78,$79,$7A,
$7C,$7D,$7E,$80,$81,$82,$84,$85,$86,$88,$89,$8A,$8C,$8D,$8E,$90,$91,$93,$94,$95,$97,$98,$9A,$9B,$9C,$9E,$9F,
$A1,$A2,$A4,$A5,$A7,$A8,$AA,$AB,$AD,$AE,$B0,$B2,$B3,$B5,$B6
blaueFarbe:
Data.a $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,
$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,
$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,
$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,
$02,$02,$02,$02,$02,$02,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$04,$04,$04,$04,$04,
$04,$04,$04,$04,$04,$04,$04,$04,$05,$05,$05,$05,$05,$05,$05,$05,$05,$05,$05,$05,$05,$06,$06,$06,$06,$06,$06,
$06,$06,$06,$06,$06,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$09,$09,
$09,$09,$09,$09,$09,$09,$09,$0A,$0A,$0A,$0A,$0A,$0A,$0A,$0A,$0B,$0B,$0B,$0B,$0B,$0B,$0B,$0B,$0C,$0C,$0C,$0C,
$0C,$0C,$0C,$0C,$0D,$0D,$0D,$0D,$0D,$0D,$0D,$0E,$0E,$0E,$0E,$0E,$0E,$0E,$0E,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$10,
$10,$10,$10,$10,$10,$11,$11,$11,$11,$11,$11,$11,$12,$12,$12
EndDataSection
; Procedure.a rotwert(Farbe.l) : ProcedureReturn (Red(Farbe) * 30) /100 : EndProcedure
; Procedure.a gruenwert(Farbe.l) : ProcedureReturn (Green(Farbe) * 59) /100 : EndProcedure
; Procedure.a blauwert(Farbe.l) : ProcedureReturn (Blue(Farbe) * 11) /100 : EndProcedure
; vm RET verbraucht 75 ms
; ScaleGrayCallback Dauer: 620018005 259 ms
; myScaleGrayCallback Dauer: 428119984 178 ms ohne Bits
; myScaleGrayCallback Dauer: 476267007 198 ms mit Bits
; bekannt vm, auskommentiert kann so nicht Linux und MacOS laufen
; offen Welche myRGBA's sind noch bekannt.
; Ideen RGBS's zur Laufzeit anpassen
; myScaleGrayCallback in C, PB-InlineASM, ASM oder Hex
; GPU
; Setbits im 2. Lauf 6 Pixel (3x64 bit) rein 4+2 Bytes (48 bits) raus