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 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_CUSTOM_PAINT_CUSTOM_PAINT_UTIL_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_CUSTOM_PAINT_CUSTOM_PAINT_UTIL_H
18 #include <string>
19 
20 #ifndef ACE_UNITTEST
21 #include "include/encode/SkJpegEncoder.h"
22 #include "include/encode/SkPngEncoder.h"
23 #include "include/encode/SkWebpEncoder.h"
24 #include "include/utils/SkBase64.h"
25 #include "core/components/common/painter/rosen_decoration_painter.h"
26 #endif
27 
28 namespace OHOS::Ace::NG {
29 
30 const std::string UNSUPPORTED = "data:image/png";
31 const std::string URL_PREFIX = "data:";
32 const std::string URL_SYMBOL = ";base64,";
33 const std::string IMAGE_PNG = "image/png";
34 const std::string IMAGE_JPEG = "image/jpeg";
35 const std::string IMAGE_WEBP = "image/webp";
36 
37 constexpr int32_t MAX_LENGTH = 2048 * 2048;
38 constexpr double DEFAULT_QUALITY = 0.92;
39 constexpr double HANGING_PERCENT = 0.8;
40 constexpr double QUALITY_COEFFICIENT = 100.0;
41 
42 struct CanvasModifierDump {
43     int64_t timestamp = 0;
44     double width = 0;
45     double height = 0;
46     size_t opItemSize = 0;
47 };
48 
49 // If args is empty or invalid format, use default: image/png
50 std::string GetMimeType(const std::string& type);
51 
52 // Quality need between 0.0 and 1.0 for MimeType jpeg and webp
53 double GetQuality(const std::string& type, const double quality);
54 
55 #ifndef ACE_UNITTEST
56 // Encode Image Format
57 bool EncodeImage(std::string& type, const double quality, SkPixmap& src, SkDynamicMemoryWStream& dst);
58 #endif
59 } // namespace OHOS::Ace::NG
60 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_CUSTOM_PAINT_CUSTOM_PAINT_UTIL_H