Chromium Code Reviews| 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 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 default:; | 429 default:; |
| 430 } | 430 } |
| 431 MD5ComputeID(text.GetBuffer(0), text.GetLength(), ID); | 431 MD5ComputeID(text.GetBuffer(0), text.GetLength(), ID); |
| 432 break; | 432 break; |
| 433 default:; | 433 default:; |
| 434 } | 434 } |
| 435 key.AppendBlock(ID, 16); | 435 key.AppendBlock(ID, 16); |
| 436 CFX_ByteString ProfileKey(key.GetBuffer(), key.GetSize()); | 436 CFX_ByteString ProfileKey(key.GetBuffer(), key.GetSize()); |
| 437 ASSERT(pTransformKey); | 437 ASSERT(pTransformKey); |
| 438 pTransformKey->AppendBlock(ProfileKey.GetBuffer(0), ProfileKey.GetLength()); | 438 pTransformKey->AppendBlock(ProfileKey.GetBuffer(0), ProfileKey.GetLength()); |
| 439 if (!m_MapProfile.Lookup(ProfileKey, (void*&)pCache)) { | 439 auto it = m_MapProfile.find(ProfileKey); |
| 440 if (it == m_MapProfile.end()) { | |
| 440 pCache = new CFX_IccProfileCache; | 441 pCache = new CFX_IccProfileCache; |
| 441 switch (pIccParam->dwProfileType) { | 442 switch (pIccParam->dwProfileType) { |
| 442 case Icc_PARAMTYPE_BUFFER: | 443 case Icc_PARAMTYPE_BUFFER: |
| 443 pCache->m_pProfile = cmsOpenProfileFromMem(pIccParam->pProfileData, | 444 pCache->m_pProfile = cmsOpenProfileFromMem(pIccParam->pProfileData, |
| 444 pIccParam->dwProfileSize); | 445 pIccParam->dwProfileSize); |
| 445 break; | 446 break; |
| 446 case Icc_PARAMTYPE_PARAM: | 447 case Icc_PARAMTYPE_PARAM: |
| 447 switch (pIccParam->ColorSpace) { | 448 switch (pIccParam->ColorSpace) { |
| 448 case IccCS_Rgb: | 449 case IccCS_Rgb: |
| 449 pCache->m_pProfile = cmsCreate_sRGBProfile(); | 450 pCache->m_pProfile = cmsCreate_sRGBProfile(); |
| 450 break; | 451 break; |
| 451 case IccCS_Gray: | 452 case IccCS_Gray: |
| 452 pCache->m_pProfile = CreateProfile_Gray(pIccParam->Gamma); | 453 pCache->m_pProfile = CreateProfile_Gray(pIccParam->Gamma); |
| 453 break; | 454 break; |
| 454 default: | 455 default: |
| 455 break; | 456 break; |
| 456 } | 457 } |
| 457 break; | 458 break; |
| 458 default: | 459 default: |
| 459 break; | 460 break; |
| 460 } | 461 } |
| 461 m_MapProfile.SetAt(ProfileKey, pCache); | 462 m_MapProfile[ProfileKey] = pCache; |
| 462 } else { | 463 } else { |
| 464 pCache = it->second; | |
| 463 pCache->m_dwRate++; | 465 pCache->m_dwRate++; |
| 464 } | 466 } |
| 465 return pCache->m_pProfile; | 467 return pCache->m_pProfile; |
| 466 } | 468 } |
| 467 void* CCodec_IccModule::CreateTransform( | 469 void* CCodec_IccModule::CreateTransform( |
| 468 ICodec_IccModule::IccParam* pInputParam, | 470 ICodec_IccModule::IccParam* pInputParam, |
| 469 ICodec_IccModule::IccParam* pOutputParam, | 471 ICodec_IccModule::IccParam* pOutputParam, |
| 470 ICodec_IccModule::IccParam* pProofParam, | 472 ICodec_IccModule::IccParam* pProofParam, |
| 471 FX_DWORD dwIntent, | 473 FX_DWORD dwIntent, |
| 472 FX_DWORD dwFlag, | 474 FX_DWORD dwFlag, |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 491 return NULL; | 493 return NULL; |
| 492 } | 494 } |
| 493 void* pProofProfile = NULL; | 495 void* pProofProfile = NULL; |
| 494 if (pProofParam) { | 496 if (pProofParam) { |
| 495 pProofProfile = CreateProfile(pProofParam, Icc_CLASS_PROOF, &key); | 497 pProofProfile = CreateProfile(pProofParam, Icc_CLASS_PROOF, &key); |
| 496 } | 498 } |
| 497 key << dwInputProfileType << dwOutputProfileType << dwIntent << dwFlag | 499 key << dwInputProfileType << dwOutputProfileType << dwIntent << dwFlag |
| 498 << (pProofProfile != NULL) << dwPrfIntent << dwPrfFlag; | 500 << (pProofProfile != NULL) << dwPrfIntent << dwPrfFlag; |
| 499 CFX_ByteStringC TransformKey(key.GetBuffer(), key.GetSize()); | 501 CFX_ByteStringC TransformKey(key.GetBuffer(), key.GetSize()); |
| 500 CFX_IccTransformCache* pTransformCache; | 502 CFX_IccTransformCache* pTransformCache; |
| 501 if (!m_MapTranform.Lookup(TransformKey, (void*&)pTransformCache)) { | 503 auto it = m_MapTranform.find(TransformKey); |
| 504 if (it == m_MapTranform.end()) { | |
| 502 pCmm = FX_Alloc(CLcmsCmm, 1); | 505 pCmm = FX_Alloc(CLcmsCmm, 1); |
| 503 pCmm->m_nSrcComponents = T_CHANNELS(dwInputProfileType); | 506 pCmm->m_nSrcComponents = T_CHANNELS(dwInputProfileType); |
| 504 pCmm->m_nDstComponents = T_CHANNELS(dwOutputProfileType); | 507 pCmm->m_nDstComponents = T_CHANNELS(dwOutputProfileType); |
| 505 pCmm->m_bLab = T_COLORSPACE(pInputParam->dwFormat) == PT_Lab; | 508 pCmm->m_bLab = T_COLORSPACE(pInputParam->dwFormat) == PT_Lab; |
| 506 pTransformCache = new CFX_IccTransformCache(pCmm); | 509 pTransformCache = new CFX_IccTransformCache(pCmm); |
| 507 if (pProofProfile) { | 510 if (pProofProfile) { |
| 508 pTransformCache->m_pIccTransform = cmsCreateProofingTransform( | 511 pTransformCache->m_pIccTransform = cmsCreateProofingTransform( |
| 509 pInputProfile, dwInputProfileType, pOutputProfile, | 512 pInputProfile, dwInputProfileType, pOutputProfile, |
| 510 dwOutputProfileType, pProofProfile, dwIntent, dwPrfIntent, dwPrfFlag); | 513 dwOutputProfileType, pProofProfile, dwIntent, dwPrfIntent, dwPrfFlag); |
| 511 } else { | 514 } else { |
| 512 pTransformCache->m_pIccTransform = | 515 pTransformCache->m_pIccTransform = |
| 513 cmsCreateTransform(pInputProfile, dwInputProfileType, pOutputProfile, | 516 cmsCreateTransform(pInputProfile, dwInputProfileType, pOutputProfile, |
| 514 dwOutputProfileType, dwIntent, dwFlag); | 517 dwOutputProfileType, dwIntent, dwFlag); |
| 515 } | 518 } |
| 516 pCmm->m_hTransform = pTransformCache->m_pIccTransform; | 519 pCmm->m_hTransform = pTransformCache->m_pIccTransform; |
| 517 m_MapTranform.SetAt(TransformKey, pTransformCache); | 520 m_MapTranform[TransformKey] = pTransformCache; |
| 518 } else { | 521 } else { |
| 522 pTransformCache = it->second; | |
| 519 pTransformCache->m_dwRate++; | 523 pTransformCache->m_dwRate++; |
| 520 } | 524 } |
| 521 return pTransformCache->m_pCmm; | 525 return pTransformCache->m_pCmm; |
| 522 } | 526 } |
| 523 CCodec_IccModule::~CCodec_IccModule() { | 527 CCodec_IccModule::~CCodec_IccModule() { |
| 524 FX_POSITION pos = m_MapProfile.GetStartPosition(); | 528 auto profile_it = m_MapProfile.begin(); |
| 525 CFX_ByteString key; | 529 while (profile_it != m_MapProfile.end()) { |
|
Lei Zhang
2015/08/15 00:47:33
Range-Based For Loops here and below?
Tom Sepez
2015/08/17 20:15:25
Done.
| |
| 526 CFX_IccProfileCache* pProfileCache; | 530 auto temp = profile_it++; |
| 527 while (pos) { | 531 delete temp->second; |
| 528 m_MapProfile.GetNextAssoc(pos, key, (void*&)pProfileCache); | 532 m_MapProfile.erase(temp); |
| 529 delete pProfileCache; | |
| 530 } | 533 } |
| 531 pos = m_MapTranform.GetStartPosition(); | 534 auto transform_it = m_MapTranform.begin(); |
| 532 CFX_IccTransformCache* pTransformCache; | 535 while (transform_it != m_MapTranform.end()) { |
| 533 while (pos) { | 536 auto temp = transform_it++; |
| 534 m_MapTranform.GetNextAssoc(pos, key, (void*&)pTransformCache); | 537 delete temp->second; |
| 535 delete pTransformCache; | 538 m_MapTranform.erase(temp); |
| 536 } | 539 } |
| 537 } | 540 } |
| 538 void* CCodec_IccModule::CreateTransform_sRGB(const uint8_t* pProfileData, | 541 void* CCodec_IccModule::CreateTransform_sRGB(const uint8_t* pProfileData, |
| 539 FX_DWORD dwProfileSize, | 542 FX_DWORD dwProfileSize, |
| 540 int32_t& nComponents, | 543 int32_t& nComponents, |
| 541 int32_t intent, | 544 int32_t intent, |
| 542 FX_DWORD dwSrcFormat) { | 545 FX_DWORD dwSrcFormat) { |
| 543 return IccLib_CreateTransform_sRGB(pProfileData, dwProfileSize, nComponents, | 546 return IccLib_CreateTransform_sRGB(pProfileData, dwProfileSize, nComponents, |
| 544 intent, dwSrcFormat); | 547 intent, dwSrcFormat); |
| 545 } | 548 } |
| (...skipping 1428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1974 uint8_t c1 = FXSYS_round(c * 255); | 1977 uint8_t c1 = FXSYS_round(c * 255); |
| 1975 uint8_t m1 = FXSYS_round(m * 255); | 1978 uint8_t m1 = FXSYS_round(m * 255); |
| 1976 uint8_t y1 = FXSYS_round(y * 255); | 1979 uint8_t y1 = FXSYS_round(y * 255); |
| 1977 uint8_t k1 = FXSYS_round(k * 255); | 1980 uint8_t k1 = FXSYS_round(k * 255); |
| 1978 uint8_t r, g, b; | 1981 uint8_t r, g, b; |
| 1979 AdobeCMYK_to_sRGB1(c1, m1, y1, k1, r, g, b); | 1982 AdobeCMYK_to_sRGB1(c1, m1, y1, k1, r, g, b); |
| 1980 R = 1.0f * r / 255; | 1983 R = 1.0f * r / 255; |
| 1981 G = 1.0f * g / 255; | 1984 G = 1.0f * g / 255; |
| 1982 B = 1.0f * b / 255; | 1985 B = 1.0f * b / 255; |
| 1983 } | 1986 } |
| OLD | NEW |