• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
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  *     http://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 FRAMEWORKS_INNERKITSIMPL_TEST_FUZZTEST_COMMON_FUZZTEST_FUNCTION_H
16 #define FRAMEWORKS_INNERKITSIMPL_TEST_FUZZTEST_COMMON_FUZZTEST_FUNCTION_H
17 
18 #include <fuzzer/FuzzedDataProvider.h>
19 #include <cstdint>
20 #include <stddef.h>
21 #include <string>
22 #include <fuzzer/FuzzedDataProvider.h>
23 namespace OHOS {
24 namespace Media {
25     class PixelMap;
26     struct DecodeOptions;
27 }
28 namespace ImagePlugin {
29     struct PixelDecodeOptions;
30 }
31 }
32 
33 const static std::vector<std::pair<std::string, std::vector<std::string>>> KEY_VALUE_MAPS = {
34     {"BitsPerSample", {"9, 7, 8", "8, 8, 8"}},
35     {"Orientation", {"Top-right", "Unknown value 0"}},
36     {"ImageLength", {"1000", "4000"}},
37     {"ImageWidth", {"500", "3000"}},
38     {"GPSLatitude", {"39, 54, 20", ""}},
39     {"GPSLongitude", {"120, 52, 26", ""}},
40     {"GPSLatitudeRef", {"N", ""}},
41     {"GPSLongitudeRef", {"E", ""}},
42     {"DateTimeOriginal", {"2024,01,25 05,51,34", "2024,01,11 09,39,58", "2023,01,19 10,39,58"}},
43     {"ExposureTime", {"1/34 sec.", "1/590 sec."}},
44     {"SceneType", {"Directly photographed"}},
45     {"ISOSpeedRatings", {"160"}},
46     {"FNumber", {"f/3.0", "f/2.0"}},
47     {"DateTime", {""}},
48     {"GPSTimeStamp", {"11,37,58.00", "01,39,58.00"}},
49     {"GPSDateStamp", {"2025,01,11", "2024,01,11"}},
50     {"ImageDescription", {"_cuva"}},
51     {"Make", {""}},
52     {"Model", {"TNY-AL00", "", "xx", "xxx"}},
53     {"SensitivityType", {"Standard output sensitivity (SOS) and ISO speed", ""}},
54     {"StandardOutputSensitivity", {"5", ""}},
55     {"RecommendedExposureIndex", {"241", ""}},
56     {"ApertureValue", {"4.00 EV (f/4.0)", "2.00 EV (f/2.0)"}},
57     {"ExposureBiasValue", {"23.00 EV", "0.00 EV"}},
58     {"MeteringMode", {"Pattern"}},
59     {"LightSource", {"Fluorescent", "Daylight"}},
60     {"Flash", {"Strobe return light not detected", "Flash did not fire"}},
61     {"FocalLength", {"31.0 mm", "6.3 mm"}},
62     {"UserComment", {"comm", ""}},
63     {"PixelXDimension", {"1000", "4000"}},
64     {"PixelYDimension", {"2000", "3000"}},
65     {"WhiteBalance", {"Manual white balance", "Auto white balance"}},
66     {"FocalLengthIn35mmFilm", {"26", "27"}},
67     {"JPEGProc", {"252", ""}},
68     {"MaxApertureValue", {"0.08 EV (f/1.0)"}},
69     {"Artist", {"Joseph.Xu"}},
70     {"NewSubfileType", {"1"}},
71     {"OECF", {"1 bytes undefined data"}},
72     {"PlanarConfiguration", {"Chunky format"}},
73     {"PrimaryChromaticities", {"124"}},
74     {"ReferenceBlackWhite", {"221"}},
75     {"ResolutionUnit", {"Inch"}},
76     {"SamplesPerPixel", {"23"}},
77     {"Compression", {"JPEG compression"}},
78     {"Software", {"MNA-AL00 4.0.0.120(C00E116R3P7)"}},
79     {"Copyright", {"xxxxxx (Photographer) - {None} (Editor)"}},
80     {"SpectralSensitivity", {"sensitivity"}},
81     {"DNGVersion", {"0x01, 0x01, 0x02, 0x03"}},
82     {"SubjectDistance", {""}},
83     {"DefaultCropSize", {"12, 1"}},
84     {"SubjectLocation", {"3"}},
85     {"TransferFunction", {"2"}},
86     {"WhitePoint", {"124.2"}},
87     {"XResolution", {"72"}},
88     {"YCbCrCoefficients", {"0.299, 0.587, 0.114"}},
89     {"YCbCrPositioning", {"Centered"}},
90     {"YCbCrSubSampling", {"3, 2"}},
91     {"YResolution", {"72"}},
92     {"Gamma", {"1.5"}},
93     {"ISOSpeed", {"200"}},
94     {"ISOSpeedLatitudeyyy", {"3"}},
95     {"ISOSpeedLatitudezzz", {"3"}},
96     {"ImageUniqueID", {"FXIC012"}},
97     {"JPEGInterchangeFormat", {""}},
98     {"JPEGInterchangeFormatLength", {""}},
99     {"GPSAltitude", {"0.00"}},
100     {"GPSAltitudeRef", {"Sea level reference"}},
101     {"GPSAreaInformation", {"23...15...57"}},
102     {"GPSDOP", {"182"}},
103     {"GPSDestBearing", {"2.6"}},
104     {"GPSDestBearingRef", {"T"}},
105     {"GPSDestDistance", {"10"}},
106     {"GPSDestDistanceRef", {"N"}},
107     {"GPSDestLatitude", {"33, 22, 11"}},
108     {"GPSDestLatitudeRef", {"N"}},
109     {"GPSDestLongitude", {"33, 22, 11"}},
110     {"GPSDestLongitudeRef", {"E"}},
111     {"GPSDifferential", {"1"}},
112     {"GPSImgDirection", {"2.23214"}},
113     {"GPSImgDirectionRef", {"M"}},
114     {"GPSMapDatum", {"xxxx"}},
115     {"GPSMeasureMode", {"2"}},
116     {"GPSProcessingMethod", {"CELLID"}},
117     {"GPSSatellites", {"xxx"}},
118     {"GPSSpeed", {"150"}},
119     {"GPSSpeedRef", {"K"}},
120     {"GPSStatus", {"V"}},
121     {"GPSTrack", {"56"}},
122     {"GPSTrackRef", {"T"}},
123     {"GPSVersionID", {"2.2.0.0"}},
124     {"GPSHPositioningError", {" 3"}},
125     {"LensMake", {"xxx"}},
126     {"LensModel", {"xxx"}},
127     {"LensSerialNumber", {"xxx"}},
128     {"LensSpecification", {" 1, 1.5,  1,  2"}},
129     {"GainControl", {"Normal"}},
130     {"OffsetTime", {"xx"}},
131     {"OffsetTimeDigitized", {"xx"}},
132     {"OffsetTimeOriginal", {"xx"}},
133     {"PhotometricInterpretation", {""}},
134     {"RelatedSoundFile", {"/usr/home/sound/sea.wav"}},
135     {"RowsPerStrip", {""}},
136     {"Saturation", {"Normal"}},
137     {"SceneCaptureType", {"Standard"}},
138     {"SensingMethod", {"Two-chip color area sensor"}},
139     {"Sharpness", {"Normal"}},
140     {"ShutterSpeedValue", {"13.00 EV (1/8192 sec.)"}},
141     {"SourceExposureTimesOfCompositeImage", {"."}},
142     {"SourceImageNumberOfCompositeImage", {"1234"}},
143     {"SpatialFrequencyResponse", {"."}},
144     {"StripByteCounts", {""}},
145     {"StripOffsets", {""}},
146     {"SubsecTime", {"427000"}},
147     {"SubsecTimeDigitized", {"427000"}},
148     {"SubsecTimeOriginal", {"427000"}},
149     {"SubfileType", {""}},
150     {"SubjectArea", {"Within rectangle (width 183, height 259) around (x,y) = (10,20)"}},
151     {"SubjectDistanceRange", {"Unknown"}},
152     {"BodySerialNumber", {"xx"}},
153     {"BrightnessValue", {"2.50 EV (19.38 cd/m^2)"}},
154     {"CFAPattern", {"1 bytes undefined data"}},
155     {"CameraOwnerName", {"xx"}},
156     {"ColorSpace", {"Adobe RGB"}},
157     {"ComponentsConfiguration", {""}},
158     {"CompositeImage", {"1"}},
159     {"CompressedBitsPerPixel", {"1.5"}},
160     {"Contrast", {"Normal"}},
161     {"CustomRendered", {"Custom process"}},
162     {"DateTimeDigitized", {"2023,01,19 10,39,58"}},
163     {"DeviceSettingDescription", {"."}},
164     {"DigitalZoomRatio", {"321"}},
165     {"ExifVersion", {""}},
166     {"ExposureIndex", {"1.5"}},
167     {"ExposureMode", {"Auto exposure"}},
168     {"ExposureProgram", {"Normal program"}},
169     {"FileSource", {"DSC"}},
170     {"FlashEnergy", {"832"}},
171     {"FlashpixVersion", {""}},
172     {"FocalPlaneResolutionUnit", {"Centimeter"}},
173     {"FocalPlaneXResolution", {"1080"}},
174     {"FocalPlaneYResolution", {"880"}}
175 };
176 
177 // create pixelMap by data, and encode to the file descriptor
178 int ConvertDataToFd(const uint8_t* data, size_t size, std::string encodeFormat = "image/jpeg");
179 
180 std::string GetNowTimeStr();
181 
182 bool WriteDataToFile(const uint8_t* data, size_t size, const std::string& filename);
183 
184 void PixelMapTest001(OHOS::Media::PixelMap* pixelMap);
185 
186 void PixelMapTest002(OHOS::Media::PixelMap* pixelMap);
187 
188 void PixelYuvTest001(OHOS::Media::PixelMap* pixelMap);
189 
190 void PixelYuvTest002(OHOS::Media::PixelMap* pixelMap);
191 
192 void SetFdpDecodeOptions(FuzzedDataProvider* fdp, OHOS::Media::DecodeOptions &decodeOpts);
193 
194 void SetFdpPixelDecodeOptions(FuzzedDataProvider* fdp, OHOS::ImagePlugin::PixelDecodeOptions &plOpts);
195 #endif