small tweaks
This commit is contained in:
3
Lib/.gitignore
vendored
Normal file
3
Lib/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
*.png
|
||||
|
||||
14
Lib/image.c
14
Lib/image.c
@@ -19,7 +19,7 @@ Image_print_version(int flag)
|
||||
char *ptr;
|
||||
|
||||
fflush(stdout);
|
||||
printf("-+- This is the `tthimage' library v%s (dwtfywl 2022) tTh\n",
|
||||
printf("-+- This is the `tthimage' library v%s (wtfyw 2022) tTh\n",
|
||||
IMAGE_VERSION_STRING);
|
||||
if (flag)
|
||||
{
|
||||
@@ -594,29 +594,25 @@ fprintf(stderr, " %p %p %p %p\n", im->Rpix, im->Gpix, im->Bpix, im->Apix);
|
||||
im->magic = 0L; /* mark dirty/invalid. */
|
||||
im->type = IMAGE_NONE; /* -1, et tusors */
|
||||
|
||||
if (im->Rpix != NULL)
|
||||
{
|
||||
if (im->Rpix != NULL) {
|
||||
for (line=0; line<im->height; line++)
|
||||
if (im->Rpix[line] != NULL) free(im->Rpix[line]);
|
||||
free(im->Rpix); im->Rpix = NULL;
|
||||
}
|
||||
|
||||
if (im->Gpix != NULL)
|
||||
{
|
||||
if (im->Gpix != NULL) {
|
||||
for (line=0; line<im->height; line++)
|
||||
if (im->Gpix[line] != NULL) free(im->Gpix[line]);
|
||||
free(im->Gpix); im->Gpix = NULL;
|
||||
}
|
||||
|
||||
if (im->Bpix != NULL)
|
||||
{
|
||||
if (im->Bpix != NULL) {
|
||||
for (line=0; line<im->height; line++)
|
||||
if (im->Bpix[line] != NULL) free(im->Bpix[line]);
|
||||
free(im->Bpix); im->Bpix = NULL;
|
||||
}
|
||||
|
||||
if (im->Apix != NULL)
|
||||
{
|
||||
if (im->Apix != NULL) {
|
||||
for (line=0; line<im->height; line++)
|
||||
if (im->Apix[line] != NULL) free(im->Apix[line]);
|
||||
free(im->Apix); im->Apix = NULL;
|
||||
|
||||
@@ -11,8 +11,7 @@
|
||||
#include "../tthimage.h"
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int
|
||||
Image_pixeliz_0(Image_Desc *src, Image_Desc *dst, int w, int h)
|
||||
int Image_pixeliz_0(Image_Desc *src, Image_Desc *dst, int w, int h)
|
||||
{
|
||||
int x, y, foo, N;
|
||||
int r, g, b;
|
||||
|
||||
67
Lib/png.c
67
Lib/png.c
@@ -1,10 +1,12 @@
|
||||
/*
|
||||
|
||||
------ libtthimage ------
|
||||
PNG aka "portable network graphics"s.
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <png.h>
|
||||
@@ -16,46 +18,69 @@
|
||||
#include "../tthimage.h"
|
||||
|
||||
/*
|
||||
* les infos et le code ici viennent de
|
||||
* http://www.libpng.org/pub/png/pngbook.html
|
||||
* http://www.libpng.org/pub/png/pngbook.html
|
||||
*/
|
||||
|
||||
|
||||
/* static mainprog_info wpng_info; */
|
||||
|
||||
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
static void writepng_version_info(void)
|
||||
void write_png_version_info(void)
|
||||
{
|
||||
fprintf(stderr, " Compiled with libpng %s; using libpng %s.\n",
|
||||
PNG_LIBPNG_VER_STRING, png_libpng_ver);
|
||||
fprintf(stderr, " Compiled with zlib %s; using zlib %s.\n",
|
||||
ZLIB_VERSION, zlib_version);
|
||||
fprintf(stderr, " Compiled with libpng %s; using libpng %s.\n",
|
||||
PNG_LIBPNG_VER_STRING, png_libpng_ver);
|
||||
fprintf(stderr, " Compiled with zlib %s; using zlib %s.\n",
|
||||
ZLIB_VERSION, zlib_version);
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
Image_Desc * Image_PNG_alloc_load(char *fname, int k)
|
||||
{
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s ( '%s' %d )\n", __func__, fname, k);
|
||||
writepng_version_info();
|
||||
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, k);
|
||||
write_png_version_info();
|
||||
#endif
|
||||
|
||||
return NULL;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* http://zarb.org/~gc/html/libpng.html
|
||||
* https://gist.github.com/niw/5963798
|
||||
*/
|
||||
int Image_save_as_PNG(Image_Desc *img, char *fname, int p1, int p2)
|
||||
{
|
||||
FILE *fp;
|
||||
int x, y, foo;
|
||||
png_uint_32 pngv;
|
||||
|
||||
FILE *fp;
|
||||
int x, y, foo;
|
||||
png_structp png;
|
||||
png_infop info;
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s ( %p '%s' %d %d )\n", __func__, img, fname, p1, p2);
|
||||
writepng_version_info();
|
||||
fprintf(stderr, ">>> %s ( %p '%s' %d %d )\n", __func__, img, fname, p1, p2);
|
||||
write_png_version_info();
|
||||
#endif
|
||||
|
||||
fp = fopen(fname, "wb");
|
||||
if (NULL == fp) {
|
||||
perror(fname);
|
||||
return BASIC_IO_WR_ERR;
|
||||
}
|
||||
|
||||
png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
|
||||
info = png_create_info_struct(png);
|
||||
|
||||
if (setjmp(png_jmpbuf(png))) abort();
|
||||
|
||||
png_init_io(png, fp);
|
||||
|
||||
|
||||
png_set_IHDR( png,
|
||||
info,
|
||||
img->width, img->height,
|
||||
8,
|
||||
PNG_COLOR_TYPE_RGBA,
|
||||
PNG_INTERLACE_NONE,
|
||||
PNG_COMPRESSION_TYPE_DEFAULT,
|
||||
PNG_FILTER_TYPE_DEFAULT );
|
||||
|
||||
png_write_info(png, info);
|
||||
|
||||
return FULL_NUCKED;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
|
||||
@@ -5,8 +5,11 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <png.h>
|
||||
|
||||
#include "../tthimage.h"
|
||||
|
||||
void write_png_version_info(void);
|
||||
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*::------------------------------------------------------------------::*/
|
||||
@@ -15,12 +18,10 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
Image_Desc *img;
|
||||
int foo;
|
||||
char *fname = "foo.png";
|
||||
char *fname = "proto.png";
|
||||
|
||||
Image_print_version(0);
|
||||
|
||||
writepng_version_info();
|
||||
|
||||
if (2==argc) {
|
||||
fname = argv[1];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user