MCPcopy Create free account
hub / github.com/Tencent/libpag / GetImageBytes

Function GetImageBytes

exporter/src/export/data/ImageBytes.cpp:86–148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84}
85
86void GetImageBytes(std::shared_ptr<PAGExportSession> session, pag::ImageBytes* imageBytes,
87 const AEGP_LayerH& layerHandle, bool isVideo, float factor) {
88 A_long width = 0;
89 A_long height = 0;
90 A_u_long srcStride = 0;
91 A_u_long dstStride = 0;
92 uint8* rgbaBytes = nullptr;
93 if (isVideo) {
94 GetVideoLayerRenderImageSize(layerHandle, srcStride, width, height);
95 } else {
96 GetImageLayerRenderImageSize(layerHandle, srcStride, width, height);
97 }
98 if (width < 0 || height < 0) {
99 return;
100 }
101 dstStride = width * 4;
102 rgbaBytes = new uint8[dstStride * height];
103 if (isVideo) {
104 GetVideoLayerRenderImage(rgbaBytes, layerHandle, srcStride, dstStride, width, height);
105 } else {
106 GetImageLayerRenderImage(rgbaBytes, layerHandle, srcStride, dstStride, width, height);
107 }
108
109 ImageRect rect = {0, 0, width, height};
110 if (session->configParam.isTagCodeSupport(pag::TagCode::ImageBytesV3)) {
111 ClipTransparentEdge(rect, rgbaBytes, width, height, dstStride);
112 }
113
114 uint8_t* data = nullptr;
115 uint8_t* scaledRGBA = nullptr;
116 int theStride = 0;
117 auto scaledWidth = static_cast<int>(ceil(rect.width * factor));
118 auto scaledHeight = static_cast<int>(ceil(rect.height * factor));
119 if (scaledWidth == rect.width && scaledHeight == rect.height) {
120 data = rgbaBytes + rect.yPos * dstStride + rect.xPos * 4;
121 theStride = dstStride;
122 } else {
123 theStride = scaledWidth * 4;
124 scaledRGBA = new uint8_t[theStride * scaledHeight + theStride * 2];
125 ScalePixels(scaledRGBA, theStride, scaledWidth, scaledHeight,
126 rgbaBytes + rect.yPos * dstStride + rect.xPos * 4, dstStride, rect.width,
127 rect.height);
128 data = scaledRGBA;
129 }
130
131 auto byteData = EncodeImageData(data, scaledWidth, scaledHeight, theStride,
132 session->configParam.imageQuality);
133 if (byteData != nullptr) {
134 imageBytes->width = width;
135 imageBytes->height = height;
136 imageBytes->anchorX = -rect.xPos;
137 imageBytes->anchorY = -rect.yPos;
138 imageBytes->scaleFactor = factor;
139 imageBytes->fileBytes = byteData;
140 }
141
142 if (scaledRGBA != nullptr) {
143 delete[] scaledRGBA;

Callers 1

exportRescaleImagesMethod · 0.85

Calls 8

GetVideoLayerRenderImageFunction · 0.85
GetImageLayerRenderImageFunction · 0.85
ClipTransparentEdgeFunction · 0.85
ScalePixelsFunction · 0.85
EncodeImageDataFunction · 0.85
isTagCodeSupportMethod · 0.80

Tested by

no test coverage detected