mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-05-31 10:36:30 +03:00
Updated stb_image.
Removed cShapeManager ( i forgot to remove it ). Added FileWrite function.
This commit is contained in:
@@ -1,121 +0,0 @@
|
||||
#include "cshapemanager.hpp"
|
||||
|
||||
namespace EE { namespace Graphics {
|
||||
|
||||
cShapeManager::cShapeManager() :
|
||||
mCount(0)
|
||||
{
|
||||
Alloc( 256 );
|
||||
}
|
||||
|
||||
cShapeManager::~cShapeManager() {
|
||||
}
|
||||
|
||||
void cShapeManager::Alloc( const Uint32& Size ) {
|
||||
mShapes.resize( Size );
|
||||
}
|
||||
|
||||
Uint32 cShapeManager::GetIndex( const Uint32& Hash ) {
|
||||
if ( 0 != Hash ) {
|
||||
for ( Uint32 i = 0; i < mShapes.size(); i++ ) {
|
||||
if ( NULL != mShapes[i] && mShapes[i]->Id() == Hash )
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return (Uint32)-1;
|
||||
}
|
||||
|
||||
Uint32 cShapeManager::GetIndex( const std::string& Name ) {
|
||||
return GetIndex( MakeHash( Name ) );
|
||||
}
|
||||
|
||||
cShape * cShapeManager::GetAt( const Uint32& Index ) {
|
||||
// assert here
|
||||
|
||||
return mShapes[ Index ];
|
||||
}
|
||||
|
||||
cShape * cShapeManager::Get( const Uint32& Hash ) {
|
||||
if ( 0 != Hash ) {
|
||||
for ( Uint32 i = mShapes.size() - 1; i >= 0; i-- ) {
|
||||
if ( NULL != mShapes[i] && mShapes[i]->Id() == Hash )
|
||||
return mShapes[i];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cShape * cShapeManager::Get( const std::string& Name ) {
|
||||
return Get( MakeHash( Name ) );
|
||||
}
|
||||
|
||||
bool cShapeManager::Remove( const Uint32& Hash ) {
|
||||
Uint32 Pos = GetIndex( Hash );
|
||||
|
||||
if ( Pos != (Uint32)-1 ) {
|
||||
eeSAFE_DELETE( mShapes[ Pos ] );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool cShapeManager::RemoveAt( const Uint32& Index ) {
|
||||
if ( Index < mShapes.size() ) {
|
||||
eeSAFE_DELETE( mShapes[ Index ] );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool cShapeManager::Remove( const std::string& Name ) {
|
||||
return Remove( MakeHash( Name ) );
|
||||
}
|
||||
|
||||
cShape * cShapeManager::Add( cShape * Shape ) {
|
||||
if ( NULL != Shape ) {
|
||||
if ( mCount < mShapes.size() ) {
|
||||
mShapes[ mCount ] = Shape;
|
||||
mCount++;
|
||||
} else {
|
||||
mShapes.push_back( Shape );
|
||||
mCount++;
|
||||
}
|
||||
}
|
||||
|
||||
return Shape;
|
||||
}
|
||||
|
||||
cShape * cShapeManager::Add( const Uint32& TexId, const std::string& Name ) {
|
||||
return Add( new cShape( TexId, Name ) );
|
||||
}
|
||||
|
||||
cShape * cShapeManager::Add( const Uint32& TexId, const eeRecti& SrcRect, const std::string& Name ) {
|
||||
return Add( new cShape( TexId, SrcRect, Name ) );
|
||||
}
|
||||
|
||||
cShape * cShapeManager::Add( const Uint32& TexId, const eeRecti& SrcRect, const eeFloat& DestWidth, const eeFloat& DestHeight, const std::string& Name ) {
|
||||
return Add( new cShape( TexId, SrcRect, DestWidth, DestHeight, Name ) );
|
||||
}
|
||||
|
||||
cShape * cShapeManager::Add( const Uint32& TexId, const eeRecti& SrcRect, const eeFloat& DestWidth, const eeFloat& DestHeight, const eeFloat& OffsetX, const eeFloat& OffsetY, const std::string& Name ) {
|
||||
return Add( new cShape( TexId, SrcRect, DestWidth, DestHeight, OffsetX, OffsetY, Name ) );
|
||||
}
|
||||
|
||||
void cShapeManager::Clear() {
|
||||
for ( Uint32 i = 0; i < mShapes.size(); i++ ) {
|
||||
if ( mShapes[i] != NULL )
|
||||
eeSAFE_DELETE( mShapes[i] );
|
||||
}
|
||||
}
|
||||
|
||||
Uint32 cShapeManager::Count() {
|
||||
return mCount;
|
||||
}
|
||||
|
||||
}}
|
||||
@@ -1,55 +0,0 @@
|
||||
#ifndef EE_GRAPHICSCSHAPEMANAGER_H
|
||||
#define EE_GRAPHICSCSHAPEMANAGER_H
|
||||
|
||||
#include "base.hpp"
|
||||
#include "cshape.hpp"
|
||||
|
||||
namespace EE { namespace Graphics {
|
||||
|
||||
class EE_API cShapeManager : public cSingleton<cShapeManager> {
|
||||
friend class cSingleton<cShapeManager>;
|
||||
public:
|
||||
cShapeManager();
|
||||
|
||||
~cShapeManager();
|
||||
|
||||
void Alloc( const Uint32& Size );
|
||||
|
||||
Uint32 GetIndex( const Uint32& Hash );
|
||||
|
||||
Uint32 GetIndex( const std::string& Name );
|
||||
|
||||
cShape * GetAt( const Uint32& Index );
|
||||
|
||||
cShape * Get( const Uint32& Hash );
|
||||
|
||||
cShape * Get( const std::string& Name );
|
||||
|
||||
bool Remove( const Uint32& Hash );
|
||||
|
||||
bool RemoveAt( const Uint32& Index );
|
||||
|
||||
bool Remove( const std::string& Name );
|
||||
|
||||
cShape * Add( cShape * Shape );
|
||||
|
||||
cShape * Add( const Uint32& TexId, const std::string& Name = "" );
|
||||
|
||||
cShape * Add( const Uint32& TexId, const eeRecti& SrcRect, const std::string& Name = "" );
|
||||
|
||||
cShape * Add( const Uint32& TexId, const eeRecti& SrcRect, const eeFloat& DestWidth, const eeFloat& DestHeight, const std::string& Name = "" );
|
||||
|
||||
cShape * Add( const Uint32& TexId, const eeRecti& SrcRect, const eeFloat& DestWidth, const eeFloat& DestHeight, const eeFloat& OffsetX, const eeFloat& OffsetY, const std::string& Name = "" );
|
||||
|
||||
void Clear();
|
||||
|
||||
Uint32 Count();
|
||||
protected:
|
||||
std::vector<cShape*> mShapes;
|
||||
|
||||
Uint32 mCount;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,4 @@
|
||||
/* stbi-1.26 - public domain JPEG/PNG reader - http://nothings.org/stb_image.c
|
||||
/* stbi-1.27 - 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
|
||||
|
||||
@@ -21,24 +21,22 @@
|
||||
- supports installable dequantizing-IDCT, YCbCr-to-RGB conversion (define STBI_SIMD)
|
||||
|
||||
Latest revisions:
|
||||
1.26 (2010-07-24)
|
||||
fix bug in file buffering for PNG reported by SpartanJ
|
||||
1.25 (2010-07-17)
|
||||
refix trans_data warning (Won Chun)
|
||||
1.24 (2010-07-12)
|
||||
perf improvements reading from files on platforms with lock-heavy fgetc()
|
||||
minor perf improvements for jpeg
|
||||
deprecated type-specific functions so we'll get feedback if they're needed
|
||||
attempt to fix trans_data warning (Won Chun)
|
||||
1.23 fixed bug in iPhone support
|
||||
1.22 (2010-07-10)
|
||||
removed image *writing* support, moved to stb_image_write.h
|
||||
stbi_info support from Jetro Lauha
|
||||
GIF support from Jean-Marc Lienher
|
||||
iPhone PNG-extensions from James Brown
|
||||
warning-fixes from Nicolas Schulz and Janez Zemva (aka Janez U+017D;emva)
|
||||
1.21 fix use of 'uint8' in header (reported by jon blow)
|
||||
1.20 added support for Softimage PIC, by Tom Seddon
|
||||
1.27 (2010-08-01) cast-to-uint8 to fix warnings (Laurent Gomila)
|
||||
allow trailing 0s at end of image data (Laurent Gomila)
|
||||
1.26 (2010-07-24) fix bug in file buffering for PNG reported by SpartanJ
|
||||
1.25 (2010-07-17) refix trans_data warning (Won Chun)
|
||||
1.24 (2010-07-12) perf improvements reading from files
|
||||
minor perf improvements for jpeg
|
||||
deprecated type-specific functions in hope of feedback
|
||||
attempt to fix trans_data warning (Won Chun)
|
||||
1.23 fixed bug in iPhone support
|
||||
1.22 (2010-07-10) removed image *writing* support to stb_image_write.h
|
||||
stbi_info support from Jetro Lauha
|
||||
GIF support from Jean-Marc Lienher
|
||||
iPhone PNG-extensions from James Brown
|
||||
warning-fixes from Nicolas Schulz and Janez Zemva
|
||||
1.21 fix use of 'uint8' in header (reported by jon blow)
|
||||
1.20 added support for Softimage PIC, by Tom Seddon
|
||||
|
||||
See end of file for full revision history.
|
||||
|
||||
@@ -62,7 +60,7 @@
|
||||
the Horde3D community
|
||||
Extensions, features Janez Zemva
|
||||
Jetro Lauha (stbi_info) Jonathan Blow
|
||||
James "moose2000" Brown (iPhone PNG)
|
||||
James "moose2000" Brown (iPhone PNG) Laurent Gomila
|
||||
|
||||
If your name should be here but isn't, let Sean know.
|
||||
|
||||
@@ -521,7 +519,7 @@ __forceinline static int at_eof(stbi *s)
|
||||
if (s->img_file) {
|
||||
if (!feof(s->img_file)) return 0;
|
||||
// if feof() is true, check if buffer = end
|
||||
// special case: we've got the one extra character at the end
|
||||
// special case: we've only got the special 0 character at the end
|
||||
if (s->from_file == 0) return 1;
|
||||
}
|
||||
#endif
|
||||
@@ -685,13 +683,13 @@ static stbi_uc *hdr_to_ldr(float *data, int x, int y, int comp)
|
||||
float z = (float) pow(data[i*comp+k]*h2l_scale_i, h2l_gamma_i) * 255 + 0.5f;
|
||||
if (z < 0) z = 0;
|
||||
if (z > 255) z = 255;
|
||||
output[i*comp + k] = float2int(z);
|
||||
output[i*comp + k] = (uint8) float2int(z);
|
||||
}
|
||||
if (k < comp) {
|
||||
float z = data[i*comp+k] * 255 + 0.5f;
|
||||
if (z < 0) z = 0;
|
||||
if (z > 255) z = 255;
|
||||
output[i*comp + k] = float2int(z);
|
||||
output[i*comp + k] = (uint8) float2int(z);
|
||||
}
|
||||
}
|
||||
free(data);
|
||||
@@ -1407,6 +1405,19 @@ static int decode_jpeg_image(jpeg *j)
|
||||
if (SOS(m)) {
|
||||
if (!process_scan_header(j)) return 0;
|
||||
if (!parse_entropy_coded_data(j)) return 0;
|
||||
if (j->marker == MARKER_none ) {
|
||||
// handle 0s at the end of image data from IP Kamera 9060
|
||||
while (!at_eof(&j->s)) {
|
||||
int x = get8(&j->s);
|
||||
if (x == 255) {
|
||||
j->marker = get8u(&j->s);
|
||||
break;
|
||||
} else if (x != 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
// if we reach eof without hitting a marker, get_marker() below will fail and we'll eventually return 0
|
||||
}
|
||||
} else {
|
||||
if (!process_marker(j, m)) return 0;
|
||||
}
|
||||
@@ -1499,6 +1510,7 @@ static uint8 *resample_row_generic(uint8 *out, uint8 *in_near, uint8 *in_far, in
|
||||
{
|
||||
// resample with nearest-neighbor
|
||||
int i,j;
|
||||
in_far = in_far;
|
||||
for (i=0; i < w; ++i)
|
||||
for (j=0; j < hs; ++j)
|
||||
out[i*hs+j] = in_near[i];
|
||||
@@ -2877,15 +2889,15 @@ static stbi_uc *bmp_load(stbi *s, int *x, int *y, int *comp, int req_comp)
|
||||
mr = mg = mb = 0;
|
||||
if (compress == 0) {
|
||||
if (bpp == 32) {
|
||||
mr = 0xff << 16;
|
||||
mg = 0xff << 8;
|
||||
mb = 0xff << 0;
|
||||
ma = 0xff << 24;
|
||||
mr = 0xffu << 16;
|
||||
mg = 0xffu << 8;
|
||||
mb = 0xffu << 0;
|
||||
ma = 0xffu << 24;
|
||||
fake_a = 1; // @TODO: check for cases like alpha value is all 0 and switch it to 255
|
||||
} else {
|
||||
mr = 31 << 10;
|
||||
mg = 31 << 5;
|
||||
mb = 31 << 0;
|
||||
mr = 31u << 10;
|
||||
mg = 31u << 5;
|
||||
mb = 31u << 0;
|
||||
}
|
||||
} else if (compress == 3) {
|
||||
mr = get32le(s);
|
||||
@@ -2923,9 +2935,9 @@ static stbi_uc *bmp_load(stbi *s, int *x, int *y, int *comp, int req_comp)
|
||||
int z=0;
|
||||
if (psize == 0 || psize > 256) { free(out); return epuc("invalid", "Corrupt BMP"); }
|
||||
for (i=0; i < psize; ++i) {
|
||||
pal[i][2] = get8(s);
|
||||
pal[i][1] = get8(s);
|
||||
pal[i][0] = get8(s);
|
||||
pal[i][2] = get8u(s);
|
||||
pal[i][1] = get8u(s);
|
||||
pal[i][0] = get8u(s);
|
||||
if (hsz != 12) get8(s);
|
||||
pal[i][3] = 255;
|
||||
}
|
||||
@@ -2981,22 +2993,22 @@ static stbi_uc *bmp_load(stbi *s, int *x, int *y, int *comp, int req_comp)
|
||||
if (easy) {
|
||||
for (i=0; i < (int) s->img_x; ++i) {
|
||||
int a;
|
||||
out[z+2] = get8(s);
|
||||
out[z+1] = get8(s);
|
||||
out[z+0] = get8(s);
|
||||
out[z+2] = get8u(s);
|
||||
out[z+1] = get8u(s);
|
||||
out[z+0] = get8u(s);
|
||||
z += 3;
|
||||
a = (easy == 2 ? get8(s) : 255);
|
||||
if (target == 4) out[z++] = a;
|
||||
if (target == 4) out[z++] = (uint8) a;
|
||||
}
|
||||
} else {
|
||||
for (i=0; i < (int) s->img_x; ++i) {
|
||||
uint32 v = (bpp == 16 ? get16le(s) : get32le(s));
|
||||
int a;
|
||||
out[z++] = shiftsigned(v & mr, rshift, rcount);
|
||||
out[z++] = shiftsigned(v & mg, gshift, gcount);
|
||||
out[z++] = shiftsigned(v & mb, bshift, bcount);
|
||||
out[z++] = (uint8) shiftsigned(v & mr, rshift, rcount);
|
||||
out[z++] = (uint8) shiftsigned(v & mg, gshift, gcount);
|
||||
out[z++] = (uint8) shiftsigned(v & mb, bshift, bcount);
|
||||
a = (ma ? shiftsigned(v & ma, ashift, acount) : 255);
|
||||
if (target == 4) out[z++] = a;
|
||||
if (target == 4) out[z++] = (uint8) a;
|
||||
}
|
||||
}
|
||||
skip(s, pad);
|
||||
@@ -3519,17 +3531,17 @@ static stbi_uc *psd_load(stbi *s, int *x, int *y, int *comp, int req_comp)
|
||||
len++;
|
||||
count += len;
|
||||
while (len) {
|
||||
*p = get8(s);
|
||||
*p = get8u(s);
|
||||
p += 4;
|
||||
len--;
|
||||
}
|
||||
} else if (len > 128) {
|
||||
uint32 val;
|
||||
uint8 val;
|
||||
// Next -len+1 bytes in the dest are replicated from next source byte.
|
||||
// (Interpret len as a negative 8-bit int.)
|
||||
len ^= 0x0FF;
|
||||
len += 2;
|
||||
val = get8(s);
|
||||
val = get8u(s);
|
||||
count += len;
|
||||
while (len) {
|
||||
*p = val;
|
||||
@@ -3556,7 +3568,7 @@ static stbi_uc *psd_load(stbi *s, int *x, int *y, int *comp, int req_comp)
|
||||
} else {
|
||||
// Read the data.
|
||||
for (i = 0; i < pixelCount; i++)
|
||||
*p = get8(s), p += 4;
|
||||
*p = get8u(s), p += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3644,7 +3656,7 @@ static stbi_uc *pic_readval(stbi *s, int channel, stbi_uc *dest)
|
||||
for (i=0; i<4; ++i, mask>>=1) {
|
||||
if (channel & mask) {
|
||||
if (at_eof(s)) return epuc("bad file","PIC file too short");
|
||||
dest[i]=get8(s);
|
||||
dest[i]=get8u(s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3676,9 +3688,9 @@ static stbi_uc *pic_load2(stbi *s,int width,int height,int *comp, stbi_uc *resul
|
||||
packet = &packets[num_packets++];
|
||||
|
||||
chained = get8(s);
|
||||
packet->size = get8(s);
|
||||
packet->type = get8(s);
|
||||
packet->channel = get8(s);
|
||||
packet->size = get8u(s);
|
||||
packet->type = get8u(s);
|
||||
packet->channel = get8u(s);
|
||||
|
||||
act_comp |= packet->channel;
|
||||
|
||||
@@ -3715,11 +3727,11 @@ static stbi_uc *pic_load2(stbi *s,int width,int height,int *comp, stbi_uc *resul
|
||||
while (left>0) {
|
||||
stbi_uc count,value[4];
|
||||
|
||||
count=get8(s);
|
||||
count=get8u(s);
|
||||
if (at_eof(s)) return epuc("bad file","file too short (pure read count)");
|
||||
|
||||
if (count > left)
|
||||
count = left;
|
||||
count = (uint8) left;
|
||||
|
||||
if (!pic_readval(s,packet->channel,value)) return 0;
|
||||
|
||||
@@ -3902,14 +3914,14 @@ int stbi_gif_test_memory (stbi_uc const *buffer, int len)
|
||||
return gif_test(&s);
|
||||
}
|
||||
|
||||
static void stbi_gif_parse_colortable(stbi *s, stbi_gif *g, uint8 pal[256][4], int num_entries, int transp)
|
||||
static void stbi_gif_parse_colortable(stbi *s, uint8 pal[256][4], int num_entries, int transp)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i < num_entries; ++i) {
|
||||
g->pal[i][2] = get8(s);
|
||||
g->pal[i][1] = get8(s);
|
||||
g->pal[i][0] = get8(s);
|
||||
g->pal[i][3] = transp ? 0 : 255;
|
||||
pal[i][2] = get8u(s);
|
||||
pal[i][1] = get8u(s);
|
||||
pal[i][0] = get8u(s);
|
||||
pal[i][3] = transp ? 0 : 255;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3919,7 +3931,7 @@ static int stbi_gif_header(stbi *s, stbi_gif *g, int *comp, int is_info)
|
||||
if (get8(s) != 'G' || get8(s) != 'I' || get8(s) != 'F' || get8(s) != '8')
|
||||
return e("not GIF", "Corrupt GIF");
|
||||
|
||||
version = get8(s);
|
||||
version = get8u(s);
|
||||
if (version != '7' && version != '9') return e("not GIF", "Corrupt GIF");
|
||||
if (get8(s) != 'a') return e("not GIF", "Corrupt GIF");
|
||||
|
||||
@@ -3936,7 +3948,7 @@ static int stbi_gif_header(stbi *s, stbi_gif *g, int *comp, int is_info)
|
||||
if (is_info) return 1;
|
||||
|
||||
if (g->flags & 0x80)
|
||||
stbi_gif_parse_colortable(s,g,g->pal, 2 << (g->flags & 7), -1);
|
||||
stbi_gif_parse_colortable(s,g->pal, 2 << (g->flags & 7), -1);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -3992,7 +4004,7 @@ static uint8 *stbi_process_gif_raster(stbi *s, stbi_gif *g)
|
||||
int32 codesize, codemask, avail, oldcode, bits, valid_bits, clear;
|
||||
stbi_gif_lzw *p;
|
||||
|
||||
lzw_cs = get8(s);
|
||||
lzw_cs = get8u(s);
|
||||
clear = 1 << lzw_cs;
|
||||
first = 1;
|
||||
codesize = lzw_cs + 1;
|
||||
@@ -4001,8 +4013,8 @@ static uint8 *stbi_process_gif_raster(stbi *s, stbi_gif *g)
|
||||
valid_bits = 0;
|
||||
for (code = 0; code < clear; code++) {
|
||||
g->codes[code].prefix = -1;
|
||||
g->codes[code].first = code;
|
||||
g->codes[code].suffix = code;
|
||||
g->codes[code].first = (uint8) code;
|
||||
g->codes[code].suffix = (uint8) code;
|
||||
}
|
||||
|
||||
// support no starting clear code
|
||||
@@ -4042,13 +4054,13 @@ static uint8 *stbi_process_gif_raster(stbi *s, stbi_gif *g)
|
||||
if (oldcode >= 0) {
|
||||
p = &g->codes[avail++];
|
||||
if (avail > 4096) return epuc("too many codes", "Corrupt GIF");
|
||||
p->prefix = oldcode;
|
||||
p->prefix = (int16) oldcode;
|
||||
p->first = g->codes[oldcode].first;
|
||||
p->suffix = (code == avail) ? p->first : g->codes[code].first;
|
||||
} else if (code == avail)
|
||||
return epuc("illegal code in raster", "Corrupt GIF");
|
||||
|
||||
stbi_out_gif_code(g, code);
|
||||
stbi_out_gif_code(g, (uint16) code);
|
||||
|
||||
if ((avail & codemask) == 0 && avail <= 0x0FFF) {
|
||||
codesize++;
|
||||
@@ -4131,7 +4143,7 @@ static uint8 *stbi_gif_load_next(stbi *s, stbi_gif *g, int *comp, int req_comp)
|
||||
}
|
||||
|
||||
if (g->lflags & 0x80) {
|
||||
stbi_gif_parse_colortable(s,g,g->lpal, 2 << (g->lflags & 7), g->eflags & 0x01 ? g->transparent : -1);
|
||||
stbi_gif_parse_colortable(s,g->lpal, 2 << (g->lflags & 7), g->eflags & 0x01 ? g->transparent : -1);
|
||||
g->color_table = (uint8 *) g->lpal;
|
||||
} else if (g->flags & 0x80) {
|
||||
for (i=0; i < 256; ++i) // @OPTIMIZE: reset only the previous transparent
|
||||
@@ -4294,7 +4306,7 @@ static char *hdr_gettoken(stbi *z, char *buffer)
|
||||
int len=0;
|
||||
char c = '\0';
|
||||
|
||||
c = get8(z);
|
||||
c = (char) get8(z);
|
||||
|
||||
while (!at_eof(z) && c != '\n') {
|
||||
buffer[len++] = c;
|
||||
@@ -4304,7 +4316,7 @@ static char *hdr_gettoken(stbi *z, char *buffer)
|
||||
;
|
||||
break;
|
||||
}
|
||||
c = get8(z);
|
||||
c = (char) get8(z);
|
||||
}
|
||||
|
||||
buffer[len] = 0;
|
||||
@@ -4357,7 +4369,7 @@ static float *hdr_load(stbi *s, int *x, int *y, int *comp, int req_comp)
|
||||
return epf("not HDR", "Corrupt HDR image");
|
||||
|
||||
// Parse header
|
||||
while (1) {
|
||||
for(;;) {
|
||||
token = hdr_gettoken(s,buffer);
|
||||
if (token[0] == 0) break;
|
||||
if (strcmp(token, "FORMAT=32-bit_rle_rgbe") == 0) valid = 1;
|
||||
@@ -4408,7 +4420,11 @@ static float *hdr_load(stbi *s, int *x, int *y, int *comp, int req_comp)
|
||||
if (c1 != 2 || c2 != 2 || (len & 0x80)) {
|
||||
// not run-length encoded, so we have to actually use THIS data as a decoded
|
||||
// pixel (note this can't be a valid pixel--one of RGB must be >= 128)
|
||||
stbi_uc rgbe[4] = { c1,c2,len, get8(s) };
|
||||
uint8 rgbe[4];
|
||||
rgbe[0] = (uint8) c1;
|
||||
rgbe[1] = (uint8) c2;
|
||||
rgbe[2] = (uint8) len;
|
||||
rgbe[3] = (uint8) get8u(s);
|
||||
hdr_convert(hdr_data, rgbe, req_comp);
|
||||
i = 1;
|
||||
j = 0;
|
||||
@@ -4423,17 +4439,17 @@ static float *hdr_load(stbi *s, int *x, int *y, int *comp, int req_comp)
|
||||
for (k = 0; k < 4; ++k) {
|
||||
i = 0;
|
||||
while (i < width) {
|
||||
count = get8(s);
|
||||
count = get8u(s);
|
||||
if (count > 128) {
|
||||
// Run
|
||||
value = get8(s);
|
||||
value = get8u(s);
|
||||
count -= 128;
|
||||
for (z = 0; z < count; ++z)
|
||||
scanline[i++ * 4 + k] = value;
|
||||
} else {
|
||||
// Dump
|
||||
for (z = 0; z < count; ++z)
|
||||
scanline[i++ * 4 + k] = get8(s);
|
||||
scanline[i++ * 4 + k] = get8u(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4524,6 +4540,8 @@ int stbi_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *c
|
||||
|
||||
/*
|
||||
revision history:
|
||||
1.27 (2010-08-01)
|
||||
cast-to-uint8 to fix warnings
|
||||
1.26 (2010-07-24)
|
||||
fix bug in file buffering for PNG reported by SpartanJ
|
||||
1.25 (2010-07-17)
|
||||
|
||||
@@ -339,3 +339,4 @@ extern int stbi_gif_info_from_file (FILE *f, int *x, int
|
||||
//
|
||||
//// end header file /////////////////////////////////////////////////////
|
||||
#endif // STBI_INCLUDE_STB_IMAGE_H
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//#ifdef STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
|
||||
#include "stb_image_write.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@@ -14,9 +14,14 @@ static void writefv(FILE *f, const char *fmt, va_list v)
|
||||
while (*fmt) {
|
||||
switch (*fmt++) {
|
||||
case ' ': break;
|
||||
case '1': { unsigned char x = va_arg(v, int); fputc(x,f); break; }
|
||||
case '2': { int x = va_arg(v,int); unsigned char b[2]; b[0] = x; b[1] = x>>8; fwrite(b,2,1,f); break; }
|
||||
case '4': { stbiw_uint32 x = va_arg(v,int); unsigned char b[4]; b[0]=x; b[1]=x>>8; b[2]=x>>16; b[3]=x>>24; fwrite(b,4,1,f); break; }
|
||||
case '1': { unsigned char x = (unsigned char) va_arg(v, int); fputc(x,f); break; }
|
||||
case '2': { int x = va_arg(v,int); unsigned char b[2];
|
||||
b[0] = (unsigned char) x; b[1] = (unsigned char) (x>>8);
|
||||
fwrite(b,2,1,f); break; }
|
||||
case '4': { stbiw_uint32 x = va_arg(v,int); unsigned char b[4];
|
||||
b[0]=(unsigned char)x; b[1]=(unsigned char)(x>>8);
|
||||
b[2]=(unsigned char)(x>>16); b[3]=(unsigned char)(x>>24);
|
||||
fwrite(b,4,1,f); break; }
|
||||
default:
|
||||
assert(0);
|
||||
return;
|
||||
@@ -135,7 +140,7 @@ static void *stbi__sbgrowf(void **arr, int increment, int itemsize)
|
||||
static unsigned char *stbi__zlib_flushf(unsigned char *data, unsigned int *bitbuffer, int *bitcount)
|
||||
{
|
||||
while (*bitcount >= 8) {
|
||||
stbi__sbpush(data, *bitbuffer);
|
||||
stbi__sbpush(data, (unsigned char) *bitbuffer);
|
||||
*bitbuffer >>= 8;
|
||||
*bitcount -= 8;
|
||||
}
|
||||
@@ -278,10 +283,10 @@ unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, int *out_l
|
||||
j += blocklen;
|
||||
blocklen = 5552;
|
||||
}
|
||||
stbi__sbpush(out, s2 >> 8);
|
||||
stbi__sbpush(out, s2);
|
||||
stbi__sbpush(out, s1 >> 8);
|
||||
stbi__sbpush(out, s1);
|
||||
stbi__sbpush(out, (unsigned char) (s2 >> 8));
|
||||
stbi__sbpush(out, (unsigned char) s2);
|
||||
stbi__sbpush(out, (unsigned char) (s1 >> 8));
|
||||
stbi__sbpush(out, (unsigned char) s1);
|
||||
}
|
||||
*out_len = stbi__sbn(out);
|
||||
// make returned pointer freeable
|
||||
@@ -292,7 +297,7 @@ unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, int *out_l
|
||||
unsigned int stbi__crc32(unsigned char *buffer, int len)
|
||||
{
|
||||
static unsigned int crc_table[256];
|
||||
unsigned int crc = ~0;
|
||||
unsigned int crc = ~0u;
|
||||
int i,j;
|
||||
if (crc_table[1] == 0)
|
||||
for(i=0; i < 256; i++)
|
||||
@@ -303,8 +308,8 @@ unsigned int stbi__crc32(unsigned char *buffer, int len)
|
||||
return ~crc;
|
||||
}
|
||||
|
||||
#define stbi__wpng4(o,a,b,c,d) ((o)[0]=(a),(o)[1]=(b),(o)[2]=(c),(o)[3]=(d),(o)+=4)
|
||||
#define stbi__wp32(data,v) stbi__wpng4(data, v>>24,v>>16,v>>8,v);
|
||||
#define stbi__wpng4(o,a,b,c,d) ((o)[0]=(unsigned char)(a),(o)[1]=(unsigned char)(b),(o)[2]=(unsigned char)(c),(o)[3]=(unsigned char)(d),(o)+=4)
|
||||
#define stbi__wp32(data,v) stbi__wpng4(data, (v)>>24,(v)>>16,(v)>>8,(v));
|
||||
#define stbi__wptag(data,s) stbi__wpng4(data, s[0],s[1],s[2],s[3])
|
||||
|
||||
static void stbi__wpcrc(unsigned char **data, int len)
|
||||
@@ -313,12 +318,12 @@ static void stbi__wpcrc(unsigned char **data, int len)
|
||||
stbi__wp32(*data, crc);
|
||||
}
|
||||
|
||||
static int stbi__paeth(int a, int b, int c)
|
||||
static unsigned char stbi__paeth(int a, int b, int c)
|
||||
{
|
||||
int p = a + b - c, pa = abs(p-a), pb = abs(p-b), pc = abs(p-c);
|
||||
if (pa <= pb && pa <= pc) return a;
|
||||
if (pb <= pc) return b;
|
||||
return c;
|
||||
if (pa <= pb && pa <= pc) return (unsigned char) a;
|
||||
if (pb <= pc) return (unsigned char) b;
|
||||
return (unsigned char) c;
|
||||
}
|
||||
|
||||
unsigned char *stbi_write_png_to_mem(unsigned char *pixels, int stride_bytes, int x, int y, int n, int *out_len)
|
||||
@@ -349,7 +354,7 @@ unsigned char *stbi_write_png_to_mem(unsigned char *pixels, int stride_bytes, in
|
||||
case 1: line_buffer[i] = z[i]; break;
|
||||
case 2: line_buffer[i] = z[i] - z[i-stride_bytes]; break;
|
||||
case 3: line_buffer[i] = z[i] - (z[i-stride_bytes]>>1); break;
|
||||
case 4: line_buffer[i] = z[i] - stbi__paeth(0,z[i-stride_bytes],0); break;
|
||||
case 4: line_buffer[i] = (signed char) (z[i] - stbi__paeth(0,z[i-stride_bytes],0)); break;
|
||||
case 5: line_buffer[i] = z[i]; break;
|
||||
case 6: line_buffer[i] = z[i]; break;
|
||||
}
|
||||
@@ -371,7 +376,7 @@ unsigned char *stbi_write_png_to_mem(unsigned char *pixels, int stride_bytes, in
|
||||
}
|
||||
}
|
||||
// when we get here, best contains the filter type, and line_buffer contains the data
|
||||
filt[j*(x*n+1)] = best;
|
||||
filt[j*(x*n+1)] = (unsigned char) best;
|
||||
memcpy(filt+j*(x*n+1)+1, line_buffer, x*n);
|
||||
}
|
||||
free(line_buffer);
|
||||
@@ -391,7 +396,7 @@ unsigned char *stbi_write_png_to_mem(unsigned char *pixels, int stride_bytes, in
|
||||
stbi__wp32(o, x);
|
||||
stbi__wp32(o, y);
|
||||
*o++ = 8;
|
||||
*o++ = ctype[n];
|
||||
*o++ = (unsigned char) ctype[n];
|
||||
*o++ = 0;
|
||||
*o++ = 0;
|
||||
*o++ = 0;
|
||||
@@ -428,6 +433,8 @@ int stbi_write_png(char const *filename, int x, int y, int comp, const void *dat
|
||||
|
||||
/* Revision history
|
||||
|
||||
0.92 (2010-08-01)
|
||||
casts to unsigned char to fix warnings
|
||||
0.91 (2010-07-17)
|
||||
first public release
|
||||
0.90 first internal release
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* stbiw-0.91 - public domain - http://nothings.org/stb/stb_image_write.h
|
||||
/* stbiw-0.92 - public domain - http://nothings.org/stb/stb_image_write.h
|
||||
writes out PNG/BMP/TGA images to C stdio - Sean Barrett 2010
|
||||
no warranty implied; use at your own risk
|
||||
|
||||
@@ -29,7 +29,7 @@ USAGE:
|
||||
int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data);
|
||||
|
||||
Each function returns 0 on failure and non-0 on success.
|
||||
|
||||
|
||||
The functions create an image file defined by the parameters. The image
|
||||
is a rectangle of pixels stored from left-to-right, top-to-bottom.
|
||||
Each pixel contains 'comp' channels of data stored interleaved with 8-bits
|
||||
@@ -42,7 +42,7 @@ USAGE:
|
||||
PNG creates output files with the same number of components as the input.
|
||||
The BMP and TGA formats expand Y to RGB in the file format. BMP does not
|
||||
output alpha.
|
||||
|
||||
|
||||
PNG supports writing rectangles of data even when the bytes storing rows of
|
||||
data are not consecutive in memory (e.g. sub-rectangles of a larger image),
|
||||
by supplying the stride between the beginning of adjacent rows. The other
|
||||
@@ -61,10 +61,10 @@ extern "C" {
|
||||
extern int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes);
|
||||
extern int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data);
|
||||
extern int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data);
|
||||
extern unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, int *out_len, int quality);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif//INCLUDE_STB_IMAGE_WRITE_H
|
||||
|
||||
|
||||
@@ -371,4 +371,22 @@ eeInt GetNumCPUs() {
|
||||
return nprocs;
|
||||
}
|
||||
|
||||
bool FileWrite( const std::string& filepath, const Uint8* data, const Uint32& dataSize ) {
|
||||
std::fstream fs( filepath.c_str() , std::ios::out | std::ios::binary );
|
||||
|
||||
if ( fs.is_open() ) {
|
||||
fs.write( reinterpret_cast<const char*> (data), dataSize );
|
||||
|
||||
fs.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FileWrite( const std::string& filepath, const std::vector<Uint8>& data ) {
|
||||
return FileWrite( filepath, reinterpret_cast<const Uint8*> ( &data[0] ), data.size() );
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -63,6 +63,12 @@ namespace EE { namespace Utils {
|
||||
*/
|
||||
std::string FileExtension( const std::string& filepath, const bool& lowerExt = true );
|
||||
|
||||
/** Write a file in binary mode and close it. */
|
||||
bool FileWrite( const std::string& filepath, const Uint8* data, const Uint32& dataSize );
|
||||
|
||||
/** Write a file in binary mode and close it. */
|
||||
bool FileWrite( const std::string& filepath, const std::vector<Uint8>& data );
|
||||
|
||||
/** @return The Number of CPUs of the system. */
|
||||
eeInt GetNumCPUs();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user