Thanks for using Compiler Explorer
Sponsors
Jakt
C++
Ada
Analysis
Android Java
Android Kotlin
Assembly
C
C3
Carbon
C++ (Circle)
CIRCT
Clean
CMake
CMakeScript
COBOL
C++ for OpenCL
MLIR
Cppx
Cppx-Blue
Cppx-Gold
Cpp2-cppfront
Crystal
C#
CUDA C++
D
Dart
Elixir
Erlang
Fortran
F#
Go
Haskell
HLSL
Hook
Hylo
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Nim
Objective-C
Objective-C++
OCaml
OpenCL C
Pascal
Pony
Python
Racket
Ruby
Rust
Snowball
Scala
Solidity
Spice
Swift
LLVM TableGen
Toit
TypeScript Native
V
Vala
Visual Basic
Zig
Javascript
GIMPLE
d source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Verbose demangling
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
dmd 2.078.3
dmd 2.079.0
dmd 2.079.1
dmd 2.080.1
dmd 2.081.2
dmd 2.082.0
dmd 2.089.0
dmd 2.092.0
dmd 2.094.2
dmd nightly
gdc (trunk)
gdc 10.1
gdc 10.2
gdc 10.5
gdc 11.1
gdc 11.3
gdc 11.4
gdc 12.1
gdc 12.2
gdc 12.3
gdc 13.1
gdc 13.2
gdc 9.2
gdc 9.3
gdc 9.5
gdc arm 12.2.0
gdc arm 12.3.0
gdc arm 13.1.0
gdc arm 13.2.0
gdc arm64 12.2.0
gdc arm64 12.3.0
gdc arm64 13.1.0
gdc arm64 13.2.0
gdc mips 12.1.0
gdc mips 12.2.0
gdc mips 12.3.0
gdc mips 13.1.0
gdc mips 13.2.0
gdc mips64 12.1.0
gdc mips64 12.2.0
gdc mips64 12.3.0
gdc mips64 13.1.0
gdc mips64 13.2.0
gdc mipsel 12.1.0
gdc mipsel 12.2.0
gdc mipsel 12.3.0
gdc mipsel 13.1.0
gdc mipsel 13.2.0
gdc powerpc 12.1.0
gdc powerpc 12.2.0
gdc powerpc 12.3.0
gdc powerpc 13.1.0
gdc powerpc 13.2.0
gdc powerpc64 12.1.0
gdc powerpc64 12.2.0
gdc powerpc64 12.3.0
gdc powerpc64 13.1.0
gdc powerpc64 13.2.0
gdc powerpc64 trunk
gdc powerpc64le 12.1.0
gdc powerpc64le 12.2.0
gdc powerpc64le 12.3.0
gdc powerpc64le 13.1.0
gdc powerpc64le 13.2.0
gdc powerpc64le trunk
gdc riscv32 12.2.0
gdc riscv32 12.3.0
gdc riscv32 13.1.0
gdc riscv32 13.2.0
gdc riscv32 trunk
gdc riscv64 12.2.0
gdc riscv64 12.3.0
gdc riscv64 13.1.0
gdc riscv64 13.2.0
gdc riscv64 trunk
gdc s390x 12.1.0
gdc s390x 12.2.0
gdc s390x 12.3.0
gdc s390x 13.1.0
gdc s390x 13.2.0
ldc 0.17.2
ldc 1.0.0
ldc 1.1.0
ldc 1.10.0
ldc 1.11.0
ldc 1.12.0
ldc 1.13.0
ldc 1.14.0
ldc 1.15.0
ldc 1.16.0
ldc 1.17.0
ldc 1.18.0
ldc 1.19.0
ldc 1.2.0
ldc 1.20.0
ldc 1.21.0
ldc 1.22.0
ldc 1.23.0
ldc 1.24.0
ldc 1.25.1
ldc 1.26.0
ldc 1.27.1
ldc 1.28.1
ldc 1.29.0
ldc 1.3.0
ldc 1.30.0
ldc 1.31.0
ldc 1.32.1
ldc 1.33.0
ldc 1.34.0
ldc 1.35.0
ldc 1.36.0
ldc 1.37.0
ldc 1.4.0
ldc 1.5.0
ldc 1.6.0
ldc 1.7.0
ldc 1.8.0
ldc 1.9.0
ldc beta
ldc latest CI
Options
Source code
alias stbi__uint32 = uint; alias stbi__uint16 = ushort; alias stbi_uc = ubyte; import core.stdc.string; struct stbi__context { int img_n; } struct stbi__png { stbi__context* s; stbi_uc* out_; } ubyte STBI__BYTECAST(int x) { return cast(ubyte)x; } int stbi__paeth(int a, int b, int c) { return a + b + c; } int stbi__create_png_image_raw(stbi__png *a, stbi_uc *raw, stbi__uint32 raw_len, int out_n, stbi__uint32 x, stbi__uint32 y, int depth, int color) { int bytes = (depth == 16? 2 : 1); stbi__context *s = a.s; stbi__uint32 i,j,stride = x*out_n*bytes; stbi__uint32 img_len, img_width_bytes; int k; int img_n = s.img_n; // copy it into a local for later int output_bytes = out_n*bytes; int filter_bytes = img_n*bytes; int width = x; assert(out_n == s.img_n || out_n == s.img_n+1); a.out_ = null; if (!a.out_) return 0; //stbi__err("outofmem", "Out of memory"); img_width_bytes = (((img_n * x * depth) + 7) >> 3); img_len = (img_width_bytes + 1) * y; // we make a separate pass to expand bits to pixels; for performance, // this could run two scanlines behind the above code, so it won't // intefere with filtering but will still be in the cache. if (depth < 8) { for (j=0; j < y; ++j) { stbi_uc *cur = a.out_ + stride*j; stbi_uc *in_ = a.out_ + stride*j + x*out_n - img_width_bytes; // unpack 1/2/4-bit into a 8-bit buffer. allows us to keep the common 8-bit path optimal at minimal cost for 1/2/4-bit // png guarante byte alignment, if width is not multiple of 8/4/2 we'll decode dummy trailing data that will be skipped in the later loop stbi_uc scale = (color == 0) ? 0 : 1; // scale grayscale values to 0..255 range // note that the final byte might overshoot and write more data than desired. // we can allocate enough data that this never writes out of memory, but it // could also overwrite the next scanline. can it overwrite non-empty data // on the next scanline? yes, consider 1-pixel-wide scanlines with 1-bit-per-pixel. // so we need to explicitly clamp the final ones if (depth == 4) { for (k=x*img_n; k >= 2; k-=2, ++in_) { *cur++ = cast(ubyte)(scale * ((*in_ >> 4)) ); *cur++ = cast(ubyte)(scale * ((*in_ ) & 0x0f)); } if (k > 0) *cur++ = cast(ubyte)(scale * ((*in_ >> 4) )); } else if (depth == 2) { for (k=x*img_n; k >= 4; k-=4, ++in_) { *cur++ = cast(ubyte)(scale * ((*in_ >> 6) )); *cur++ = cast(ubyte)(scale * ((*in_ >> 4) & 0x03)); *cur++ = cast(ubyte)(scale * ((*in_ >> 2) & 0x03)); *cur++ = cast(ubyte)(scale * ((*in_ ) & 0x03)); } if (k > 0) *cur++ = cast(ubyte)(scale * ((*in_ >> 6) )); if (k > 1) *cur++ = cast(ubyte)(scale * ((*in_ >> 4) & 0x03)); if (k > 2) *cur++ = cast(ubyte)(scale * ((*in_ >> 2) & 0x03)); } else { for (k=x*img_n; k >= 8; k-=8, ++in_) { *cur++ = (scale * ((*in_ >> 7) )); *cur++ = (scale * ((*in_ >> 6) & 0x01)); *cur++ = (scale * ((*in_ >> 5) & 0x01)); *cur++ = (scale * ((*in_ >> 4) & 0x01)); *cur++ = (scale * ((*in_ >> 3) & 0x01)); *cur++ = (scale * ((*in_ >> 2) & 0x01)); *cur++ = (scale * ((*in_ >> 1) & 0x01)); *cur++ = (scale * ((*in_ ) & 0x01)); } if (k > 0) *cur++ = (scale * ((*in_ >> 7) )); if (k > 1) *cur++ = (scale * ((*in_ >> 6) & 0x01)); if (k > 2) *cur++ = (scale * ((*in_ >> 5) & 0x01)); if (k > 3) *cur++ = (scale * ((*in_ >> 4) & 0x01)); if (k > 4) *cur++ = (scale * ((*in_ >> 3) & 0x01)); if (k > 5) *cur++ = (scale * ((*in_ >> 2) & 0x01)); if (k > 6) *cur++ = (scale * ((*in_ >> 1) & 0x01)); } if (img_n != out_n) { int q; // insert alpha = 255 cur = a.out_ + stride*j; if (img_n == 1) { for (q=x-1; q >= 0; --q) { cur[q*2+1] = 255; cur[q*2+0] = cur[q]; } } else { assert(img_n == 3); for (q=x-1; q >= 0; --q) { cur[q*4+3] = 255; cur[q*4+2] = cur[q*3+2]; cur[q*4+1] = cur[q*3+1]; cur[q*4+0] = cur[q*3+0]; } } } } } return 1; } void main() { }
Become a Patron
Sponsor on GitHub
Donate via PayPal
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
About the author
Statistics
Changelog
Version tree