Example #1
0
static void
flx_decode_color (GstFlxDec * flxdec, guchar * data, guchar * dest, gint scale)
{
  guint packs, count, indx;

  g_return_if_fail (flxdec != NULL);

  packs = (data[0] + (data[1] << 8));

  data += 2;
  indx = 0;

  GST_LOG ("GstFlxDec: cmap packs: %d", packs);
  while (packs--) {
    /* color map index + skip count */
    indx += *data++;

    /* number of rgb triplets */
    count = *data++ & 0xff;
    if (count == 0)
      count = 256;

    GST_LOG ("GstFlxDec: cmap count: %d (indx: %d)", count, indx);
    flx_set_palette_vector (flxdec->converter, indx, count, data, scale);

    data += (count * 3);
  }
}
static gboolean
flx_decode_color (GstFlxDec * flxdec, GstByteReader * reader,
    GstByteWriter * writer, gint scale)
{
  guint8 count, indx;
  guint16 packs;

  if (!gst_byte_reader_get_uint16_le (reader, &packs))
    goto error;
  indx = 0;

  GST_LOG ("GstFlxDec: cmap packs: %d", (guint) packs);
  while (packs--) {
    const guint8 *data;
    guint16 actual_count;

    /* color map index + skip count */
    if (!gst_byte_reader_get_uint8 (reader, &indx))
      goto error;

    /* number of rgb triplets */
    if (!gst_byte_reader_get_uint8 (reader, &count))
      goto error;

    actual_count = count == 0 ? 256 : count;

    if (!gst_byte_reader_get_data (reader, count * 3, &data))
      goto error;

    GST_LOG_OBJECT (flxdec, "cmap count: %d (indx: %d)", actual_count, indx);
    flx_set_palette_vector (flxdec->converter, indx, actual_count,
        (guchar *) data, scale);
  }

  return TRUE;

error:
  GST_ERROR_OBJECT (flxdec, "Error decoding color palette");
  return FALSE;
}