MCPcopy Create free account
hub / github.com/RenderKit/embree / EncodeTiledLevel

Function EncodeTiledLevel

tutorials/common/image/tinyexr.h:7318–7444  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7316}
7317
7318static int EncodeTiledLevel(const EXRImage* level_image, const EXRHeader* exr_header,
7319 const std::vector<tinyexr::ChannelInfo>& channels,
7320 std::vector<std::vector<unsigned char> >& data_list,
7321 size_t start_index, // for data_list
7322 int num_x_tiles, int num_y_tiles,
7323 const std::vector<size_t>& channel_offset_list,
7324 int pixel_data_size,
7325 const void* compression_param, // must be set if zfp compression is enabled
7326 std::string* err) {
7327 int num_tiles = num_x_tiles * num_y_tiles;
7328 if (num_tiles != level_image->num_tiles) {
7329 if (err) {
7330 (*err) += "Invalid number of tiles in argument.\n";
7331 }
7332 return TINYEXR_ERROR_INVALID_ARGUMENT;
7333 }
7334
7335 if ((exr_header->tile_size_x > level_image->width || exr_header->tile_size_y > level_image->height) &&
7336 level_image->level_x == 0 && level_image->level_y == 0) {
7337 if (err) {
7338 (*err) += "Failed to encode tile data.\n";
7339 }
7340 return TINYEXR_ERROR_INVALID_DATA;
7341 }
7342
7343
7344#if TINYEXR_HAS_CXX11 && (TINYEXR_USE_THREAD > 0)
7345 std::atomic<bool> invalid_data(false);
7346#else
7347 bool invalid_data(false);
7348#endif
7349
7350#if TINYEXR_HAS_CXX11 && (TINYEXR_USE_THREAD > 0)
7351 std::vector<std::thread> workers;
7352 std::atomic<int> tile_count(0);
7353
7354 int num_threads = std::max(1, int(std::thread::hardware_concurrency()));
7355#if (TINYEXR_MAX_THREADS > 0)
7356 num_threads = std::min(num_threads,TINYEXR_MAX_THREADS);
7357#endif
7358 if (num_threads > int(num_tiles)) {
7359 num_threads = int(num_tiles);
7360 }
7361
7362 for (int t = 0; t < num_threads; t++) {
7363 workers.emplace_back(std::thread([&]() {
7364 int i = 0;
7365 while ((i = tile_count++) < num_tiles) {
7366
7367#else
7368 // Use signed int since some OpenMP compiler doesn't allow unsigned type for
7369 // `parallel for`
7370#if TINYEXR_USE_OPENMP
7371#pragma omp parallel for
7372#endif
7373 for (int i = 0; i < num_tiles; i++) {
7374
7375#endif

Callers 1

EncodeChunkFunction · 0.85

Calls 7

EncodePixelDataFunction · 0.85
swap4Function · 0.85
joinMethod · 0.80
maxFunction · 0.50
minFunction · 0.50
resizeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected