Skip to content

Commit c715cae

Browse files
committed
Some tweaks
1 parent 98a7d35 commit c715cae

3 files changed

Lines changed: 15 additions & 24 deletions

File tree

src/external/rgif.h

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
#ifndef RGIF_H
8282
#define RGIF_H
8383

84-
#include <stdio.h> // Required for: FILE
84+
#include <stdio.h> // Required for: FILE
8585

8686
//#define RGIF_STATIC
8787
#ifdef RGIF_STATIC
@@ -117,16 +117,6 @@ RGIFDEF bool GifEnd();
117117
#include <stdio.h> // Required for: FILE, fopen(), fclose()
118118
#include <string.h> // Required for: memcpy()
119119

120-
// Define these macros to hook into a custom memory allocator.
121-
// RGIF_TEMP_MALLOC and RGIF_TEMP_FREE will only be called in stack fashion - frees in the reverse order of mallocs
122-
// and any temp memory allocated by a function will be freed before it exits.
123-
#if !defined(RGIF_TEMP_MALLOC)
124-
#include <stdlib.h>
125-
126-
#define RGIF_TEMP_MALLOC malloc
127-
#define RGIF_TEMP_FREE free
128-
#endif
129-
130120
// Check if custom malloc/free functions defined, if not, using standard ones
131121
// RGIF_MALLOC and RGIF_FREE are used only by GifBegin and GifEnd respectively,
132122
// to allocate a buffer the size of the image, which is used to find changed pixels for delta-encoding.
@@ -185,7 +175,7 @@ typedef struct GifLzwNode {
185175
//----------------------------------------------------------------------------------
186176
const int gifTransparentIndex = 0; // Transparent color index
187177

188-
static FILE *gifFile;
178+
static FILE *gifFile = NULL;
189179
unsigned char *gifFrame;
190180

191181
//----------------------------------------------------------------------------------
@@ -201,9 +191,10 @@ static void GifMakePalette(const unsigned char *lastFrame, const unsigned char *
201191
static void GifDitherImage(const unsigned char *lastFrame, const unsigned char *nextFrame, unsigned char *outFrame, unsigned int width, unsigned int height, GifPalette *pPal);
202192
static void GifThresholdImage(const unsigned char *lastFrame, const unsigned char *nextFrame, unsigned char *outFrame, unsigned int width, unsigned int height, GifPalette *pPal);
203193
static void GifWriteBit(GifBitStatus *stat, unsigned int bit);
194+
204195
static void GifWriteChunk(FILE *f, GifBitStatus *stat);
196+
static void GifWritePalette(FILE *f, const GifPalette *pPal);
205197
static void GifWriteCode(FILE *f, GifBitStatus *stat, unsigned int code, unsigned int length);
206-
static void GifWritePalette(const GifPalette *pPal, FILE *f);
207198
static void GifWriteLzwImage(FILE *f, unsigned char *image, unsigned int left, unsigned int top, unsigned int width, unsigned int height, unsigned int delay, GifPalette *pPal);
208199

209200
//----------------------------------------------------------------------------------
@@ -591,7 +582,7 @@ static void GifMakePalette(const unsigned char *lastFrame, const unsigned char *
591582
// SplitPalette is destructive (it sorts the pixels by color) so
592583
// we must create a copy of the image for it to destroy
593584
int imageSize = width*height*4*sizeof(unsigned char);
594-
unsigned char *destroyableImage = (unsigned char*)RGIF_TEMP_MALLOC(imageSize);
585+
unsigned char *destroyableImage = (unsigned char*)RGIF_MALLOC(imageSize);
595586
memcpy(destroyableImage, nextFrame, imageSize);
596587

597588
int numPixels = width*height;
@@ -604,7 +595,7 @@ static void GifMakePalette(const unsigned char *lastFrame, const unsigned char *
604595

605596
GifSplitPalette(destroyableImage, numPixels, 1, lastElt, splitElt, splitDist, 1, buildForDither, pPal);
606597

607-
RGIF_TEMP_FREE(destroyableImage);
598+
RGIF_FREE(destroyableImage);
608599

609600
// add the bottom node for the transparency index
610601
pPal->treeSplit[1 << (bitDepth-1)] = 0;
@@ -621,7 +612,7 @@ static void GifDitherImage(const unsigned char *lastFrame, const unsigned char *
621612
// quantPixels initially holds color*256 for all pixels
622613
// The extra 8 bits of precision allow for sub-single-color error values
623614
// to be propagated
624-
int *quantPixels = (int*)RGIF_TEMP_MALLOC(sizeof(int)*numPixels*4);
615+
int *quantPixels = (int*)RGIF_MALLOC(sizeof(int)*numPixels*4);
625616

626617
for (int ii=0; ii<numPixels*4; ++ii)
627618
{
@@ -719,7 +710,7 @@ static void GifDitherImage(const unsigned char *lastFrame, const unsigned char *
719710
outFrame[ii] = quantPixels[ii];
720711
}
721712

722-
RGIF_TEMP_FREE(quantPixels);
713+
RGIF_FREE(quantPixels);
723714
}
724715

725716
// Picks palette colors for the image using simple thresholding, no dithering
@@ -805,7 +796,7 @@ static void GifWriteCode(FILE *f, GifBitStatus *stat, unsigned int code, unsigne
805796
}
806797

807798
// write a 256-color (8-bit) image palette to the file
808-
static void GifWritePalette(const GifPalette *pPal, FILE *f)
799+
static void GifWritePalette(FILE *f, const GifPalette *pPal)
809800
{
810801
fputc(0, f); // first color: transparency
811802
fputc(0, f);
@@ -852,14 +843,14 @@ static void GifWriteLzwImage(FILE *f, unsigned char *image, unsigned int left, u
852843
//fputc(0x80, f); // no local color table, but transparency
853844

854845
fputc(0x80 + pPal->bitDepth-1, f); // local color table present, 2 ^ bitDepth entries
855-
GifWritePalette(pPal, f);
846+
GifWritePalette(f, pPal);
856847

857848
const int minCodeSize = pPal->bitDepth;
858849
const unsigned int clearCode = 1 << pPal->bitDepth;
859850

860851
fputc(minCodeSize, f); // min code size 8 bits
861852

862-
GifLzwNode *codetree = (GifLzwNode *)RGIF_TEMP_MALLOC(sizeof(GifLzwNode)*4096);
853+
GifLzwNode *codetree = (GifLzwNode *)RGIF_MALLOC(sizeof(GifLzwNode)*4096);
863854

864855
memset(codetree, 0, sizeof(GifLzwNode)*4096);
865856
int curCode = -1;
@@ -933,7 +924,7 @@ static void GifWriteLzwImage(FILE *f, unsigned char *image, unsigned int left, u
933924

934925
fputc(0, f); // image block terminator
935926

936-
RGIF_TEMP_FREE(codetree);
927+
RGIF_FREE(codetree);
937928
}
938929

939930
#endif // RGIF_IMPLEMENTATION

src/models.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ ModelAnimation *LoadModelAnimations(const char *filename, int *animCount)
930930
unsigned int flags;
931931
} IQMAnim;
932932

933-
FILE *iqmFile;
933+
FILE *iqmFile = NULL;
934934
IQMHeader iqm;
935935

936936
iqmFile = fopen(filename,"rb");
@@ -3061,7 +3061,7 @@ static Model LoadIQM(const char *fileName)
30613061

30623062
Model model = { 0 };
30633063

3064-
FILE *iqmFile;
3064+
FILE *iqmFile = NULL;
30653065
IQMHeader iqm;
30663066

30673067
IQMMesh *imesh;

src/raudio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1729,7 +1729,7 @@ static Wave LoadWAV(const char *fileName)
17291729
WAVData wavData;
17301730

17311731
Wave wave = { 0 };
1732-
FILE *wavFile;
1732+
FILE *wavFile = NULL;
17331733

17341734
wavFile = fopen(fileName, "rb");
17351735

0 commit comments

Comments
 (0)