| 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 #include "core/fxge/include/fx_ge.h" | 5 #include "core/fxge/include/fx_ge.h" |
| 6 | 6 |
| 7 #if defined(_SKIA_SUPPORT_) | 7 #if defined(_SKIA_SUPPORT_) |
| 8 #include "core/fxcodec/include/fx_codec.h" | 8 #include "core/fxcodec/include/fx_codec.h" |
| 9 | 9 |
| 10 #include "core/fpdfapi/fpdf_page/cpdf_shadingpattern.h" | 10 #include "core/fpdfapi/fpdf_page/cpdf_shadingpattern.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 case FXDIB_BLEND_COLOR: | 149 case FXDIB_BLEND_COLOR: |
| 150 return SkXfermode::kColor_Mode; | 150 return SkXfermode::kColor_Mode; |
| 151 case FXDIB_BLEND_LUMINOSITY: | 151 case FXDIB_BLEND_LUMINOSITY: |
| 152 return SkXfermode::kLuminosity_Mode; | 152 return SkXfermode::kLuminosity_Mode; |
| 153 case FXDIB_BLEND_NORMAL: | 153 case FXDIB_BLEND_NORMAL: |
| 154 default: | 154 default: |
| 155 return SkXfermode::kSrcOver_Mode; | 155 return SkXfermode::kSrcOver_Mode; |
| 156 } | 156 } |
| 157 } | 157 } |
| 158 | 158 |
| 159 bool AddColors(const CPDF_Function* pFunc, SkTDArray<SkColor>* skColors) { | 159 bool AddColors(const CPDF_ExpIntFunc* pFunc, SkTDArray<SkColor>* skColors) { |
| 160 if (pFunc->CountInputs() != 1) | 160 if (pFunc->CountInputs() != 1) |
| 161 return false; | 161 return false; |
| 162 ASSERT(CPDF_Function::Type::kType2ExpotentialInterpolation == | 162 if (pFunc->m_Exponent != 1) |
| 163 pFunc->GetType()); | |
| 164 const CPDF_ExpIntFunc* expIntFunc = | |
| 165 static_cast<const CPDF_ExpIntFunc*>(pFunc); | |
| 166 if (expIntFunc->m_Exponent != 1) | |
| 167 return false; | 163 return false; |
| 168 if (expIntFunc->m_nOrigOutputs != 3) | 164 if (pFunc->m_nOrigOutputs != 3) |
| 169 return false; | 165 return false; |
| 170 skColors->push(SkColorSetARGB( | |
| 171 0xFF, SkUnitScalarClampToByte(expIntFunc->m_pBeginValues[0]), | |
| 172 SkUnitScalarClampToByte(expIntFunc->m_pBeginValues[1]), | |
| 173 SkUnitScalarClampToByte(expIntFunc->m_pBeginValues[2]))); | |
| 174 skColors->push( | 166 skColors->push( |
| 175 SkColorSetARGB(0xFF, SkUnitScalarClampToByte(expIntFunc->m_pEndValues[0]), | 167 SkColorSetARGB(0xFF, SkUnitScalarClampToByte(pFunc->m_pBeginValues[0]), |
| 176 SkUnitScalarClampToByte(expIntFunc->m_pEndValues[1]), | 168 SkUnitScalarClampToByte(pFunc->m_pBeginValues[1]), |
| 177 SkUnitScalarClampToByte(expIntFunc->m_pEndValues[2]))); | 169 SkUnitScalarClampToByte(pFunc->m_pBeginValues[2]))); |
| 170 skColors->push( |
| 171 SkColorSetARGB(0xFF, SkUnitScalarClampToByte(pFunc->m_pEndValues[0]), |
| 172 SkUnitScalarClampToByte(pFunc->m_pEndValues[1]), |
| 173 SkUnitScalarClampToByte(pFunc->m_pEndValues[2]))); |
| 178 return true; | 174 return true; |
| 179 } | 175 } |
| 180 | 176 |
| 181 uint32_t GetBits32(const uint8_t* pData, int bitpos, int nbits) { | 177 uint32_t GetBits32(const uint8_t* pData, int bitpos, int nbits) { |
| 182 ASSERT(0 < nbits && nbits <= 32); | 178 ASSERT(0 < nbits && nbits <= 32); |
| 183 const uint8_t* dataPtr = &pData[bitpos / 8]; | 179 const uint8_t* dataPtr = &pData[bitpos / 8]; |
| 184 int bitShift; | 180 int bitShift; |
| 185 int bitMask; | 181 int bitMask; |
| 186 int dstShift; | 182 int dstShift; |
| 187 int bitCount = bitpos & 0x07; | 183 int bitCount = bitpos & 0x07; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 206 result |= *dataPtr++ >> bitShift & bitMask; | 202 result |= *dataPtr++ >> bitShift & bitMask; |
| 207 } | 203 } |
| 208 return result; | 204 return result; |
| 209 } | 205 } |
| 210 | 206 |
| 211 uint8_t FloatToByte(FX_FLOAT f) { | 207 uint8_t FloatToByte(FX_FLOAT f) { |
| 212 ASSERT(0 <= f && f <= 1); | 208 ASSERT(0 <= f && f <= 1); |
| 213 return (uint8_t)(f * 255.99f); | 209 return (uint8_t)(f * 255.99f); |
| 214 } | 210 } |
| 215 | 211 |
| 216 bool AddSamples(const CPDF_Function* pFunc, | 212 bool AddSamples(const CPDF_SampledFunc* pFunc, |
| 217 SkTDArray<SkColor>* skColors, | 213 SkTDArray<SkColor>* skColors, |
| 218 SkTDArray<SkScalar>* skPos) { | 214 SkTDArray<SkScalar>* skPos) { |
| 219 if (pFunc->CountInputs() != 1) | 215 if (pFunc->CountInputs() != 1) |
| 220 return false; | 216 return false; |
| 221 if (pFunc->CountOutputs() != 3) // expect rgb | 217 if (pFunc->CountOutputs() != 3) // expect rgb |
| 222 return false; | 218 return false; |
| 223 ASSERT(CPDF_Function::Type::kType0Sampled == pFunc->GetType()); | 219 if (pFunc->GetEncodeInfo().empty()) |
| 224 const CPDF_SampledFunc* sampledFunc = | |
| 225 static_cast<const CPDF_SampledFunc*>(pFunc); | |
| 226 if (!sampledFunc->m_pEncodeInfo) | |
| 227 return false; | 220 return false; |
| 228 const CPDF_SampledFunc::SampleEncodeInfo& encodeInfo = | 221 const CPDF_SampledFunc::SampleEncodeInfo& encodeInfo = |
| 229 sampledFunc->m_pEncodeInfo[0]; | 222 pFunc->GetEncodeInfo()[0]; |
| 230 if (encodeInfo.encode_min != 0) | 223 if (encodeInfo.encode_min != 0) |
| 231 return false; | 224 return false; |
| 232 if (encodeInfo.encode_max != encodeInfo.sizes - 1) | 225 if (encodeInfo.encode_max != encodeInfo.sizes - 1) |
| 233 return false; | 226 return false; |
| 234 uint32_t sampleSize = sampledFunc->m_nBitsPerSample; | 227 uint32_t sampleSize = pFunc->GetBitsPerSample(); |
| 235 uint32_t sampleCount = encodeInfo.sizes; | 228 uint32_t sampleCount = encodeInfo.sizes; |
| 236 if (sampleCount != 1U << sampleSize) | 229 if (sampleCount != 1U << sampleSize) |
| 237 return false; | 230 return false; |
| 238 if (sampledFunc->m_pSampleStream->GetSize() < | 231 if (pFunc->GetSampleStream()->GetSize() < sampleCount * 3 * sampleSize / 8) |
| 239 sampleCount * 3 * sampleSize / 8) { | |
| 240 return false; | 232 return false; |
| 241 } | 233 |
| 242 FX_FLOAT colorsMin[3]; | 234 FX_FLOAT colorsMin[3]; |
| 243 FX_FLOAT colorsMax[3]; | 235 FX_FLOAT colorsMax[3]; |
| 244 for (int i = 0; i < 3; ++i) { | 236 for (int i = 0; i < 3; ++i) { |
| 245 colorsMin[i] = sampledFunc->GetRange(i * 2); | 237 colorsMin[i] = pFunc->GetRange(i * 2); |
| 246 colorsMax[i] = sampledFunc->GetRange(i * 2 + 1); | 238 colorsMax[i] = pFunc->GetRange(i * 2 + 1); |
| 247 } | 239 } |
| 248 const uint8_t* pSampleData = sampledFunc->m_pSampleStream->GetData(); | 240 const uint8_t* pSampleData = pFunc->GetSampleStream()->GetData(); |
| 249 for (uint32_t i = 0; i < sampleCount; ++i) { | 241 for (uint32_t i = 0; i < sampleCount; ++i) { |
| 250 FX_FLOAT floatColors[3]; | 242 FX_FLOAT floatColors[3]; |
| 251 for (uint32_t j = 0; j < 3; ++j) { | 243 for (uint32_t j = 0; j < 3; ++j) { |
| 252 int sample = GetBits32(pSampleData, (i * 3 + j) * sampleSize, sampleSize); | 244 int sample = GetBits32(pSampleData, (i * 3 + j) * sampleSize, sampleSize); |
| 253 FX_FLOAT interp = (FX_FLOAT)sample / (sampleCount - 1); | 245 FX_FLOAT interp = (FX_FLOAT)sample / (sampleCount - 1); |
| 254 floatColors[j] = colorsMin[j] + (colorsMax[j] - colorsMin[j]) * interp; | 246 floatColors[j] = colorsMin[j] + (colorsMax[j] - colorsMin[j]) * interp; |
| 255 } | 247 } |
| 256 SkColor color = | 248 SkColor color = |
| 257 SkPackARGB32(0xFF, FloatToByte(floatColors[0]), | 249 SkPackARGB32(0xFF, FloatToByte(floatColors[0]), |
| 258 FloatToByte(floatColors[1]), FloatToByte(floatColors[2])); | 250 FloatToByte(floatColors[1]), FloatToByte(floatColors[2])); |
| 259 skColors->push(color); | 251 skColors->push(color); |
| 260 skPos->push((FX_FLOAT)i / (sampleCount - 1)); | 252 skPos->push((FX_FLOAT)i / (sampleCount - 1)); |
| 261 } | 253 } |
| 262 return true; | 254 return true; |
| 263 } | 255 } |
| 264 | 256 |
| 265 bool AddStitching(const CPDF_Function* pFunc, | 257 bool AddStitching(const CPDF_StitchFunc* pFunc, |
| 266 SkTDArray<SkColor>* skColors, | 258 SkTDArray<SkColor>* skColors, |
| 267 SkTDArray<SkScalar>* skPos) { | 259 SkTDArray<SkScalar>* skPos) { |
| 268 int inputs = pFunc->CountInputs(); | 260 int inputs = pFunc->CountInputs(); |
| 269 ASSERT(CPDF_Function::Type::kType3Stitching == pFunc->GetType()); | 261 FX_FLOAT boundsStart = pFunc->GetDomain(0); |
| 270 const CPDF_StitchFunc* stitchFunc = | |
| 271 static_cast<const CPDF_StitchFunc*>(pFunc); | |
| 272 FX_FLOAT boundsStart = stitchFunc->GetDomain(0); | |
| 273 | 262 |
| 263 const auto& subFunctions = pFunc->GetSubFunctions(); |
| 274 for (int i = 0; i < inputs; ++i) { | 264 for (int i = 0; i < inputs; ++i) { |
| 275 const CPDF_Function* pSubFunc = stitchFunc->m_pSubFunctions[i]; | 265 const CPDF_ExpIntFunc* pSubFunc = subFunctions[i]->ToExpIntFunc(); |
| 276 if (pSubFunc->GetType() != | 266 if (!pSubFunc) |
| 277 CPDF_Function::Type::kType2ExpotentialInterpolation) | |
| 278 return false; | 267 return false; |
| 279 if (!AddColors(pSubFunc, skColors)) | 268 if (!AddColors(pSubFunc, skColors)) |
| 280 return false; | 269 return false; |
| 281 FX_FLOAT boundsEnd = | 270 FX_FLOAT boundsEnd = |
| 282 i < inputs - 1 ? stitchFunc->m_pBounds[i] : stitchFunc->GetDomain(1); | 271 i < inputs - 1 ? pFunc->GetBound(i) : pFunc->GetDomain(1); |
| 283 skPos->push(boundsStart); | 272 skPos->push(boundsStart); |
| 284 skPos->push(boundsEnd); | 273 skPos->push(boundsEnd); |
| 285 boundsStart = boundsEnd; | 274 boundsStart = boundsEnd; |
| 286 } | 275 } |
| 287 return true; | 276 return true; |
| 288 } | 277 } |
| 289 | 278 |
| 290 void RgbByteOrderTransferBitmap(CFX_DIBitmap* pBitmap, | 279 void RgbByteOrderTransferBitmap(CFX_DIBitmap* pBitmap, |
| 291 int dest_left, | 280 int dest_left, |
| 292 int dest_top, | 281 int dest_top, |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 if (!pCoords) | 796 if (!pCoords) |
| 808 return true; | 797 return true; |
| 809 // TODO(caryclark) Respect Domain[0], Domain[1]. (Don't know what they do | 798 // TODO(caryclark) Respect Domain[0], Domain[1]. (Don't know what they do |
| 810 // yet.) | 799 // yet.) |
| 811 SkTDArray<SkColor> skColors; | 800 SkTDArray<SkColor> skColors; |
| 812 SkTDArray<SkScalar> skPos; | 801 SkTDArray<SkScalar> skPos; |
| 813 for (int j = 0; j < nFuncs; j++) { | 802 for (int j = 0; j < nFuncs; j++) { |
| 814 const CPDF_Function* pFunc = pFuncs[j]; | 803 const CPDF_Function* pFunc = pFuncs[j]; |
| 815 if (!pFunc) | 804 if (!pFunc) |
| 816 continue; | 805 continue; |
| 817 switch (pFunc->GetType()) { | 806 |
| 818 case CPDF_Function::Type::kType0Sampled: | 807 if (const CPDF_SampledFunc* pSampledFunc = pFunc->ToSampledFunc()) { |
| 819 /* TODO(caryclark) | 808 /* TODO(caryclark) |
| 820 Type 0 Sampled Functions in PostScript can also have an Order integer | 809 Type 0 Sampled Functions in PostScript can also have an Order integer |
| 821 in the dictionary. PDFium doesn't appear to check for this anywhere. | 810 in the dictionary. PDFium doesn't appear to check for this anywhere. |
| 822 */ | 811 */ |
| 823 if (!AddSamples(pFunc, &skColors, &skPos)) | 812 if (!AddSamples(pSampledFunc, &skColors, &skPos)) |
| 824 return false; | |
| 825 break; | |
| 826 case CPDF_Function::Type::kType2ExpotentialInterpolation: | |
| 827 if (!AddColors(pFunc, &skColors)) | |
| 828 return false; | |
| 829 skPos.push(0); | |
| 830 skPos.push(1); | |
| 831 break; | |
| 832 case CPDF_Function::Type::kType3Stitching: | |
| 833 if (!AddStitching(pFunc, &skColors, &skPos)) | |
| 834 return false; | |
| 835 break; | |
| 836 default: | |
| 837 return false; | 813 return false; |
| 814 } else if (const CPDF_ExpIntFunc* pExpIntFuc = pFunc->ToExpIntFunc()) { |
| 815 if (!AddColors(pExpIntFuc, &skColors)) |
| 816 return false; |
| 817 skPos.push(0); |
| 818 skPos.push(1); |
| 819 } else if (const CPDF_StitchFunc* pStitchFunc = pFunc->ToStitchFunc()) { |
| 820 if (!AddStitching(pStitchFunc, &skColors, &skPos)) |
| 821 return false; |
| 822 } else { |
| 823 return false; |
| 838 } | 824 } |
| 839 } | 825 } |
| 840 CPDF_Array* pArray = pDict->GetArrayBy("Extend"); | 826 CPDF_Array* pArray = pDict->GetArrayBy("Extend"); |
| 841 bool clipStart = !pArray || !pArray->GetIntegerAt(0); | 827 bool clipStart = !pArray || !pArray->GetIntegerAt(0); |
| 842 bool clipEnd = !pArray || !pArray->GetIntegerAt(1); | 828 bool clipEnd = !pArray || !pArray->GetIntegerAt(1); |
| 843 SkPaint paint; | 829 SkPaint paint; |
| 844 paint.setAntiAlias(true); | 830 paint.setAntiAlias(true); |
| 845 paint.setAlpha(alpha); | 831 paint.setAlpha(alpha); |
| 846 SkMatrix skMatrix = ToSkMatrix(*pMatrix); | 832 SkMatrix skMatrix = ToSkMatrix(*pMatrix); |
| 847 SkRect skRect = SkRect::MakeLTRB(clip_rect.left, clip_rect.top, | 833 SkRect skRect = SkRect::MakeLTRB(clip_rect.left, clip_rect.top, |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1186 SetDeviceDriver(pDriver); | 1172 SetDeviceDriver(pDriver); |
| 1187 return true; | 1173 return true; |
| 1188 } | 1174 } |
| 1189 | 1175 |
| 1190 CFX_FxgeDevice::~CFX_FxgeDevice() { | 1176 CFX_FxgeDevice::~CFX_FxgeDevice() { |
| 1191 if (m_bOwnedBitmap && GetBitmap()) | 1177 if (m_bOwnedBitmap && GetBitmap()) |
| 1192 delete GetBitmap(); | 1178 delete GetBitmap(); |
| 1193 } | 1179 } |
| 1194 | 1180 |
| 1195 #endif | 1181 #endif |
| OLD | NEW |