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