See header for documentation. */
| 26 | |
| 27 | /* See header for documentation. */ |
| 28 | astcenc_image_ptr alloc_image( |
| 29 | unsigned int bitness, |
| 30 | unsigned int dim_x, |
| 31 | unsigned int dim_y, |
| 32 | unsigned int dim_z |
| 33 | ) { |
| 34 | astcenc_image_ptr img { new astcenc_image }; |
| 35 | |
| 36 | // Initialize everything so that we can handle deletion of a partially |
| 37 | // constructed object if new[] throws a bad_alloc exception |
| 38 | img->dim_x = dim_x; |
| 39 | img->dim_y = dim_y; |
| 40 | img->dim_z = dim_z; |
| 41 | img->data_type = ASTCENC_TYPE_U8; |
| 42 | img->data = nullptr; |
| 43 | |
| 44 | // Ensure this is done as a size_t to avoid overflow - calling code has |
| 45 | // checked that the product will fit in a size_t without overflowing. |
| 46 | size_t plane_components = static_cast<size_t>(dim_x) * dim_y * 4; |
| 47 | |
| 48 | void** data = new void*[dim_z] {}; |
| 49 | img->data = data; |
| 50 | |
| 51 | if (bitness == 8) |
| 52 | { |
| 53 | img->data_type = ASTCENC_TYPE_U8; |
| 54 | for (unsigned int z = 0; z < dim_z; z++) |
| 55 | { |
| 56 | data[z] = new uint8_t[plane_components]; |
| 57 | } |
| 58 | } |
| 59 | else if (bitness == 16) |
| 60 | { |
| 61 | img->data_type = ASTCENC_TYPE_F16; |
| 62 | for (unsigned int z = 0; z < dim_z; z++) |
| 63 | { |
| 64 | data[z] = new uint16_t[plane_components]; |
| 65 | } |
| 66 | } |
| 67 | else // if (bitness == 32) |
| 68 | { |
| 69 | assert(bitness == 32); |
| 70 | img->data_type = ASTCENC_TYPE_F32; |
| 71 | for (unsigned int z = 0; z < dim_z; z++) |
| 72 | { |
| 73 | data[z] = new float[plane_components]; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | return img; |
| 78 | } |
| 79 | |
| 80 | /* See header for documentation. */ |
| 81 | void astcenc_image_deleter::operator()( |
no outgoing calls
no test coverage detected