- #include <stdio.h>
- #include <math.h>
- #include <png.h>
- #include "bsfr.h"
-
- #define BITS 8
- const int ascii = 1;
-
- png_byte row [ 4 * (1 << BITS) ];
-
-
-
-
- int lca_bin (int a, int b)
- {
- if (a == b)
- return 255;
-
-
- if (b > a)
- a ^= b ^= a ^= b;
-
-
-
-
-
- if (!(b & 1) && a < b + (1 << (bsf (b))))
- return (b);
-
- return a & ~((1 << bsr (a ^ b))-1);
- }
-
-
- int lca_bin_cool (int a, int b, int mask)
- {
- if (a == b)
- return 255&mask;
-
-
- if (b > a)
- a ^= b ^= a ^= b;
-
- if (!(b & 1) && a < b + (1 << (bsf (b))))
- return 127&mask;
-
- if (mask)
- return 0;
- else
- return a & ~((1 << bsr (a ^ b))-1);
- }
-
- void write_row_callback(png_structp png_ptr, png_uint_32 row, int pass)
- {
- printf (".");
- return;
- }
-
- const char *user_error_ptr = "";
- static void user_error_fn(png_structp a, png_const_charp error_msg)
- {
- printf ("%s\n", error_msg);
- }
-
- static void user_warning_fn(png_structp a, png_const_charp warning_msg)
- {
- printf ("%s\n", warning_msg);
- }
-
- int main(int argc, char **argv)
- {
- FILE *fp = fopen(--argc?*++argv:"output.png", "wb");
- int j, i;
- png_structp png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING,
- (png_voidp)user_error_ptr, user_error_fn, user_warning_fn);
- png_infop info_ptr;
- png_bytep row_pointer;
-
-
- if (!fp)
- {
- printf (" [!] Failed while trying to create output file\n");
- return (-1);
- }
- if (!png_ptr)
- {
- printf (" [+] png_crate_write_struct failed!\n");
- return (-1);
- }
-
- if (!(info_ptr = png_create_info_struct(png_ptr)))
- {
- printf (" [!] png_create_info_struct failed!\n");
- png_destroy_write_struct (&png_ptr, (png_infopp)NULL);
- return (-1);
- }
-
- if (setjmp (png_jmpbuf (png_ptr)))
- {
- png_destroy_write_struct (&png_ptr, &info_ptr);
- fclose (fp);
- return (-1);
- }
- png_init_io (png_ptr, fp);
- png_set_write_status_fn (png_ptr, write_row_callback);
-
-
-
- png_set_IHDR (png_ptr, info_ptr, 1 << BITS, 1 << BITS,
- 8, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
- PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
-
-
-
-
- png_set_invert_alpha (png_ptr);
- png_write_info (png_ptr, info_ptr);
-
- for (j = 0; j < 1 << BITS; j++)
- {
- if (j)
- for (i = 1; i < 1 << BITS; i++) {
- row [4*i + 0] = lca_bin_cool(i, j, 0xff);
- row [4*i + 1] = 0;
- row [4*i + 2] = 0;
- row [4*i + 3] = 0;
- }
- row_pointer = row;
- png_write_row (png_ptr, row_pointer);
- }
-
- png_write_end (png_ptr, info_ptr);
- png_destroy_write_struct (&png_ptr, &info_ptr);
- printf ("\n [+] image written!\n");
-
- fclose(fp);
-
- return 0;
- }
-
This document should validate, please check by clicking: