• 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 #ifndef UPDATER_UI_ANIMATION_LABLE_H
16 #define UPDATER_UI_ANIMATION_LABLE_H
17 #include <ctime>
18 #include <thread>
19 #include <unistd.h>
20 #include <vector>
21 #include "frame.h"
22 #include "png.h"
23 
24 namespace updater {
25 constexpr int IMG_LIST_MAX_SIZE = 255;
26 constexpr int PNG_HEADER_SIZE = 8;
27 constexpr useconds_t SECOND_PER_MS = 1000;
28 constexpr int MAX_PICTURE_CHANNELS = 3;
29 constexpr int MAX_BIT_DEPTH = 8;
30 class AnimationLable : public View {
31 public:
32     enum PlayMode {
33         ANIMATION_MODE = 0,
34         STATIC_MODE,
35     };
36     AnimationLable(int startX, int startY, int w, int h, Frame *parent);
37     ~AnimationLable() override;
38 public:
39     void AddImg(const std::string &imgFileName);
40     int AddStaticImg(const std::string &imgFileName);
41     void SetStaticImg(int picId);
42     void SetPlayMode(AnimationLable::PlayMode mode);
43     void SetInterval(int ms);
44     void Start();
45     void Stop();
46     std::thread updateThread;
47     bool selectable = false;
48 private:
49     struct PictureAttr {
50         png_uint_32 pictureWidth;
51         png_uint_32 pictureHeight;
52         png_byte pictureChannels;
53         int bitDepth;
54         int colorType;
55     };
56     void UpdateLoop();
57     void* LoadPng(const std::string &imgFileName);
58     int LoadPngInternalWithFile(FILE *fp, png_structpp pngPtr, png_infopp pngInfoPtr,
59         struct PictureAttr &attr);
60     void CopyPictureBuffer(struct PictureAttr &attr, char *pictureBufferTmp,
61         BRGA888Pixel *pictureBuffer) const;
62     Frame* parent_ {};
63     bool needStop_ = false;
64     int intervalMs_ = 50;
65     std::vector<void*> imgList_ {};
66     void *staticImgList_[IMG_LIST_MAX_SIZE] {};
67     bool startFlag_ = false;
68     int staticShowId_ = 0;
69     bool showStatic_ = false;
70     int staticImgSize_ = 0;
71 };
72 } // namespace updater
73 #endif // UPDATER_UI_ANIMATION_LABLE_H
74