| 1540 | typedef std::set<int> IntSet; |
| 1541 | |
| 1542 | ImageData* PSDReader::MergeLayers(PSDLayerInfo* group, const std::vector<int>& layerIndices, ImageData* bottomImage) |
| 1543 | { |
| 1544 | AutoPerf gPerf("PSDReader::MergeLayers"); |
| 1545 | |
| 1546 | bool isImageAllocated = false; |
| 1547 | ImageData* combinedImage = bottomImage; |
| 1548 | |
| 1549 | ImageData* prevBottom = NULL; |
| 1550 | bool doPostGroupBlend = false; |
| 1551 | bool needsPrevBottom = (group != NULL) && (group->mOpacity != 255); |
| 1552 | |
| 1553 | for (int indexIdx = 0; indexIdx < (int) layerIndices.size(); indexIdx++) |
| 1554 | { |
| 1555 | PSDLayerInfo* layerInfo = mPSDLayerInfoVector[layerIndices[indexIdx]]; |
| 1556 | if (layerInfo->mBits == NULL) |
| 1557 | layerInfo->ReadData(); |
| 1558 | if (layerInfo->mKnockout == 1) // Shallow |
| 1559 | needsPrevBottom = true; |
| 1560 | } |
| 1561 | |
| 1562 | if ((group != NULL) && (bottomImage != NULL) && (group->mSectionBlendMode != 'pass')) |
| 1563 | { |
| 1564 | doPostGroupBlend = true; |
| 1565 | combinedImage = NULL; |
| 1566 | } |
| 1567 | |
| 1568 | if (needsPrevBottom && (bottomImage != NULL)) |
| 1569 | prevBottom = bottomImage->Duplicate(); |
| 1570 | |
| 1571 | bool hasAllocatedClipBase = false; |
| 1572 | PSDLayerInfo* clipBaseLayer = NULL; |
| 1573 | ImageData* clipBaseImage = NULL; |
| 1574 | |
| 1575 | for (int indexIdx = 0; indexIdx <= (int) layerIndices.size(); indexIdx++) |
| 1576 | { |
| 1577 | PSDLayerInfo* layerInfo = NULL; |
| 1578 | |
| 1579 | if (indexIdx < (int) layerIndices.size()) |
| 1580 | layerInfo = mPSDLayerInfoVector[layerIndices[indexIdx]]; |
| 1581 | |
| 1582 | PSDLayerInfo* pendingFlushLayer = NULL; |
| 1583 | ImageData* pendingFlushImage = NULL; |
| 1584 | |
| 1585 | if ((layerInfo != NULL) && (!layerInfo->mBaseClipping)) |
| 1586 | { |
| 1587 | if (clipBaseLayer != NULL) |
| 1588 | { |
| 1589 | if (clipBaseLayer->mBlendClippedElementsAsGroup) |
| 1590 | { |
| 1591 | ImageData* newImage = layerInfo->mImageEffects->FlattenInto(clipBaseImage, layerInfo, layerInfo, prevBottom, NULL); |
| 1592 | SetImageAlpha(newImage, 255); |
| 1593 | |
| 1594 | if (hasAllocatedClipBase) |
| 1595 | delete clipBaseImage; |
| 1596 | |
| 1597 | hasAllocatedClipBase = true; |
| 1598 | clipBaseImage = newImage; |
| 1599 | } |