xref: /aosp_15_r20/external/sandboxed-api/oss-internship-2020/libpng/tests/libpng.h (revision ec63e07ab9515d95e79c211197c445ef84cefa6a)
1 // Copyright 2020 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef LIBPNG_TESTS_LIBPNG_H_
16 #define LIBPNG_TESTS_LIBPNG_H_
17 
18 // Defines from libpng library. The problem is that the build throws the error
19 // "Duplicate functions" if #include <png.h> is added.
20 
21 #define PNG_FORMAT_FLAG_ALPHA 0x01U
22 #define PNG_FORMAT_FLAG_COLOR 0x02U
23 #define PNG_FORMAT_FLAG_LINEAR 0x04U
24 #define PNG_FORMAT_FLAG_COLORMAP 0x08U
25 
26 #ifdef PNG_FORMAT_BGR_SUPPORTED
27 #define PNG_FORMAT_FLAG_BGR 0x10U
28 #endif
29 
30 #ifdef PNG_FORMAT_AFIRST_SUPPORTED
31 #define PNG_FORMAT_FLAG_AFIRST 0x20U
32 #endif
33 
34 #define PNG_FORMAT_FLAG_ASSOCIATED_ALPHA 0x40U
35 
36 #define PNG_FORMAT_GRAY 0
37 #define PNG_FORMAT_GA PNG_FORMAT_FLAG_ALPHA
38 #define PNG_FORMAT_AG (PNG_FORMAT_GA | PNG_FORMAT_FLAG_AFIRST)
39 #define PNG_FORMAT_RGB PNG_FORMAT_FLAG_COLOR
40 #define PNG_FORMAT_BGR (PNG_FORMAT_FLAG_COLOR | PNG_FORMAT_FLAG_BGR)
41 #define PNG_FORMAT_RGBA (PNG_FORMAT_RGB | PNG_FORMAT_FLAG_ALPHA)
42 #define PNG_FORMAT_ARGB (PNG_FORMAT_RGBA | PNG_FORMAT_FLAG_AFIRST)
43 #define PNG_FORMAT_BGRA (PNG_FORMAT_BGR | PNG_FORMAT_FLAG_ALPHA)
44 #define PNG_FORMAT_ABGR (PNG_FORMAT_BGRA | PNG_FORMAT_FLAG_AFIRST)
45 
46 #define PNG_IMAGE_VERSION 1
47 
48 #define PNG_IMAGE_PIXEL_(test, fmt) \
49   (((fmt)&PNG_FORMAT_FLAG_COLORMAP) ? 1 : test(fmt))
50 
51 #define PNG_IMAGE_SAMPLE_CHANNELS(fmt) \
52   (((fmt) & (PNG_FORMAT_FLAG_COLOR | PNG_FORMAT_FLAG_ALPHA)) + 1)
53 
54 #define PNG_IMAGE_PIXEL_CHANNELS(fmt) \
55   PNG_IMAGE_PIXEL_(PNG_IMAGE_SAMPLE_CHANNELS, fmt)
56 
57 #define PNG_IMAGE_ROW_STRIDE(image) \
58   (PNG_IMAGE_PIXEL_CHANNELS((image).format) * (image).width)
59 
60 #define PNG_IMAGE_SAMPLE_COMPONENT_SIZE(fmt) \
61   ((((fmt)&PNG_FORMAT_FLAG_LINEAR) >> 2) + 1)
62 
63 #define PNG_IMAGE_PIXEL_COMPONENT_SIZE(fmt) \
64   PNG_IMAGE_PIXEL_(PNG_IMAGE_SAMPLE_COMPONENT_SIZE, fmt)
65 
66 #define PNG_IMAGE_BUFFER_SIZE(image, row_stride)                     \
67   (PNG_IMAGE_PIXEL_COMPONENT_SIZE((image).format) * (image).height * \
68    (row_stride))
69 
70 #define PNG_IMAGE_SIZE(image) \
71   PNG_IMAGE_BUFFER_SIZE(image, PNG_IMAGE_ROW_STRIDE(image))
72 
73 typedef uint8_t *png_bytep;
74 
75 #if UINT_MAX == 65535
76 typedef unsigned int png_uint_16;
77 #elif USHRT_MAX == 65535
78 typedef unsigned short png_uint_16;  // NOLINT(runtime/int)
79 #else
80 #error "libpng requires an unsigned 16-bit type"
81 #endif
82 
83 #define PNG_LIBPNG_VER_STRING "1.6.38.git"
84 
85 #define PNG_COLOR_MASK_COLOR 2
86 #define PNG_COLOR_MASK_ALPHA 4
87 
88 #define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
89 #define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
90 #define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA
91 
92 #define PNG_FILTER_TYPE_BASE 0
93 #define PNG_COMPRESSION_TYPE_BASE 0
94 #define PNG_INTERLACE_NONE 0
95 
96 #endif  // LIBPNG_TESTS_LIBPNG_H_
97