Commit 03e27cbe authored by Jeffrey Lee's avatar Jeffrey Lee
Browse files

Add support for *iconspriting of alpha-masked sprites. Fix icon...

Add support for *iconspriting of alpha-masked sprites. Fix icon shading/inverting to work with true colour sprites.

Detail:
  Options/s/!Default, s/NewSWIs, s/Wimp01:

  Updated ROM sprite find code, *IconSprites and Wimp_Extend 13 to understand a new spritefile suffix.
  If the Wimp detects that RISC OS Select style alpha masked sprites are supported, and we're not using the mode 23 sprites, then the code will enable support for alpha masked sprites of the form !SpritesA1, !SpritesA2, !SpritesA, etc. Alpha-masked sprites are only looked for when looking for square pixel sprites or just before looking for the default sprites. This means the full search pattern for (e.g.) a !Sprites21 mode would be as follows:

  !Sprites21  (original mode)
  !SpritesA2  (next squarer mode, alpha sprites)
  !Sprites22  (next squarer mode)
  !SpritesA   (default alpha sprites)
  !Sprites    (default sprites)

  Like with !Sprites11 support, this feature can be toggled off via the SpritesA option if necessary.

  s/Wimp01, s/Wimp04:

  Updated icon plotting code (wimp_SpriteOp_putsprite and calculateinverse) to allow true colour sprites/icons to be rendered shaded/inverted.
  For this to work the Wimp needs a version of SpriteExtend which supports colour mapping (specifically it checks for the relevant ROOL version number).
  The colour mapping function which is used to build the translation tables used for shading/inverting palettised sprites is too slow to be sensibly used on a per-pixel basis, so the first time a shaded/inverted true colour sprite is requested the Wimp will generate a set of lookup tables which can be used by a much simpler colour mapping routine.
  To keep memory usage down these lookup tables only use 4K colours each; however the quality isn't always that great and so this may need revising in future.

Admin:
  Tested on BB-xM


Version 5.34. Tagged as 'Wimp-5_34'
parent c5074988
......@@ -85,6 +85,7 @@
Option RO4, false ; RISC OS 4 extensions
Option Sprites11, true ; sprite selection scheme that allows use of Sprites11 files
Option SpritesA, true ; look for alpha iconsprite files if OS supports the format
Option ToolTables, true ; look for precalculated tool translation tables
Option RegisterMessages, false
......
......@@ -11,13 +11,13 @@
GBLS Module_HelpVersion
GBLS Module_ComponentName
GBLS Module_ComponentPath
Module_MajorVersion SETS "5.33"
Module_Version SETA 533
Module_MajorVersion SETS "5.34"
Module_Version SETA 534
Module_MinorVersion SETS ""
Module_Date SETS "07 Oct 2013"
Module_ApplicationDate SETS "07-Oct-13"
Module_Date SETS "30 Nov 2013"
Module_ApplicationDate SETS "30-Nov-13"
Module_ComponentName SETS "Wimp"
Module_ComponentPath SETS "castle/RiscOS/Sources/Desktop/Wimp"
Module_FullVersion SETS "5.33"
Module_HelpVersion SETS "5.33 (07 Oct 2013)"
Module_FullVersion SETS "5.34"
Module_HelpVersion SETS "5.34 (30 Nov 2013)"
END
/* (5.33)
/* (5.34)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 5.33
#define Module_MajorVersion_CMHG 5.34
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 07 Oct 2013
#define Module_Date_CMHG 30 Nov 2013
#define Module_MajorVersion "5.33"
#define Module_Version 533
#define Module_MajorVersion "5.34"
#define Module_Version 534
#define Module_MinorVersion ""
#define Module_Date "07 Oct 2013"
#define Module_Date "30 Nov 2013"
#define Module_ApplicationDate "07-Oct-13"
#define Module_ApplicationDate "30-Nov-13"
#define Module_ComponentName "Wimp"
#define Module_ComponentPath "castle/RiscOS/Sources/Desktop/Wimp"
#define Module_FullVersion "5.33"
#define Module_HelpVersion "5.33 (07 Oct 2013)"
#define Module_LibraryVersionInfo "5:33"
#define Module_FullVersion "5.34"
#define Module_HelpVersion "5.34 (30 Nov 2013)"
#define Module_LibraryVersionInfo "5:34"
......@@ -688,7 +688,14 @@ loop2 LDRB LR, [R1], #1
LDRB R6, romspr_suffix+1
SUB R5, R5, #'0'
SUB R6, R6, #'0'
loop3 ADD LR, R5, #'0'
loop3
[ SpritesA
CMP R5,R6
LDREQB R0,alphaspriteflag
CMPEQ R0,#255
MOVEQ R5,#'A'-'0' ; Try alpha before square pixels
]
loop4 ADD LR, R5, #'0'
STRB LR, [R2]
ADD LR, R6, #'0'
STRB LR, [R2, #1]
......@@ -700,6 +707,12 @@ loop3 ADD LR, R5, #'0'
SWIVC XOS_Find
BVC ExitWimp ; buffer contains a valid file, so exit
[ SpritesA
CMP R5,#'A'-'0'
MOVEQ R5,R6
BEQ loop4 ; Try square pixels if alpha failed
]
TEQ R6, #3
MOVEQ R6, #2
BEQ loop3 ; after Sprites23, try Sprites22
......@@ -715,6 +728,25 @@ loop3 ADD LR, R5, #'0'
MOVEQ R6, #2
BEQ loop3 ; after Sprites11, try Sprites22
]
[ SpritesA
LDRB R0,alphaspriteflag
CMP R0,#0
BEQ %FT135
MOV R14,#'A'
STRB R14,[R2]
MOV R14,#0
STRB R14,[R2,#1]
MOV R0, #&4C
LDR R1, [SP, #1*4]
SWI XOS_Find ; try just <filename>A before falling back to the original
MOVVC R1, R0
MOVVC R0, #0
SWIVC XOS_Find
BVC ExitWimp
135
]
MOV LR, #0
STRB LR, [R2]
MOV R0, #&4C
......
......@@ -1135,6 +1135,11 @@ stickyedges # 1 ; nonzero => interpret "force on screen"
buttontype # 1 ; nonzero => buttons are release-type
]
[ SpritesA
alphaspriteflag # 1 ; nonzero => *iconsprites looks for alpha sprites
]
checkedcolourmapping # 1 ; nonzero => we've checked for colour mapping support in SpriteExtend (and generated the tables)
[ PoppingIconBar
popiconbar # 1 ; nonzero => enable autofronting
ALIGNHASH 4
......@@ -1143,6 +1148,8 @@ popiconbar_pause # 4 ; configured pause time (cs)
ALIGNHASH 4
inversecolourmap # 4 ; pointer to colour mapping descriptors and LUTs used for true colour sprite shading & inversion
[ MultiClose
nextwindowtoiconise # 4 ; pointer through window stack so far
]
......@@ -2940,7 +2947,15 @@ IconSprites_Code
SUB R5,R5,#'0'
SUB R6,R6,#'0'
SUB sp,sp,#4
02 ADD R14,R5,R6,LSL #8
02
[ SpritesA
CMP R5,R6
LDREQB R0,alphaspriteflag
CMPEQ R0,#255
MOVEQ R5,#'A'-'0' ; Try alpha before square pixels
]
025
ADD R14,R5,R6,LSL #8
ADD R14,R14,#'0'
ADD R14,R14,#'0':SHL:8
STR R14,[sp]
......@@ -2953,6 +2968,12 @@ IconSprites_Code
SWI XWimp_SpriteOp
BVC %FT03
[ SpritesA
CMP R5,#'A'-'0'
MOVEQ R5,R6
BEQ %BT025 ; Try square pixels if alpha failed
]
TEQ R6,#3
MOVEQ R6,#2
BEQ %BT02 ; after Sprites23, try Sprites22
......@@ -2968,6 +2989,23 @@ IconSprites_Code
MOVEQ R6,#2
BEQ %BT02 ; after Sprites11, try Sprites22
]
[ SpritesA
LDRB R0,alphaspriteflag
CMP R0,#0
BEQ %FT029
MOV R14,#'A'
STR R14,[sp]
MOV R0,sp
MOV R1,R3
BL getspritefname
MOV R2,R1
MOV R0,#SpriteReason_MergeSpriteFile
SWI XWimp_SpriteOp ; try just <filename>A before falling back to the original
BVC %FT03
029
]
MOV R2,R3 ; R2 -> original filename
MOV R0,#SpriteReason_MergeSpriteFile
SWI XWimp_SpriteOp
......@@ -3746,6 +3784,8 @@ gotwork
STR R0,tile_pixtable
]
]
STRB R0,checkedcolourmapping
STR R0,inversecolourmap
;
BL freetoolarea ; tidy the tool area
;
......@@ -3767,6 +3807,48 @@ errcantclaim
iconbarlogtable
DCD 0, 20, 50, 100, 200, 500, 1000, 2000, -1
[ SpritesA
checkalphasprites
Entry "R0-R2"
; Check if the kernel + SpriteExtend understand alpha masked sprites
; If they do, assume everything else is OK and that we can render them
LDR R0, testalphaspritemode
MOV R1, #VduExt_NColour
SWI XOS_ReadModeVariable
CMP R2, #1
MOVNE R0, #0
BNE %FT50
LDR R0, =SpriteReason_CheckSpriteArea+512
ADR R1, testalphaspritearea
ADR R2, testalphasprite
SWI XOS_SpriteOp
MOVVS R0, #0
MOVVC R0, #255
50
STRB R0, alphaspriteflag
EXIT
testalphaspritearea
DCD &44
DCD 1
DCD &10
DCD &44
testalphasprite
DCD &34
DCD &61 ; 'a'
DCD 0
DCD 0
DCD 0 ; width
DCD 0 ; height
DCD 0 ; left bit
DCD 0 ; right bit
DCD &2C ; image offset
DCD &30 ; mask offset
testalphaspritemode
DCD &80000001+(90<<1)+(90<<14)+(1<<27) ; 1bpp + alpha mask
; Image & mask data can just be any old garbage
]
;.................................................................................
; Declare resource files to ResourceFS
......@@ -4144,6 +4226,19 @@ getromsprites
MOVEQ R5,#2
MOVEQ R6,#2 ; '1y' or 'x1' -> '22'
]
[ SpritesA
BL checkalphasprites
TEQ R5,#2
TEQEQ R6,#3
MOVEQ R0,#0
STREQB R0,alphaspriteflag ; Completely ignore alpha sprites in mode 23
LDRNEB R0,alphaspriteflag
CMP R0,#255 ; If alpha sprites supported
CMPEQ R5,R6 ; And square pixel mode
MOVEQ R5,#'A' ; Look for alpha version
]
ADD R14,R5,R6,LSL #8
ADD R14,R14,#'0'
ADD R14,R14,#'0':SHL:8
......@@ -4152,7 +4247,14 @@ getromsprites
STR R14,romspr_suffix
;
SUB sp,sp,#4
01 ADD R14,R5,R6,LSL #8
01
[ SpritesA
CMP R5,R6
LDREQB R0,alphaspriteflag
CMPEQ R0,#255
MOVEQ R5,#'A'-'0' ; Try alpha before square pixels
]
02 ADD R14,R5,R6,LSL #8
ADD R14,R14,#'0'
ADD R14,R14,#'0':SHL:8
STR R14,[sp]
......@@ -4166,6 +4268,12 @@ getromsprites
;
BVC %FT04
[ SpritesA
CMP R5,#'A'-'0'
MOVEQ R5,R6
BEQ %BT02 ; Try square pixels if alpha failed
]
TEQ R6,#3
MOVEQ R6,#2
BEQ %BT01 ; after Sprites23, try Sprites22
......@@ -4181,6 +4289,22 @@ getromsprites
MOVEQ R6,#2
BEQ %BT01 ; after Sprites11, try Sprites22
]
[ SpritesA
LDRB R0,alphaspriteflag
CMP R0,#0
BEQ %FT03
MOV R14,#'A'
STR R14,[sp]
MOV R0,sp
ADR R1,spritesfname
BL getspritefname
MOV R0,#OSFind_ReadFile
SWI XOS_Find ; try just <filename>A before falling back to the original
BVC %FT04
03
]
ADR R1,spritesfname ; R1 -> original filename
MOV R0,#OSFind_ReadFile ; try again!
SWI XOS_Find
......@@ -4596,11 +4720,17 @@ deallocateptrs ROUT
LDR R2,fileaddress
CMP R2,#0
BLNE XROS_Module ; release the template loading buffer (ignore errors)
;
LDR R2,inversecolourmap
CMP R2,#0
BLNE XROS_Module ; release colour mapping tables
;
STR R1,pixtable_at
STR R1,pixtable_size
STR R1,filehandle
STR R1,fileaddress ; tag as free'd
STR R1,inversecolourmap
STRB R1,checkedcolourmapping ; ensure we check again before we try using the duff pointer
;
BL freelist ; de-allocate list buffer (for sprite cache)
BL freetoolarea
......
......@@ -3892,7 +3892,7 @@ scaled
BL wimp_SpriteOp
ADD sp,sp,#4*4
Pull "R8-R11"
Pull "R1,R6-R7,PC"
Pull "R1,R5-R7,PC"
;
; Plot sprite
......@@ -3903,7 +3903,7 @@ scaled
;
wimp_SpriteOp_putsprite
Push "R1,R6-R7,LR"
Push "R1,R5-R7,LR"
;
LDR R7,pixtable_at ; -> translation table
;
......@@ -3911,7 +3911,7 @@ wimp_SpriteOp_putsprite
[ PlotSpritesFromPalette
BICNE R5,R5,#16 ; ensure we don't use the palette
]
BLNE calcinverse ; updates R7
BLNE calcinverse ; updates R5, R7
;
LDRB R0,sprite_needsfactors
TEQ R0,#0 ; do I need to translate
......@@ -3924,7 +3924,7 @@ wimp_SpriteOp_putsprite
MOV R0,#SpriteReason_PutSpriteUserCoords
unscaled
BL wimp_SpriteOp
Pull "R1,R6-R7,PC"
Pull "R1,R5-R7,PC"
;
; do sprite operation
......@@ -3992,9 +3992,10 @@ do_spriteop
;----------------------------------------------------------
; calculate new ttr table to deal with inverting the sprite
; Entry: R1 = icon flag word
; R5 = plot flags
; R0,R6 = input/output log2bpp <-- don't count on this!
; R7 --> pixtable
; Exit: pixtable updated to allow for inverting/shading
; Exit: R5, R7 updated to allow for inverting/shading
;---------------------------------------------------------
calcinverse ROUT
......@@ -4003,11 +4004,14 @@ calcinverse ROUT
ADR R7,inversefunc ; pointer to the transfer function
MOV R6,R1
LDR R1,sprite_log2bpp
CMP R1,#3
BGT %FT50
LDR R4,pixtable_at
TEQ R4,#0
EXIT EQ ; no pixtable!
[ true ; BJGA bugfix: was sometimes trying to work from a paged-out sprite!
LDR R1, sprite_log2bpp ; if <256-colour sprite without palette, we pass palette from Wimp workspace, so no problem
; if <256-colour sprite without palette, we pass palette from Wimp workspace, so no problem
CMP R1, #3 ; if <256-colour sprite with palette, cachespritedata has already updated selecttable_args
BLGE cachespriteaddress ; R2 -> this sprite, ie *not* the first sprite in this run of matching-mode sprites!
EXIT VS ; bail out now if sprite not found!
......@@ -4032,6 +4036,30 @@ calcinverse ROUT
CLRV
EXIT
50
; For true colour sprites we want to ignore pixtable_at (it could be
; left pointing at an old table) and set things up to use a colour
; mapping descriptor - if SpriteExtend supports them
LDRB R7,checkedcolourmapping
CMP R7,#0
BLEQ checkandgenerateinversecolourmap
LDR R7,inversecolourmap
CMP R7,#0
EXIT EQ
ASSERT is_inverted = 1<<21
ASSERT is_shaded = 1<<22
AND R1,R6,#is_inverted+is_shaded
SUB R1,R1,#is_inverted ; at least one should be set
ADD R7,R7,R1,LSR #21-3 ; index the correct descriptor
STR R7,[SP,#7*4] ; swap pixtable pointer for descriptor
CLRV
PullEnv
ORR R5,R5,#128 ; set colour mapping flag
STRB R5,sprite_needsfactors ; and ensure PutScaled used
MOV PC,LR
;------------------------------------------------------------------------------
; Routine called to process the RGB and generate a suitable output RGB based
; on the shading or inversion required.
......@@ -4201,6 +4229,84 @@ inversefunc EntryS "R1-R4"
ORR R0,R0,R3,LSL #24 ; recombine to make &BBGGRRxx
EXITS
;------------------------------------------------------------------------------
; Check for whether SpriteExtend supports colour mapping descriptors
; If it does, generate a series of lookup tables we can use for shading
; or inverting true colour sprites.
;------------------------------------------------------------------------------
checkandgenerateinversecolourmap ROUT
Entry "r0-r3,r12"
MOV R0,#255
STRB R0,checkedcolourmapping
; Checking explicitly for colour mapping without rendering something
; isn't really possible, so just use a simple RMEnsure
ADR R0,rmensure_colourmapping
SWI XOS_CLI
BVS %FT90
; Allocate the memory we need
; We're going to build three lookup tables containing 4K words each
; Plus we need 3*8 bytes of header space for the colour mapping descriptors
MOV R0,#ModHandReason_Claim
LDR R3,=4096*4*3+8*3
BL XROS_Module
MOVVS R0,#0
STRVSB R0,checkedcolourmapping ; try again later if this allocation failed
BVS %FT90
STR R2,inversecolourmap
ASSERT is_shaded = is_inverted*2
ADD R3,R2,#8*3
MOV R12,#is_inverted
10
ADR R14,colourmapfunc
STMIA R2!,{R3,R14} ; set up the descriptor
; Now loop around generating a 4K colour lookup table, using inversefunc
; to perform the inversion/shading
MOV R1,#0
20
MOV R0,R1
BL inversefunc
STR R0,[R3],#4
ADD R1,R1,#&00001100 ; Increment red
TST R1, #&00000F00 ; Check for overflow
ADDEQ R1,R1,#&000FF000 ; Increment green, accounting for the overflow from red
TSTEQ R1, #&000F0000
ADDEQ R1,R1,#&0FF00000 ; Blue
TSTEQ R1, #&0F000000
BNE %BT20
ADD R12,R12,#is_inverted
TST R12,#is_inverted+is_shaded
BNE %BT10
90
CLRV
EXIT
; 1.55 is the first version of ROOL's SpriteExtend to support colour mapping
rmensure_colourmapping
DCB "RMEnsure SpriteExtend 1.55", 0
ALIGN
;------------------------------------------------------------------------------
; Colour mapping routine which uses a 4K colour lookup table to perform
; any arbitrary conversion
;
; in:
; R0 = &BBGGRR00
; R12 = table pointer
; out:
; R0 = updated colour
; All other registers preserved
;------------------------------------------------------------------------------
colourmapfunc ROUT
Entry "R1"
AND R1,R0, #&0000F000 ; High red nibble
AND R14,R0,#&00F00000 ; green
AND R0,R0, #&F0000000 ; blue
ADD R1,R12,R1,LSR #10 ; add red straight onto address to try and avoid stalling on R0
ORR R0,R0,R14,LSL #4
LDR R0,[R1,R0,LSR #18]
EXIT
;; ---------------------------------------------------------------------------
;; Miscellaneous routines
;; ---------------------------------------------------------------------------
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment