I’m trying to get the average pixel color of an image.
My source image is a 512x512 image with these colors:
There’s a single pixel on the very top left with the rgb colors 64,191,84.
The target image has the same format and the dimensions 1x1.
I’ve tried using [i]vkCmdBlitImage[/i] to copy and rescale the image:
int32_t wSrc = 512;
int32_t hSrc = 512;
int32_t wDest = 1;
int32_t hDest = 1;
vk::ImageSubresourceLayers srcLayer {vk::ImageAspectFlagBits::eColor,0,0,1};
vk::ImageSubresourceLayers destLayer {vk::ImageAspectFlagBits::eColor,0,0,1};
vk::ImageBlit blit {
srcLayer,
{
vk::Offset3D{0,0,0},
vk::Offset3D{
wSrc,
hSrc,1
}
},destLayer,
{
vk::Offset3D{0,0,0},
vk::Offset3D{
wDest,
hDest,1
}
}
};
m_buffer.blitImage(imgSrc,vk::ImageLayout::eTransferSrcOptimal,imgDest,vk::ImageLayout::eTransferDstOptimal,1,&blit,vk::Filter::eLinear);
However, this results in the target image having the color 64,191,84 for its pixel. It seems to just grab the pixel at the top left without doing any interpolation at all.
If I use larger dimensions for the target image, it works:
64x64 | 16x16:
At lower dimensions, some of the colors ‘vanish’, and they’re not incorporated into the final image at all:
4x4 | 2x2:
I’ve tried using nearest filtering instead, same result.
How can I get around this? I suppose one way would be to generate multiple images (With half the size of the previous image) until I’ve reached 1x1 (Essentially generate all of the mipmaps), however I need to do this each frame. Is there a faster way?