pBuftarget->bHasPLTE = MNG_TRUE;  for (iX = 0; iX < pBufdelta->iPLTEcount; iX++) { pBuftarget->aPLTEentries[iX].iRed   = pBufdelta->aPLTEentries[iX].iRed; pBuftarget->aPLTEentries[iX].iGreen = pBufdelta->aPLTEentries[iX].iGreen; pBuftarget->aPLTEentries[iX].iBlue  = pBufdelta->aPLTEentries[iX].iBlue;
pBuftarget->bHasPLTE = MNG_TRUE;  for (iX = 0; iX < pBufdelta->iPLTEcount; iX++) { pBuftarget->aPLTEentries[iX].iRed   = pBufdelta->aPLTEentries[iX].iRed; pBuftarget->aPLTEentries[iX].iGreen = pBufdelta->aPLTEentries[iX].iGreen; pBuftarget->aPLTEentries[iX].iBlue  = pBufdelta->aPLTEentries[iX].iBlue; } }  if (pBufdelta->bHasTRNS)            { switch (pData->iColortype)        { case 0: {                       pBuftarget->iTRNSgray  = pBufdelta->iTRNSgray; pBuftarget->iTRNSred   = 0; pBuftarget->iTRNSgreen = 0; pBuftarget->iTRNSblue  = 0; pBuftarget->iTRNScount = 0; break; } case 2: {                       pBuftarget->iTRNSgray  = 0; pBuftarget->iTRNSred   = pBufdelta->iTRNSred; pBuftarget->iTRNSgreen = pBufdelta->iTRNSgreen; pBuftarget->iTRNSblue  = pBufdelta->iTRNSblue; pBuftarget->iTRNScount = 0; break; } case 3: {                       pBuftarget->iTRNSgray  = 0; pBuftarget->iTRNSred   = 0; pBuftarget->iTRNSgreen = 0; pBuftarget->iTRNSblue  = 0;  if ((!pBuftarget->bHasTRNS) || (pBuftarget->iTRNScount < pBufdelta->iTRNScount)) pBuftarget->iTRNScount = pBufdelta->iTRNScount;  MNG_COPY (pBuftarget->aTRNSentries, pBufdelta->aTRNSentries, pBufdelta->iTRNScount) break; } }  pBuftarget->bHasTRNS = MNG_TRUE;  }  if (pBufdelta->bHasBKGD)            {                                   pBuftarget->bHasBKGD   = MNG_TRUE; pBuftarget->iBKGDindex = pBufdelta->iBKGDindex; pBuftarget->iBKGDgray  = pBufdelta->iBKGDgray; pBuftarget->iBKGDred   = pBufdelta->iBKGDred; pBuftarget->iBKGDgreen = pBufdelta->iBKGDgreen; pBuftarget->iBKGDblue  = pBufdelta->iBKGDblue; }  if (pBufdelta->bHasGAMA)            { pBuftarget->bHasGAMA = MNG_TRUE;  pBuftarget->iGamma   = pBufdelta->iGamma; }  if (pBufdelta->bHasCHRM)            {                                   pBuftarget->bHasCHRM       = MNG_TRUE; pBuftarget->iWhitepointx   = pBufdelta->iWhitepointx; pBuftarget->iWhitepointy   = pBufdelta->iWhitepointy; pBuftarget->iPrimaryredx   = pBufdelta->iPrimaryredx; pBuftarget->iPrimaryredy   = pBufdelta->iPrimaryredy; pBuftarget->iPrimarygreenx = pBufdelta->iPrimarygreenx; pBuftarget->iPrimarygreeny = pBufdelta->iPrimarygreeny; pBuftarget->iPrimarybluex  = pBufdelta->iPrimarybluex; pBuftarget->iPrimarybluey  = pBufdelta->iPrimarybluey; }  if (pBufdelta->bHasSRGB)            {                                   pBuftarget->bHasSRGB         = MNG_TRUE; pBuftarget->iRenderingintent = pBufdelta->iRenderingintent; }  if (pBufdelta->bHasICCP)            { pBuftarget->bHasICCP = MNG_TRUE;   if (pBuftarget->pProfile)         MNG_FREEX (pData, pBuftarget->pProfile, pBuftarget->iProfilesize)  MNG_ALLOC (pData, pBuftarget->pProfile, pBufdelta->iProfilesize) MNG_COPY  (pBuftarget->pProfile, pBufdelta->pProfile, pBufdelta->iProfilesize)  pBuftarget->iProfilesize = pBufdelta->iProfilesize; }  if ((!pData->bDeltaimmediate) && (pData->iDeltatype != MNG_DELTATYPE_NOCHANGE)) { pData->fScalerow = MNG_NULL;       switch (pBuftarget->iBitdepth)    {   }  pData->fDeltarow = MNG_NULL;       switch (pBuftarget->iColortype)   { case  0 : ; case  8 : {                      if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE          ) || (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD    ) || (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE)    ) { if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3) || (pBufdelta->iColortype == 8)) { switch (pBuftarget->iBitdepth) { case  1 : { pData->fDeltarow = delta_g1_g1;   break; } case  2 : { pData->fDeltarow = delta_g2_g2;   break; } case  4 : { pData->fDeltarow = delta_g4_g4;   break; } case  8 : { pData->fDeltarow = delta_g8_g8;   break; } case 16 : { pData->fDeltarow = delta_g16_g16; break; } } } }  break; }  case  2 : ; case 10 : {                      if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE          ) || (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD    ) || (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE)    ) { if ((pBufdelta->iColortype == 2) || (pBufdelta->iColortype == 10)) { switch (pBuftarget->iBitdepth) { case  8 : { pData->fDeltarow = delta_rgb8_rgb8;   break; } case 16 : { pData->fDeltarow = delta_rgb16_rgb16; break; } } } }  break; }  case  3 : {                      if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE          ) || (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD    ) || (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE)    ) { if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3)) { switch (pBuftarget->iBitdepth) { case  1 : { pData->fDeltarow = delta_g1_g1; break; } case  2 : { pData->fDeltarow = delta_g2_g2; break; } case  4 : { pData->fDeltarow = delta_g4_g4; break; } case  8 : { pData->fDeltarow = delta_g8_g8; break; } } } }  break; }  case  4 : ; case 12 : {                      if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE          ) || (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD    ) || (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE)    ) { if ((pBufdelta->iColortype == 4) || (pBufdelta->iColortype == 12)) { switch (pBuftarget->iBitdepth) { case  8 : { pData->fDeltarow = delta_ga8_ga8;   break; } case 16 : { pData->fDeltarow = delta_ga16_ga16; break; } } } } else if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD    ) || (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE)    ) { if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3) || (pBufdelta->iColortype == 8)) { switch (pBuftarget->iBitdepth) { case  8 : { pData->fDeltarow = delta_ga8_g8;   break; } case 16 : { pData->fDeltarow = delta_ga16_g16; break; } } } } else if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD    ) || (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE)    ) { if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3)) { switch (pBuftarget->iBitdepth) { case  8 : { pData->fDeltarow = delta_ga8_a8;   break; } case 16 : { pData->fDeltarow = delta_ga16_a16; break; } } } }  break; }  case  6 : ; case 14 : {                      if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE          ) || (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD    ) || (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE)    ) { if ((pBufdelta->iColortype == 6) || (pBufdelta->iColortype == 14)) { switch (pBuftarget->iBitdepth) { case  8 : { pData->fDeltarow = delta_rgba8_rgba8;   break; } case 16 : { pData->fDeltarow = delta_rgba16_rgba16; break; } } } } else if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD    ) || (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE)    ) { if ((pBufdelta->iColortype == 2) || (pBufdelta->iColortype == 10)) { switch (pBuftarget->iBitdepth) { case  8 : { pData->fDeltarow = delta_rgba8_rgb8;   break; } case 16 : { pData->fDeltarow = delta_rgba16_rgb16; break; } } } } else if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD    ) || (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE)    ) { if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3)) { switch (pBuftarget->iBitdepth) { case  8 : { pData->fDeltarow = delta_rgba8_a8;   break; } case 16 : { pData->fDeltarow = delta_rgba16_a16; break; } } } }  break; }  }  if (pData->fDeltarow)             { pData->iPass        = -1;       pData->iRow         = pData->iDeltaBlocky; pData->iRowinc      = 1; pData->iCol         = pData->iDeltaBlockx; pData->iColinc      = 1; pData->iRowsamples  = pBufdelta->iWidth; pData->iRowsize     = pBuftarget->iRowsize;  pData->pRetrieveobj = (mng_objectp)pDelta; pData->pStoreobj    = (mng_objectp)pTarget;  MNG_ALLOC (pData, pData->pRGBArow, pBufdelta->iRowsize)  iY       = 0;                   iRetcode = MNG_NOERROR;          while ((!iRetcode) && (iY < pBufdelta->iHeight)) {                               mng_uint8p pWork = pBufdelta->pImgdata + (iY * pBufdelta->iRowsize);  MNG_COPY (pData->pRGBArow, pWork, pBufdelta->iRowsize);  if (pData->fScalerow)         iRetcode = ((mng_scalerow)pData->fScalerow) (pData);  if (!iRetcode)                iRetcode = ((mng_deltarow)pData->fDeltarow) (pData);  if (!iRetcode)                iRetcode = next_row (pData);  iY++;                         }  MNG_FREE (pData, pData->pRGBArow, pBufdelta->iRowsize)  if (iRetcode)                   return iRetcode;  } else MNG_ERROR (pData, MNG_INVALIDDELTA)
mng_retcode execute_delta_image (mng_datap  pData,                                 mng_imagep pTarget,                                 mng_imagep pDelta){  mng_imagedatap pBuftarget = pTarget->pImgbuf;  mng_imagedatap pBufdelta  = pDelta->pImgbuf;#ifdef MNG_SUPPORT_TRACE  MNG_TRACE (pData, MNG_FN_EXECUTE_DELTA_IMAGE, MNG_LC_START)#endif  if (pBufdelta->bHasPLTE)             /* palette in delta ? */  {    mng_uint32 iX;                                       /* new palette larger than old one ? */    if ((!pBuftarget->bHasPLTE) || (pBuftarget->iPLTEcount < pBufdelta->iPLTEcount))      pBuftarget->iPLTEcount = pBufdelta->iPLTEcount;                                       /* it's definitely got a PLTE now */    pBuftarget->bHasPLTE = MNG_TRUE;    for (iX = 0; iX < pBufdelta->iPLTEcount; iX++)    {      pBuftarget->aPLTEentries[iX].iRed   = pBufdelta->aPLTEentries[iX].iRed;      pBuftarget->aPLTEentries[iX].iGreen = pBufdelta->aPLTEentries[iX].iGreen;      pBuftarget->aPLTEentries[iX].iBlue  = pBufdelta->aPLTEentries[iX].iBlue;    }  }  if (pBufdelta->bHasTRNS)             /* cheap transparency in delta ? */  {    switch (pData->iColortype)         /* drop it into the target */    {      case 0: {                        /* gray */                pBuftarget->iTRNSgray  = pBufdelta->iTRNSgray;                pBuftarget->iTRNSred   = 0;                pBuftarget->iTRNSgreen = 0;                pBuftarget->iTRNSblue  = 0;                pBuftarget->iTRNScount = 0;                break;              }      case 2: {                        /* rgb */                pBuftarget->iTRNSgray  = 0;                pBuftarget->iTRNSred   = pBufdelta->iTRNSred;                pBuftarget->iTRNSgreen = pBufdelta->iTRNSgreen;                pBuftarget->iTRNSblue  = pBufdelta->iTRNSblue;                pBuftarget->iTRNScount = 0;                break;              }      case 3: {                        /* indexed */                pBuftarget->iTRNSgray  = 0;                pBuftarget->iTRNSred   = 0;                pBuftarget->iTRNSgreen = 0;                pBuftarget->iTRNSblue  = 0;                                       /* existing range smaller than new one ? */                if ((!pBuftarget->bHasTRNS) || (pBuftarget->iTRNScount < pBufdelta->iTRNScount))                  pBuftarget->iTRNScount = pBufdelta->iTRNScount;                MNG_COPY (pBuftarget->aTRNSentries, pBufdelta->aTRNSentries, pBufdelta->iTRNScount)                break;              }    }    pBuftarget->bHasTRNS = MNG_TRUE;   /* tell it it's got a tRNS now */  }    /* TODO: copy bKGD (if it exists!) */  if (pBufdelta->bHasGAMA)             /* gamma in source ? */  {    pBuftarget->bHasGAMA = MNG_TRUE;   /* drop it onto the target */    pBuftarget->iGamma   = pBufdelta->iGamma;  }  if (pBufdelta->bHasCHRM)             /* chroma in delta ? */  {                                    /* drop it onto the target */    pBuftarget->bHasCHRM       = MNG_TRUE;    pBuftarget->iWhitepointx   = pBufdelta->iWhitepointx;    pBuftarget->iWhitepointy   = pBufdelta->iWhitepointy;    pBuftarget->iPrimaryredx   = pBufdelta->iPrimaryredx;    pBuftarget->iPrimaryredy   = pBufdelta->iPrimaryredy;    pBuftarget->iPrimarygreenx = pBufdelta->iPrimarygreenx;    pBuftarget->iPrimarygreeny = pBufdelta->iPrimarygreeny;    pBuftarget->iPrimarybluex  = pBufdelta->iPrimarybluex;    pBuftarget->iPrimarybluey  = pBufdelta->iPrimarybluey;  }  if (pBufdelta->bHasSRGB)             /* sRGB in delta ? */  {                                    /* drop it onto the target */    pBuftarget->bHasSRGB         = MNG_TRUE;    pBuftarget->iRenderingintent = pBufdelta->iRenderingintent;  }  if (pBufdelta->bHasICCP)             /* ICC profile in delta ? */  {    pBuftarget->bHasICCP = MNG_TRUE;   /* drop it onto the target */    if (pBuftarget->pProfile)          /* profile existed ? */      MNG_FREEX (pData, pBuftarget->pProfile, pBuftarget->iProfilesize)                                       /* allocate a buffer & copy it */    MNG_ALLOC (pData, pBuftarget->pProfile, pBufdelta->iProfilesize)    MNG_COPY  (pBuftarget->pProfile, pBufdelta->pProfile, pBufdelta->iProfilesize)                                       /* store it's length as well */    pBuftarget->iProfilesize = pBufdelta->iProfilesize;  }  if (!pData->bDeltaimmediate)         /* need to execute delta pixels ? */  {    /* TODO: execute delta pixels (if they exist!) */  }  #ifdef MNG_SUPPORT_TRACE  MNG_TRACE (pData, MNG_FN_EXECUTE_DELTA_IMAGE, MNG_LC_END)#endif  return MNG_NOERROR;}