MCPcopy Create free account
hub / github.com/defold/defold / Load

Function Load

engine/dlib/src/dlib/image.cpp:86–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84 }
85
86 Result Load(const void* buffer, uint32_t buffer_size, bool premult, bool flip_vertically, Image* image)
87 {
88 int x, y, comp;
89
90 stbi_set_flip_vertically_on_load(flip_vertically);
91
92 unsigned char* ret = stbi_load_from_memory((const stbi_uc*) buffer, (int) buffer_size, &x, &y, &comp, 0);
93
94 // Reset to default state
95 stbi_set_flip_vertically_on_load(0);
96
97 if (ret) {
98 Image i;
99 i.m_Width = (uint32_t) x;
100 i.m_Height = (uint32_t) y;
101 switch (comp) {
102 case 1:
103 i.m_Type = TYPE_LUMINANCE;
104 break;
105 case 2:
106 i.m_Type = TYPE_LUMINANCE_ALPHA;
107 if (premult)
108 {
109 PremultiplyLuminance(ret, x, y);
110 }
111 break;
112 case 3:
113 i.m_Type = TYPE_RGB;
114 break;
115 case 4:
116 i.m_Type = TYPE_RGBA;
117 if (premult)
118 {
119 PremultiplyRGBA(ret, x, y);
120 }
121 break;
122 default:
123 dmLogError("Unexpected number of components in image (%d)", comp);
124 free(ret);
125 return RESULT_IMAGE_ERROR;
126 }
127 i.m_Buffer = (void*) ret;
128 *image = i;
129 return RESULT_OK;
130 } else {
131 dmLogError("Failed to load image: '%s'", stbi_failure_reason());
132 return RESULT_IMAGE_ERROR;
133 }
134 }
135
136 void Free(Image* image)
137 {

Callers 12

NewImageFunction · 0.70
LaunchFunction · 0.50
SetUpMethod · 0.50
SetUpMethod · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
TESTFunction · 0.50
engine.cppFile · 0.50
mainFunction · 0.50
mainFunction · 0.50

Calls 6

stbi_load_from_memoryFunction · 0.85
PremultiplyLuminanceFunction · 0.85
PremultiplyRGBAFunction · 0.85
freeFunction · 0.85
stbi_failure_reasonFunction · 0.85

Tested by 9

SetUpMethod · 0.40
SetUpMethod · 0.40
mainFunction · 0.40
mainFunction · 0.40
mainFunction · 0.40
mainFunction · 0.40
TESTFunction · 0.40
mainFunction · 0.40
mainFunction · 0.40