mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 11:35:08 -04:00
Get default.zip generated at last
This commit is contained in:
parent
c26d71eded
commit
3aea8a5b1c
37
src/Bitmap.c
37
src/Bitmap.c
@ -507,21 +507,17 @@ ReturnCode Png_Decode(Bitmap* bmp, struct Stream* stream) {
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*------------------------------------------------------PNG encoder--------------------------------------------------------*
|
*------------------------------------------------------PNG encoder--------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static void Png_Filter(uint8_t filter, const uint8_t* cur, const uint8_t* prior, uint8_t* best, int lineLen) {
|
static void Png_Filter(uint8_t filter, const uint8_t* cur, const uint8_t* prior, uint8_t* best, int lineLen, int bpp) {
|
||||||
/* 3 bytes per pixel constant */
|
/* 3 bytes per pixel constant */
|
||||||
uint8_t a, b, c;
|
uint8_t a, b, c;
|
||||||
int i, p, pa, pb, pc;
|
int i, p, pa, pb, pc;
|
||||||
|
|
||||||
switch (filter) {
|
switch (filter) {
|
||||||
case PNG_FILTER_NONE:
|
|
||||||
Mem_Copy(best, cur, lineLen);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PNG_FILTER_SUB:
|
case PNG_FILTER_SUB:
|
||||||
best[0] = cur[0]; best[1] = cur[1]; best[2] = cur[2];
|
for (i = 0; i < bpp; i++) { best[i] = cur[i]; }
|
||||||
|
|
||||||
for (i = 3; i < lineLen; i++) {
|
for (; i < lineLen; i++) {
|
||||||
best[i] = cur[i] - cur[i - 3];
|
best[i] = cur[i] - cur[i - bpp];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -532,22 +528,18 @@ static void Png_Filter(uint8_t filter, const uint8_t* cur, const uint8_t* prior,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case PNG_FILTER_AVERAGE:
|
case PNG_FILTER_AVERAGE:
|
||||||
best[0] = cur[0] - (prior[0] >> 1);
|
for (i = 0; i < bpp; i++) { best[i] = cur[i] - (prior[i] >> 1); }
|
||||||
best[1] = cur[1] - (prior[1] >> 1);
|
|
||||||
best[2] = cur[2] - (prior[2] >> 1);
|
|
||||||
|
|
||||||
for (i = 3; i < lineLen; i++) {
|
for (; i < lineLen; i++) {
|
||||||
best[i] = cur[i] - ((prior[i] + cur[i - 3]) >> 1);
|
best[i] = cur[i] - ((prior[i] + cur[i - bpp]) >> 1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PNG_FILTER_PAETH:
|
case PNG_FILTER_PAETH:
|
||||||
best[0] = cur[0] - prior[0];
|
for (i = 0; i < bpp; i++) { best[i] = cur[i] - prior[i]; }
|
||||||
best[1] = cur[1] - prior[1];
|
|
||||||
best[2] = cur[2] - prior[2];
|
|
||||||
|
|
||||||
for (i = 3; i < lineLen; i++) {
|
for (; i < lineLen; i++) {
|
||||||
a = cur[i - 3]; b = prior[i]; c = prior[i - 3];
|
a = cur[i - bpp]; b = prior[i]; c = prior[i - bpp];
|
||||||
p = a + b - c;
|
p = a + b - c;
|
||||||
|
|
||||||
pa = Math_AbsI(p - a);
|
pa = Math_AbsI(p - a);
|
||||||
@ -576,7 +568,7 @@ static void Png_MakeRow(const BitmapCol* src, uint8_t* dst, int lineLen, bool al
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Png_EncodeRow(const uint8_t* cur, const uint8_t* prior, uint8_t* best, int lineLen) {
|
static void Png_EncodeRow(const uint8_t* cur, const uint8_t* prior, uint8_t* best, int lineLen, bool alpha) {
|
||||||
uint8_t* dst;
|
uint8_t* dst;
|
||||||
int bestFilter, bestEstimate = Int32_MaxValue;
|
int bestFilter, bestEstimate = Int32_MaxValue;
|
||||||
int x, filter, estimate;
|
int x, filter, estimate;
|
||||||
@ -584,7 +576,7 @@ static void Png_EncodeRow(const uint8_t* cur, const uint8_t* prior, uint8_t* bes
|
|||||||
dst = best + 1;
|
dst = best + 1;
|
||||||
/* NOTE: Waste of time trying the PNG_NONE filter */
|
/* NOTE: Waste of time trying the PNG_NONE filter */
|
||||||
for (filter = PNG_FILTER_SUB; filter <= PNG_FILTER_PAETH; filter++) {
|
for (filter = PNG_FILTER_SUB; filter <= PNG_FILTER_PAETH; filter++) {
|
||||||
Png_Filter(filter, cur, prior, dst, lineLen);
|
Png_Filter(filter, cur, prior, dst, lineLen, alpha ? 4 : 3);
|
||||||
|
|
||||||
/* Estimate how well this filtered line will compress, based on */
|
/* Estimate how well this filtered line will compress, based on */
|
||||||
/* smallest sum of magnitude of each byte (signed) in the line */
|
/* smallest sum of magnitude of each byte (signed) in the line */
|
||||||
@ -602,7 +594,7 @@ static void Png_EncodeRow(const uint8_t* cur, const uint8_t* prior, uint8_t* bes
|
|||||||
/* The bytes in dst are from last filter run (paeth) */
|
/* The bytes in dst are from last filter run (paeth) */
|
||||||
/* However, we want dst to be bytes from the best filter */
|
/* However, we want dst to be bytes from the best filter */
|
||||||
if (bestFilter != PNG_FILTER_PAETH) {
|
if (bestFilter != PNG_FILTER_PAETH) {
|
||||||
Png_Filter(bestFilter, cur, prior, dst, lineLen);
|
Png_Filter(bestFilter, cur, prior, dst, lineLen, alpha ? 4 : 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
best[0] = bestFilter;
|
best[0] = bestFilter;
|
||||||
@ -659,7 +651,8 @@ ReturnCode Png_Encode(Bitmap* bmp, struct Stream* stream, Png_RowSelector select
|
|||||||
uint8_t* cur = (y & 1) == 0 ? curLine : prevLine;
|
uint8_t* cur = (y & 1) == 0 ? curLine : prevLine;
|
||||||
|
|
||||||
Png_MakeRow(src, cur, lineSize, alpha);
|
Png_MakeRow(src, cur, lineSize, alpha);
|
||||||
Png_EncodeRow(cur, prev, bestLine, lineSize);
|
Png_EncodeRow(cur, prev, bestLine, lineSize, alpha);
|
||||||
|
|
||||||
/* +1 for filter byte */
|
/* +1 for filter byte */
|
||||||
if ((res = Stream_Write(&zlStream, bestLine, lineSize + 1))) return res;
|
if ((res = Stream_Write(&zlStream, bestLine, lineSize + 1))) return res;
|
||||||
}
|
}
|
||||||
|
@ -520,7 +520,7 @@ static ReturnCode TexPatcher_NewFiles(struct Stream* s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void TexPatcher_PatchTile(Bitmap* src, int srcX, int srcY, int dstX, int dstY) {
|
static void TexPatcher_PatchTile(Bitmap* src, int srcX, int srcY, int dstX, int dstY) {
|
||||||
Bitmap_CopyBlock(srcX, srcY, dstX * 16, dstY & 16, src, &terrainBmp, 16);
|
Bitmap_CopyBlock(srcX, srcY, dstX * 16, dstY * 16, src, &terrainBmp, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ReturnCode TexPatcher_Terrain(struct Stream* s) {
|
static ReturnCode TexPatcher_Terrain(struct Stream* s) {
|
||||||
@ -798,7 +798,7 @@ void Fetcher_Update(void) {
|
|||||||
if (Resources_Files[i].Downloaded) continue;
|
if (Resources_Files[i].Downloaded) continue;
|
||||||
Fetcher_CheckFile(&Resources_Files[i]);
|
Fetcher_CheckFile(&Resources_Files[i]);
|
||||||
}
|
}
|
||||||
//if (Resources_Files[3].Data) TexPatcher_MakeDefaultZip();
|
if (Resources_Files[3].Data) TexPatcher_MakeDefaultZip();
|
||||||
|
|
||||||
for (i = 0; i < Array_Elems(Resources_Music); i++) {
|
for (i = 0; i < Array_Elems(Resources_Music); i++) {
|
||||||
if (Resources_Music[i].Downloaded) continue;
|
if (Resources_Music[i].Downloaded) continue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user