/src/cms_cie_cam02_fuzzer.c
Line | Count | Source |
1 | | /* Copyright 2023 Google LLC |
2 | | Licensed under the Apache License, Version 2.0 (the "License"); |
3 | | you may not use this file except in compliance with the License. |
4 | | You may obtain a copy of the License at |
5 | | http://www.apache.org/licenses/LICENSE-2.0 |
6 | | Unless required by applicable law or agreed to in writing, software |
7 | | distributed under the License is distributed on an "AS IS" BASIS, |
8 | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
9 | | See the License for the specific language governing permissions and |
10 | | limitations under the License. |
11 | | */ |
12 | | |
13 | | #include <stdint.h> |
14 | | #include "lcms2.h" |
15 | | |
16 | 10.6k | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
17 | | |
18 | 10.6k | if (size < sizeof(cmsViewingConditions)) { |
19 | 15 | return 0; |
20 | 15 | } |
21 | | |
22 | | // Define and initialize the viewing conditions structure |
23 | 10.6k | cmsViewingConditions viewingConditions; |
24 | 10.6k | viewingConditions.whitePoint.X = data[0]/ 255.0; |
25 | 10.6k | viewingConditions.whitePoint.Y = data[1]/ 255.0; |
26 | 10.6k | viewingConditions.whitePoint.Z = data[2]/ 255.0; |
27 | 10.6k | viewingConditions.Yb = data[3] / 255.0; |
28 | 10.6k | viewingConditions.La = data[4]/ 255.0; |
29 | 10.6k | viewingConditions.surround = data[5] % 4 + 1; //from 1 to 4 |
30 | 10.6k | viewingConditions.D_value = data[6] / 255.0; |
31 | | |
32 | 10.6k | cmsContext context = cmsCreateContext(NULL, NULL); |
33 | | |
34 | 10.6k | cmsHANDLE hModel = cmsCIECAM02Init(context, &viewingConditions); |
35 | | |
36 | 10.6k | if (hModel) { |
37 | | // Perform forward and reverse CAM02 transformations with appropriate input data |
38 | 1.95k | cmsCIEXYZ inputXYZ; |
39 | 1.95k | inputXYZ.X = data[0]/ 255.0; // Random value between 0 and 1 |
40 | 1.95k | inputXYZ.Y = data[1] / 255.0; |
41 | 1.95k | inputXYZ.Z = data[2] / 255.0; |
42 | 1.95k | cmsJCh outputJCh; |
43 | 1.95k | cmsCIEXYZ outputXYZ; |
44 | 1.95k | cmsCIECAM02Forward(hModel, &inputXYZ, &outputJCh); |
45 | 1.95k | cmsCIECAM02Reverse(hModel, &outputJCh, &outputXYZ); |
46 | 1.95k | cmsCIECAM02Done(hModel); |
47 | 1.95k | } |
48 | 10.6k | cmsDeleteContext(context); |
49 | | |
50 | 10.6k | return 0; |
51 | 10.6k | } |