Optimize the alpha-only code paths
The code coverage report indicates that the if self.is_alpha_only() {
block in ImageSurface::convolve()
is never used:
This is only called from gaussian_blur.rs:gaussian_blur()
. The intent is that blurring an alpha-only surface will only process a single channel. However, I think all alpha-only surfaces are actually full ARGB. From ImageSurface::extract_alpha()
:
pub fn extract_alpha(&self, bounds: IRect) -> Result<SharedImageSurface, cairo::Error> {
let mut output_surface =
cairo::ImageSurface::create(cairo::Format::ARgb32, self.width, self.height)?;
let output_stride = output_surface.stride() as usize;
{
let mut output_data = output_surface.data().unwrap();
for (x, y, Pixel { a, .. }) in Pixels::within(self, bounds) {
let output_pixel = Pixel {
r: 0,
g: 0,
b: 0,
a,
};
output_data.set_pixel(output_stride, output_pixel, x, y);
}
}
SharedImageSurface::wrap(output_surface, SurfaceType::AlphaOnly)
}
That function could very well output a cairo::Format::A8
. I don't know if the rest of the code is equipped to handle that (we assume ARGB in a lot of places), but it's worth finding where it's not handled and fixing it.