Advertisement
LeventeDaradici

pngle.h

May 11th, 2023
1,045
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.93 KB | Source Code | 0 0
  1. /*-
  2.  * MIT License
  3.  *
  4.  * Copyright (c) 2019 kikuchan
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person obtaining a copy
  7.  * of this software and associated documentation files (the "Software"), to deal
  8.  * in the Software without restriction, including without limitation the rights
  9.  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10.  * copies of the Software, and to permit persons to whom the Software is
  11.  * furnished to do so, subject to the following conditions:
  12.  *
  13.  * The above copyright notice and this permission notice shall be included in all
  14.  * copies or substantial portions of the Software.
  15.  *
  16.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19.  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21.  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22.  * SOFTWARE.
  23.  */
  24.  
  25. #ifndef __PNGLE_H__
  26. #define __PNGLE_H__
  27.  
  28. #include <stdint.h>
  29.  
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33.  
  34. // Main Pngle object
  35. typedef struct _pngle_t pngle_t;
  36.  
  37. // Callback signatures
  38. typedef void (*pngle_init_callback_t)(pngle_t *pngle, uint32_t w, uint32_t h);
  39. typedef void (*pngle_draw_callback_t)(pngle_t *pngle, uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint8_t rgba[4]);
  40. typedef void (*pngle_done_callback_t)(pngle_t *pngle);
  41.  
  42. // ----------------
  43. // Basic interfaces
  44. // ----------------
  45. pngle_t *pngle_new();
  46. void pngle_destroy(pngle_t *pngle);
  47. void pngle_reset(pngle_t *pngle); // clear its internal state (not applied to pngle_set_* functions)
  48. const char *pngle_error(pngle_t *pngle);
  49. int pngle_feed(pngle_t *pngle, const void *buf, size_t len); // returns -1: On error, 0: Need more data, n: n bytes eaten
  50.  
  51. uint32_t pngle_get_width(pngle_t *pngle);
  52. uint32_t pngle_get_height(pngle_t *pngle);
  53.  
  54. void pngle_set_init_callback(pngle_t *png, pngle_init_callback_t callback);
  55. void pngle_set_draw_callback(pngle_t *png, pngle_draw_callback_t callback);
  56. void pngle_set_done_callback(pngle_t *png, pngle_done_callback_t callback);
  57.  
  58. void pngle_set_display_gamma(pngle_t *pngle, double display_gamma); // enables gamma correction by specifying display gamma, typically 2.2. No effect when gAMA chunk is missing
  59.  
  60. void pngle_set_user_data(pngle_t *pngle, void *user_data);
  61. void *pngle_get_user_data(pngle_t *pngle);
  62.  
  63.  
  64. // ----------------
  65. // Debug interfaces
  66. // ----------------
  67.  
  68. typedef struct _pngle_ihdr_t {
  69.   uint32_t width;
  70.   uint32_t height;
  71.   uint8_t depth;
  72.   uint8_t color_type;
  73.   uint8_t compression;
  74.   uint8_t filter;
  75.   uint8_t interlace;
  76. } pngle_ihdr_t;
  77.  
  78. // Get IHDR information
  79. pngle_ihdr_t *pngle_get_ihdr(pngle_t *pngle);
  80.  
  81.  
  82. #ifdef __cplusplus
  83. }
  84. #endif
  85.  
  86. #endif /* __PNGLE_H__ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement