Merge branch 'ppm' into working

Conflicts:
	stb_image.h
This commit is contained in:
Sean Barrett 2014-12-21 08:23:34 -08:00
commit e4fb737f66

View File

@ -1,4 +1,4 @@
/* stb_image - v1.48 - public domain JPEG/PNG reader - http://nothings.org/stb_image.c
/* stb_image - v1.49 - public domain JPEG/PNG reader - http://nothings.org/stb_image.c
when you control the images you're loading
no warranty implied; use at your own risk
@ -24,6 +24,7 @@
GIF (*comp always reports as 4-channel)
HDR (radiance rgbE format)
PIC (Softimage PIC)
PNM (PPM and PGM binary only)
- decode from memory or through FILE (define STBI_NO_STDIO to remove code)
- decode from arbitrary I/O callbacks
@ -72,12 +73,18 @@
removed in future versions of the library. It is only intended for
back-compatibility use.
- Added support for PNM images.
- Added STBI_MALLOC, STBI_REALLOC, and STBI_FREE macros for replacing
the memory allocator. Unlike other STBI libraries, these macros don't
support a context parameter, so if you need to pass a context in to
the allocator, you'll have to store it in a global or a thread-local
variable.
Latest revision history:
1.49 (2014-12-25) optimize JPG, incl. x86 SIMD
PGM/PPM support
allocation macros
stbi_load_into() -- load into pre-defined memory
STBI_MALLOC,STBI_REALLOC,STBI_FREE
1.48 (2014-12-14) fix incorrectly-named assert()
1.47 (2014-12-14) 1/2/4-bit PNG support (both grayscale and paletted)
@ -85,10 +92,6 @@
fix bug in interlaced PNG with user-specified channel count
1.46 (2014-08-26) fix broken tRNS chunk in non-paletted PNG
1.45 (2014-08-16) workaround MSVC-ARM internal compiler error by wrapping malloc
1.44 (2014-08-07) warnings
1.43 (2014-07-15) fix MSVC-only bug in 1.42
1.42 (2014-07-09) no _CRT_SECURE_NO_WARNINGS; error-path fixes; STBI_ASSERT
1.41 (2014-06-25) fix search&replace that messed up comments/error messages
See end of file for full revision history.
@ -102,26 +105,34 @@
Jean-Marc Lienher (gif) Won Chun
Tom Seddon (pic) the Horde3D community
Thatcher Ulrich (psd) Janez Zemva
Jonathan Blow
Ken Miller (pgm, ppm) Jonathan Blow
Laurent Gomila
Extensions, features Aruelien Pocheville
Jetro Lauha (stbi_info) Ryamond Barbiero
James "moose2000" Brown (iPhone PNG) David Woo
Ben "Disch" Wenger (io callbacks) Roy Eltham
Martin "SpartanJ" Golini Luke Graham
Omar Cornut (1/2/4-bit png) Thomas Ruf
Aruelien Pocheville
Extensions, features Ryamond Barbiero
Jetro Lauha (stbi_info) David Woo
Martin "SpartanJ" Golini (stbi_info) Martin Golini
James "moose2000" Brown (iPhone PNG) Roy Eltham
Ben "Disch" Wenger (io callbacks) Luke Graham
Omar Cornut (1/2/4-bit PNG) Thomas Ruf
John Bartholomew
Optimizations & bugfixes Ken Hamada
Fabian "ryg" Giesen Cort Stratton
Arseny Kapoulkine Blazej Dariusz Roszkowski
Thibault Reuille
Ken Hamada
Optimizations & bugfixes Cort Stratton
Fabian "ryg" Giesen Blazej Dariusz Roszkowski
Arseny Kapoulkine Thibault Reuille
Paul Du Bois
Guillaume George
Jerry Jansson
If your name should be here but Hayaki Saito
isn't, let Sean know. Johan Duparc
If your name should be here but Jerry Jansson
isn't, let Sean know. Hayaki Saito
Johan Duparc
Ronny Chevalier
Michal Cichon
Tero Hanninen
License:
This software is in the public domain. Where that dedication is not
recognized, you are granted a perpetual, irrevocable license to copy
and modify this file as you see fit.
*/
#ifndef STBI_INCLUDE_STB_IMAGE_H
@ -640,6 +651,9 @@ static stbi_uc *stbi__pic_load(stbi__context *s, int *x, int *y, int *comp, int
static int stbi__gif_test(stbi__context *s);
static stbi_uc *stbi__gif_load(stbi__context *s, int *x, int *y, int *comp, int req_comp);
static int stbi__gif_info(stbi__context *s, int *x, int *y, int *comp);
static int stbi__pnm_test(stbi__context *s);
static stbi_uc *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req_comp);
static int stbi__pnm_info(stbi__context *s, int *x, int *y, int *comp);
// this is not threadsafe
@ -694,6 +708,7 @@ static unsigned char *stbi_load_main(stbi__context *s, int *x, int *y, int *comp
if (stbi__gif_test(s)) return stbi__gif_load(s,x,y,comp,req_comp);
if (stbi__psd_test(s)) return stbi__psd_load(s,x,y,comp,req_comp);
if (stbi__pic_test(s)) return stbi__pic_load(s,x,y,comp,req_comp);
if (stbi__pnm_test(s)) return stbi__pnm_load(s,x,y,comp,req_comp);
#ifndef STBI_NO_HDR
if (stbi__hdr_test(s)) {
@ -5480,6 +5495,112 @@ static int stbi__pic_info(stbi__context *s, int *x, int *y, int *comp)
return 1;
}
// *************************************************************************************************
// Portable Gray Map and Portable Pixel Map loader
// by Ken Miller
//
// PGM: http://netpbm.sourceforge.net/doc/pgm.html
// PPM: http://netpbm.sourceforge.net/doc/ppm.html
//
// Known limitations:
// Does not support comments in the header section
// Does not support ASCII image data (formats P2 and P3)
// Does not support 16-bit-per-channel
static int stbi__pnm_test(stbi__context *s)
{
char p, t;
p = (char) stbi__get8(s);
t = (char) stbi__get8(s);
if (p != 'P' || (t != '5' && t != '6')) {
stbi__rewind( s );
return 0;
}
return 1;
}
static stbi_uc *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req_comp)
{
stbi_uc *out;
if (!stbi__pnm_info(s, (int *)&s->img_x, (int *)&s->img_y, (int *)&s->img_n))
return 0;
*x = s->img_x;
*y = s->img_y;
*comp = s->img_n;
out = (stbi_uc *) stbi__malloc(s->img_n * s->img_x * s->img_y);
if (!out) return stbi__errpuc("outofmem", "Out of memory");
stbi__getn(s, out, s->img_n * s->img_x * s->img_y);
if (req_comp && req_comp != s->img_n) {
out = stbi__convert_format(out, s->img_n, req_comp, s->img_x, s->img_y);
if (out == NULL) return out; // stbi__convert_format frees input on failure
}
return out;
}
static int stbi__pnm_isspace(char c)
{
return c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r';
}
static void stbi__pnm_skip_whitespace(stbi__context *s, char *c)
{
while (!stbi__at_eof(s) && stbi__pnm_isspace(*c))
*c = (char) stbi__get8(s);
}
static int stbi__pnm_isdigit(char c)
{
return c >= '0' && c <= '9';
}
static int stbi__pnm_getinteger(stbi__context *s, char *c)
{
int value = 0;
while (!stbi__at_eof(s) && stbi__pnm_isdigit(*c)) {
value = value*10 + (*c - '0');
*c = (char) stbi__get8(s);
}
return value;
}
static int stbi__pnm_info(stbi__context *s, int *x, int *y, int *comp)
{
int maxv;
char c, p, t;
stbi__rewind( s );
// Get identifier
p = (char) stbi__get8(s);
t = (char) stbi__get8(s);
if (p != 'P' || (t != '5' && t != '6')) {
stbi__rewind( s );
return 0;
}
*comp = (t == '6') ? 3 : 1; // '5' is 1-component .pgm; '6' is 3-component .ppm
c = (char) stbi__get8(s);
stbi__pnm_skip_whitespace(s, &c);
*x = stbi__pnm_getinteger(s, &c); // read width
stbi__pnm_skip_whitespace(s, &c);
*y = stbi__pnm_getinteger(s, &c); // read height
stbi__pnm_skip_whitespace(s, &c);
maxv = stbi__pnm_getinteger(s, &c); // read max value
if (maxv > 255)
return stbi__err("max value > 255", "PPM image not 8-bit");
else
return 1;
}
static int stbi__info_main(stbi__context *s, int *x, int *y, int *comp)
{
if (stbi__jpeg_info(s, x, y, comp))
@ -5494,6 +5615,8 @@ static int stbi__info_main(stbi__context *s, int *x, int *y, int *comp)
return 1;
if (stbi__pic_info(s, x, y, comp))
return 1;
if (stbi__pnm_info(s, x, y, comp))
return 1;
#ifndef STBI_NO_HDR
if (stbi__hdr_info(s, x, y, comp))
return 1;
@ -5545,6 +5668,10 @@ STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const *c, void *user, int
/*
revision history:
1.49 (2014-12-25) optimize JPG, incl. x86 SIMD (ryg)
PGM/PPM support (Ken Miller)
STBI_MALLOC,STBI_REALLOC,STBI_FREE
stbi_load_into() -- load into pre-defined memory
1.48 (2014-12-14) fix incorrectly-named assert()
1.47 (2014-12-14) 1/2/4-bit PNG support, both direct and paletted (Omar Cornut & stb)
optimize PNG (ryg)