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

📄 libpng.3

📁 Linux下的基于X11的图形开发环境。
💻 3
📖 第 1 页 / 共 5 页
字号:
    and translated keywords that can be NULL pointers, the    structure returned by png_get_text will always contain    regular zero-terminated C strings.  They might be    empty strings but they will never be NULL pointers.    num_spalettes = png_get_sPLT(png_ptr, info_ptr,       &palette_ptr);    palette_ptr    - array of palette structures holding                     contents of one or more sPLT chunks                     read.    num_spalettes  - number of sPLT chunks read.    png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y,       &unit_type);    offset_x       - positive offset from the left edge                     of the screen    offset_y       - positive offset from the top edge                     of the screen    unit_type      - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER    png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y,       &unit_type);    res_x          - pixels/unit physical resolution in                     x direction    res_y          - pixels/unit physical resolution in                     x direction    unit_type      - PNG_RESOLUTION_UNKNOWN,                     PNG_RESOLUTION_METER    png_get_sCAL(png_ptr, info_ptr, &unit, &width,       &height)    unit        - physical scale units (an integer)    width       - width of a pixel in physical scale units    height      - height of a pixel in physical scale units                 (width and height are doubles)    png_get_sCAL_s(png_ptr, info_ptr, &unit, &width,       &height)    unit        - physical scale units (an integer)    width       - width of a pixel in physical scale units    height      - height of a pixel in physical scale units                 (width and height are strings like "2.54")    num_unknown_chunks = png_get_unknown_chunks(png_ptr,       info_ptr, &unknowns)    unknowns          - array of png_unknown_chunk                        structures holding unknown chunks    unknowns[i].name  - name of unknown chunk    unknowns[i].data  - data of unknown chunk    unknowns[i].size  - size of unknown chunk's data    unknowns[i].location - position of chunk in file    The value of "i" corresponds to the order in which the    chunks were read from the PNG file or inserted with the    png_set_unknown_chunks() function.The data from the pHYs chunk can be retrieved in several convenientforms:    res_x = png_get_x_pixels_per_meter(png_ptr,       info_ptr)    res_y = png_get_y_pixels_per_meter(png_ptr,       info_ptr)    res_x_and_y = png_get_pixels_per_meter(png_ptr,       info_ptr)    res_x = png_get_x_pixels_per_inch(png_ptr,       info_ptr)    res_y = png_get_y_pixels_per_inch(png_ptr,       info_ptr)    res_x_and_y = png_get_pixels_per_inch(png_ptr,       info_ptr)    aspect_ratio = png_get_pixel_aspect_ratio(png_ptr,       info_ptr)   (Each of these returns 0 [signifying "unknown"] if       the data is not present or if res_x is 0;       res_x_and_y is 0 if res_x != res_y)The data from the oFFs chunk can be retrieved in several convenientforms:    x_offset = png_get_x_offset_microns(png_ptr, info_ptr);    y_offset = png_get_y_offset_microns(png_ptr, info_ptr);    x_offset = png_get_x_offset_inches(png_ptr, info_ptr);    y_offset = png_get_y_offset_inches(png_ptr, info_ptr);   (Each of these returns 0 [signifying "unknown" if both       x and y are 0] if the data is not present or if the       chunk is present but the unit is the pixel)For more information, see the png_info definition in png.h and thePNG specification for chunk contents.  Be careful with trustingrowbytes, as some of the transformations could increase the spaceneeded to hold a row (expand, filler, gray_to_rgb, etc.).See png_read_update_info(), below.A quick word about text_ptr and num_text.  PNG stores comments inkeyword/text pairs, one pair per chunk, with no limit on the numberof text chunks, and a 2^31 byte limit on their size.  While there aresuggested keywords, there is no requirement to restrict the use to thesestrings.  It is strongly suggested that keywords and text be sensibleto humans (that's the point), so don't use abbreviations.  Non-printingsymbols are not allowed.  See the PNG specification for more details.There is also no requirement to have text after the keyword.Keywords should be limited to 79 Latin-1 characters without leading ortrailing spaces, but non-consecutive spaces are allowed within thekeyword.  It is possible to have the same keyword any number of times.The text_ptr is an array of png_text structures, each holding apointer to a language string, a pointer to a keyword and a pointer toa text string.  The text string, language code, and translatedkeyword may be empty or NULL pointers.  The keyword/textpairs are put into the array in the order that they are received.However, some or all of the text chunks may be after the image, so, tomake sure you have read all the text chunks, don't mess with theseuntil after you read the stuff after the image.  This will bementioned again below in the discussion that goes with png_read_end()..SS Input transformationsAfter you've read the header information, you can set up the libraryto handle any special transformations of the image data.  The variousways to transform the data will be described in the order that theyshould occur.  This is important, as some of these change the colortype and/or bit depth of the data, and some others only work oncertain color types and bit depths.  Even though each transformationchecks to see if it has data that it can do something with, you shouldmake sure to only enable a transformation if it will be valid for thedata.  For example, don't swap red and blue on grayscale data.The colors used for the background and transparency values should besupplied in the same format/depth as the current image data.  Theyare stored in the same format/depth as the image data in a bKGD or tRNSchunk, so this is what libpng expects for this data.  The colors aretransformed to keep in sync with the image data when an applicationcalls the png_read_update_info() routine (see below).Data will be decoded into the supplied row buffers packed into bytesunless the library has been told to transform it into another format.For example, 4 bit/pixel paletted or grayscale data will be returned2 pixels/byte with the leftmost pixel in the high-order bits of thebyte, unless png_set_packing() is called.  8-bit RGB data will be storedin RGB RGB RGB format unless png_set_filler() is called to insert fillerbytes, either before or after each RGB triplet.  16-bit RGB data willbe returned RRGGBB RRGGBB, with the most significant byte of the colorvalue first, unless png_set_strip_16() is called to transform it toregular RGB RGB triplets, or png_set_filler() is called to insertfiller bytes, either before or after each RRGGBB triplet.  Similarly,8-bit or 16-bit grayscale data can be modified with png_set_filler()or png_set_strip_16().The following code transforms grayscale images of less than 8 to 8 bits,changes paletted images to RGB, and adds a full alpha channel if there istransparency information in a tRNS chunk.  This is most useful ongrayscale images with bit depths of 2 or 4 or if there is a multiple-imageviewing application that wishes to treat all images in the same way.    if (color_type == PNG_COLOR_TYPE_PALETTE)        png_set_palette_to_rgb(png_ptr);    if (color_type == PNG_COLOR_TYPE_GRAY &&        bit_depth < 8) png_set_gray_1_2_4_to_8(png_ptr);    if (png_get_valid(png_ptr, info_ptr,        PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr);These three functions are actually aliases for png_set_expand(), addedin libpng version 1.0.4, with the function names expanded to improve codereadability.  In some future version they may actually do differentthings.PNG can have files with 16 bits per channel.  If you only can handle8 bits per channel, this will strip the pixels down to 8 bit.    if (bit_depth == 16)        png_set_strip_16(png_ptr);If, for some reason, you don't need the alpha channel on an image,and you want to remove it rather than combining it with the background(but the image author certainly had in mind that you *would* combineit with the background, so that's what you should probably do):    if (color_type & PNG_COLOR_MASK_ALPHA)        png_set_strip_alpha(png_ptr);In PNG files, the alpha channel in an imageis the level of opacity.  If you need the alpha channel in an image tobe the level of transparency instead of opacity, you can invert thealpha channel (or the tRNS chunk data) after it's read, so that 0 isfully opaque and 255 (in 8-bit or paletted images) or 65535 (in 16-bitimages) is fully transparent, with    png_set_invert_alpha(png_ptr);PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small asthey can, resulting in, for example, 8 pixels per byte for 1 bitfiles.  This code expands to 1 pixel per byte without changing thevalues of the pixels:    if (bit_depth < 8)        png_set_packing(png_ptr);PNG files have possible bit depths of 1, 2, 4, 8, and 16.  All pixelsstored in a PNG image have been "scaled" or "shifted" up to the nexthigher possible bit depth (e.g. from 5 bits/sample in the range [0,31] to8 bits/sample in the range [0, 255]).  However, it is also possible toconvert the PNG pixel data back to the original bit depth of the image.This call reduces the pixels back down to the original bit depth:    png_color_8p sig_bit;    if (png_get_sBIT(png_ptr, info_ptr, &sig_bit))        png_set_shift(png_ptr, sig_bit);PNG files store 3-color pixels in red, green, blue order.  This codechanges the storage of the pixels to blue, green, red:    if (color_type == PNG_COLOR_TYPE_RGB ||        color_type == PNG_COLOR_TYPE_RGB_ALPHA)        png_set_bgr(png_ptr);PNG files store RGB pixels packed into 3 or 6 bytes. This code expands theminto 4 or 8 bytes for windowing systems that need them in this format:    if (color_type == PNG_COLOR_TYPE_RGB)        png_set_filler(png_ptr, filler, PNG_FILLER_BEFORE);where "filler" is the 8 or 16-bit number to fill with, and the location iseither PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whetheryou want the filler before the RGB or after.  This transformationdoes not affect images that already have full alpha channels.  To add anopaque alpha channel, use filler=0xff or 0xffff and PNG_FILLER_AFTER whichwill generate RGBA pixels.If you are reading an image with an alpha channel, and you need thedata as ARGB instead of the normal PNG format RGBA:    if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)        png_set_swap_alpha(png_ptr);For some uses, you may want a grayscale image to be represented asRGB.  This code will do that conversion:    if (color_type == PNG_COLOR_TYPE_GRAY ||        color_type == PNG_COLOR_TYPE_GRAY_ALPHA)          png_set_gray_to_rgb(png_ptr);Conversely, you can convert an RGB or RGBA image to grayscale or grayscalewith alpha.    if (color_type == PNG_COLOR_TYPE_RGB ||        color_type == PNG_COLOR_TYPE_RGB_ALPHA)          png_set_rgb_to_gray_fixed(png_ptr, error_action,             int red_weight, int green_weight);    error_action = 1: silently do the conversion    error_action = 2: issue a warning if the original                      image has any pixel where                      red != green or red != blue    error_action = 3: issue an error and abort the                      conversion if the original                      image has any pixel where                      red != green or red != blue    red_weight:       weight of red component times 100000    green_weight:     weight of green component times 100000                      If either weight is negative, default                      weights (21268, 71514) are used.If you have set error_action = 1 or 2, you canlater check whether the image really was gray, after processingthe image rows, with the png_get_rgb_to_gray_status(png_ptr) function.It will return a png_byte that is zero if the image was gray or1 if there were any non-gray pixels.  bKGD and sBIT datawill be silently converted to grayscale, using the green channeldata, regardless of the error_action setting.With red_weight+green_weight<=100000,the normalized graylevel is computed:    int rw = red_weight * 65536;    int gw = green_weight * 65536;    int bw = 65536 - (rw + gw);    gray = (rw*red + gw*green + bw*blue)/65536;The default values approximate those recommended in the CharlesPoynton's Color FAQ, <http://www.inforamp.net/~poynton/>Copyright (c) 1998-01-04 Charles Poynton poynton@inforamp.net    Y = 0.212671 * R + 0.715160 * G + 0.072169 * BLibpng approximates this with    Y = 0.21268 * R    + 0.7151 * G    + 0.07217 * Bwhich can be expressed with integers as    Y = (6969 * R + 23434 * G + 2365 * B)/32768The calculation is done in a linear colorspace, if the image gammais known.If you have a grayscale and you are using png_set_expand_depth(),png_set_expand(), or png_set_gray_to_rgb to change to truecolor or toa higher bit-depth, you must either supply the background color as a grayvalue at the original file bit-depth (need_expand = 1) or else supply thebackground color as an RGB triplet at the final, expanded bit depth(need_expand = 0).  Similarly, if you are reading a paletted image, youmust either supply the background color as a palette index (need_expand = 1)or as an RGB triplet that may or may not be in the palette (need_expand = 0).    png_color_16 my_background;    png_color_16p image_background;    if (png_get_bKGD(png_ptr, info_ptr, &image_background))        png_set_background(png_ptr, image_background,          PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);    else        png_set_background(png_ptr, &my_background,          PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);The png_set_background() function tells libpng to composite imageswith alpha or simple transparency against the supplied backgroundcolor.  If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid),you may use this color, or supply another color more suitable forthe current display (e.g., the background color from a web page).  Youneed to tell libpng whether the color is in the gamma space of thedisplay (PNG_BACKGROUND_GAMMA_SCREEN for colors you supply), the file(PNG_BACKGROUND_GAMMA_FILE for colors from the bKGD chunk), or onethat is neither of these gammas (PNG_BACKGROUND_GAMMA_UNIQUE - I don'tknow why anyone would use this, but it's here).To properly display PNG images on any kind of system, the application needsto know what the display gamma is.  Ideally, the user will know this, andthe application will allow them to set it.  One method of allowing the userto set the display gamma separately for each system is to check for aSCREEN_GAMMA or DISPLAY_GAMMA environment variable, which will hopefully becorrectly set.Note that display_gamma is the overall gamma correction required to producepleasing results, which depends on the lighting cond

⌨️ 快捷键说明

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