if ((iRawlen == 0) && (!pData->bHasglobalTRNS))
if ((iRawlen == 0) && (!pData->bHasglobalPLTE))
READ_CHUNK (read_plte){#if defined(MNG_SUPPORT_DISPLAY) || defined(MNG_STORE_CHUNKS)  mng_uint32  iX;  mng_uint8p  pRawdata2;#endif#ifdef MNG_SUPPORT_DISPLAY  mng_uint32  iRawlen2;#endif#ifdef MNG_SUPPORT_TRACE  MNG_TRACE (pData, MNG_FN_READ_PLTE, MNG_LC_START)#endif                                       /* sequence checks */  if ((!pData->bHasMHDR) && (!pData->bHasIHDR) &&      (!pData->bHasBASI) && (!pData->bHasDHDR)    )    MNG_ERROR (pData, MNG_SEQUENCEERROR)#ifdef MNG_INCLUDE_JNG  if ((pData->bHasIDAT) || (pData->bHasJHDR))#else  if (pData->bHasIDAT)#endif      MNG_ERROR (pData, MNG_SEQUENCEERROR)                                       /* multiple PLTE only inside BASI */  if ((pData->bHasPLTE) && (!pData->bHasBASI))    MNG_ERROR (pData, MNG_MULTIPLEERROR)                                       /* length must be multiple of 3 */  if (((iRawlen % 3) != 0) || (iRawlen > 768))    MNG_ERROR (pData, MNG_INVALIDLENGTH)  if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR))  {                                    /* only allowed for indexed-color or                                          rgb(a)-color! */    if ((pData->iColortype != 2) && (pData->iColortype != 3) && (pData->iColortype != 6))      MNG_ERROR (pData, MNG_CHUNKNOTALLOWED)                                       /* empty only allowed if global present */    if ((iRawlen == 0) && (!pData->bHasglobalTRNS))        MNG_ERROR (pData, MNG_CANNOTBEEMPTY)  }  else  {    if (iRawlen == 0)                  /* cannot be empty as global! */      MNG_ERROR (pData, MNG_CANNOTBEEMPTY)  }  if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR))    pData->bHasPLTE = MNG_TRUE;        /* got it! */  else    pData->bHasglobalPLTE = MNG_TRUE;  pData->iPLTEcount = iRawlen / 3;  #ifdef MNG_SUPPORT_DISPLAY  if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR))  {    mng_imagep     pImage;    mng_imagedatap pBuf;    if (pData->bHasDHDR)               /* processing delta-image ? */    {                                  /* store in object 0 !!! */      pImage           = (mng_imagep)pData->pObjzero;      pBuf             = pImage->pImgbuf;      pBuf->bHasPLTE   = MNG_TRUE;     /* it's definitely got a PLTE now */      pBuf->iPLTEcount = iRawlen / 3;  /* this is the exact length */      pRawdata2        = pRawdata;     /* copy the entries */      for (iX = 0; iX < iRawlen / 3; iX++)      {        pBuf->aPLTEentries[iX].iRed   = *pRawdata2;        pBuf->aPLTEentries[iX].iGreen = *(pRawdata2+1);        pBuf->aPLTEentries[iX].iBlue  = *(pRawdata2+2);        pRawdata2 += 3;      }    }    else    {                                  /* get the current object */      pImage = (mng_imagep)pData->pCurrentobj;      if (!pImage)                     /* no object then dump it in obj 0 */        pImage = (mng_imagep)pData->pObjzero;      pBuf = pImage->pImgbuf;          /* address the object buffer */      pBuf->bHasPLTE = MNG_TRUE;       /* and tell it it's got a PLTE now */      if (!iRawlen)                    /* if empty, inherit from global */      {        pBuf->iPLTEcount = pData->iGlobalPLTEcount;        MNG_COPY (pBuf->aPLTEentries, pData->aGlobalPLTEentries,                  sizeof (pBuf->aPLTEentries))        if (pData->bHasglobalTRNS)     /* also copy global tRNS ? */        {                              /* indicate tRNS available */          pBuf->bHasTRNS = MNG_TRUE;          iRawlen2  = pData->iGlobalTRNSrawlen;          pRawdata2 = (mng_uint8p)(pData->aGlobalTRNSrawdata);                                       /* global length oke ? */          if ((iRawlen2 == 0) || (iRawlen2 > pBuf->iPLTEcount))            MNG_ERROR (pData, MNG_GLOBALLENGTHERR)                                       /* copy it */          pBuf->iTRNScount = iRawlen2;          MNG_COPY (pBuf->aTRNSentries, pRawdata2, iRawlen2)        }      }      else      {                                /* store fields for future reference */        pBuf->iPLTEcount = iRawlen / 3;        pRawdata2        = pRawdata;        for (iX = 0; iX < pBuf->iPLTEcount; iX++)        {          pBuf->aPLTEentries[iX].iRed   = *pRawdata2;          pBuf->aPLTEentries[iX].iGreen = *(pRawdata2+1);          pBuf->aPLTEentries[iX].iBlue  = *(pRawdata2+2);          pRawdata2 += 3;        }      }    }  }  else                                 /* store as global */  {    pData->iGlobalPLTEcount = iRawlen / 3;    pRawdata2               = pRawdata;    for (iX = 0; iX < pData->iGlobalPLTEcount; iX++)    {      pData->aGlobalPLTEentries[iX].iRed   = *pRawdata2;      pData->aGlobalPLTEentries[iX].iGreen = *(pRawdata2+1);      pData->aGlobalPLTEentries[iX].iBlue  = *(pRawdata2+2);      pRawdata2 += 3;    }    {                                  /* create an animation object */      mng_retcode iRetcode = create_ani_plte (pData, pData->iGlobalPLTEcount,                                              pData->aGlobalPLTEentries);      if (iRetcode)                    /* on error bail out */        return iRetcode;    }  }#endif /* MNG_SUPPORT_DISPLAY */#ifdef MNG_STORE_CHUNKS  if (pData->bStorechunks)  {                                    /* initialize storage */    mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk);    if (iRetcode)                      /* on error bail out */      return iRetcode;                                       /* store the fields */    ((mng_pltep)*ppChunk)->bEmpty      = (mng_bool)(iRawlen == 0);    ((mng_pltep)*ppChunk)->iEntrycount = iRawlen / 3;    pRawdata2                          = pRawdata;    for (iX = 0; iX < ((mng_pltep)*ppChunk)->iEntrycount; iX++)    {      ((mng_pltep)*ppChunk)->aEntries[iX].iRed   = *pRawdata2;      ((mng_pltep)*ppChunk)->aEntries[iX].iGreen = *(pRawdata2+1);      ((mng_pltep)*ppChunk)->aEntries[iX].iBlue  = *(pRawdata2+2);      pRawdata2 += 3;    }  }#endif /* MNG_STORE_CHUNKS */#ifdef MNG_SUPPORT_TRACE  MNG_TRACE (pData, MNG_FN_READ_PLTE, MNG_LC_END)#endif  return MNG_NOERROR;                  /* done */}