Code : Tout sélectionner
;==============================================================================
;== Amstrad CPC Image Decoder
;== Version 0.5, 2015-09-06
;== Author: Case, Flype
;==============================================================================
DeclareModule CPC
Declare LoadSCR(fileName.s, mode.i)
EndDeclareModule
Module CPC
Structure Longs
l.Long[0]
EndStructure
Prototype Decode(*a, x, y, w)
Procedure Decode0(*a, x, y, w)
Protected b = PeekB(*a+((y&7)<<11)+(y>>3)*80+(x>>2))
If (x&2)=0 : b>>1 : EndIf
ProcedureReturn ((b&1)<<3)+((b>>2)&4)+((b>>1)&2)+((b>>6)&1)
EndProcedure
Procedure Decode1(*a, x, y, w)
Protected b = PeekB(*a+((y&7)<<11)+(y>>3)*80+(x>>2))>>(~x&3)
ProcedureReturn ((b>>3)&2)+(b&1)
EndProcedure
Procedure Decode2(*a, x, y, w)
ProcedureReturn (PeekB(*a+((y&7)<<11)+(((y>>3)*w+x)>>3))>>(~x&7))&1
EndProcedure
Procedure Decode(mode.i, *a, *b.Longs, *c.Longs)
Protected x, y, w, h, i, d.Decode
Select mode
Case 0: w = 320 : h = 200 : d = @Decode0()
Case 1: w = 320 : h = 200 : d = @Decode1()
Case 2: w = 640 : h = 200 : d = @Decode2()
EndSelect
i = CreateImage(#PB_Any, w, h)
If i
If StartDrawing(ImageOutput(i))
For y = 0 To h - 1
For x = 0 To w - 1
Plot(x, y, *b\l[*c\l[d(*a, x, y, w)]\l]\l)
Next
Next
StopDrawing()
EndIf
EndIf
ProcedureReturn i
EndProcedure
Procedure LoadSCR(fileName.s, mode.i)
Protected f, l, i, *m
l = FileSize(fileName)
If l > 0
f = ReadFile(#PB_Any, fileName)
If f
*m = AllocateMemory(l)
If *m
If ReadData(f, *m, l)
i = Decode(mode, *m + 128, ?CPC_Palette, ?CPC_Pen)
EndIf
FreeMemory(*m)
EndIf
CloseFile(f)
EndIf
EndIf
ProcedureReturn i
EndProcedure
DataSection ;{
CPC_Pen:
Data.l 1, 24, 20, 6, 26, 0, 2, 8, 10, 12, 14, 16, 18, 22, 3, 5
CPC_Palette:
Data.l $0000,$800000,$FF0000,$0080,$800080,$FF0080,$00FF,$8000FF,$FF00FF
Data.l $8000,$808000,$FF8000,$8080,$808080,$FF5050,$80FF,$8080FF,$FF80FF
Data.l $FF00,$80FF00,$FFFF00,$FF80,$80FF80,$FFFF80,$FFFF,$80FFFF,$FFFFFF
EndDataSection ;}
EndModule
;==============================================================================
Define file$ = "KRAUSCH.ECR"
Define image = CPC::LoadSCR(file$, 0)
If image
Define w = ImageWidth(image) * 1
Define h = ImageHeight(image) * 1
ResizeImage(image, w, h, #PB_Image_Raw)
If OpenWindow(0, 100, 100, w, h, file$)
ImageGadget(0, 0, 0, w, h, ImageID(image))
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
EndIf
;==============================================================================