Skip to content

Instantly share code, notes, and snippets.

@harieamjari

harieamjari/lb.c

Last active Mar 30, 2021
Embed
What would you like to do?
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <png.h>
#ifdef NDEBUG
#error "Don't turn NDEBUG!!"
#endif
static png_byte
x2val (int x)
{
double p = pow (M_E, (double) x / 150.0);
return (p > 255.0) ? (png_byte) 255 : (png_byte) p;
}
int
main ()
{
#pragma omp parallel for
for (int file = 0; file < 300; file++)
{
FILE *fpout = NULL;
png_bytep *rowp = malloc (sizeof (png_bytep) * 700);
assert (rowp != NULL);
#pragma omp parallel for
for (int y = 0; y < 700; y++)
assert ((rowp[y] = malloc (4 * 1000)) != NULL);
char buff[50] = { 0 };
sprintf (buff, "tt-%03d.png", file);
fpout = fopen (buff, "wb");
if (fpout == NULL)
{
perror (buff);
exit (1);;
}
png_structp png =
png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
assert (png != NULL);
png_infop info = png_create_info_struct (png);
assert (info != NULL);
if (setjmp (png_jmpbuf (png)))
abort ();
png_init_io (png, fpout);
// INDENT-OFF
png_set_IHDR (png,
info,
1000, 700,
8,
PNG_COLOR_TYPE_RGBA,
PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
// INDENT-ON
png_write_info (png, info);
printf ("%s\n", buff);
for (int y = 0; y < 700; y++)
{
png_bytep row = rowp[y];
for (int x = 0; x < 1000; x++)
{
memset (row + (x * 4), x2val (x + (file * 4)), 4);
row[(x * 4) + 3] = 255;
}
}
png_write_image (png, rowp);
png_write_end (png, NULL);
fclose (fpout);
png_destroy_write_struct (&png, &info);
#pragma omp parallel for
for (int y = 0; y < 700; y++)
free (rowp[y]);
free (rowp);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment