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

📄 cmscnvrt.c

📁 Linux下的无线网卡通用驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
////  Little cms//  Copyright (C) 1998-2005 Marti Maria//// Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the Software // is furnished to do so, subject to the following conditions://// The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software.//// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.#include "lcms.h"/*       This module provides conversion stages for handling intents.The chain of evaluation in a transform is:                PCS1            PCS2                    PCS3          PCS4|From |  |From  |  |Conversion |  |Preview |  |Gamut   |  |Conversion |  |To    |  |To     ||Input|->|Device|->|Stage 1    |->|handling|->|Checking|->|Stage 2    |->|Device|->|output |--------  -------  -------------   ---------  ----------  -------------   -------  ---------          AToB0                     prew0       gamut                     BToA0Formatting LUT      Adjusting        LUT         LUT       Adjusting       LUT      Formatting          Intent     Intent 1       intent      intent      Intent 2      IntentSome of these LUT may be missingThere are two intents involved here, the intent of the transform itself, and theintent the proof is being done, if is the case. Since the first intent is to beapplied to preview, is the proofing intent. The second intent  identifies thetransform intent. Input data of any stage is taked as relative colorimetricalways.NOTES: V4 states than perceptual & saturation intents between mixed v2 & v4 profiles should scale PCS from a black point equal to ZERO in v2 profiles to the reference media black ofperceptual v4 PCS. Since I found many v2 profiles to be using a perceptual intent with black point not zero at all, I'm implementing that as a black point compensation from whatever black from perceptal intent to the reference media black for v4 profiles.*/int cdecl cmsChooseCnvrt(int Absolute,                 int Phase1, LPcmsCIEXYZ BlackPointIn,                             LPcmsCIEXYZ WhitePointIn,                             LPcmsCIEXYZ IlluminantIn,                             LPMAT3 ChromaticAdaptationMatrixIn,                 int Phase2, LPcmsCIEXYZ BlackPointOut,                             LPcmsCIEXYZ WhitePointOut,                             LPcmsCIEXYZ IlluminantOut,                             LPMAT3 ChromaticAdaptationMatrixOut,                int DoBlackPointCompensation,                double AdaptationState,                 _cmsADJFN *fn1,                 LPWMAT3 wm, LPWVEC3 wof);// -------------------------------------------------------------------------// D50 - Widely usedLCMSAPI LPcmsCIEXYZ LCMSEXPORT cmsD50_XYZ(void){    static cmsCIEXYZ D50XYZ = {D50X, D50Y, D50Z};    return &D50XYZ;}LCMSAPI LPcmsCIExyY LCMSEXPORT cmsD50_xyY(void){    static cmsCIExyY D50xyY;    cmsXYZ2xyY(&D50xyY, cmsD50_XYZ());    return &D50xyY;}// ---------------- From LUT to LUT --------------------------// Calculate m, offset Relativ -> Absolute undoing any chromatic // adaptation done by the profile. #ifdef _MSC_VER#pragma warning(disable : 4100 4505)#endif// join scalings to obtain://     relative input to absolute and then to relative outputstaticvoid Rel2RelStepAbsCoefs(double AdaptationState,                         LPcmsCIEXYZ BlackPointIn,                         LPcmsCIEXYZ WhitePointIn,                         LPcmsCIEXYZ IlluminantIn,                         LPMAT3 ChromaticAdaptationMatrixIn,                         LPcmsCIEXYZ BlackPointOut,                         LPcmsCIEXYZ WhitePointOut,                         LPcmsCIEXYZ IlluminantOut,                         LPMAT3 ChromaticAdaptationMatrixOut,                         LPMAT3 m, LPVEC3 of){              VEC3 WtPtIn, WtPtInAdapted;       VEC3 WtPtOut, WtPtOutAdapted;       MAT3 Scale, m1, m2, m3;              VEC3init(&WtPtIn, WhitePointIn->X, WhitePointIn->Y, WhitePointIn->Z);       MAT3eval(&WtPtInAdapted, ChromaticAdaptationMatrixIn, &WtPtIn);                         VEC3init(&WtPtOut, WhitePointOut->X, WhitePointOut->Y, WhitePointOut->Z);       MAT3eval(&WtPtOutAdapted, ChromaticAdaptationMatrixOut, &WtPtOut);       VEC3init(&Scale.v[0], WtPtInAdapted.n[0] / WtPtOutAdapted.n[0], 0, 0);       VEC3init(&Scale.v[1], 0, WtPtInAdapted.n[1] / WtPtOutAdapted.n[1], 0);       VEC3init(&Scale.v[2], 0, 0, WtPtInAdapted.n[2] / WtPtOutAdapted.n[2]);       // Adaptation state       if (AdaptationState == 1.0) {           // Observer is fully adapted. Keep chromatic adaptation            CopyMemory(m, &Scale, sizeof(MAT3));       }       else {            // Observer is not adapted, undo the chromatic adaptation            m1 = *ChromaticAdaptationMatrixIn;            MAT3inverse(&m1, &m2);                   MAT3per(&m3, &m2, &Scale);            MAT3per(m, &m3, ChromaticAdaptationMatrixOut);       }                   VEC3init(of, 0.0, 0.0, 0.0);                    }// The (in)famous black point compensation. Right now implemented as// a linear scaling in XYZstaticvoid ComputeBlackPointCompensationFactors(LPcmsCIEXYZ BlackPointIn,                      LPcmsCIEXYZ WhitePointIn,                      LPcmsCIEXYZ IlluminantIn,                      LPcmsCIEXYZ BlackPointOut,                      LPcmsCIEXYZ WhitePointOut,                      LPcmsCIEXYZ IlluminantOut,                      LPMAT3 m, LPVEC3 of){       cmsCIEXYZ RelativeBlackPointIn, RelativeBlackPointOut;   double ax, ay, az, bx, by, bz, tx, ty, tz;      // At first, convert both black points to relative.   cmsAdaptToIlluminant(&RelativeBlackPointIn,  WhitePointIn, IlluminantIn, BlackPointIn);   cmsAdaptToIlluminant(&RelativeBlackPointOut, WhitePointOut, IlluminantOut, BlackPointOut);      // Now we need to compute a matrix plus an offset m and of such of   // [m]*bpin + off = bpout   // [m]*D50  + off = D50   //   // This is a linear scaling in the form ax+b, where   // a = (bpout - D50) / (bpin - D50)   // b = - D50* (bpout - bpin) / (bpin - D50)   tx = RelativeBlackPointIn.X - IlluminantIn ->X;   ty = RelativeBlackPointIn.Y - IlluminantIn ->Y;   tz = RelativeBlackPointIn.Z - IlluminantIn ->Z;   ax = (RelativeBlackPointOut.X - IlluminantOut ->X) / tx;   ay = (RelativeBlackPointOut.Y - IlluminantOut ->Y) / ty;   az = (RelativeBlackPointOut.Z - IlluminantOut ->Z) / tz;   bx = - IlluminantOut -> X * (RelativeBlackPointOut.X - RelativeBlackPointIn.X) / tx;   by = - IlluminantOut -> Y * (RelativeBlackPointOut.Y - RelativeBlackPointIn.Y) / ty;   bz = - IlluminantOut -> Z * (RelativeBlackPointOut.Z - RelativeBlackPointIn.Z) / tz;   MAT3identity(m);   m->v[VX].n[0] = ax;   m->v[VY].n[1] = ay;   m->v[VZ].n[2] = az;   VEC3init(of, bx, by, bz);}// Return TRUE if both m and of are empy -- "m" being identity and "of" being 0staticBOOL IdentityParameters(LPWMAT3 m, LPWVEC3 of){       WVEC3 wv0;    VEC3initF(&wv0, 0, 0, 0);    if (!MAT3isIdentity(m, 0.00001)) return FALSE;    if (!VEC3equal(of, &wv0, 0.00001)) return FALSE;    return TRUE;}// ----------------------------------------- Inter PCS conversions// XYZ to XYZ linear scaling. Aso used on Black point compensationstaticvoid XYZ2XYZ(WORD In[], WORD Out[], LPWMAT3 m, LPWVEC3 of){    WVEC3 a, r;    a.n[0] = In[0] << 1;    a.n[1] = In[1] << 1;    a.n[2] = In[2] << 1;    MAT3evalW(&r, m, &a);    Out[0] = _cmsClampWord((r.n[VX] + of->n[VX]) >> 1);    Out[1] = _cmsClampWord((r.n[VY] + of->n[VY]) >> 1);    Out[2] = _cmsClampWord((r.n[VZ] + of->n[VZ]) >> 1);}// XYZ to Lab, scaling firststaticvoid XYZ2Lab(WORD In[], WORD Out[], LPWMAT3 m, LPWVEC3 of){  WORD XYZ[3];  XYZ2XYZ(In, XYZ, m, of);  cmsXYZ2LabEncoded(XYZ, Out);}// Lab to XYZ, then scallingstaticvoid Lab2XYZ(WORD In[], WORD Out[], LPWMAT3 m, LPWVEC3 of){       WORD XYZ[3];       cmsLab2XYZEncoded(In, XYZ);       XYZ2XYZ(XYZ, Out, m, of);}// Lab to XYZ, scalling and then, back to Labstaticvoid Lab2XYZ2Lab(WORD In[], WORD Out[], LPWMAT3 m, LPWVEC3 of){       WORD XYZ[3], XYZ2[3];       cmsLab2XYZEncoded(In, XYZ);       XYZ2XYZ(XYZ, XYZ2, m, of);       cmsXYZ2LabEncoded(XYZ2, Out);}// ------------------------------------------------------------------// Dispatcher for XYZ Relative LUTstaticint FromXYZRelLUT(int Absolute,                             LPcmsCIEXYZ BlackPointIn,                             LPcmsCIEXYZ WhitePointIn,                             LPcmsCIEXYZ IlluminantIn,                             LPMAT3 ChromaticAdaptationMatrixIn,                 int Phase2, LPcmsCIEXYZ BlackPointOut,                             LPcmsCIEXYZ WhitePointOut,                             LPcmsCIEXYZ IlluminantOut,                             LPMAT3 ChromaticAdaptationMatrixOut,                 int DoBlackPointCompensation,                 double AdaptationState,                 _cmsADJFN *fn1,

⌨️ 快捷键说明

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