Welcome to the Creatures Wiki! Log in and join the community.

Difference between revisions of "555/565"

From Creatures Wiki
Jump to navigation Jump to search
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
== Summary ==
 
== Summary ==
555 and 565 are used to describe different allocations of bits inside a 16-bit integer representing a pixel, as used in [[Creatures]] [[sprite]] files such as [[BLK files|BLK]] and [[C16 files|C16]].
+
555 and 565 are used to describe different allocations of bits inside a 16-bit integer representing a pixel, as used in [[Creatures]] [[sprite]] files such as [[BLK files|BLK]] and [[C16 files|C16]].  This is briefly discussed in the [[Creating Agent Art]] tutorial for Creatures 2.
  
 
== Technical Information ==
 
== Technical Information ==
Line 7: Line 7:
 
<pre>
 
<pre>
 
  0123 4567 0123 4567
 
  0123 4567 0123 4567
  -rrr rr-- ---- ----
+
  -rrr rr-- ---- ---- (bitmask: 0x7C00)
  ---- --gg ggg- ----
+
  ---- --gg ggg- ---- (bitmask: 0x3E0)
  ---- ---- ---b bbbb
+
  ---- ---- ---b bbbb (bitmask: 0x1F)
 
</pre>
 
</pre>
  
Line 16: Line 16:
 
<pre>
 
<pre>
 
  0123 4567 0123 4567
 
  0123 4567 0123 4567
  rrrr r--- ---- ----
+
  rrrr r--- ---- ---- (bitmask: 0xF800)
  ---- -ggg ggg- ----
+
  ---- -ggg ggg- ---- (bitmask: 0x7E0)
  ---- ---- ---b bbbb
+
  ---- ---- ---b bbbb (bitmask: 0x1F)
 
</pre>
 
</pre>
  
Line 30: Line 30:
  
 
#define DECODE_555(v)          \
 
#define DECODE_555(v)          \
(qRgb(                      \
+
(RGB(                      \
  ((uint32_t)(v) & 0x7800) &gt;&gt; 7,  \
+
  ((uint32_t)(v) & 0x7c00) &gt;&gt; 7,  \
 
  ((uint32_t)(v) & 0x03e0) &gt;&gt; 2,  \
 
  ((uint32_t)(v) & 0x03e0) &gt;&gt; 2,  \
 
  ((uint32_t)(v) & 0x001f) &lt;&lt; 3  \
 
  ((uint32_t)(v) & 0x001f) &lt;&lt; 3  \
Line 37: Line 37:
  
 
#define DECODE_565(v)          \
 
#define DECODE_565(v)          \
(qRgb(                      \
+
(RGB(                      \
 
  ((uint32_t)(v) & 0xf800) &gt;&gt; 8 , \
 
  ((uint32_t)(v) & 0xf800) &gt;&gt; 8 , \
 
  ((uint32_t)(v) & 0x07e0) &gt;&gt; 3 , \
 
  ((uint32_t)(v) & 0x07e0) &gt;&gt; 3 , \

Revision as of 21:41, 5 September 2018

Summary

555 and 565 are used to describe different allocations of bits inside a 16-bit integer representing a pixel, as used in Creatures sprite files such as BLK and C16. This is briefly discussed in the Creating Agent Art tutorial for Creatures 2.

Technical Information

In 555 format, the bits are allocated as follows:

 0123 4567 0123 4567
 -rrr rr-- ---- ---- (bitmask: 0x7C00)
 ---- --gg ggg- ---- (bitmask: 0x3E0)
 ---- ---- ---b bbbb (bitmask: 0x1F)

In 565 format, the bits are allocated as follows:

 0123 4567 0123 4567
 rrrr r--- ---- ---- (bitmask: 0xF800)
 ---- -ggg ggg- ---- (bitmask: 0x7E0)
 ---- ---- ---b bbbb (bitmask: 0x1F)

The following macros can be used in C or C++ to decode these values to normal 24-bit format:


/* Decoding macros by bd_ aka bdonlan. I release these into the public domain. */

#define RGB(r, g, b) ((r) << 16 | (g) << 8 | (b))

#define DECODE_555(v)           \
	(RGB(                      \
		  ((uint32_t)(v) & 0x7c00) >> 7,  \
		  ((uint32_t)(v) & 0x03e0) >> 2,  \
		  ((uint32_t)(v) & 0x001f) << 3  \
		 ))

#define DECODE_565(v)           \
	(RGB(                      \
		  ((uint32_t)(v) & 0xf800) >> 8 , \
		  ((uint32_t)(v) & 0x07e0) >> 3 , \
		  ((uint32_t)(v) & 0x001f) << 3   \
		 ))