亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? readpng2.c

?? Borland C++BuilderT 6 Developer s Guide
?? C
字號:
/*---------------------------------------------------------------------------

   rpng2 - progressive-model PNG display program                 readpng2.c

  ---------------------------------------------------------------------------

      Copyright (c) 1998-2000 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.

      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.

  ---------------------------------------------------------------------------*/


#include <stdlib.h>     /* for exit() prototype */

#include "png.h"        /* libpng header; includes zlib.h and setjmp.h */
#include "readpng2.h"   /* typedefs, common macros, public prototypes */


/* local prototypes */

static void readpng2_info_callback(png_structp png_ptr, png_infop info_ptr);
static void readpng2_row_callback(png_structp png_ptr, png_bytep new_row,
                                 png_uint_32 row_num, int pass);
static void readpng2_end_callback(png_structp png_ptr, png_infop info_ptr);
static void readpng2_error_handler(png_structp png_ptr, png_const_charp msg);




void readpng2_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);
}




int readpng2_check_sig(uch *sig, int num)
{
    return png_check_sig(sig, num);
}




/* returns 0 for success, 2 for libpng problem, 4 for out of memory */

int readpng2_init(mainprog_info *mainprog_ptr)
{
    png_structp  png_ptr;       /* note:  temporary variables! */
    png_infop  info_ptr;


    /* could also replace libpng warning-handler (final NULL), but no need: */

    png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, mainprog_ptr,
      readpng2_error_handler, NULL);
    if (!png_ptr)
        return 4;   /* out of memory */

    info_ptr = png_create_info_struct(png_ptr);
    if (!info_ptr) {
        png_destroy_read_struct(&png_ptr, NULL, NULL);
        return 4;   /* out of memory */
    }


    /* we could create a second info struct here (end_info), but it's only
     * useful if we want to keep pre- and post-IDAT chunk info separated
     * (mainly for PNG-aware image editors and converters) */


    /* setjmp() must be called in every function that calls a PNG-reading
     * libpng function, unless an alternate error handler was installed--
     * but compatible error handlers must either use longjmp() themselves
     * (as in this program) or exit immediately, so here we are: */

    if (setjmp(mainprog_ptr->jmpbuf)) {
        png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
        return 2;
    }


    /* instead of doing png_init_io() here, now we set up our callback
     * functions for progressive decoding */

    png_set_progressive_read_fn(png_ptr, mainprog_ptr,
      readpng2_info_callback, readpng2_row_callback, readpng2_end_callback);


    /* make sure we save our pointers for use in readpng2_decode_data() */

    mainprog_ptr->png_ptr = png_ptr;
    mainprog_ptr->info_ptr = info_ptr;


    /* and that's all there is to initialization */

    return 0;
}




/* returns 0 for success, 2 for libpng (longjmp) problem */

int readpng2_decode_data(mainprog_info *mainprog_ptr, uch *rawbuf, ulg length)
{
    png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
    png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;


    /* setjmp() must be called in every function that calls a PNG-reading
     * libpng function */

    if (setjmp(mainprog_ptr->jmpbuf)) {
        png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
        mainprog_ptr->png_ptr = NULL;
        mainprog_ptr->info_ptr = NULL;
        return 2;
    }


    /* hand off the next chunk of input data to libpng for decoding */

    png_process_data(png_ptr, info_ptr, rawbuf, length);

    return 0;
}




static void readpng2_info_callback(png_structp png_ptr, png_infop info_ptr)
{
    mainprog_info  *mainprog_ptr;
    int  color_type, bit_depth;
    double  gamma;


    /* setjmp() doesn't make sense here, because we'd either have to exit(),
     * longjmp() ourselves, or return control to libpng, which doesn't want
     * to see us again.  By not doing anything here, libpng will instead jump
     * to readpng2_decode_data(), which can return an error value to the main
     * program. */


    /* retrieve the pointer to our special-purpose struct, using the png_ptr
     * that libpng passed back to us (i.e., not a global this time--there's
     * no real difference for a single image, but for a multithreaded browser
     * decoding several PNG images at the same time, one needs to avoid mixing
     * up different images' structs) */

    mainprog_ptr = png_get_progressive_ptr(png_ptr);

    if (mainprog_ptr == NULL) {         /* we be hosed */
        fprintf(stderr,
          "readpng2 error:  main struct not recoverable in info_callback.\n");
        fflush(stderr);
        return;
        /*
         * Alternatively, we could call our error-handler just like libpng
         * does, which would effectively terminate the program.  Since this
         * can only happen if png_ptr gets redirected somewhere odd or the
         * main PNG struct gets wiped, we're probably toast anyway.  (If
         * png_ptr itself is NULL, we would not have been called.)
         */
    }


    /* this is just like in the non-progressive case */

    png_get_IHDR(png_ptr, info_ptr, &mainprog_ptr->width,
      &mainprog_ptr->height, &bit_depth, &color_type, NULL, NULL, NULL);


    /* since we know we've read all of the PNG file's "header" (i.e., up
     * to IDAT), we can check for a background color here */

    if (mainprog_ptr->need_bgcolor &&
        png_get_valid(png_ptr, info_ptr, PNG_INFO_bKGD))
    {
        png_color_16p pBackground;

        /* it is not obvious from the libpng documentation, but this function
         * takes a pointer to a pointer, and it always returns valid red,
         * green and blue values, regardless of color_type: */
        png_get_bKGD(png_ptr, info_ptr, &pBackground);

        /* however, it always returns the raw bKGD data, regardless of any
         * bit-depth transformations, so check depth and adjust if necessary */
        if (bit_depth == 16) {
            mainprog_ptr->bg_red   = pBackground->red   >> 8;
            mainprog_ptr->bg_green = pBackground->green >> 8;
            mainprog_ptr->bg_blue  = pBackground->blue  >> 8;
        } else if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) {
            if (bit_depth == 1)
                mainprog_ptr->bg_red = mainprog_ptr->bg_green =
                  mainprog_ptr->bg_blue = pBackground->gray? 255 : 0;
            else if (bit_depth == 2)
                mainprog_ptr->bg_red = mainprog_ptr->bg_green =
                  mainprog_ptr->bg_blue = (255/3) * pBackground->gray;
            else /* bit_depth == 4 */
                mainprog_ptr->bg_red = mainprog_ptr->bg_green =
                  mainprog_ptr->bg_blue = (255/15) * pBackground->gray;
        } else {
            mainprog_ptr->bg_red   = (uch)pBackground->red;
            mainprog_ptr->bg_green = (uch)pBackground->green;
            mainprog_ptr->bg_blue  = (uch)pBackground->blue;
        }
    }


    /* as before, let libpng expand palette images to RGB, low-bit-depth
     * grayscale images to 8 bits, transparency chunks to full alpha channel;
     * strip 16-bit-per-sample images to 8 bits per sample; and convert
     * grayscale to RGB[A] */

    if (color_type == PNG_COLOR_TYPE_PALETTE)
        png_set_expand(png_ptr);
    if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
        png_set_expand(png_ptr);
    if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
        png_set_expand(png_ptr);
    if (bit_depth == 16)
        png_set_strip_16(png_ptr);
    if (color_type == PNG_COLOR_TYPE_GRAY ||
        color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
        png_set_gray_to_rgb(png_ptr);


    /* Unlike the basic viewer, which was designed to operate on local files,
     * this program is intended to simulate a web browser--even though we
     * actually read from a local file, too.  But because we are pretending
     * that most of the images originate on the Internet, we follow the recom-
     * mendation of the sRGB proposal and treat unlabelled images (no gAMA
     * chunk) as existing in the sRGB color space.  That is, we assume that
     * such images have a file gamma of 0.45455, which corresponds to a PC-like
     * display system.  This change in assumptions will have no effect on a
     * PC-like system, but on a Mac, SGI, NeXT or other system with a non-
     * identity lookup table, it will darken unlabelled images, which effec-
     * tively favors images from PC-like systems over those originating on
     * the local platform.  Note that mainprog_ptr->display_exponent is the
     * "gamma" value for the entire display system, i.e., the product of
     * LUT_exponent and CRT_exponent. */

    if (png_get_gAMA(png_ptr, info_ptr, &gamma))
        png_set_gamma(png_ptr, mainprog_ptr->display_exponent, gamma);
    else
        png_set_gamma(png_ptr, mainprog_ptr->display_exponent, 0.45455);


    /* we'll let libpng expand interlaced images, too */

    mainprog_ptr->passes = png_set_interlace_handling(png_ptr);


    /* all transformations have been registered; now update info_ptr data and
     * then get rowbytes and channels */

    png_read_update_info(png_ptr, info_ptr);

    mainprog_ptr->rowbytes = (int)png_get_rowbytes(png_ptr, info_ptr);
    mainprog_ptr->channels = png_get_channels(png_ptr, info_ptr);


    /* Call the main program to allocate memory for the image buffer and
     * initialize windows and whatnot.  (The old-style function-pointer
     * invocation is used for compatibility with a few supposedly ANSI
     * compilers that nevertheless barf on "fn_ptr()"-style syntax.) */

    (*mainprog_ptr->mainprog_init)();


    /* and that takes care of initialization */

    return;
}





static void readpng2_row_callback(png_structp png_ptr, png_bytep new_row,
                                  png_uint_32 row_num, int pass)
{
    mainprog_info  *mainprog_ptr;


    /* first check whether the row differs from the previous pass; if not,
     * nothing to combine or display */

    if (!new_row)
        return;


    /* retrieve the pointer to our special-purpose struct so we can access
     * the old rows and image-display callback function */

    mainprog_ptr = png_get_progressive_ptr(png_ptr);


    /* save the pass number for optional use by the front end */

    mainprog_ptr->pass = pass;


    /* have libpng either combine the new row data with the existing row data
     * from previous passes (if interlaced) or else just copy the new row
     * into the main program's image buffer */

    png_progressive_combine_row(png_ptr, mainprog_ptr->row_pointers[row_num],
      new_row);


    /* finally, call the display routine in the main program with the number
     * of the row we just updated */

    (*mainprog_ptr->mainprog_display_row)(row_num);


    /* and we're ready for more */

    return;
}





static void readpng2_end_callback(png_structp png_ptr, png_infop info_ptr)
{
    mainprog_info  *mainprog_ptr;


    /* retrieve the pointer to our special-purpose struct */

    mainprog_ptr = png_get_progressive_ptr(png_ptr);


    /* let the main program know that it should flush any buffered image
     * data to the display now and set a "done" flag or whatever, but note
     * that it SHOULD NOT DESTROY THE PNG STRUCTS YET--in other words, do
     * NOT call readpng2_cleanup() either here or in the finish_display()
     * routine; wait until control returns to the main program via
     * readpng2_decode_data() */

    (*mainprog_ptr->mainprog_finish_display)();


    /* all done */

    return;
}





void readpng2_cleanup(mainprog_info *mainprog_ptr)
{
    png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
    png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;

    if (png_ptr && info_ptr)
        png_destroy_read_struct(&png_ptr, &info_ptr, NULL);

    mainprog_ptr->png_ptr = NULL;
    mainprog_ptr->info_ptr = NULL;
}





static void readpng2_error_handler(png_structp png_ptr, png_const_charp msg)
{
    mainprog_info  *mainprog_ptr;

    /* This function, aside from the extra step of retrieving the "error
     * pointer" (below) and the fact that it exists within the application
     * rather than within libpng, is essentially identical to libpng's
     * default error handler.  The second point is critical:  since both
     * setjmp() and longjmp() are called from the same code, they are
     * guaranteed to have compatible notions of how big a jmp_buf is,
     * regardless of whether _BSD_SOURCE or anything else has (or has not)
     * been defined. */

    fprintf(stderr, "readpng2 libpng error: %s\n", msg);
    fflush(stderr);

    mainprog_ptr = png_get_error_ptr(png_ptr);
    if (mainprog_ptr == NULL) {         /* we are completely hosed now */
        fprintf(stderr,
          "readpng2 severe error:  jmpbuf not recoverable; terminating.\n");
        fflush(stderr);
        exit(99);
    }

    longjmp(mainprog_ptr->jmpbuf, 1);
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品嫩草影院av蜜臀| 91精品国产色综合久久| 欧美激情一区二区三区| 国产一区91精品张津瑜| 久久精品日产第一区二区三区高清版 | 精品一区二区免费看| 日韩欧美国产午夜精品| 国产中文一区二区三区| 国产网站一区二区| caoporen国产精品视频| 亚洲一卡二卡三卡四卡五卡| 在线观看91av| 狠狠色丁香婷婷综合久久片| 日本一区二区成人在线| 色8久久精品久久久久久蜜| 午夜精品在线看| 26uuu欧美| 91天堂素人约啪| 天堂一区二区在线免费观看| 久久在线免费观看| 91在线视频播放地址| 图片区小说区区亚洲影院| 久久久一区二区三区捆绑**| 91原创在线视频| 奇米777欧美一区二区| 国产精品毛片久久久久久| 欧美日韩中文精品| 国产99久久久国产精品潘金| 亚洲综合色噜噜狠狠| 欧美mv日韩mv亚洲| 欧美中文字幕不卡| 国产在线播精品第三| 综合色中文字幕| 欧美不卡视频一区| 在线日韩一区二区| 国产一区二区不卡老阿姨| 亚洲成a人v欧美综合天堂下载| 欧美精品一区二区三区蜜桃| 欧美最猛黑人xxxxx猛交| 国产一区二区免费视频| 五月天精品一区二区三区| 国产精品色噜噜| 精品日韩一区二区三区免费视频| 91在线一区二区| 国产成人三级在线观看| 蜜臀av国产精品久久久久| 一区二区三区精密机械公司| 欧美国产日韩精品免费观看| 日韩欧美另类在线| 欧美在线免费观看亚洲| 成人少妇影院yyyy| 韩国视频一区二区| 日本不卡123| 亚洲成av人片观看| 亚洲精品欧美激情| 亚洲婷婷在线视频| 国产精品人妖ts系列视频| 精品国产91洋老外米糕| 欧美另类z0zxhd电影| 91国偷自产一区二区三区观看| 国产99久久久国产精品潘金网站| 久热成人在线视频| 天堂在线亚洲视频| 午夜私人影院久久久久| 亚洲午夜免费电影| 亚洲精品综合在线| 亚洲视频在线观看一区| 国产精品污网站| 欧美国产精品专区| 国产欧美日韩综合精品一区二区 | 欧美巨大另类极品videosbest | 337p粉嫩大胆色噜噜噜噜亚洲 | 色综合久久综合网97色综合| 9人人澡人人爽人人精品| 国产成人免费视频精品含羞草妖精 | 久久久久久久久久久久久久久99| 日韩视频在线你懂得| 欧美一区二区三区视频免费| 91精品国产全国免费观看| 欧美日韩国产系列| 欧美日韩高清影院| 91精品国产综合久久久久久| 91精品国产一区二区| 日韩一级大片在线观看| 精品国产乱码久久久久久久久| 欧美mv和日韩mv国产网站| 久久精品日产第一区二区三区高清版| 国产亚洲欧美一区在线观看| 国产日韩欧美亚洲| 中文字幕永久在线不卡| 亚洲色图自拍偷拍美腿丝袜制服诱惑麻豆 | 欧美视频在线观看一区二区| 欧美在线观看一区二区| 欧美区视频在线观看| 日韩一区二区三区四区| 久久亚洲一级片| 国产精品美女久久久久aⅴ国产馆 国产精品美女久久久久av爽李琼 国产精品美女久久久久高潮 | 香蕉乱码成人久久天堂爱免费| 亚洲va韩国va欧美va| 捆绑调教美女网站视频一区| 激情综合色播激情啊| 成人免费看黄yyy456| 91在线视频免费观看| 欧美喷水一区二区| 国产日产欧产精品推荐色| 久久久精品欧美丰满| 国产一区二区毛片| 国产精品成人午夜| 亚洲欧美一区二区三区国产精品| 亚洲色图色小说| 亚洲成av人综合在线观看| 久久99精品久久久久久动态图| 国产电影一区在线| 欧美亚洲愉拍一区二区| 精品福利一二区| 亚洲欧美日韩国产另类专区 | 1000精品久久久久久久久| 亚洲国产成人91porn| 国内外成人在线| 日本丰满少妇一区二区三区| 91精品婷婷国产综合久久性色 | 欧美一级片在线观看| 欧美经典一区二区三区| 亚洲综合一二三区| 国产一区不卡视频| 欧美日韩精品一区视频| 久久免费美女视频| 日韩在线卡一卡二| 97se亚洲国产综合自在线| 精品久久久久久久久久久久久久久| 中文字幕在线观看一区| 久草在线在线精品观看| 欧美日韩一级黄| 国产精品毛片久久久久久久 | 成人av综合一区| 91麻豆精品国产| 亚洲视频一区二区在线观看| 国产精品综合二区| 欧美一区二区在线不卡| 亚洲一区在线电影| 北条麻妃国产九九精品视频| 日韩欧美色综合| 日韩精品一级二级 | 欧美va亚洲va国产综合| 亚洲一区日韩精品中文字幕| 成人免费视频免费观看| www久久久久| 麻豆极品一区二区三区| 欧美巨大另类极品videosbest | 懂色av中文一区二区三区| 欧美精品电影在线播放| 亚洲精品视频在线看| 成人在线视频一区二区| 久久无码av三级| 久久精品99国产精品日本| 欧美色图天堂网| 一区二区三区成人在线视频| 一本到一区二区三区| 国产精品美女视频| 成人av免费网站| 国产三级精品三级在线专区| 国产精品综合二区| 久久精品日韩一区二区三区| 国产一区二区不卡在线| 久久综合五月天婷婷伊人| 久久国产婷婷国产香蕉| 日韩免费观看高清完整版| 全国精品久久少妇| 欧美mv日韩mv国产| 国产一区二区三区四区五区入口| 精品久久久久久无| 国产电影一区二区三区| 欧美国产日产图区| 91免费版pro下载短视频| 亚洲精品视频在线观看免费| 欧美主播一区二区三区| 五月天激情综合网| 日韩一区二区在线观看视频播放| 蜜桃免费网站一区二区三区| 精品国一区二区三区| 懂色av一区二区三区免费看| 国产精品色在线| 91精品91久久久中77777| 亚洲图片有声小说| 日韩一级免费观看| 成人午夜在线视频| 一区二区免费在线| 欧美大白屁股肥臀xxxxxx| 国产剧情一区二区| 亚洲免费观看高清完整版在线| 欧美少妇bbb| 韩国中文字幕2020精品| 中文字幕中文字幕在线一区| 在线免费观看成人短视频| 日韩国产欧美一区二区三区| 久久噜噜亚洲综合| 在线免费观看一区| 国产在线精品一区二区| 亚洲卡通动漫在线| 亚洲精品在线观看视频|