Skip to content

Commit ceeb6b5

Browse files
author
Guillaume Piolat
committed
reducing phobos impact
1 parent 5003f23 commit ceeb6b5

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

source/gamut/codecs/stb_image_write.d

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ version(encodeJPEG)
105105

106106
version(compileSTBImageWrite):
107107

108-
import std.math: abs;
109108
import core.stdc.stdlib: malloc, realloc, free;
110109
import core.stdc.string: memcpy, memmove;
111110
import miniz;
@@ -252,9 +251,14 @@ static void stbiw__wpcrc(ubyte **data, int len)
252251
stbiw__wp32(*data, crc);
253252
}
254253

254+
int abs_int(int x)
255+
{
256+
return x >= 0 ? x : -cast(int)x;
257+
}
258+
255259
ubyte stbiw__paeth(int a, int b, int c)
256260
{
257-
int p = a + b - c, pa = abs(p-a), pb = abs(p-b), pc = abs(p-c);
261+
int p = a + b - c, pa = abs_int(p-a), pb = abs_int(p-b), pc = abs_int(p-c);
258262
if (pa <= pb && pa <= pc) return STBIW_UCHAR(a);
259263
if (pb <= pc) return STBIW_UCHAR(b);
260264
return STBIW_UCHAR(c);
@@ -388,7 +392,7 @@ public ubyte *stbi_write_png_to_mem(const(ubyte*) pixels, int stride_bytes, int
388392
// Estimate the entropy of the line using this filter; the less, the better.
389393
est = 0;
390394
for (i = 0; i < x*n; ++i) { // Note: adapting that entropy for 16-bit samples wins nothing.
391-
est += abs(line_buffer[i]);
395+
est += abs_int(line_buffer[i]);
392396
}
393397
if (est < best_filter_val) {
394398
best_filter_val = est;

source/gamut/codecs/stbdec.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2499,5 +2499,5 @@ version(decodeBMP)
24992499

25002500
int abs_int(int x)
25012501
{
2502-
return x >= 0 ? x : cast(int) -x;
2502+
return x >= 0 ? x : -cast(int)x;
25032503
}

0 commit comments

Comments
 (0)