MCPcopy Create free account
hub / github.com/OpenPathGuidingLibrary/openpgl / EncodeTiledLevel

Function EncodeTiledLevel

third-party/tinyexr/tinyexr.h:7234–7357  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7232}
7233
7234static int EncodeTiledLevel(const EXRImage* level_image, const EXRHeader* exr_header,
7235 const std::vector<tinyexr::ChannelInfo>& channels,
7236 std::vector<std::vector<unsigned char> >& data_list,
7237 size_t start_index, // for data_list
7238 int num_x_tiles, int num_y_tiles,
7239 const std::vector<size_t>& channel_offset_list,
7240 int pixel_data_size,
7241 const void* compression_param, // must be set if zfp compression is enabled
7242 std::string* err) {
7243 int num_tiles = num_x_tiles * num_y_tiles;
7244 if (num_tiles != level_image->num_tiles) {
7245 if (err) {
7246 (*err) += "Invalid number of tiles in argument.\n";
7247 }
7248 return TINYEXR_ERROR_INVALID_ARGUMENT;
7249 }
7250
7251 if ((exr_header->tile_size_x > level_image->width || exr_header->tile_size_y > level_image->height) &&
7252 level_image->level_x == 0 && level_image->level_y == 0) {
7253 if (err) {
7254 (*err) += "Failed to encode tile data.\n";
7255 }
7256 return TINYEXR_ERROR_INVALID_DATA;
7257 }
7258
7259
7260#if TINYEXR_HAS_CXX11 && (TINYEXR_USE_THREAD > 0)
7261 std::atomic<bool> invalid_data(false);
7262#else
7263 bool invalid_data(false);
7264#endif
7265
7266#if TINYEXR_HAS_CXX11 && (TINYEXR_USE_THREAD > 0)
7267 std::vector<std::thread> workers;
7268 std::atomic<int> tile_count(0);
7269
7270 int num_threads = std::max(1, int(std::thread::hardware_concurrency()));
7271 if (num_threads > int(num_tiles)) {
7272 num_threads = int(num_tiles);
7273 }
7274
7275 for (int t = 0; t < num_threads; t++) {
7276 workers.emplace_back(std::thread([&]() {
7277 int i = 0;
7278 while ((i = tile_count++) < num_tiles) {
7279
7280#else
7281 // Use signed int since some OpenMP compiler doesn't allow unsigned type for
7282 // `parallel for`
7283#if TINYEXR_USE_OPENMP
7284#pragma omp parallel for
7285#endif
7286 for (int i = 0; i < num_tiles; i++) {
7287
7288#endif
7289 size_t tile_idx = static_cast<size_t>(i);
7290 size_t data_idx = tile_idx + start_index;
7291

Callers 1

EncodeChunkFunction · 0.85

Calls 5

EncodePixelDataFunction · 0.85
swap4Function · 0.85
maxFunction · 0.50
resizeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected