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