Last active
January 2, 2019 03:25
-
-
Save Liam0205/78132b55266e6a80648333984370c842 to your computer and use it in GitHub Desktop.
2D-light demo for computer graphics enthusiasts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "svpng.inc" | |
#include <math.h> // fabsf(), fminf(), fmaxf(), sinf(), cosf(), sqrt() | |
#include <stdlib.h> // rand(), RAND_MAX | |
#define TWO_PI 6.28318530718f | |
#define W 512 | |
#define H 512 | |
#define N 256 | |
#define MAX_STEP 64 | |
#define MAX_DISTANCE 5.0f | |
#define EPSILON 1e-6f | |
#define BIAS 1e-4f | |
#define MAX_DEPTH 3 | |
typedef struct { float sd, emissive, reflectivity, eta; } Result; | |
unsigned char img[W * H * 3]; | |
float circleSDF(float x, float y, float cx, float cy, float r) { | |
float ux = x - cx, uy = y - cy; | |
return sqrtf(ux * ux + uy * uy) - r; | |
} | |
float boxSDF(float x, float y, float cx, float cy, float theta, float sx, float sy) { | |
float costheta = cosf(theta), sintheta = sinf(theta); | |
float dx = fabs((x - cx) * costheta + (y - cy) * sintheta) - sx; | |
float dy = fabs((y - cy) * costheta - (x - cx) * sintheta) - sy; | |
float ax = fmaxf(dx, 0.0f), ay = fmaxf(dy, 0.0f); | |
return fminf(fmaxf(dx, dy), 0.0f) + sqrtf(ax * ax + ay * ay); | |
} | |
float planeSDF(float x, float y, float px, float py, float nx, float ny) { | |
return (x - px) * nx + (y - py) * ny; | |
} | |
Result unionOp(Result a, Result b) { | |
return a.sd < b.sd ? a : b; | |
} | |
Result intersectOp(Result a, Result b) { | |
return a.sd > b.sd ? a : b; | |
} | |
Result subtractOp(Result a, Result b) { | |
Result r = a; | |
r.sd = (a.sd > -b.sd) ? a.sd : -b.sd; | |
return r; | |
} | |
Result scene(float x, float y) { | |
Result a = { circleSDF(x, y, -0.2f, -0.2f, 0.1f), 10.0f, 0.0f, 0.0f }; | |
Result b = { boxSDF(x, y, 0.5f, 0.5f, 0.0f, 0.3, 0.2f), 0.0f, 0.2f, 1.5f }; | |
Result c = { circleSDF(x, y, 0.5f, -0.5f, 0.05f), 20.0f, 0.0f, 0.0f }; | |
Result d = { circleSDF(x, y, 0.5f, 0.2f, 0.35f), 0.0f, 0.2f, 1.5f }; | |
Result e = { circleSDF(x, y, 0.5f, 0.8f, 0.35f), 0.0f, 0.2f, 1.5f }; | |
Result f = { boxSDF(x, y, 0.5f, 0.5f, 0.0f, 0.2, 0.1f), 0.0f, 0.2f, 1.5f }; | |
Result g = { circleSDF(x, y, 0.5f, 0.12f, 0.35f), 0.0f, 0.2f, 1.5f }; | |
Result h = { circleSDF(x, y, 0.5f, 0.87f, 0.35f), 0.0f, 0.2f, 1.5f }; | |
Result i = { circleSDF(x, y, 0.5f, 0.5f, 0.2f), 0.0f, 0.2f, 1.5f }; | |
Result j = { planeSDF(x, y, 0.5f, 0.5f, 0.0f, -1.0f), 0.0f, 0.2f, 1.5f }; | |
// return unionOp(a, b); | |
// return unionOp(c, intersectOp(d, e)); | |
// return unionOp(c, subtractOp(f, unionOp(g, h))); | |
return unionOp(c, intersectOp(i, j)); | |
} | |
void gradient(float x, float y, float* nx, float* ny) { | |
*nx = (scene(x + EPSILON, y).sd - scene(x - EPSILON, y).sd) * (0.5f / EPSILON); | |
*ny = (scene(x, y + EPSILON).sd - scene(x, y - EPSILON).sd) * (0.5f / EPSILON); | |
} | |
void reflect(float ix, float iy, float nx, float ny, float* rx, float* ry) { | |
float idotn2 = (ix * nx + iy * ny) * 2.0f; | |
*rx = ix - idotn2 * nx; | |
*ry = iy - idotn2 * ny; | |
} | |
int refract(float ix, float iy, float nx, float ny, float eta, float* rx, float* ry) { | |
float idotn = ix * nx + iy * ny; | |
float k = 1.0f - eta * eta * (1.0f - idotn * idotn); | |
if (k < 0.0f) | |
return 0; // Total internal reflection | |
float a = eta * idotn + sqrtf(k); | |
*rx = eta * ix - a * nx; | |
*ry = eta * iy - a * ny; | |
return 1; | |
} | |
float trace(float ox, float oy, float dx, float dy, int depth) { | |
float t = 1e-3f; | |
float sign = scene(ox, oy).sd > 0.0f ? 1.0f : -1.0f; | |
for (int i = 0; i < MAX_STEP && t < MAX_DISTANCE; i++) { | |
float x = ox + dx * t, y = oy + dy * t; | |
Result r = scene(x, y); | |
if (r.sd * sign < EPSILON) { | |
float sum = r.emissive; | |
if (depth < MAX_DEPTH && (r.reflectivity > 0.0f || r.eta > 0.0f)) { | |
float nx, ny, rx, ry, refl = r.reflectivity; | |
gradient(x, y, &nx, &ny); | |
nx *= sign; | |
ny *= sign; | |
if (r.eta > 0.0f) { | |
if (refract(dx, dy, nx, ny, sign < 0.0f ? r.eta : 1.0f / r.eta, &rx, &ry)) | |
sum += (1.0f - refl) * trace(x - nx * BIAS, y - ny * BIAS, rx, ry, depth + 1); | |
else | |
refl = 1.0f; // Total internal reflection | |
} | |
if (refl > 0.0f) { | |
reflect(dx, dy, nx, ny, &rx, &ry); | |
sum += refl * trace(x + nx * BIAS, y + ny * BIAS, rx, ry, depth + 1); | |
} | |
} | |
return sum; | |
} | |
t += r.sd * sign; | |
} | |
return 0.0f; | |
} | |
float sample(float x, float y) { | |
float sum = 0.0f; | |
for (int i = 0; i < N; i++) { | |
float a = TWO_PI * (i + (float)rand() / RAND_MAX) / N; | |
sum += trace(x, y, cosf(a), sinf(a), 0); | |
} | |
return sum / N; | |
} | |
int main() { | |
float a = TWO_PI * 0.73f; | |
printf("%f", trace(0.6f, 0.6f, cosf(a), sinf(a), 0)); | |
unsigned char* p = img; | |
for (int y = 0; y < H; y++) | |
for (int x = 0; x < W; x++, p += 3) | |
p[0] = p[1] = p[2] = (int)(fminf(sample((float)x / W, (float)y / H) * 255.0f, 255.0f)); | |
svpng(fopen("refraction.png", "wb"), W, H, img, 0); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "svpng.inc" | |
#include <math.h> // fabsf(), fminf(), fmaxf(), sinf(), cosf(), sqrt() | |
#include <stdlib.h> // rand(), RAND_MAX | |
#define TWO_PI 6.28318530718f | |
#define W 1024 | |
#define H 1024 | |
#define N 256 | |
#define MAX_STEP 64 | |
#define MAX_DISTANCE 5.0f | |
#define EPSILON 1e-6f | |
#define BIAS 1e-4f | |
#define MAX_DEPTH 5 | |
typedef struct { float sd, emissive, reflectivity, eta; } Result; | |
unsigned char img[W * H * 3]; | |
float circleSDF(float x, float y, float cx, float cy, float r) { | |
float ux = x - cx, uy = y - cy; | |
return sqrtf(ux * ux + uy * uy) - r; | |
} | |
float capsuleSDF(float x, float y, float ax, float ay, float bx, float by, float r) { | |
float vx = x - ax, vy = y - ay, ux = bx - ax, uy = by - ay; | |
float t = fmaxf(fminf((vx * ux + vy * uy) / (ux * ux + uy * uy), 1.0f), 0.0f); | |
float dx = vx - ux * t, dy = vy - uy * t; | |
return sqrtf(dx * dx + dy * dy) - r; | |
} | |
Result unionOp(Result a, Result b) { | |
return a.sd < b.sd ? a : b; | |
} | |
Result scene(float x, float y) { | |
x = fabsf(x - 0.5f) + 0.5f; | |
Result a = { capsuleSDF(x, y, 0.75f, 0.25f, 0.75f, 0.75f, 0.05f), 0.0f, 0.2f, 1.5f }; | |
Result b = { capsuleSDF(x, y, 0.75f, 0.25f, 0.50f, 0.75f, 0.05f), 0.0f, 0.2f, 1.5f }; | |
y = fabsf(y - 0.5f) + 0.5f; | |
Result c = { circleSDF(x, y, 1.05f, 1.05f, 0.05f), 5.0f, 0.0f, 0.0f }; | |
return unionOp(a, unionOp(b, c)); | |
} | |
void gradient(float x, float y, float* nx, float* ny) { | |
*nx = (scene(x + EPSILON, y).sd - scene(x - EPSILON, y).sd) * (0.5f / EPSILON); | |
*ny = (scene(x, y + EPSILON).sd - scene(x, y - EPSILON).sd) * (0.5f / EPSILON); | |
} | |
void reflect(float ix, float iy, float nx, float ny, float* rx, float* ry) { | |
float idotn2 = (ix * nx + iy * ny) * 2.0f; | |
*rx = ix - idotn2 * nx; | |
*ry = iy - idotn2 * ny; | |
} | |
int refract(float ix, float iy, float nx, float ny, float eta, float* rx, float* ry) { | |
float idotn = ix * nx + iy * ny; | |
float k = 1.0f - eta * eta * (1.0f - idotn * idotn); | |
if (k < 0.0f) | |
return 0; // Total internal reflection | |
float a = eta * idotn + sqrtf(k); | |
*rx = eta * ix - a * nx; | |
*ry = eta * iy - a * ny; | |
return 1; | |
} | |
float trace(float ox, float oy, float dx, float dy, int depth) { | |
float t = 1e-3f; | |
float sign = scene(ox, oy).sd > 0.0f ? 1.0f : -1.0f; | |
for (int i = 0; i < MAX_STEP && t < MAX_DISTANCE; i++) { | |
float x = ox + dx * t, y = oy + dy * t; | |
Result r = scene(x, y); | |
if (r.sd * sign < EPSILON) { | |
float sum = r.emissive; | |
if (depth < MAX_DEPTH && (r.reflectivity > 0.0f || r.eta > 0.0f)) { | |
float nx, ny, rx, ry, refl = r.reflectivity; | |
gradient(x, y, &nx, &ny); | |
nx *= sign; | |
ny *= sign; | |
if (r.eta > 0.0f) { | |
if (refract(dx, dy, nx, ny, sign < 0.0f ? r.eta : 1.0f / r.eta, &rx, &ry)) | |
sum += (1.0f - refl) * trace(x - nx * BIAS, y - ny * BIAS, rx, ry, depth + 1); | |
else | |
refl = 1.0f; // Total internal reflection | |
} | |
if (refl > 0.0f) { | |
reflect(dx, dy, nx, ny, &rx, &ry); | |
sum += refl * trace(x + nx * BIAS, y + ny * BIAS, rx, ry, depth + 1); | |
} | |
} | |
return sum; | |
} | |
t += r.sd * sign; | |
} | |
return 0.0f; | |
} | |
float sample(float x, float y) { | |
float sum = 0.0f; | |
for (int i = 0; i < N; i++) { | |
float a = TWO_PI * (i + (float)rand() / RAND_MAX) / N; | |
sum += trace(x, y, cosf(a), sinf(a), 0); | |
} | |
return sum / N; | |
} | |
int main() { | |
unsigned char* p = img; | |
for (int y = 0; y < H; y++) | |
for (int x = 0; x < W; x++, p += 3) | |
p[0] = p[1] = p[2] = (int)(fminf(sample((float)x / W, (float)y / H) * 255.0f, 255.0f)); | |
svpng(fopen("refraction_m.png", "wb"), W, H, img, 0); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "svpng.inc" | |
#include <math.h> // fminf(), sinf(), cosf(), sqrt() | |
#include <stdlib.h> // rand(), RAND_MAX | |
#define TWO_PI 6.28318530718f | |
#define W 512 | |
#define H 512 | |
#define N 64 | |
#define MAX_STEP 64 | |
#define MAX_DISTANCE 2.0f | |
#define EPSILON 1e-6f | |
typedef struct { float sd, emissive; } Result; | |
unsigned char img[W * H * 3]; | |
float circleSDF(float x, float y, float cx, float cy, float r) { | |
float ux = x - cx, uy = y - cy; | |
return sqrtf(ux * ux + uy * uy) - r; | |
} | |
float planeSDF(float x, float y, float px, float py, float nx, float ny) { | |
return (x - px) * nx + (y - py) * ny; | |
} | |
float segmentSDF(float x, float y, float ax, float ay, float bx, float by) { | |
float vx = x - ax, vy = y - ay, ux = bx - ax, uy = by - ay; | |
float t = fmaxf(fminf((vx * ux + vy * uy) / (ux * ux + uy * uy), 1.0f), 0.0f); | |
float dx = vx - ux * t, dy = vy - uy * t; | |
return sqrtf(dx * dx + dy * dy); | |
} | |
float capsuleSDF(float x, float y, float ax, float ay, float bx, float by, float r) { | |
return segmentSDF(x, y, ax, ay, bx, by) - r; | |
} | |
float boxSDF(float x, float y, float cx, float cy, float theta, float sx, float sy) { | |
float costheta = cosf(theta), sintheta = sinf(theta); | |
float dx = fabs((x - cx) * costheta + (y - cy) * sintheta) - sx; | |
float dy = fabs((y - cy) * costheta - (x - cx) * sintheta) - sy; | |
float ax = fmaxf(dx, 0.0f), ay = fmaxf(dy, 0.0f); | |
return fminf(fmaxf(dx, dy), 0.0f) + sqrtf(ax * ax + ay * ay); | |
} | |
float triangleSDF(float x, float y, float ax, float ay, float bx, float by, float cx, float cy) { | |
float d = fminf(fminf( | |
segmentSDF(x, y, ax, ay, bx, by), | |
segmentSDF(x, y, bx, by, cx, cy)), | |
segmentSDF(x, y, cx, cy, ax, ay)); | |
return (bx - ax) * (y - ay) > (by - ay) * (x - ax) && | |
(cx - bx) * (y - by) > (cy - by) * (x - bx) && | |
(ax - cx) * (y - cy) > (ay - cy) * (x - cx) ? -d : d; | |
} | |
Result intersectOp(Result a, Result b) { | |
return a.sd > b.sd ? a : b; | |
} | |
Result scene(float x, float y) { | |
Result a = { circleSDF(x, y, 0.5f, 0.5f, 0.2f), 1.0f }; | |
Result b = { planeSDF(x, y, 0.0f, 0.5f, 0.0f, 1.0f), 0.8f }; | |
Result c = { capsuleSDF(x, y, 0.4f, 0.4f, 0.6f, 0.6f, 0.1f), 1.0f }; | |
Result d = { boxSDF(x, y, 0.5f, 0.5f, TWO_PI / 16.0f, 0.3f, 0.1f), 1.0f }; | |
Result e = { boxSDF(x, y, 0.5f, 0.5f, TWO_PI / 16.0f, 0.3f, 0.1f) - 0.1f, 1.0f }; | |
Result f = { triangleSDF(x, y, 0.5f, 0.2f, 0.8f, 0.8f, 0.3f, 0.6f), 1.0f }; | |
Result g = { triangleSDF(x, y, 0.5f, 0.2f, 0.8f, 0.8f, 0.3f, 0.6f) - 0.1f, 1.0f }; | |
// return a; | |
// return b; | |
return intersectOp(a, b); | |
// return c; | |
// return d; | |
// return e; | |
// return f; | |
// return g; | |
} | |
float trace(float ox, float oy, float dx, float dy) { | |
float t = 0.0f; | |
for (int i = 0; i < MAX_STEP && t < MAX_DISTANCE; i++) { | |
Result r = scene(ox + dx * t, oy + dy * t); | |
if (r.sd < EPSILON) | |
return r.emissive; | |
t += r.sd; | |
} | |
return 0.0f; | |
} | |
float sample(float x, float y) { | |
float sum = 0.0f; | |
for (int i = 0; i < N; i++) { | |
float a = TWO_PI * (i + (float)rand() / RAND_MAX) / N; | |
sum += trace(x, y, cosf(a), sinf(a)); | |
} | |
return sum / N; | |
} | |
int main() { | |
unsigned char* p = img; | |
for (int y = 0; y < H; y++) | |
for (int x = 0; x < W; x++, p += 3) | |
p[0] = p[1] = p[2] = (int)(fminf(sample((float)x / W, (float)y / H) * 255.0f, 255.0f)); | |
svpng(fopen("shapes.png", "wb"), W, H, img, 0); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Copyright (C) 2017 Milo Yip. All rights reserved. | |
Redistribution and use in source and binary forms, with or without | |
modification, are permitted provided that the following conditions are met: | |
* Redistributions of source code must retain the above copyright notice, this | |
list of conditions and the following disclaimer. | |
* Redistributions in binary form must reproduce the above copyright notice, | |
this list of conditions and the following disclaimer in the documentation | |
and/or other materials provided with the distribution. | |
* Neither the name of pngout nor the names of its | |
contributors may be used to endorse or promote products derived from | |
this software without specific prior written permission. | |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
*/ | |
/*! \file | |
\brief svpng() is a minimalistic C function for saving RGB/RGBA image into uncompressed PNG. | |
\author Milo Yip | |
\version 0.1.1 | |
\copyright MIT license | |
\sa http://github.com/miloyip/svpng | |
*/ | |
#ifndef SVPNG_INC_ | |
#define SVPNG_INC_ | |
/*! \def SVPNG_LINKAGE | |
\brief User customizable linkage for svpng() function. | |
By default this macro is empty. | |
User may define this macro as static for static linkage, | |
and/or inline in C99/C++, etc. | |
*/ | |
#ifndef SVPNG_LINKAGE | |
#define SVPNG_LINKAGE | |
#endif | |
/*! \def SVPNG_OUTPUT | |
\brief User customizable output stream. | |
By default, it uses C file descriptor and fputc() to output bytes. | |
In C++, for example, user may use std::ostream or std::vector instead. | |
*/ | |
#ifndef SVPNG_OUTPUT | |
#include <stdio.h> | |
#define SVPNG_OUTPUT FILE* fp | |
#endif | |
/*! \def SVPNG_PUT | |
\brief Write a byte | |
*/ | |
#ifndef SVPNG_PUT | |
#define SVPNG_PUT(u) fputc(u, fp) | |
#endif | |
/*! | |
\brief Save a RGB/RGBA image in PNG format. | |
\param SVPNG_OUTPUT Output stream (by default using file descriptor). | |
\param w Width of the image. (<16383) | |
\param h Height of the image. | |
\param img Image pixel data in 24-bit RGB or 32-bit RGBA format. | |
\param alpha Whether the image contains alpha channel. | |
*/ | |
SVPNG_LINKAGE void svpng(SVPNG_OUTPUT, unsigned w, unsigned h, const unsigned char* img, int alpha) { | |
static const unsigned t[] = { 0, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, | |
/* CRC32 Table */ 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c }; | |
unsigned a = 1, b = 0, c, p = w * (alpha ? 4 : 3) + 1, x, y, i; /* ADLER-a, ADLER-b, CRC, pitch */ | |
#define SVPNG_U8A(ua, l) for (i = 0; i < l; i++) SVPNG_PUT((ua)[i]); | |
#define SVPNG_U32(u) do { SVPNG_PUT((u) >> 24); SVPNG_PUT(((u) >> 16) & 255); SVPNG_PUT(((u) >> 8) & 255); SVPNG_PUT((u) & 255); } while(0) | |
#define SVPNG_U8C(u) do { SVPNG_PUT(u); c ^= (u); c = (c >> 4) ^ t[c & 15]; c = (c >> 4) ^ t[c & 15]; } while(0) | |
#define SVPNG_U8AC(ua, l) for (i = 0; i < l; i++) SVPNG_U8C((ua)[i]) | |
#define SVPNG_U16LC(u) do { SVPNG_U8C((u) & 255); SVPNG_U8C(((u) >> 8) & 255); } while(0) | |
#define SVPNG_U32C(u) do { SVPNG_U8C((u) >> 24); SVPNG_U8C(((u) >> 16) & 255); SVPNG_U8C(((u) >> 8) & 255); SVPNG_U8C((u) & 255); } while(0) | |
#define SVPNG_U8ADLER(u) do { SVPNG_U8C(u); a = (a + (u)) % 65521; b = (b + a) % 65521; } while(0) | |
#define SVPNG_BEGIN(s, l) do { SVPNG_U32(l); c = ~0U; SVPNG_U8AC(s, 4); } while(0) | |
#define SVPNG_END() SVPNG_U32(~c) | |
SVPNG_U8A("\x89PNG\r\n\32\n", 8); /* Magic */ | |
SVPNG_BEGIN("IHDR", 13); /* IHDR chunk { */ | |
SVPNG_U32C(w); SVPNG_U32C(h); /* Width & Height (8 bytes) */ | |
SVPNG_U8C(8); SVPNG_U8C(alpha ? 6 : 2); /* Depth=8, Color=True color with/without alpha (2 bytes) */ | |
SVPNG_U8AC("\0\0\0", 3); /* Compression=Deflate, Filter=No, Interlace=No (3 bytes) */ | |
SVPNG_END(); /* } */ | |
SVPNG_BEGIN("IDAT", 2 + h * (5 + p) + 4); /* IDAT chunk { */ | |
SVPNG_U8AC("\x78\1", 2); /* Deflate block begin (2 bytes) */ | |
for (y = 0; y < h; y++) { /* Each horizontal line makes a block for simplicity */ | |
SVPNG_U8C(y == h - 1); /* 1 for the last block, 0 for others (1 byte) */ | |
SVPNG_U16LC(p); SVPNG_U16LC(~p); /* Size of block in little endian and its 1's complement (4 bytes) */ | |
SVPNG_U8ADLER(0); /* No filter prefix (1 byte) */ | |
for (x = 0; x < p - 1; x++, img++) | |
SVPNG_U8ADLER(*img); /* Image pixel data */ | |
} | |
SVPNG_U32C((b << 16) | a); /* Deflate block end with adler (4 bytes) */ | |
SVPNG_END(); /* } */ | |
SVPNG_BEGIN("IEND", 0); SVPNG_END(); /* IEND chunk {} */ | |
} | |
#endif /* SVPNG_INC_ */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment