1 /* 2 * Copyright (c) 2023 Shenzhen Kaihong DID 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 CODEC_JPEG_HELPER_H 16 #define CODEC_JPEG_HELPER_H 17 #include <cinttypes> 18 #include <codec_jpeg_vdi.h> 19 #include <memory> 20 namespace OHOS { 21 namespace VDI { 22 namespace JPEG { 23 class CodecJpegHelper { 24 public: 25 enum JpegMarker : int16_t { 26 SOF0 = 0xffc0, 27 DHT = 0xffc4, 28 SOI = 0xffd8, 29 EOI = 0xffd9, 30 SOS = 0xffda, 31 DQT = 0xffdb, 32 DRI = 0xffdd, 33 UNKNOWN = 0xffff 34 }; 35 explicit CodecJpegHelper() = default; 36 37 ~CodecJpegHelper() = default; 38 39 int32_t JpegAssemble(const struct CodecJpegDecInfo &decInfo, int8_t *buffer, int32_t fd); 40 41 bool DessambleJpeg(int8_t *buffer, size_t bufferLen, struct CodecJpegDecInfo &decInfo, 42 std::unique_ptr<int8_t[]> &compressBuffer, int32_t &comBufLen); 43 44 private: 45 int32_t FindMarker(int8_t *start); 46 47 int32_t JpegDqtAssemble(const struct CodecJpegDecInfo &decInfo, int8_t *buffer, int32_t curPos); 48 49 int32_t JpegDriAssemble(const struct CodecJpegDecInfo &decInfo, int8_t *buffer, int32_t curPos); 50 51 int32_t JpegDhtAssemble(const struct CodecJpegDecInfo &decInfo, int8_t *buffer, int32_t curPos); 52 53 int32_t JpegDhtAssemble( 54 const std::vector<CodecJpegHuffTable> &table, int8_t *buffer, int32_t curPos, bool dc = true); 55 56 int32_t JpegSofAssemble(const struct CodecJpegDecInfo &decInfo, int8_t *buffer, int32_t curPos); 57 58 int32_t JpegSosAssemble(const struct CodecJpegDecInfo &decInfo, int8_t *buffer, int32_t curPos); 59 60 int32_t JpegDataAssemble(int8_t *buffer, int32_t curPos, int32_t fd); 61 62 int32_t DessambleSof(int8_t *buffer, struct CodecJpegDecInfo &decInfo); 63 64 int32_t DessambleSos(int8_t *buffer, struct CodecJpegDecInfo &decInfo); 65 66 int32_t DessambleCompressData(int8_t *buffer, std::unique_ptr<int8_t[]> &compressBuffer, int32_t &comBufLen); 67 68 int32_t DessambleDqt(int8_t *buffer, struct CodecJpegDecInfo &decInfo); 69 70 int32_t DessambleDht(int8_t *buffer, struct CodecJpegDecInfo &decInfo); 71 72 int32_t PutInt16(int8_t *buffer, int32_t curPos, int16_t value); 73 74 int32_t PutInt8(int8_t *buffer, int32_t curPos, int8_t value); 75 76 int32_t GetInt8(int8_t *buffer); 77 78 int32_t GetInt16(int8_t *buffer); 79 80 private: 81 static constexpr int32_t MAX_BUFFER_LEN = 128; 82 }; 83 } // namespace JPEG 84 } // namespace VDI 85 } // namespace OHOS 86 #endif 87