1 /* 2 * Copyright (c) 2020-2021 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 GRAPHIC_LITE_FILE_IMG_DECODER_H 17 #define GRAPHIC_LITE_FILE_IMG_DECODER_H 18 19 #include "draw/draw_image.h" 20 #include "draw/draw_utils.h" 21 22 namespace OHOS { 23 constexpr uint8_t BYTE_TO_BIT_SHIFT = 3; 24 constexpr uint8_t ONE_BIT_LEN_IN_BIT = 1; 25 constexpr uint8_t TWO_BIT_LEN_IN_BIT = 2; 26 constexpr uint8_t FOUR_BIT_LEN_IN_BIT = 4; 27 constexpr uint8_t BYTE_LEN_IN_BIT = 8; 28 29 enum class RetCode { 30 OK, 31 FAIL, 32 }; 33 34 class FileImgDecoder : public HeapBase { 35 public: 36 static FileImgDecoder& GetInstance(); 37 38 struct ImgResDsc { 39 FileImgDecoder* decoder; 40 const char* path; 41 ImageInfo imgInfo; 42 uint32_t timeToOpen; 43 int32_t fd; 44 ImageSrcType srcType; 45 bool inCache_; 46 }; 47 48 RetCode Open(ImgResDsc& dsc); 49 50 RetCode Close(ImgResDsc& dsc); 51 52 RetCode GetHeader(ImgResDsc& dsc); 53 54 RetCode ReadLine(ImgResDsc& dsc, const Point& start, int16_t len, uint8_t* buf); 55 56 RetCode ReadToCache(ImgResDsc& dsc); 57 58 private: FileImgDecoder()59 FileImgDecoder() {}; ~FileImgDecoder()60 ~FileImgDecoder() {}; 61 IsImgValidMode(uint8_t colorMode)62 bool IsImgValidMode(uint8_t colorMode) 63 { 64 if ((colorMode == RGB565) || (colorMode == RGB888) || (colorMode == ARGB8888)) { 65 return true; 66 } else { 67 return false; 68 } 69 } 70 RetCode ReadLineTrueColor(ImgResDsc& dsc, const Point& start, int16_t len, uint8_t* buf); 71 72 FileImgDecoder(const FileImgDecoder&) = delete; 73 FileImgDecoder& operator=(const FileImgDecoder&) = delete; 74 FileImgDecoder(FileImgDecoder&&) = delete; 75 FileImgDecoder& operator=(FileImgDecoder&&) = delete; 76 }; 77 } 78 #endif