MCPcopy Create free account
hub / github.com/ARM-software/astc-encoder / main

Function main

Utils/Example/astc_api_example.cpp:40–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38#include "ThirdParty/stb_image_write.h"
39
40int main(int argc, char **argv)
41{
42 // Parse command line
43 if (argc != 3)
44 {
45 printf("Usage:\n"
46 " %s <source> <dest>\n\n"
47 " <source> : Uncompressed LDR source image.\n"
48 " <dest> : Uncompressed LDR destination image (png).\n"
49 , argv[0]);
50 return 1;
51 }
52
53 // ------------------------------------------------------------------------
54 // For the purposes of this sample we hard-code the compressor settings
55 static const unsigned int thread_count = 1;
56 static const unsigned int block_x = 6;
57 static const unsigned int block_y = 6;
58 static const unsigned int block_z = 1;
59 static const astcenc_profile profile = ASTCENC_PRF_LDR;
60 static const float quality = ASTCENC_PRE_MEDIUM;
61 static const astcenc_swizzle swizzle {
62 ASTCENC_SWZ_R, ASTCENC_SWZ_G, ASTCENC_SWZ_B, ASTCENC_SWZ_A
63 };
64
65 // ------------------------------------------------------------------------
66 // Load input image, forcing 4 components
67 int image_x, image_y, image_c;
68 uint8_t *image_data = (uint8_t*)stbi_load(argv[1], &image_x, &image_y, &image_c, 4);
69 if (!image_data)
70 {
71 printf("Failed to load image \"%s\"\n", argv[1]);
72 return 1;
73 }
74
75 // Compute the number of ASTC blocks in each dimension
76 unsigned int block_count_x = (image_x + block_x - 1) / block_x;
77 unsigned int block_count_y = (image_y + block_y - 1) / block_y;
78
79 // ------------------------------------------------------------------------
80 // Initialize the default configuration for the block size and quality
81 astcenc_config config;
82 astcenc_error status;
83 status = astcenc_config_init(profile, block_x, block_y, block_z, quality, 0, &config);
84 if (status != ASTCENC_SUCCESS)
85 {
86 printf("ERROR: Codec config init failed: %s\n", astcenc_get_error_string(status));
87 return 1;
88 }
89
90 // ... power users can customize any config settings after calling
91 // config_init() and before calling context alloc().
92
93 // ------------------------------------------------------------------------
94 // Create a context based on the configuration
95 astcenc_context* context;
96 status = astcenc_context_alloc(&config, thread_count, &context, nullptr);
97 if (status != ASTCENC_SUCCESS)

Callers

nothing calls this directly

Calls 9

stbi_loadFunction · 0.85
astcenc_config_initFunction · 0.85
astcenc_get_error_stringFunction · 0.85
astcenc_context_allocFunction · 0.85
astcenc_compress_imageFunction · 0.85
astcenc_decompress_imageFunction · 0.85
stbi_write_pngFunction · 0.85
stbi_image_freeFunction · 0.85
astcenc_context_freeFunction · 0.85

Tested by

no test coverage detected