summaryrefslogtreecommitdiff
path: root/src/lodepng.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lodepng.cpp')
-rw-r--r--src/lodepng.cpp34
1 files changed, 14 insertions, 20 deletions
diff --git a/src/lodepng.cpp b/src/lodepng.cpp
index b237d5a..084f1c8 100644
--- a/src/lodepng.cpp
+++ b/src/lodepng.cpp
@@ -1406,7 +1406,7 @@ static unsigned deflateDynamic(ucvector* out, const unsigned char* data, size_t
for(i = 0; i < numcodes; i++) uivector_push_back(&lldll, HuffmanTree_getLength(&codes, (unsigned)i));
for(i = 0; i < numcodesD; i++) uivector_push_back(&lldll, HuffmanTree_getLength(&codesD, (unsigned)i));
- /*make lldl smaller by using repeat codes 16 (copy length 3-6 times), 17 (3-10 zeroes), 18 (11-138 zeroes)*/
+ /*make lldl smaller by using repeat codes 16 (copy length 3-6 times), 17 (3-10 zeros), 18 (11-138 zeros)*/
for(i = 0; i < (unsigned)lldll.size; i++)
{
unsigned j = 0;
@@ -2547,7 +2547,7 @@ unsigned LodePNG_convert(unsigned char* out, const unsigned char* in, LodePNG_In
return 0;
}
-/*Paeth predicter, used by PNG filter type 4*/
+/*Path predictor, used by PNG filter type 4*/
static int paethPredictor(int a, int b, int c)
{
int p = a + b - c;
@@ -2795,7 +2795,7 @@ static unsigned postProcessScanlines(unsigned char* out, unsigned char* in, cons
{
/*
This function converts the filtered-padded-interlaced data into pure 2D image buffer with the PNG's colortype. Steps:
- *) if no Adam7: 1) unfilter 2) remove padding bits (= posible extra bits per scanline if bpp < 8)
+ *) if no Adam7: 1) unfilter 2) remove padding bits (= possible extra bits per scanline if bpp < 8)
*) if adam7: 1) 7x unfilter 2) 7x remove padding bits 3) Adam7_deinterlace
NOTE: the in buffer will be overwritten with intermediate data!
*/
@@ -3535,20 +3535,11 @@ static void filterScanline(unsigned char* out, const unsigned char* scanline, co
switch(filterType)
{
case 0:
- if(prevline) for(i = 0; i < length; i++) out[i] = scanline[i];
- else for(i = 0; i < length; i++) out[i] = scanline[i];
+ for(i = 0; i < length; i++) out[i] = scanline[i];
break;
case 1:
- if(prevline)
- {
- for(i = 0; i < bytewidth; i++) out[i] = scanline[i];
- for(i = bytewidth; i < length ; i++) out[i] = scanline[i] - scanline[i - bytewidth];
- }
- else
- {
- for(i = 0; i < bytewidth; i++) out[i] = scanline[i];
- for(i = bytewidth; i < length; i++) out[i] = scanline[i] - scanline[i - bytewidth];
- }
+ for(i = 0; i < bytewidth; i++) out[i] = scanline[i];
+ for(i = bytewidth; i < length; i++) out[i] = scanline[i] - scanline[i - bytewidth];
break;
case 2:
if(prevline) for(i = 0; i < length; i++) out[i] = scanline[i] - prevline[i];
@@ -3772,7 +3763,7 @@ static unsigned preProcessScanlines(unsigned char** out, size_t* outsize, const
{
/*
This function converts the pure 2D image with the PNG's colortype, into filtered-padded-interlaced data. Steps:
- *) if no Adam7: 1) add padding bits (= posible extra bits per scanline if bpp < 8) 2) filter
+ *) if no Adam7: 1) add padding bits (= possible extra bits per scanline if bpp < 8) 2) filter
*) if adam7: 1) Adam7_interlace 2) 7x add padding bits 3) 7x filter
*/
unsigned bpp = LodePNG_InfoColor_getBpp(&infoPng->color);
@@ -3800,7 +3791,7 @@ static unsigned preProcessScanlines(unsigned char** out, size_t* outsize, const
}
ucvector_cleanup(&padded);
}
- else error = filter(*out, in, w, h, &infoPng->color); /*we can immediatly filter into the out buffer, no other steps needed*/
+ else error = filter(*out, in, w, h, &infoPng->color); /*we can immediately filter into the out buffer, no other steps needed*/
}
}
else /*interlaceMethod is 1 (Adam7)*/
@@ -4134,9 +4125,12 @@ unsigned LodePNG_loadFile(unsigned char** out, size_t* outsize, const char* file
rewind(file);
/*read contents of the file into the vector*/
- *outsize = 0;
- *out = (unsigned char*)malloc((size_t)size);
- if(size && (*out)) (*outsize) = fread(*out, 1, (size_t)size, file);
+ if (size>0)
+ {
+ *outsize = 0;
+ *out = (unsigned char*)malloc((size_t)size);
+ if(size && (*out)) (*outsize) = fread(*out, 1, (size_t)size, file);
+ }
fclose(file);
if(!(*out) && size) return 80; /*the above malloc failed*/