Files: a18e2f94c5c1c202b703482e5aabdaa261c3d95a / lupng.h
2723 bytesRaw
1 | /* |
2 | * The MIT License (MIT) |
3 | * |
4 | * Copyright (c) 2014 Jan Solanti |
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 | |
26 | extern "C" { |
27 | |
28 | |
29 | |
30 | |
31 | |
32 | typedef struct { |
33 | int32_t width; |
34 | int32_t height; |
35 | uint8_t channels; |
36 | uint8_t depth; // must be 8 or 16 |
37 | size_t dataSize; |
38 | uint8_t *data; |
39 | } LuImage; |
40 | |
41 | typedef size_t (*PngReadProc)(void *outPtr, size_t size, size_t count, void *userPtr); |
42 | typedef size_t (*PngWriteProc)(const void *inPtr, size_t size, size_t count, void *userPtr); |
43 | |
44 | /** |
45 | * Creates a new Image object with the specified attributes. |
46 | * The data store of the Image is allocated but its contents are undefined. |
47 | * Only 8 and 16 bits deep images with 1-4 channels are supported. |
48 | */ |
49 | LuImage *luImageCreate(size_t width, size_t height, uint8_t channels, uint8_t depth); |
50 | |
51 | /** |
52 | * Releases the memory associated with the given Image object. |
53 | */ |
54 | void luImageRelease(LuImage *img); |
55 | |
56 | /** |
57 | * Decodes a PNG image with the provided read function into a LuImage struct |
58 | * |
59 | * @param readProc a function pointer to a user-defined function to use for |
60 | * reading the PNG data. |
61 | * @param userPtr an opaque pointer provided as an argument to readProc |
62 | */ |
63 | LuImage *luPngRead(PngReadProc readProc, void *userPtr); |
64 | |
65 | /** |
66 | * Encodes a LuImage struct to PNG and writes it out using a user-defined write |
67 | * function. |
68 | * |
69 | * @param writeProc a function pointer to a user-defined function that will be |
70 | * used for writing the final PNG data. |
71 | * @param userPtr an opaque pointer provided as an argument to writeProc |
72 | * @param img the LuImage to encode |
73 | */ |
74 | int luPngWrite(PngWriteProc writeProc, void *userPtr, LuImage *img); |
75 | |
76 | |
77 | } |
78 | |
79 |
Built with git-ssb-web