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

Function EncodeTiledLevel

Source/ThirdParty/tinyexr.h:8827–8953  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8825}
8826
8827static int EncodeTiledLevel(const EXRImage* level_image, const EXRHeader* exr_header,
8828 const std::vector<tinyexr::ChannelInfo>& channels,
8829 std::vector<std::vector<unsigned char> >& data_list,
8830 size_t start_index, // for data_list
8831 int num_x_tiles, int num_y_tiles,
8832 const std::vector<size_t>& channel_offset_list,
8833 int pixel_data_size,
8834 const void* compression_param, // must be set if zfp compression is enabled
8835 std::string* err) {
8836 int num_tiles = num_x_tiles * num_y_tiles;
8837 if (num_tiles != level_image->num_tiles) {
8838 if (err) {
8839 (*err) += "Invalid number of tiles in argument.\n";
8840 }
8841 return TINYEXR_ERROR_INVALID_ARGUMENT;
8842 }
8843
8844 if ((exr_header->tile_size_x > level_image->width || exr_header->tile_size_y > level_image->height) &&
8845 level_image->level_x == 0 && level_image->level_y == 0) {
8846 if (err) {
8847 (*err) += "Failed to encode tile data.\n";
8848 }
8849 return TINYEXR_ERROR_INVALID_DATA;
8850 }
8851
8852
8853#if TINYEXR_HAS_CXX11 && (TINYEXR_USE_THREAD > 0)
8854 std::atomic<bool> invalid_data(false);
8855#else
8856 bool invalid_data(false);
8857#endif
8858
8859#if TINYEXR_HAS_CXX11 && (TINYEXR_USE_THREAD > 0)
8860 std::vector<std::thread> workers;
8861 std::atomic<int> tile_count(0);
8862
8863 int num_threads = std::max(1, int(std::thread::hardware_concurrency()));
8864#if (TINYEXR_MAX_THREADS > 0)
8865 num_threads = std::min(num_threads,TINYEXR_MAX_THREADS);
8866#endif
8867 if (num_threads > int(num_tiles)) {
8868 num_threads = int(num_tiles);
8869 }
8870
8871 for (int t = 0; t < num_threads; t++) {
8872 workers.emplace_back(std::thread([&]() {
8873 int i = 0;
8874 while ((i = tile_count++) < num_tiles) {
8875
8876#else
8877 // Use signed int since some OpenMP compiler doesn't allow unsigned type for
8878 // `parallel for`
8879#if TINYEXR_USE_OPENMP
8880#pragma omp parallel for
8881#endif
8882 for (int i = 0; i < num_tiles; i++) {
8883
8884#endif

Callers 1

EncodeChunkFunction · 0.85

Calls 4

EncodePixelDataFunction · 0.85
swap4Function · 0.85
maxFunction · 0.50
minFunction · 0.50

Tested by

no test coverage detected