⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wpng.c

📁 openmeetings组件之GS openmeetings组件之GS openmeetings组件之GS
💻 C
📖 第 1 页 / 共 3 页
字号:
/*---------------------------------------------------------------------------   wpng - simple PNG-writing program                                 wpng.c   This program converts certain NetPBM binary files (grayscale and RGB,   maxval = 255) to PNG.  Non-interlaced PNGs are written progressively;   interlaced PNGs are read and written in one memory-intensive blast.   Thanks to Jean-loup Gailly for providing the necessary trick to read   interactive text from the keyboard while stdin is redirected.  Thanks   to Cosmin Truta for Cygwin fixes.   NOTE:  includes provisional support for PNM type "8" (portable alphamap)          images, presumed to be a 32-bit interleaved RGBA format; no pro-          vision for possible interleaved grayscale+alpha (16-bit) format.          THIS IS UNLIKELY TO BECOME AN OFFICIAL NETPBM ALPHA FORMAT!   to do:    - delete output file if quit before calling any writepng routines    - process backspace with -text option under DOS/Win? (currently get ^H)  ---------------------------------------------------------------------------   Changelog:    - 1.01:  initial public release    - 1.02:  modified to allow abbreviated options    - 1.03:  removed extraneous character from usage screen; fixed bug in              command-line parsing    - 1.04:  fixed DOS/OS2/Win32 detection, including partial Cygwin fix              (see http://home.att.net/~perlspinr/diffs/GregBook_cygwin.diff)    - 2.00:  dual-licensed (added GNU GPL)        [REPORTED BUG (win32 only):  "contrib/gregbook/wpng.c - cmd line         dose not work!  In order to do something useful I needed to redirect         both input and output, with cygwin and with bcc32 as well.  Under         Linux, the same wpng appears to work fine.  I don't know what is         the problem."]  ---------------------------------------------------------------------------      Copyright (c) 1998-2007 Greg Roelofs.  All rights reserved.      This software is provided "as is," without warranty of any kind,      express or implied.  In no event shall the author or contributors      be held liable for any damages arising in any way from the use of      this software.      The contents of this file are DUAL-LICENSED.  You may modify and/or      redistribute this software according to the terms of one of the      following two licenses (at your option):      LICENSE 1 ("BSD-like with advertising clause"):      Permission is granted to anyone to use this software for any purpose,      including commercial applications, and to alter it and redistribute      it freely, subject to the following restrictions:      1. Redistributions of source code must retain the above copyright         notice, disclaimer, and this list of conditions.      2. Redistributions in binary form must reproduce the above copyright         notice, disclaimer, and this list of conditions in the documenta-         tion and/or other materials provided with the distribution.      3. All advertising materials mentioning features or use of this         software must display the following acknowledgment:            This product includes software developed by Greg Roelofs            and contributors for the book, "PNG: The Definitive Guide,"            published by O'Reilly and Associates.      LICENSE 2 (GNU GPL v2 or later):      This program is free software; you can redistribute it and/or modify      it under the terms of the GNU General Public License as published by      the Free Software Foundation; either version 2 of the License, or      (at your option) any later version.      This program is distributed in the hope that it will be useful,      but WITHOUT ANY WARRANTY; without even the implied warranty of      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      GNU General Public License for more details.      You should have received a copy of the GNU General Public License      along with this program; if not, write to the Free Software Foundation,      Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  ---------------------------------------------------------------------------*/#define PROGNAME  "wpng"#define VERSION   "2.00 of 2 June 2007"#define APPNAME   "Simple PGM/PPM/PAM to PNG Converter"#if defined(__MSDOS__) || defined(__OS2__)#  define DOS_OS2_W32#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__)#  ifndef __GNUC__   /* treat Win32 native ports of gcc as Unix environments */#    define DOS_OS2_W32#  endif#endif#include <stdio.h>#include <stdlib.h>#include <string.h>#include <setjmp.h>     /* for jmpbuf declaration in writepng.h */#include <time.h>#ifdef DOS_OS2_W32#  include <io.h>       /* for isatty(), setmode() prototypes */#  include <fcntl.h>    /* O_BINARY for fdopen() without text translation */#  ifdef __EMX__#    ifndef getch#      define getch() _read_kbd(0, 1, 0)    /* need getche() */#    endif#  else /* !__EMX__ */#    ifdef __GO32__#      include <pc.h>#      define getch() getkey()  /* GRR:  need getche() */#    else#      include <conio.h>        /* for getche() console input */#    endif#  endif /* ?__EMX__ */#  define FGETS(buf,len,stream)  dos_kbd_gets(buf,len)#else#  include <unistd.h>           /* for isatty() prototype */#  define FGETS fgets#endif/* #define DEBUG  :  this enables the Trace() macros *//* #define FORBID_LATIN1_CTRL  :  this requires the user to re-enter any   text that includes control characters discouraged by the PNG spec; text   that includes an escape character (27) must be re-entered regardless */#include "writepng.h"   /* typedefs, common macros, writepng prototypes *//* local prototypes */static int  wpng_isvalid_latin1(uch *p, int len);static void wpng_cleanup(void);#ifdef DOS_OS2_W32   static char *dos_kbd_gets(char *buf, int len);#endifstatic mainprog_info wpng_info;   /* lone global */int main(int argc, char **argv){#ifndef DOS_OS2_W32    FILE *keybd;#endif#ifdef sgi    FILE *tmpfile;      /* or we could just use keybd, since no overlap */    char tmpline[80];#endif    char *inname = NULL, outname[256];    char *p, pnmchar, pnmline[256];    char *bgstr, *textbuf = NULL;    ulg rowbytes;    int rc, len = 0;    int error = 0;    int text = FALSE;    int maxval;    double LUT_exponent;                /* just the lookup table */    double CRT_exponent = 2.2;          /* just the monitor */    double default_display_exponent;    /* whole display system */    double default_gamma = 0.0;    wpng_info.infile = NULL;    wpng_info.outfile = NULL;    wpng_info.image_data = NULL;    wpng_info.row_pointers = NULL;    wpng_info.filter = FALSE;    wpng_info.interlaced = FALSE;    wpng_info.have_bg = FALSE;    wpng_info.have_time = FALSE;    wpng_info.have_text = 0;    wpng_info.gamma = 0.0;    /* First get the default value for our display-system exponent, i.e.,     * the product of the CRT exponent and the exponent corresponding to     * the frame-buffer's lookup table (LUT), if any.  If the PNM image     * looks correct on the user's display system, its file gamma is the     * inverse of this value.  (Note that this is not an exhaustive list     * of LUT values--e.g., OpenStep has a lot of weird ones--but it should     * cover 99% of the current possibilities.  This section must ensure     * that default_display_exponent is positive.) */#if defined(NeXT)    /* third-party utilities can modify the default LUT exponent */    LUT_exponent = 1.0 / 2.2;    /*    if (some_next_function_that_returns_gamma(&next_gamma))        LUT_exponent = 1.0 / next_gamma;     */#elif defined(sgi)    LUT_exponent = 1.0 / 1.7;    /* there doesn't seem to be any documented function to     * get the "gamma" value, so we do it the hard way */    tmpfile = fopen("/etc/config/system.glGammaVal", "r");    if (tmpfile) {        double sgi_gamma;        fgets(tmpline, 80, tmpfile);        fclose(tmpfile);        sgi_gamma = atof(tmpline);        if (sgi_gamma > 0.0)            LUT_exponent = 1.0 / sgi_gamma;    }#elif defined(Macintosh)    LUT_exponent = 1.8 / 2.61;    /*    if (some_mac_function_that_returns_gamma(&mac_gamma))        LUT_exponent = mac_gamma / 2.61;     */#else    LUT_exponent = 1.0;   /* assume no LUT:  most PCs */#endif    /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */    default_display_exponent = LUT_exponent * CRT_exponent;    /* If the user has set the SCREEN_GAMMA environment variable as suggested     * (somewhat imprecisely) in the libpng documentation, use that; otherwise     * use the default value we just calculated.  Either way, the user may     * override this via a command-line option. */    if ((p = getenv("SCREEN_GAMMA")) != NULL) {        double exponent = atof(p);        if (exponent > 0.0)            default_gamma = 1.0 / exponent;    }    if (default_gamma == 0.0)        default_gamma = 1.0 / default_display_exponent;    /* Now parse the command line for options and the PNM filename. */    while (*++argv && !error) {        if (!strncmp(*argv, "-i", 2)) {            wpng_info.interlaced = TRUE;        } else if (!strncmp(*argv, "-time", 3)) {            wpng_info.modtime = time(NULL);            wpng_info.have_time = TRUE;        } else if (!strncmp(*argv, "-text", 3)) {            text = TRUE;        } else if (!strncmp(*argv, "-gamma", 2)) {            if (!*++argv)                ++error;            else {                wpng_info.gamma = atof(*argv);                if (wpng_info.gamma <= 0.0)                    ++error;                else if (wpng_info.gamma > 1.01)                    fprintf(stderr, PROGNAME                      " warning:  file gammas are usually less than 1.0\n");            }        } else if (!strncmp(*argv, "-bgcolor", 4)) {            if (!*++argv)                ++error;            else {                bgstr = *argv;                if (strlen(bgstr) != 7 || bgstr[0] != '#')                    ++error;                else {                    unsigned r, g, b;  /* this way quiets compiler warnings */                    sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b);                    wpng_info.bg_red   = (uch)r;                    wpng_info.bg_green = (uch)g;                    wpng_info.bg_blue  = (uch)b;                    wpng_info.have_bg = TRUE;                }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -