Created
September 11, 2020 17:43
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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