| 53 | } |
| 54 | |
| 55 | void |
| 56 | FrameEntry::copy(const FrameEntry& other) |
| 57 | { |
| 58 | U8* dstPixels = data(); |
| 59 | |
| 60 | assert(dstPixels); |
| 61 | if (!dstPixels) { |
| 62 | return; |
| 63 | } |
| 64 | const U8* srcPixels = other.data(); |
| 65 | const TextureRect& srcBounds = other.getKey().getTexRect(); |
| 66 | const TextureRect& dstBounds = _key.getTexRect(); |
| 67 | std::size_t srcRowSize = srcBounds.width(); |
| 68 | unsigned int srcPixelSize = 4; |
| 69 | if ( (ImageBitDepthEnum)other.getKey().getBitDepth() == eImageBitDepthFloat ) { |
| 70 | srcPixelSize *= sizeof(float); |
| 71 | } |
| 72 | srcRowSize *= srcPixelSize; |
| 73 | |
| 74 | std::size_t dstRowSize = srcBounds.width(); |
| 75 | unsigned int dstPixelSize = 4; |
| 76 | if ( (ImageBitDepthEnum)_key.getBitDepth() == eImageBitDepthFloat ) { |
| 77 | dstPixelSize *= sizeof(float); |
| 78 | } |
| 79 | dstRowSize *= dstPixelSize; |
| 80 | |
| 81 | // Fill with black and transparent because src might be smaller |
| 82 | if ( !srcPixels || |
| 83 | !srcBounds.contains(dstBounds) || |
| 84 | other.getKey().getBitDepth() != _key.getBitDepth() ) { |
| 85 | std::memset( dstPixels, 0, dstRowSize * dstBounds.height() ); |
| 86 | |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | // Copy pixels over the intersection |
| 91 | RectI srcBoundsRect; |
| 92 | srcBoundsRect.x1 = srcBounds.x1; |
| 93 | srcBoundsRect.x2 = srcBounds.x2; |
| 94 | srcBoundsRect.y1 = srcBounds.y1; |
| 95 | srcBoundsRect.y2 = srcBounds.y2; |
| 96 | RectI roi; |
| 97 | if ( !dstBounds.intersect(srcBoundsRect, &roi) ) { |
| 98 | return; |
| 99 | } |
| 100 | |
| 101 | dstPixels += (roi.y1 - dstBounds.y1) * dstRowSize + (roi.x1 - dstBounds.x1) * dstPixelSize; |
| 102 | srcPixels += (roi.y1 - srcBounds.y1) * srcRowSize + (roi.x1 - srcBounds.x1) * srcPixelSize; |
| 103 | |
| 104 | std::size_t roiRowSize = dstPixelSize * roi.width(); |
| 105 | |
| 106 | //Align dstPixel to srcPixels point |
| 107 | for (int y = roi.y1; y < roi.y2; ++y, |
| 108 | srcPixels += srcRowSize, |
| 109 | dstPixels += dstRowSize) { |
| 110 | std::memcpy(dstPixels, srcPixels, roiRowSize); |
| 111 | } |
| 112 | } // FrameEntry::copy |