• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 PICTURE_UTILS_H
17 #define PICTURE_UTILS_H
18 
19 #include <csetjmp>
20 #include <cstdio>
21 #include <memory>
22 #include <string>
23 
24 #include "jpeglib.h"
25 
26 namespace IC {
27 struct MyErrorMgr {
28     struct jpeg_error_mgr pub;
29     jmp_buf setjmp_buffer;
30 };
31 
32 using MyErrorPtr = MyErrorMgr *;
33 
34 // The index order of BGR format
35 enum BgrIndex {
36     BGR_BLUE = 0,
37     BGR_GREEN,
38     BGR_RED,
39 };
40 
41 // The index order of RGB format
42 enum RgbIndex {
43     RGB_RED = 0,
44     RGB_GREEN,
45     RGB_BLUE,
46 };
47 
48 // Information about picture
49 struct PicInfo {
50     int widthSrc;
51     int heightSrc;
52     int widthDest;
53     int heightDest;
54 };
55 
56 // Change this to your own settings
57 const std::string JPEG_SRC_PATH = "/storage/data/image_classification_demo.jpg";
58 const int WIDTH_DEST = 224;
59 const int HEIGHT_DEST = 224;
60 const int NUM_CHANNELS = 3;
61 
62 int WriteJpegFile(const std::string &filename, int quality, uint8_t *srcBuffer, int srcWidth, int srcHeight);
63 int WriteBgrFile(const std::string &filename, uint8_t *dataBuffer, int bufferSize);
64 uint8_t *ConvertToCaffeInput(uint8_t *dataBuffer, int maxSize);
65 uint8_t *ReadJpegFile(const std::string &filename, int &srcWidth, int &srcHeight);
66 uint8_t *Resize(const int widthDest, const int heightDest, uint8_t *src, int widthSrc, int heightSrc);
67 }  // namespace IC
68 #endif  // PICTURE_UTILS_H
69