MCPcopy Create free account
hub / github.com/axmolengine/axmol / getImageData

Function getImageData

core/renderer/TextureCube.cpp:37–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35{
36
37unsigned char* getImageData(Image* img, backend::PixelFormat& ePixFmt)
38{
39 unsigned char* pTmpData = img->getData();
40 unsigned int* inPixel32 = nullptr;
41 unsigned char* inPixel8 = nullptr;
42 unsigned short* outPixel16 = nullptr;
43 bool bHasAlpha = img->hasAlpha();
44 size_t uBPP = img->getBitPerPixel();
45
46 int nWidth = img->getWidth();
47 int nHeight = img->getHeight();
48
49 // compute pixel format
50 if (bHasAlpha)
51 {
52 ePixFmt = backend::PixelFormat::RGBA8;
53 }
54 else
55 {
56 if (uBPP >= 8)
57 {
58 ePixFmt = backend::PixelFormat::RGB8;
59 }
60 else
61 {
62 ePixFmt = backend::PixelFormat::RGB565;
63 }
64 }
65
66 // Repack the pixel data into the right format
67 unsigned int uLen = nWidth * nHeight;
68
69 if (ePixFmt == backend::PixelFormat::RGB565)
70 {
71 if (bHasAlpha)
72 {
73 // Convert "RRRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA" to "RRRRRGGGGGGBBBBB"
74 inPixel32 = (unsigned int*)img->getData();
75 pTmpData = (unsigned char*)malloc(nWidth * nHeight * 2);
76 outPixel16 = (unsigned short*)pTmpData;
77
78 for (unsigned int i = 0; i < uLen; ++i, ++inPixel32)
79 {
80 *outPixel16++ = ((((*inPixel32 >> 0) & 0xFF) >> 3) << 11) | // R
81 ((((*inPixel32 >> 8) & 0xFF) >> 2) << 5) | // G
82 ((((*inPixel32 >> 16) & 0xFF) >> 3) << 0); // B
83 }
84 }
85 else
86 {
87 // Convert "RRRRRRRRGGGGGGGGBBBBBBBB" to "RRRRRGGGGGGBBBBB"
88 pTmpData = (unsigned char*)malloc(nWidth * nHeight * 2);
89 outPixel16 = (unsigned short*)pTmpData;
90 inPixel8 = (unsigned char*)img->getData();
91
92 for (unsigned int i = 0; i < uLen; ++i)
93 {
94 unsigned char R = *inPixel8++;

Callers 1

initMethod · 0.85

Calls 5

hasAlphaMethod · 0.80
getBitPerPixelMethod · 0.80
getDataMethod · 0.45
getWidthMethod · 0.45
getHeightMethod · 0.45

Tested by

no test coverage detected