RtInt TParameterDeclaration::getBytes(RtInt colorComps) const { RtInt typeNum = getType(); if ( typeNum == TYPE_COLOR ) return getCardinality() * colorComps * m_typeSizes[typeNum]; return getCardinality() * m_typeSizes[typeNum]; }
bool TinyBitmap::add(const uint32_t val){ const uint16_t val_div = val >> 16; const uint16_t val_mod = val & 0xFFFF; if (tiny_bmp == nullptr){ const int aligned_alloc = posix_memalign(reinterpret_cast<void**>(&tiny_bmp), 8, sizes[0] * sizeof(uint16_t)); if (aligned_alloc != 0){ cerr << "TinyBitmap::add(): Aligned memory could not be allocated with error " << aligned_alloc << endl; exit(1); } std::memset(tiny_bmp, 0, sizes[0] * sizeof(uint16_t)); tiny_bmp[0] = (sizes[0] << 3) | bmp_mode | bits_16; tiny_bmp[2] = val_div; } if (getOffset() != val_div) return false; uint16_t sz = getSize(); uint16_t mode = getMode(); uint16_t cardinality = getCardinality(); // Compute if inserting new value triggers an increase of the container size if (((mode == bmp_mode) && (val_mod >= ((sz - 3) << 4))) || ((mode != bmp_mode) && (cardinality >= (sz - 3 - (mode == rle_list_mode))))){ // Means that in its current mode, container size must be increased to add a value // We need to compute if which mode has the smaller container size if ((mode != bmp_mode) && contains(val)) return true; runOptimize(); sz = getSize(); mode = getMode(); cardinality = getCardinality(); if ((mode != rle_list_mode) || (cardinality > (sz - 5))){ const uint16_t nb_uint_bmp = getNextSize((std::max(val_mod, static_cast<const uint16_t>(maximum() & 0xFFFF)) >> 4) + 4); bool res; if (mode == rle_list_mode){ const uint16_t nb_val = size(); const uint16_t nb_val_rle_list = getNextSize(getNextSize(sz) + 1); const uint16_t nb_val_list = getNextSize(nb_val + 4); const uint16_t nb_val_min = (nb_val > (0xFFFF - 48)) ? 0xFFFF : std::min(nb_val_rle_list, std::min(nb_val_list, nb_uint_bmp)); //cout << "TinyBitmap::add(): Size must be increased" << endl; //cout << "TinyBitmap::add(): nb_val_rle_list = " << nb_val_rle_list << endl; //cout << "TinyBitmap::add(): nb_val_list = " << nb_val_list << endl; //cout << "TinyBitmap::add(): nb_uint_bmp = " << nb_uint_bmp << endl; //cout << "TinyBitmap::add(): nb_val_min = " << nb_val_min << endl; if (nb_val_min > sizes[nb_sizes - 1]) return false; res = (nb_val_rle_list == nb_val_min); res = res ? change_sz(nb_val_min) : switch_mode(nb_val_min, (nb_val_list <= nb_uint_bmp) ? list_mode : bmp_mode); cardinality = getCardinality(); } else { const uint16_t nb_val_list = getNextSize(cardinality + 4); //cout << "TinyBitmap::add(): Size must be increased" << endl; //cout << "TinyBitmap::add(): max_val_mode = " << max_val_mode << endl; //cout << "TinyBitmap::add(): nb_uint_bmp = " << nb_uint_bmp << endl; //cout << "TinyBitmap::add(): nb_val_list = " << nb_val_list << endl; if (mode == bmp_mode) res = (nb_uint_bmp <= nb_val_list) ? change_sz(nb_uint_bmp) : switch_mode(nb_val_list, list_mode); else res = (nb_val_list <= nb_uint_bmp) ? change_sz(nb_val_list) : switch_mode(nb_uint_bmp, bmp_mode); } if (!res) return false; mode = getMode(); } } //cout << "TinyBitmap::add(): mode = " << mode << endl; if (mode == bmp_mode){ // Bitmap mode uint16_t& div = tiny_bmp[(val_mod >> 4) + 3]; const uint16_t mod = 1U << (val_mod & 0xF); tiny_bmp[1] += ((div & mod) == 0); // += (1 << 8) if not already set (increase cardinality in header), 0 otherwise div |= mod; // Insert new value }