fn rasterbytes_ceilpos(value: f64) -> f64 { let rest = value % 1.0; if rest > 0.0 { return value - rest + 1.0; } value } fn rasterbytes_finite(values: vector) -> bool { let mut i = 0; while i < len(values) { let value = at(values, i); if !(value - value == 0.0) { return false; } i += 1; } true } fn rasterbytes_compute(width: f64, height: f64, channels: f64, alignment: f64) -> vector { let raw = width * channels; let stride = rasterbytes_ceilpos(raw / alignment) * alignment; let bytes = stride * height; if bytes > 9007199254740991.0 { return []; } [raw, stride, bytes] } // Estimate uncompressed raster storage with aligned scanlines. // Returns [bytes per unpadded row, aligned stride, total bytes]. Each channel takes one byte. Counts must stay in the exact integer range. pub fn rasterbytes_storage(width: f64, height: f64, channels: f64, alignment: f64) -> vector { if !(width >= 1.0 && width <= 9007199254740991.0 && width % 1.0 == 0.0) { return []; } if !(height >= 1.0 && height <= 9007199254740991.0 && height % 1.0 == 0.0) { return []; } if !(channels >= 1.0 && channels <= 9007199254740991.0 && channels % 1.0 == 0.0) { return []; } if !(alignment >= 1.0 && alignment <= 9007199254740991.0 && alignment % 1.0 == 0.0) { return []; } let result = rasterbytes_compute(width, height, channels, alignment); if !rasterbytes_finite(result) { return []; } result }