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

Function Image_GetAstcHeader

engine/gamesys/src/gamesys/scripts/script_image.cpp:359–396  ·  view source on GitHub ↗

get the header of an .astc buffer * get the header of an .astc buffer * * @name image.get_astc_header * @param buffer [type:string] .astc file data buffer * * @return table [type:table|nil] header or `nil` if buffer is not a valid .astc. The header has these fields: * * - [type:number] `width`: image width * - [type:number] `height`: image height * - [type:n

Source from the content-addressed store, hash-verified

357 * ```
358 */
359 int Image_GetAstcHeader(lua_State* L)
360 {
361 int top = lua_gettop(L);
362 luaL_checktype(L, 1, LUA_TSTRING);
363 size_t data_len = 0;
364 const char* data = lua_tolstring(L, 1, &data_len);
365
366 uint32_t width, height, depth;
367 if (!dmImage::GetAstcDimensions((void*)data, (uint32_t)data_len, &width, &height, &depth))
368 {
369 return luaL_error(L, "Data is not a valid .astc file");
370 }
371
372 uint32_t block_size_x, block_size_y, block_size_z;
373 if (!dmImage::GetAstcBlockSize((void*)data, (uint32_t)data_len, &block_size_x, &block_size_y, &block_size_z))
374 {
375 return luaL_error(L, "Data is not a valid .astc file");
376 }
377
378 lua_newtable(L);
379
380 lua_pushinteger(L, width);
381 lua_setfield(L, -2, "width");
382 lua_pushinteger(L, height);
383 lua_setfield(L, -2, "height");
384 lua_pushinteger(L, depth);
385 lua_setfield(L, -2, "depth");
386
387 lua_pushinteger(L, block_size_x);
388 lua_setfield(L, -2, "block_size_x");
389 lua_pushinteger(L, block_size_y);
390 lua_setfield(L, -2, "block_size_y");
391 lua_pushinteger(L, block_size_z);
392 lua_setfield(L, -2, "block_size_z");
393
394 assert(top + 1 == lua_gettop(L));
395 return 1;
396 }
397
398 static const luaL_reg ScriptImage_methods[] =
399 {

Callers

nothing calls this directly

Calls 9

lua_gettopFunction · 0.85
luaL_checktypeFunction · 0.85
lua_tolstringFunction · 0.85
luaL_errorFunction · 0.85
lua_pushintegerFunction · 0.85
lua_setfieldFunction · 0.85
GetAstcDimensionsFunction · 0.50
GetAstcBlockSizeFunction · 0.50
assertFunction · 0.50

Tested by

no test coverage detected