Programowanie w systemie UNIX/c grafika/libpng

InstalacjaEdytuj

sudo apt-get install libpng-dev

PrzykładyEdytuj

Czytanie plikuEdytuj

/*

based on the 
https://github.com/gbenison/png-text-embed
with small modifications

gcc png-text-dump.c -L/usr/local/lib -lpng -o png-text-dump // with png library
./png-text-dump r.png


*/
#include <stdio.h>
#include <png.h> // libpng 

int
main(int argc, char *argv[])
{
  FILE *infile = stdin;
  if (argc > 1)
    infile = fopen(argv[1], "r");

  if (infile == NULL)
    {
      fprintf(stderr, "Could not open %s\n", argv[1]);
      return 1;
    }

  fprintf(stdout, "File %s opened with libpng version  %s\n", argv[1], PNG_LIBPNG_VER_STRING);

  /* allocate png structures */
  png_structp read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
						NULL, NULL, NULL);

  png_infop read_info_ptr = png_create_info_struct(read_ptr);
  png_infop end_info_ptr = png_create_info_struct(read_ptr);

  png_init_io(read_ptr, infile);
  png_read_png(read_ptr, read_info_ptr, 0, NULL);
  
  png_textp text_ptr;
  int num_text;
  png_get_text(read_ptr, read_info_ptr, &text_ptr, &num_text);

  /* echo text contents. */
  int i;
  for (i = 0; i < num_text; ++i)
    {
      printf("==== text chunk %d: \"%s\" = tEXt%s ====\n", i + 1, text_ptr[i].key, text_ptr[i].key);
      printf("%s\n\n", text_ptr[i].text);
    }

  return 0;
}

Wczytamy plik z commons:

 
plik z opisem
./png-text-dump r.png

i otrzymamy:

 File r.png opened with libpng version  1.2.50
==== text chunk 1: "Title" = tEXtTitle ====
RGBA Logo

==== text chunk 2: "Author" = tEXtAuthor ====
Shlomi Tal

==== text chunk 3: "Description" = tEXtDescription ====
Image demonstrating the use of an alpha channel for anti-aliasing of transparency and for translucency

==== text chunk 4: "Comment" = tEXtComment ====
This is the large version, with a dot size of 100 micrometres (254 DPI), yielding 15 cm for both width and height

==== text chunk 5: "Comment" = tEXtComment ====
Colours are from the Gretag-Macbeth palette

==== text chunk 6: "Copyright" = tEXtCopyright ====
Creative Commons Attribution-ShareAlike 3.0 and older

==== text chunk 7: "Software" = tEXtSoftware ====
GIMP 2.2.10

==== text chunk 8: "Creation Time" = tEXtCreation Time ====
Tue 18 Mar 2008 16:03 +0200


Tworzenie plikuEdytuj

  • program wg Andrew Greensted[1]

Programy wykorzystujące libpngEdytuj

  • Image Magic

pomocEdytuj

  • stackoverflow - libpng [2]

źródłaEdytuj

  1. program tworzenia pliku png - Andrew Greensted
  2. stackoverflow. questions tagged : libpng