void Image_VGA_Planar::convert(const Pixels& newContent, const Pixels& newMask) { auto dims = this->dimensions(); unsigned long dataSize = dims.x * dims.y; stream::pos len = this->content->size(); // Cut off any leftover data or resize so there's enough space if (dataSize + this->off != len) { this->content->truncate(dataSize + this->off); } // else size didn't need to change, e.g. fixed-size VGA image Pixels pix; pix.resize(dataSize, 0); // Convert the linear data to planar unsigned int planeWidth = dims.x / 4; unsigned int planeSize = planeWidth * dims.y; for (unsigned int i = 0; i < dataSize; i++) { pix[i] = newContent[i % planeSize * 4 + i / planeSize]; } this->content->seekp(this->off, stream::start); this->content->write(pix.data(), dataSize); return; }