Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stb_image: Fix 16bits PNM images endianness handling #1710

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions stb_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ RECENT REVISION HISTORY:
Jonathan Blow Ken Hamada Tero Hanninen github:svdijk
Eugene Golushkov Laurent Gomila Cort Stratton github:snagar
Aruelien Pocheville Sergio Gonzalez Thibault Reuille github:Zelex
Cass Everitt Ryamond Barbiero github:grim210
Cass Everitt Ryamond Barbiero Philip Abbet github:grim210
Paul Du Bois Engin Manap Aldo Culquicondor github:sammyhw
Philipp Wiesemann Dale Weiler Oriol Ferrer Mesia github:phprus
Josh Tobin Neil Bickford Matthew Gregan github:poppolopoppo
Expand Down Expand Up @@ -7529,6 +7529,21 @@ static void *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req
return stbi__errpuc("bad PNM", "PNM file truncated");
}

// convert the image data from big-endian to platform-native
if (ri->bits_per_channel == 16) {
int i;
int img_len = s->img_n * s->img_x * s->img_y;
stbi_uc* src = (stbi_uc *) out;
stbi_us* dst = (stbi_us *) out;

for (i = 0; i < img_len; ++i)
{
*dst = (src[0] << 8) | src[1];
src += 2;
++dst;
}
}

if (req_comp && req_comp != s->img_n) {
if (ri->bits_per_channel == 16) {
out = (stbi_uc *) stbi__convert_format16((stbi__uint16 *) out, s->img_n, req_comp, s->img_x, s->img_y);
Expand Down Expand Up @@ -7985,4 +8000,4 @@ AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------------
*/
*/