- int32_t *pal = ((int32_t*)p->data[1]) + first_clr;
- for(t = 0; t < colors; t++){
- *pal++ = (0xff<<24) | bytestream_get_le24(&buf);
+ uint32_t *pal = ((uint32_t *)p->data[1]) + first_clr;
+
+ switch (pal_sample_size) {
+ case 3:
+ /* RGB24 */
+ for (t = 0; t < colors; t++)
+ *pal++ = (0xffU<<24) | bytestream_get_le24(&buf);
+ break;
+ case 2:
+ /* RGB555 */
+ for (t = 0; t < colors; t++) {
+ uint32_t v = bytestream_get_le16(&buf);
+ v = ((v & 0x7C00) << 9) |
+ ((v & 0x03E0) << 6) |
+ ((v & 0x001F) << 3);
+ /* left bit replication */
+ v |= (v & 0xE0E0E0U) >> 5;
+ *pal++ = (0xffU<<24) | v;
+ }
+ break;