if ((pData->bHasIDAT) || (pData->bHasJDAT))
if ((pData->bHasIDAT) || (pData->bHasJDAT) || (pData->bHasJDAA))
READ_CHUNK (read_bkgd){#ifdef MNG_SUPPORT_DISPLAY  mng_imagep     pImage = (mng_imagep)pData->pCurrentobj;  mng_imagedatap pBuf;#endif#ifdef MNG_SUPPORT_TRACE  MNG_TRACE (pData, MNG_FN_READ_BKGD, MNG_LC_START)#endif                                       /* sequence checks */#ifdef MNG_INCLUDE_JNG  if ((!pData->bHasMHDR) && (!pData->bHasIHDR) &&      (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR))#else  if ((!pData->bHasMHDR) && (!pData->bHasIHDR) &&      (!pData->bHasBASI) && (!pData->bHasDHDR)    )#endif    MNG_ERROR (pData, MNG_SEQUENCEERROR)#ifdef MNG_INCLUDE_JNG  if ((pData->bHasIDAT) || (pData->bHasJDAT))#else  if (pData->bHasIDAT)#endif    MNG_ERROR (pData, MNG_SEQUENCEERROR)  if (iRawlen > 6)                     /* it just can't be bigger than that! */    MNG_ERROR (pData, MNG_INVALIDLENGTH)#ifdef MNG_INCLUDE_JNG                 /* length checks */  if (pData->bHasJHDR)  {    if (((pData->iJHDRcolortype == 8) || (pData->iJHDRcolortype == 12)) && (iRawlen != 2))      MNG_ERROR (pData, MNG_INVALIDLENGTH)    if (((pData->iJHDRcolortype == 10) || (pData->iJHDRcolortype == 14)) && (iRawlen != 6))      MNG_ERROR (pData, MNG_INVALIDLENGTH)  }  else#endif /* MNG_INCLUDE_JNG */  if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR))  {    if (((pData->iColortype == 0) || (pData->iColortype == 4)) && (iRawlen != 2))      MNG_ERROR (pData, MNG_INVALIDLENGTH)    if (((pData->iColortype == 2) || (pData->iColortype == 6)) && (iRawlen != 6))      MNG_ERROR (pData, MNG_INVALIDLENGTH)    if ((pData->iColortype == 3) && (iRawlen != 1))      MNG_ERROR (pData, MNG_INVALIDLENGTH)  }  else  {    if (iRawlen != 6)                  /* global is always 16-bit RGB ! */      MNG_ERROR (pData, MNG_INVALIDLENGTH)  }#ifdef MNG_INCLUDE_JNG  if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR))#else  if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR))#endif    pData->bHasBKGD = MNG_TRUE;        /* indicate bKGD available */  else    pData->bHasglobalBKGD = (mng_bool)(iRawlen != 0);#ifdef MNG_SUPPORT_DISPLAY  if (!pImage)                         /* if no object dump it in obj 0 */    pImage = (mng_imagep)pData->pObjzero;  pBuf = pImage->pImgbuf;              /* address object buffer */#ifdef MNG_INCLUDE_JNG  if (pData->bHasJHDR)  {    pBuf->bHasBKGD = MNG_TRUE;         /* tell the object it's got bKGD now */    switch (pData->iJHDRcolortype)     /* store fields for future reference */    {      case  8 : ;      case 12 : {                      /* gray */                  pBuf->iBKGDgray  = mng_get_uint16 (pRawdata);                  break;                }      case 10 : ;      case 14 : {                      /* rgb */                  pBuf->iBKGDred   = mng_get_uint16 (pRawdata);                  pBuf->iBKGDgreen = mng_get_uint16 (pRawdata+2);                  pBuf->iBKGDblue  = mng_get_uint16 (pRawdata+4);                  break;                }    }  }  else#endif /* MNG_INCLUDE_JNG */  if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR))  {    pBuf->bHasBKGD = MNG_TRUE;         /* tell the object it's got bKGD now */    switch (pData->iColortype)         /* store fields for future reference */    {      case 0: {                        /* gray */                pBuf->iBKGDgray  = mng_get_uint16 (pRawdata);                break;              }      case 2: {                        /* rgb */                pBuf->iBKGDred   = mng_get_uint16 (pRawdata);                pBuf->iBKGDgreen = mng_get_uint16 (pRawdata+2);                pBuf->iBKGDblue  = mng_get_uint16 (pRawdata+4);                break;              }      case 3: {                        /* indexed */                pBuf->iBKGDindex = *pRawdata;                break;              }    }  }  else                                 /* store as global */  {    if (iRawlen)    {      pData->iGlobalBKGDred   = mng_get_uint16 (pRawdata);      pData->iGlobalBKGDgreen = mng_get_uint16 (pRawdata+2);      pData->iGlobalBKGDblue  = mng_get_uint16 (pRawdata+4);    }    {                                  /* create an animation object */      mng_retcode iRetcode = create_ani_bkgd (pData, pData->iGlobalBKGDred,                                              pData->iGlobalBKGDgreen,                                              pData->iGlobalBKGDblue);      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_bkgdp)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0);    ((mng_bkgdp)*ppChunk)->iType  = pData->iColortype;    if (iRawlen)    {      switch (iRawlen)                 /* guess from length */      {        case 1 : {                     /* indexed */                   ((mng_bkgdp)*ppChunk)->iType  = 3;                   ((mng_bkgdp)*ppChunk)->iIndex = *pRawdata;                   break;                 }        case 2 : {                     /* gray */                   ((mng_bkgdp)*ppChunk)->iType  = 0;                   ((mng_bkgdp)*ppChunk)->iGray  = mng_get_uint16 (pRawdata);                   break;                 }        case 6 : {                     /* rgb */                   ((mng_bkgdp)*ppChunk)->iType  = 2;                   ((mng_bkgdp)*ppChunk)->iRed   = mng_get_uint16 (pRawdata);                   ((mng_bkgdp)*ppChunk)->iGreen = mng_get_uint16 (pRawdata+2);                   ((mng_bkgdp)*ppChunk)->iBlue  = mng_get_uint16 (pRawdata+4);                   break;                 }      }    }  }#endif /* MNG_STORE_CHUNKS */#ifdef MNG_SUPPORT_TRACE  MNG_TRACE (pData, MNG_FN_READ_BKGD, MNG_LC_END)#endif  return MNG_NOERROR;                  /* done */}