⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 libmng_cms.c

📁 一款最完整的工业组态软源代码
💻 C
📖 第 1 页 / 共 3 页
字号:

#if defined(MNG_GAMMA_ONLY) || defined(MNG_FULL_CMS) || defined(MNG_APP_CMS)
mng_retcode mng_correct_gamma_only (mng_datap pData)
{
  mng_uint8p pWork;
  mng_int32  iX;

#ifdef MNG_SUPPORT_TRACE
  MNG_TRACE (pData, MNG_FN_CORRECT_GAMMA_ONLY, MNG_LC_START)
#endif

  pWork = pData->pRGBArow;             /* address intermediate row */

  if (pData->bIsRGBA16)                /* 16-bit intermediate row ? */
  {

  
     /* TODO: 16-bit precision gamma processing */
     /* we'll just do the high-order byte for now */

     
                                       /* convert all samples in the row */
     for (iX = 0; iX < pData->iRowsamples; iX++)
     {                                 /* using the precalculated gamma lookup table */
       *pWork     = pData->aGammatab [*pWork];
       *(pWork+2) = pData->aGammatab [*(pWork+2)];
       *(pWork+4) = pData->aGammatab [*(pWork+4)];

       pWork += 8;
     }
  }
  else
  {                                    /* convert all samples in the row */
     for (iX = 0; iX < pData->iRowsamples; iX++)
     {                                 /* using the precalculated gamma lookup table */
       *pWork     = pData->aGammatab [*pWork];
       *(pWork+1) = pData->aGammatab [*(pWork+1)];
       *(pWork+2) = pData->aGammatab [*(pWork+2)];

       pWork += 4;
     }
  }

#ifdef MNG_SUPPORT_TRACE
  MNG_TRACE (pData, MNG_FN_CORRECT_GAMMA_ONLY, MNG_LC_END)
#endif

  return MNG_NOERROR;
}
#endif /* MNG_GAMMA_ONLY || MNG_FULL_CMS || MNG_APP_CMS */

/* ************************************************************************** */

#ifdef MNG_APP_CMS
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;
}
#endif /* MNG_APP_CMS */

/* ************************************************************************** */

#ifdef MNG_APP_CMS
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;
}
#endif /* MNG_APP_CMS */

/* ************************************************************************** */

#endif /* MNG_INCLUDE_DISPLAY_PROCS */

/* ************************************************************************** */
/* * end of file                                                            * */
/* ************************************************************************** */



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -