Commit Graph

148 Commits

Author SHA1 Message Date
Daniel Gibson
d235049322 stb_image.h: Fix TGA colormap support
* Calculate correct stb format (incl. proper 16bit support) also when
  using a colormap (palette)
* Create colormap with tga_comp, to correctly support 16bit RGB
  (instead of using tga_palette_bits/8 and just copying the data)
* For TGAs with colormap, the TGA bits per pixel field specifies the
  size of an index to the colormap - the "real" color depth
  of the image is saved in the color map specification's bits per pixel
  field. I think only 8 and 16bit indices make sense (16 should be
  supported, otherwise the colormap length could be u8 instead of u16),
  so I added support for both.
* Helper functions stbi__tga_get_comp() to calculate stb pixelformat and
  stbi__tga_read_rgb16() to read one 16bit pixel and convert it to
  24/32bit RGB(A) - for less duplicate code
2015-12-06 04:33:37 +01:00
Daniel Gibson
57409c3d15 stb_image.h: Improve stbi__tga_info() and stbi__tga_test()
* for paletted images, .._info()'s comp should be based on the palette's
  bits per pixel, not the images bits per pixel (which describes the
  size of an index into the palette and is also checked now)
* make sure the color (map) type and the image type fields of the header
  are consistent (=> if TGA color type is 1 for paletted, the TGA image
  type must be 1 or 9)
* .._test() does some more checks and uses stbi__get16le() instead of
  stbi__get16be() - TGA is little endian.
* .._test() now always rewinds (sometimes it used to do only return 0;
  without rewinding)
* remove "error check" at the beginning of stbi__tga_load(), because
  all that is already tested in stbi__tga_test()
2015-12-06 04:33:30 +01:00
Daniel Gibson
7453e1bfa4 stb_image.h: Support 15/16bit per pixel RGB(A) TGAs
stbi__tga_* assumed that 16bit TGAs were Grayscale + Alpha.
However, if the TGA imagetype is not one of the gray ones, it's 16Bit
RGB data, with 5 Bits per channel. If the TGA image descriptor field
has alpha bits (the 3 least significant ones) set, the pixel's most
significant bit is for alpha: 1 for opaque and 0 for translucent.
Furthermore people claim that TGAs can also pretend to have 15bpp,
which is the same as 16bpp but definitely without alpha.

So 15/16bpp TGAs are now decoded to STBI_rgb(_alpha).
2015-12-06 00:25:22 +01:00
Sean Barrett
6b8938124e Merge branch 'fix-vs2015-warnings' of https://github.com/Reedbeta/stb into working 2015-09-13 11:09:23 -07:00
Sean Barrett
d5b8af12cb fix missing "defined" in #if defined(STBI_NO_foo);
fix incorrect initialization of alpha channel for RGB PSD
2015-09-13 11:08:40 -07:00
Nathan Reed
36574182c0 Fix new VS2015 warnings in stb_image 2.07
- conversion from int to stbi_uc
- unused parameter
2015-09-13 11:00:46 -07:00
Sean Barrett
90dc93a1cc fix bug where we couldn't rewind a file that reached EOF, which can happen with < 92-byte PIC,PNM,HDR,TGA 2015-09-13 05:41:21 -07:00
Sean Barrett
28a29dd0f1 credit for michaelangel007 patch 2015-09-13 05:15:09 -07:00
Sean Barrett
ddd05479e9 Merge branch 'master' of https://github.com/Michaelangel007/stb into working 2015-09-13 05:13:57 -07:00
Sean Barrett
0eb5da55a7 er, fix typo in the fix-rmitton checkin 2015-09-13 05:12:53 -07:00
Sean Barrett
082289b528 Merge branch 'master' of https://github.com/rmitton/stb into working 2015-09-13 05:12:35 -07:00
Sean Barrett
5607c25cf4 tweak rmitton 16-bit psd patch;
adjust credits
2015-09-13 05:11:51 -07:00
Sean Barrett
69d6fd573c Merge branch 'psd16' of https://github.com/rmitton/stb into working 2015-09-13 04:58:48 -07:00
Sean Barrett
1ea670e0a5 Merge branch 'urraka-gif-patch' of https://github.com/urraka/stb into working 2015-09-13 04:49:04 -07:00
Sean Barrett
52d400741c detect all 0-alpha bmp and replace with all-255;
fix bug in reedbeta patch
2015-09-13 04:46:50 -07:00
Sean Barrett
fee80f3d83 tweaks to patch from reedbeta 2015-09-13 04:27:24 -07:00
Nathan Reed
26c98260b6 Fix warnings about "conversion to a greater size" that appear in VS2015 in x64 with /W4.
The warning concerns the return value of stbi_err, which is an int, being converted to a pointer. In VS2015 it seems casting directly from a 32-bit int to a 64-bit pointer triggers this warning. Worked around by first converting to a 64-bit int (here size_t) and then to a pointer.
2015-09-10 01:20:35 -07:00
Nathan Reed
6d613ed8ce Fix variable-shadowing warnings that appear in VS2015 on /W4 2015-09-10 01:13:54 -07:00
Sean Barrett
7ac0f9c9b0 fix typo in accidentally-checked-in stb_image.h 2015-09-03 22:55:01 -07:00
Sean Barrett
60939ec653 fix some more signed shifts 2015-09-03 11:18:40 -07:00
urraka
23dfb8c06b GIF loading improvements.
- Fixed possible memory leak.
- Fix for transparent backgrounds.
- Adapted internal function to allow proper animation loading.
2015-08-03 22:59:16 -03:00
Sean Barrett
c9859afcf9 reverse some of the public-domain-license changes that I didn't
actually want
2015-08-01 23:53:49 -07:00
Ryan Whitworth
f0e456b809 Added public domain license text 2015-08-01 14:52:12 -04:00
rmitton
6645ea5915 Fixed stupid endianness bug.
Incorrect endianness hilariously doesn't manifest _if_ the original
image was upconverted from 8-bit to 16-bit.
2015-07-24 12:00:09 -07:00
rmitton
608cbec1f5 Fixed overflow for high values.
0xffff would accidentally round to 0x10000.
2015-07-07 15:47:37 -07:00
rmitton
a371b204f5 Added support for 16-bit PSD loading.
This extends the current PSD loader to add support for 16-bit images, by
quantizing them down to 8-bit upon load.
2015-07-07 15:15:38 -07:00
rmitton
fcfa17b847 Fixed double-free in JPEG allocation
It was incorrectly setting the wrong field to NULL, causing it to get
freed again later.
2015-07-06 13:32:40 -07:00
Michaelangel007
c11532b872 Cleanup unused functions 2015-06-30 08:54:14 -06:00
Michaelangel007
2762b410fe Fix unused vars warning in stbi_is_hdr_from_file stbi_is_hdr_from_callbacks 2015-06-30 08:02:24 -06:00
Sean Barrett
aa89970d6b stb_image.h: fix *comp value when loading PSDs
stb_voxel_render.h: fix STBVOX_CONFIG_OPTIMIZED_VHEIGHT
2015-05-28 22:11:45 -07:00
Sean Barrett
947bdcd027 update version numbers & docs 2015-04-19 04:19:55 -07:00
Sean Barrett
8f9c8b682d Merge branch 'master' of https://github.com/nguillemot/stb 2015-04-19 04:17:21 -07:00
Sean Barrett
ac5e25ae01 bump stb_image to version 2.05, tweak docs 2015-04-19 04:15:33 -07:00
Fabian Giesen
f224bc2cdb stb_image: Progressive AC decoding - fix ZRL code.
The original AC decoding logic handled ZRL (runs of 16 zeros)
incorrectly.

The problem is that the original flow set r=16 and skipped the
final coeff write when s=0. This is not actually correct. The
problem is the intervening "refinement" bits.

With the original logic, even once we decrement r to 0, we keep
reading more refinement bits for subsequent coefficients until
we find the next currently-unsent AC in the current scan. That is,
it works as if it was trying to place 17 new AC values, and only
bails at the last minute from actually setting that 17th value.

This is wrong. Once we've found the 16th previously-unsent AC, we
need to stop reading refinement bits, otherwise we get out of sync
with the bit stream (which expects us to read a huffman code next).

The easiest fix is to just do what the JPEG standard implicitly
assumes anyway: treat ZRL as a run of 15 zeros followed by an
explicit magnitude-zero AC coeff. (That is, leave s=0 and actually
write s). So this is what this fix does.
2015-04-19 01:49:16 -07:00
Nicolas Guillemot
1894bede3f fix signed/unsignted compare warning 2015-04-18 21:23:34 -07:00
Sean Barrett
d710ada2f9 try to re-enable SSE2 support by default on mingw 64-bit 2015-04-15 02:31:12 -07:00
Sean Barrett
66a75195dc rename STBI_X86_TARGET to STBI__X86_TARGET 2015-04-12 09:36:01 -07:00
Sean Barrett
c83abb051a Merge branch 'mingwfix' of https://github.com/rygorous/stb into work2
Conflicts:
	stb_image.h
2015-04-12 09:33:26 -07:00
Sean Barrett
e5fde30800 merge two x86/x64 tests into one; update credits 2015-04-12 09:30:05 -07:00
Sean Barrett
c8852111cc Merge branch 'master' of https://github.com/pmj/stb into work2 2015-04-12 09:26:25 -07:00
Sean Barrett
f22efc6151 update credits/docs 2015-04-12 09:26:16 -07:00
Sean Barrett
9d7499bca6 Merge branch 'master' of https://github.com/hpesoj/stb into work2 2015-04-12 09:23:07 -07:00
Sean Barrett
040df963c8 modifications to vertical flip API:
more consistent name,
 refactor stbi_load_main to preserve old code,
 support float HDR path,
 minor bugfix
2015-04-12 09:20:31 -07:00
Sean Barrett
e3214d7ff7 Merge branch 'master' of https://github.com/nguillemot/stb into work2 2015-04-12 09:07:32 -07:00
Sean Barrett
24e50cbd5d remove asserts that are now run-time checks;
bump version and update credits;
minor whitespace changes;
2015-04-12 09:04:43 -07:00
Martins Mozeiko
b2d440cfb5 Fixing various crashes when loading jpg, png and tga images. 2015-04-11 15:51:20 -07:00
Nicolas Guillemot
c500a90375 added stbi_vertically_flip_on_load 2015-03-29 03:03:09 -07:00
Sean Barrett
0b05bde303 quick fixes w/o version updates 2015-02-22 14:26:21 -08:00
Joseph Thomson
a60912f145 Avoid GCC sign-compare warning.
GCC 4.7 gave the warning "signed and unsigned type in conditional
expression" because the ternary operator mixes signed and unsigned
integers. Fixed by casting to unsigned inside the "if" branch instead
of casting the result of the entire conditional.
2015-02-20 10:15:08 +00:00
Fabian Giesen
4b0c6f6634 stb_image: NEON and SSE2 SIMD detection fixes.
This fixes two things. First, the logic to disable SSE2 on
GCC unless "-msse2" was not specific enough, and ended up
disabling SIMD support on NEON targets entirely. Shuffle
the detection logic around to make that bit x86-specific.

Second, 32-bit MinGW assumes 16-byte aligned stacks, but this is
not in the Windows ABI and hence DLLs and callbacks don't
necessarily provide it. This caused a crash.

This can be fixed by providing the right command-line option,
which we have no control over. As a compromise, disable the SSE2
path on MinGW unless a specific #define explained in the comments
is set. That way, we default to safe (never-crashing) behavior
unless the user explicitly signals they know what they're doing.
2015-02-17 01:21:40 -08:00