home *** CD-ROM | disk | FTP | other *** search
/ Kosovo Orphans' Appeal Charity CD / KosovoOrphansAppeal.iso / graphicssoftware / _changefsi / 256sprites < prev    next >
Text File  |  1996-03-11  |  5KB  |  123 lines

  1.          256 entry palettes in the RISC OS sprite format
  2.          ===============================================
  3.  
  4. Introduction
  5. ------------
  6.  
  7. The RISC OS sprite format provides for pictures with and without palettes in
  8. 1, 2 and 4 bits per pixel. For 8 bits per pixel a picture with no palette is
  9. dealt with rationally, but a picture with a palette will end up with 64
  10. (pairs of) palette entries. (The pairs of entries are for the possibly
  11. flashing colours). The reader of the format must know how VIDC1's 16 entry
  12. palette works in 8bit mode and apply the necessary bit reordering.
  13.  
  14. By stepping gingerly around the sprite operations and using ColourTrans
  15. appropriately, sprites with 256 entry palettes can be created and
  16. displayed on all RISC OS machines. Of course, this ability to create and
  17. process a sprite with (say) 256 grey levels in it does not magically
  18. endow the hardware with the ability to display 256 grey levels! The display
  19. will be as close as possible i.e. 16 grey levels with standard hardware;
  20. unless the machine has been hardware extended (e.g. the PCATS Graphics
  21. Enhancer).
  22.  
  23. Format of a 256 entry palette sprite
  24. ------------------------------------
  25.  
  26. A 256 entry palette sprite is precisely like a 16 entry palette sprite, save
  27. that there are 256 palette entries, each one consisting of a pair of
  28. "palette entry" words of the form &BBGGRR00 as for ColourTrans. All bits of
  29. the entry are significant.
  30.  
  31. Creating a 256 entry palette sprite
  32. -----------------------------------
  33.  
  34. If you use OS_SpriteOp 15 to create a sprite with a palette, the OS will
  35. create a 64 entry palette as before. The best thing to do is to create a
  36. sprite with no palette and then to add 2048 to the following entries:
  37.  
  38. word 1: offset to next sprite
  39. word 9: offset to sprite image
  40. word 10: offset to sprite image/transparency mask
  41.  
  42. of the sprite and then to add 2048 to
  43.  
  44. word 4: offset to first free word
  45.  
  46. of the sprite area control block.
  47.  
  48. Then write the 256 double words of palette entries starting at word 12
  49. of the sprite, keeping both items in a pair identical:
  50.  
  51. SYS"OS_SpriteOp",&10f,ram%,name$,0,X,Y,spritemode
  52. sptr%=ram%+ram%!8
  53. pal%=sptr%+11*4
  54. !(sptr%+8*4)+=2048
  55. !(sptr%+9*4)+=2048
  56. !sptr%+=2048
  57. !(ram%+12)+=2048
  58. FORZ%=0TO255:B%=palette!(Z%<<2)ANDNOT&FF
  59.  pal%!(Z%*8)=B%:pal%!(Z%*8+4)=B%
  60. NEXT
  61.  
  62. Manipulating a 256 entry palette sprite
  63. ---------------------------------------
  64.  
  65. All sprite operations work on the 256 entry palette sprite. One can even
  66. switch output to it and generate 256 grey level output into it (with
  67. appropriate care over the GCOL and TINT values required by the OS). Sprite
  68. areas containing 256 entry palette sprites may be loaded, saved etc.
  69.  
  70. Testing to see if a sprite is a 256 entry palette sprite
  71. --------------------------------------------------------
  72.  
  73. After creation, the 256 entry palette sprite behaves just like all the
  74. others, so its important to be able to distinguish it on the occasions when
  75. it is needed (for example, when displaying it on the screen).
  76.  
  77. A 256 entry palette sprite will have the lowest of words 9 and 10 of the
  78. sprite control block equal to 2048+44 (&82C). (If it is already known that
  79. the sprite has no transparency mask, then one can test only word 9).
  80.  
  81. Displaying a 256 entry palette sprite
  82. -------------------------------------
  83.  
  84. The call "ColourTrans_SelectTable" takes a 64 entry palette sprite (and 2, 4
  85. and 16) and returns a pixel translation table as needed for OS_SpriteOp 52.
  86. For a 256 entry sprite, one needs to build a similar pixel translation
  87. table directly. The following code will compute a pixel translation table
  88. for any sprite (which hasn't a transparency mask):
  89.  
  90. IF sptr%!32=44 THEN
  91.  palptr%=0
  92. ELSE
  93.  FOR grab%=0 TO 2048-8 STEP 8
  94.   paltemp%!(grab%>>1)=sptr%!(grab%+44)
  95.  NEXT
  96.  palptr%=paltemp%
  97. ENDIF
  98. FORQ%=0TO255:pixtrans%?Q%=Q%:NEXT
  99. IFsptr%!32=44+2048 THEN
  100.  FORQ%=0TO255
  101.   SYS"ColourTrans_ReturnColourNumber",palptr%!(Q%<<2) TO pixtrans%?Q%
  102.  NEXT
  103. ELSE
  104.  SYS "ColourTrans_SelectTable",m,palptr%,-1,-1,pixtrans%
  105. ENDIF
  106. spx%=-1:FORQ%=0TO255:IFpixtrans%?Q%<>Q% spx%=pixtrans%
  107. NEXT
  108.  
  109. spx% is either -1 (if no translation needs to be done - this speeds up
  110. OS_SpriteOp 52 a lot!) or pixtrans%; it is passed to OS_SpriteOp 52 in
  111. register 7.
  112.  
  113. Conclusion
  114. ----------
  115.  
  116. The ability to store, process and display 256 entry palette sprites
  117. represents a small but useful gain for the RISC OS desktop. Common formats
  118. can be converted to sprites without any loss of information and meaningfully
  119. displayed. (Greater fidelity of display can be had with !ChangeFSI (which
  120. can read and generate 256 entry palette sprites) or !Translator)
  121.  
  122. It is still a good idea to use the default desktop palette whenever possible.
  123.