| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "../../../../third_party/lcms2-2.6/include/lcms2.h" | 7 #include "../../../../third_party/lcms2-2.6/include/lcms2.h" |
| 8 #include "../../../include/fxcodec/fx_codec.h" | 8 #include "../../../include/fxcodec/fx_codec.h" |
| 9 #include "codec_int.h" | 9 #include "codec_int.h" |
| 10 | 10 |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 default:; | 427 default:; |
| 428 } | 428 } |
| 429 MD5ComputeID(text.GetBuffer(0), text.GetLength(), ID); | 429 MD5ComputeID(text.GetBuffer(0), text.GetLength(), ID); |
| 430 break; | 430 break; |
| 431 default:; | 431 default:; |
| 432 } | 432 } |
| 433 key.AppendBlock(ID, 16); | 433 key.AppendBlock(ID, 16); |
| 434 CFX_ByteString ProfileKey(key.GetBuffer(), key.GetSize()); | 434 CFX_ByteString ProfileKey(key.GetBuffer(), key.GetSize()); |
| 435 ASSERT(pTransformKey); | 435 ASSERT(pTransformKey); |
| 436 pTransformKey->AppendBlock(ProfileKey.GetBuffer(0), ProfileKey.GetLength()); | 436 pTransformKey->AppendBlock(ProfileKey.GetBuffer(0), ProfileKey.GetLength()); |
| 437 if (!m_MapProfile.Lookup(ProfileKey, (void*&)pCache)) { | 437 auto it = m_MapProfile.find(ProfileKey); |
| 438 if (it == m_MapProfile.end()) { |
| 438 pCache = new CFX_IccProfileCache; | 439 pCache = new CFX_IccProfileCache; |
| 439 switch (pIccParam->dwProfileType) { | 440 switch (pIccParam->dwProfileType) { |
| 440 case Icc_PARAMTYPE_BUFFER: | 441 case Icc_PARAMTYPE_BUFFER: |
| 441 pCache->m_pProfile = cmsOpenProfileFromMem(pIccParam->pProfileData, | 442 pCache->m_pProfile = cmsOpenProfileFromMem(pIccParam->pProfileData, |
| 442 pIccParam->dwProfileSize); | 443 pIccParam->dwProfileSize); |
| 443 break; | 444 break; |
| 444 case Icc_PARAMTYPE_PARAM: | 445 case Icc_PARAMTYPE_PARAM: |
| 445 switch (pIccParam->ColorSpace) { | 446 switch (pIccParam->ColorSpace) { |
| 446 case IccCS_Rgb: | 447 case IccCS_Rgb: |
| 447 pCache->m_pProfile = cmsCreate_sRGBProfile(); | 448 pCache->m_pProfile = cmsCreate_sRGBProfile(); |
| 448 break; | 449 break; |
| 449 case IccCS_Gray: | 450 case IccCS_Gray: |
| 450 pCache->m_pProfile = CreateProfile_Gray(pIccParam->Gamma); | 451 pCache->m_pProfile = CreateProfile_Gray(pIccParam->Gamma); |
| 451 break; | 452 break; |
| 452 default: | 453 default: |
| 453 break; | 454 break; |
| 454 } | 455 } |
| 455 break; | 456 break; |
| 456 default: | 457 default: |
| 457 break; | 458 break; |
| 458 } | 459 } |
| 459 m_MapProfile.SetAt(ProfileKey, pCache); | 460 m_MapProfile[ProfileKey] = pCache; |
| 460 } else { | 461 } else { |
| 462 pCache = it->second; |
| 461 pCache->m_dwRate++; | 463 pCache->m_dwRate++; |
| 462 } | 464 } |
| 463 return pCache->m_pProfile; | 465 return pCache->m_pProfile; |
| 464 } | 466 } |
| 465 void* CCodec_IccModule::CreateTransform( | 467 void* CCodec_IccModule::CreateTransform( |
| 466 ICodec_IccModule::IccParam* pInputParam, | 468 ICodec_IccModule::IccParam* pInputParam, |
| 467 ICodec_IccModule::IccParam* pOutputParam, | 469 ICodec_IccModule::IccParam* pOutputParam, |
| 468 ICodec_IccModule::IccParam* pProofParam, | 470 ICodec_IccModule::IccParam* pProofParam, |
| 469 FX_DWORD dwIntent, | 471 FX_DWORD dwIntent, |
| 470 FX_DWORD dwFlag, | 472 FX_DWORD dwFlag, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 489 return NULL; | 491 return NULL; |
| 490 } | 492 } |
| 491 void* pProofProfile = NULL; | 493 void* pProofProfile = NULL; |
| 492 if (pProofParam) { | 494 if (pProofParam) { |
| 493 pProofProfile = CreateProfile(pProofParam, Icc_CLASS_PROOF, &key); | 495 pProofProfile = CreateProfile(pProofParam, Icc_CLASS_PROOF, &key); |
| 494 } | 496 } |
| 495 key << dwInputProfileType << dwOutputProfileType << dwIntent << dwFlag | 497 key << dwInputProfileType << dwOutputProfileType << dwIntent << dwFlag |
| 496 << (pProofProfile != NULL) << dwPrfIntent << dwPrfFlag; | 498 << (pProofProfile != NULL) << dwPrfIntent << dwPrfFlag; |
| 497 CFX_ByteStringC TransformKey(key.GetBuffer(), key.GetSize()); | 499 CFX_ByteStringC TransformKey(key.GetBuffer(), key.GetSize()); |
| 498 CFX_IccTransformCache* pTransformCache; | 500 CFX_IccTransformCache* pTransformCache; |
| 499 if (!m_MapTranform.Lookup(TransformKey, (void*&)pTransformCache)) { | 501 auto it = m_MapTranform.find(TransformKey); |
| 502 if (it == m_MapTranform.end()) { |
| 500 pCmm = FX_Alloc(CLcmsCmm, 1); | 503 pCmm = FX_Alloc(CLcmsCmm, 1); |
| 501 pCmm->m_nSrcComponents = T_CHANNELS(dwInputProfileType); | 504 pCmm->m_nSrcComponents = T_CHANNELS(dwInputProfileType); |
| 502 pCmm->m_nDstComponents = T_CHANNELS(dwOutputProfileType); | 505 pCmm->m_nDstComponents = T_CHANNELS(dwOutputProfileType); |
| 503 pCmm->m_bLab = T_COLORSPACE(pInputParam->dwFormat) == PT_Lab; | 506 pCmm->m_bLab = T_COLORSPACE(pInputParam->dwFormat) == PT_Lab; |
| 504 pTransformCache = new CFX_IccTransformCache(pCmm); | 507 pTransformCache = new CFX_IccTransformCache(pCmm); |
| 505 if (pProofProfile) { | 508 if (pProofProfile) { |
| 506 pTransformCache->m_pIccTransform = cmsCreateProofingTransform( | 509 pTransformCache->m_pIccTransform = cmsCreateProofingTransform( |
| 507 pInputProfile, dwInputProfileType, pOutputProfile, | 510 pInputProfile, dwInputProfileType, pOutputProfile, |
| 508 dwOutputProfileType, pProofProfile, dwIntent, dwPrfIntent, dwPrfFlag); | 511 dwOutputProfileType, pProofProfile, dwIntent, dwPrfIntent, dwPrfFlag); |
| 509 } else { | 512 } else { |
| 510 pTransformCache->m_pIccTransform = | 513 pTransformCache->m_pIccTransform = |
| 511 cmsCreateTransform(pInputProfile, dwInputProfileType, pOutputProfile, | 514 cmsCreateTransform(pInputProfile, dwInputProfileType, pOutputProfile, |
| 512 dwOutputProfileType, dwIntent, dwFlag); | 515 dwOutputProfileType, dwIntent, dwFlag); |
| 513 } | 516 } |
| 514 pCmm->m_hTransform = pTransformCache->m_pIccTransform; | 517 pCmm->m_hTransform = pTransformCache->m_pIccTransform; |
| 515 m_MapTranform.SetAt(TransformKey, pTransformCache); | 518 m_MapTranform[TransformKey] = pTransformCache; |
| 516 } else { | 519 } else { |
| 520 pTransformCache = it->second; |
| 517 pTransformCache->m_dwRate++; | 521 pTransformCache->m_dwRate++; |
| 518 } | 522 } |
| 519 return pTransformCache->m_pCmm; | 523 return pTransformCache->m_pCmm; |
| 520 } | 524 } |
| 521 CCodec_IccModule::~CCodec_IccModule() { | 525 CCodec_IccModule::~CCodec_IccModule() { |
| 522 FX_POSITION pos = m_MapProfile.GetStartPosition(); | 526 for (const auto& pair : m_MapProfile) { |
| 523 CFX_ByteString key; | 527 delete pair.second; |
| 524 CFX_IccProfileCache* pProfileCache; | |
| 525 while (pos) { | |
| 526 m_MapProfile.GetNextAssoc(pos, key, (void*&)pProfileCache); | |
| 527 delete pProfileCache; | |
| 528 } | 528 } |
| 529 pos = m_MapTranform.GetStartPosition(); | 529 m_MapProfile.clear(); |
| 530 CFX_IccTransformCache* pTransformCache; | 530 for (const auto& pair : m_MapTranform) { |
| 531 while (pos) { | 531 delete pair.second; |
| 532 m_MapTranform.GetNextAssoc(pos, key, (void*&)pTransformCache); | |
| 533 delete pTransformCache; | |
| 534 } | 532 } |
| 533 m_MapTranform.clear(); |
| 535 } | 534 } |
| 536 void* CCodec_IccModule::CreateTransform_sRGB(const uint8_t* pProfileData, | 535 void* CCodec_IccModule::CreateTransform_sRGB(const uint8_t* pProfileData, |
| 537 FX_DWORD dwProfileSize, | 536 FX_DWORD dwProfileSize, |
| 538 int32_t& nComponents, | 537 int32_t& nComponents, |
| 539 int32_t intent, | 538 int32_t intent, |
| 540 FX_DWORD dwSrcFormat) { | 539 FX_DWORD dwSrcFormat) { |
| 541 return IccLib_CreateTransform_sRGB(pProfileData, dwProfileSize, nComponents, | 540 return IccLib_CreateTransform_sRGB(pProfileData, dwProfileSize, nComponents, |
| 542 intent, dwSrcFormat); | 541 intent, dwSrcFormat); |
| 543 } | 542 } |
| 544 void* CCodec_IccModule::CreateTransform_CMYK(const uint8_t* pSrcProfileData, | 543 void* CCodec_IccModule::CreateTransform_CMYK(const uint8_t* pSrcProfileData, |
| (...skipping 1427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1972 uint8_t c1 = FXSYS_round(c * 255); | 1971 uint8_t c1 = FXSYS_round(c * 255); |
| 1973 uint8_t m1 = FXSYS_round(m * 255); | 1972 uint8_t m1 = FXSYS_round(m * 255); |
| 1974 uint8_t y1 = FXSYS_round(y * 255); | 1973 uint8_t y1 = FXSYS_round(y * 255); |
| 1975 uint8_t k1 = FXSYS_round(k * 255); | 1974 uint8_t k1 = FXSYS_round(k * 255); |
| 1976 uint8_t r, g, b; | 1975 uint8_t r, g, b; |
| 1977 AdobeCMYK_to_sRGB1(c1, m1, y1, k1, r, g, b); | 1976 AdobeCMYK_to_sRGB1(c1, m1, y1, k1, r, g, b); |
| 1978 R = 1.0f * r / 255; | 1977 R = 1.0f * r / 255; |
| 1979 G = 1.0f * g / 255; | 1978 G = 1.0f * g / 255; |
| 1980 B = 1.0f * b / 255; | 1979 B = 1.0f * b / 255; |
| 1981 } | 1980 } |
| OLD | NEW |