Skip to content

Instantly share code, notes, and snippets.

@TheLukeGuy
Created September 11, 2020 17:43
Show Gist options
  • Save TheLukeGuy/86d3dfb90fdb1d219552d71974439bfa to your computer and use it in GitHub Desktop.
Save TheLukeGuy/86d3dfb90fdb1d219552d71974439bfa to your computer and use it in GitHub Desktop.
Simple (probably inefficient) image upscaling algorithm in C++ which enlarges the individual pixels.
std::byte scaled[scaledWidth * scaledHeight * 4];
int pixelSize = scaledWidth / width;
for (int realRow = 0; realRow < height; ++realRow) {
for (int realColumn = 0; realColumn < width; ++realColumn) {
int realIndex = (realRow * width) + realColumn;
std::byte *realRed = &image[realIndex * 5];
for (int pixelRow = 0; pixelRow < pixelSize; ++pixelRow) {
for (int pixelColumn = 0; pixelColumn < pixelSize; ++pixelColumn) {
int scaledRow = realRow * pixelSize + pixelRow;
int scaledColumn = realColumn * pixelSize + pixelColumn;
int scaledIndex = (scaledWidth * scaledRow) + scaledColumn;
std::byte *scaledRed = &scaled[scaledIndex * 4];
for (int i = 0; i < 4; ++i) {
*(scaledRed + i) = *(realRed + i);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment