mng_retcode mng_correct_app_cms (mng_datap pData) { #ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_CORRECT_APP_CMS, MNG_LC_START); #endif if (pData->fProcessarow) /* let the app do something with our row */ if (!pData->fProcessarow ((mng_handle)pData, pData->iRowsamples, pData->bIsRGBA16, pData->pRGBArow)) MNG_ERROR (pData, MNG_APPCMSERROR); #ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_CORRECT_APP_CMS, MNG_LC_END); #endif return MNG_NOERROR; }
mng_retcode mngjpeg_decompressdata (mng_datap pData, mng_uint32 iRawsize, mng_uint8p pRawdata) { mng_retcode iRetcode; mng_uint32 iRemain; mng_uint8p pWork; #ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_START) #endif #if defined (MNG_INCLUDE_IJG6B) && defined(MNG_USE_SETJMP) iRetcode = setjmp (pData->sErrorbuf);/* initialize local JPEG error-recovery */ if (iRetcode != 0) /* got here from longjmp ? */ MNG_ERRORJ (pData, iRetcode) /* then IJG-lib issued an error */ #endif pWork = pRawdata; iRemain = iRawsize; if (pData->iJPEGtoskip) /* JPEG-lib told us to skip some more data ? */ { if (iRemain > pData->iJPEGtoskip) /* enough data in this buffer ? */ { iRemain -= pData->iJPEGtoskip; /* skip enough to access the next byte */ pWork += pData->iJPEGtoskip; pData->iJPEGtoskip = 0; /* no more to skip then */ } else { pData->iJPEGtoskip -= iRemain; /* skip all data in the buffer */ iRemain = 0; /* and indicate this accordingly */ } /* the skip set current-pointer to NULL ! */ pData->pJPEGcurrent = pData->pJPEGbuf; } while (iRemain) /* repeat until no more input-bytes */ { /* need to shift anything ? */ if ((pData->pJPEGcurrent > pData->pJPEGbuf) && (pData->pJPEGcurrent - pData->pJPEGbuf + pData->iJPEGbufremain + iRemain > pData->iJPEGbufmax)) { if (pData->iJPEGbufremain > 0) /* then do so */ MNG_COPY (pData->pJPEGbuf, pData->pJPEGcurrent, pData->iJPEGbufremain) pData->pJPEGcurrent = pData->pJPEGbuf; } /* does the remaining input fit into the buffer ? */ if (pData->iJPEGbufremain + iRemain <= pData->iJPEGbufmax) { /* move the lot */ MNG_COPY ((pData->pJPEGcurrent + pData->iJPEGbufremain), pWork, iRemain) pData->iJPEGbufremain += iRemain;/* adjust remaining_bytes counter */ iRemain = 0; /* and indicate there's no input left */ } else { /* calculate what does fit */ mng_uint32 iFits = pData->iJPEGbufmax - pData->iJPEGbufremain; if (iFits <= 0) /* no space is just bugger 'm all */ MNG_ERROR (pData, MNG_JPEGBUFTOOSMALL) /* move that */ MNG_COPY ((pData->pJPEGcurrent + pData->iJPEGbufremain), pWork, iFits) pData->iJPEGbufremain += iFits; /* adjust remain_bytes counter */ iRemain -= iFits; /* and the input-parms */ pWork += iFits; } #ifdef MNG_INCLUDE_IJG6B pData->pJPEGdinfo->src->next_input_byte = pData->pJPEGcurrent; pData->pJPEGdinfo->src->bytes_in_buffer = pData->iJPEGbufremain; if (!pData->bJPEGhasheader) /* haven't got the header yet ? */ { void *temp; /* call jpeg_read_header() to obtain image info */ #ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_READ_HEADER) #endif if (jpeg_read_header (pData->pJPEGdinfo, TRUE) != JPEG_SUSPENDED) { /* indicate the header's oke */ pData->bJPEGhasheader = MNG_TRUE; /* let's do some sanity checks ! */ if ((pData->pJPEGdinfo->image_width != pData->iDatawidth ) || (pData->pJPEGdinfo->image_height != pData->iDataheight) ) MNG_ERROR (pData, MNG_JPEGPARMSERR) if ( ((pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAY ) || (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA) ) && (pData->pJPEGdinfo->jpeg_color_space != JCS_GRAYSCALE ) ) MNG_ERROR (pData, MNG_JPEGPARMSERR) if ( ((pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLOR ) || (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) ) && (pData->pJPEGdinfo->jpeg_color_space != JCS_YCbCr ) ) MNG_ERROR (pData, MNG_JPEGPARMSERR) /* indicate whether or not it's progressive */ pData->bJPEGprogressive = (mng_bool)jpeg_has_multiple_scans (pData->pJPEGdinfo); /* progressive+alpha can't display "on-the-fly"!! */ if ((pData->bJPEGprogressive) && ((pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA ) || (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) )) pData->fDisplayrow = MNG_NULL; /* allocate a row of JPEG-samples */ if (pData->pJPEGdinfo->jpeg_color_space == JCS_YCbCr) pData->iJPEGrowlen = pData->pJPEGdinfo->image_width * 3; else pData->iJPEGrowlen = pData->pJPEGdinfo->image_width; MNG_ALLOC (pData, temp, pData->iJPEGrowlen) pData->pJPEGrow = (mng_uint8p)temp; pData->iJPEGrgbrow = 0; /* quite empty up to now */ } pData->pJPEGcurrent = (mng_uint8p)pData->pJPEGdinfo->src->next_input_byte; pData->iJPEGbufremain = (mng_uint32)pData->pJPEGdinfo->src->bytes_in_buffer; }
mng_retcode mng_init_app_cms (mng_datap pData, mng_bool bGlobal, mng_bool bObject, mng_bool bRetrobj) { mng_imagep pImage = MNG_NULL; mng_imagedatap pBuf = MNG_NULL; mng_bool bDone = MNG_FALSE; mng_retcode iRetcode; #ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_INIT_APP_CMS, MNG_LC_START); #endif if (bObject) /* use object if present ? */ { /* current object ? */ if ((mng_imagep)pData->pCurrentobj) pImage = (mng_imagep)pData->pCurrentobj; else /* if not; use object 0 */ pImage = (mng_imagep)pData->pObjzero; } if (bRetrobj) /* retrieving from an object ? */ pImage = (mng_imagep)pData->pRetrieveobj; if (pImage) /* are we using an object ? */ pBuf = pImage->pImgbuf; /* then address the buffer */ if ((!pBuf) || (!pBuf->bCorrected)) /* is the buffer already corrected ? */ { #ifndef MNG_SKIPCHUNK_iCCP if ( (pData->fProcessiccp) && (((pBuf) && (pBuf->bHasICCP)) || ((bGlobal) && (pData->bHasglobalICCP))) ) { mng_uint32 iProfilesize; mng_ptr pProfile; if ((pBuf) && (pBuf->bHasICCP)) /* get the right profile */ { iProfilesize = pBuf->iProfilesize; pProfile = pBuf->pProfile; } else { iProfilesize = pData->iGlobalProfilesize; pProfile = pData->pGlobalProfile; } /* inform the app */ if (!pData->fProcessiccp ((mng_handle)pData, iProfilesize, pProfile)) MNG_ERROR (pData, MNG_APPCMSERROR); /* load color-correction routine */ pData->fCorrectrow = (mng_fptr)mng_correct_app_cms; bDone = MNG_TRUE; } #endif if ( (pData->fProcesssrgb) && (((pBuf) && (pBuf->bHasSRGB)) || ((bGlobal) && (pData->bHasglobalSRGB))) ) { mng_uint8 iIntent; if ((pBuf) && (pBuf->bHasSRGB)) /* determine rendering intent */ iIntent = pBuf->iRenderingintent; else iIntent = pData->iGlobalRendintent; /* inform the app */ if (!pData->fProcesssrgb ((mng_handle)pData, iIntent)) MNG_ERROR (pData, MNG_APPCMSERROR); /* load color-correction routine */ pData->fCorrectrow = (mng_fptr)mng_correct_app_cms; bDone = MNG_TRUE; } #ifndef MNG_SKIPCHUNK_cHRM if ( (pData->fProcesschroma) && (((pBuf) && (pBuf->bHasCHRM)) || ((bGlobal) && (pData->bHasglobalCHRM))) ) { mng_uint32 iWhitepointx, iWhitepointy; mng_uint32 iPrimaryredx, iPrimaryredy; mng_uint32 iPrimarygreenx, iPrimarygreeny; mng_uint32 iPrimarybluex, iPrimarybluey; if ((pBuf) && (pBuf->bHasCHRM)) /* local cHRM ? */ { iWhitepointx = pBuf->iWhitepointx; iWhitepointy = pBuf->iWhitepointy; iPrimaryredx = pBuf->iPrimaryredx; iPrimaryredy = pBuf->iPrimaryredy; iPrimarygreenx = pBuf->iPrimarygreenx; iPrimarygreeny = pBuf->iPrimarygreeny; iPrimarybluex = pBuf->iPrimarybluex; iPrimarybluey = pBuf->iPrimarybluey; } else { iWhitepointx = pData->iGlobalWhitepointx; iWhitepointy = pData->iGlobalWhitepointy; iPrimaryredx = pData->iGlobalPrimaryredx; iPrimaryredy = pData->iGlobalPrimaryredy; iPrimarygreenx = pData->iGlobalPrimarygreenx; iPrimarygreeny = pData->iGlobalPrimarygreeny; iPrimarybluex = pData->iGlobalPrimarybluex; iPrimarybluey = pData->iGlobalPrimarybluey; } /* inform the app */ if (!pData->fProcesschroma ((mng_handle)pData, iWhitepointx, iWhitepointy, iPrimaryredx, iPrimaryredy, iPrimarygreenx, iPrimarygreeny, iPrimarybluex, iPrimarybluey)) MNG_ERROR (pData, MNG_APPCMSERROR); /* load color-correction routine */ pData->fCorrectrow = (mng_fptr)mng_correct_app_cms; bDone = MNG_TRUE; } #endif if ( (pData->fProcessgamma) && (((pBuf) && (pBuf->bHasGAMA)) || ((bGlobal) && (pData->bHasglobalGAMA))) ) { mng_uint32 iGamma; if ((pBuf) && (pBuf->bHasGAMA)) /* get the gamma value */ iGamma = pBuf->iGamma; else iGamma = pData->iGlobalGamma; /* inform the app */ if (!pData->fProcessgamma ((mng_handle)pData, iGamma)) { /* app wants us to use internal routines ! */ iRetcode = mng_init_gamma_only (pData, bGlobal, bObject, bRetrobj); if (iRetcode) /* on error bail out */ return iRetcode; } else { /* load color-correction routine */ pData->fCorrectrow = (mng_fptr)mng_correct_app_cms; } bDone = MNG_TRUE; } if (!bDone) /* no color-info at all ? */ { /* then use default image gamma ! */ if (!pData->fProcessgamma ((mng_handle)pData, (mng_uint32)((pData->dDfltimggamma * 100000) + 0.5))) { /* app wants us to use internal routines ! */ iRetcode = mng_init_gamma_only (pData, bGlobal, bObject, bRetrobj); if (iRetcode) /* on error bail out */ return iRetcode; } else { /* load color-correction routine */ pData->fCorrectrow = (mng_fptr)mng_correct_app_cms; } } } #ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_INIT_APP_CMS, MNG_LC_END); #endif return MNG_NOERROR; }