Merge pull request #26220 from 78andyp/blurayfixes
[xbmc.git] / xbmc / pictures / Picture.h
blob390ff169f58d885c553eb55beb9dd473176a0da7
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #pragma once
11 #include "pictures/PictureScalingAlgorithm.h"
12 #include "utils/Job.h"
14 #include <cstddef>
15 #include <cstdint>
16 #include <memory>
17 #include <string>
18 #include <vector>
20 extern "C"
22 #include <libavutil/pixfmt.h>
25 class CTexture;
27 class CPicture
29 public:
30 static bool GetThumbnailFromSurface(const unsigned char* buffer, int width, int height, int stride, const std::string &thumbFile, uint8_t* &result, size_t& result_size);
31 static bool CreateThumbnailFromSurface(const unsigned char* buffer, int width, int height, int stride, const std::string &thumbFile);
33 static std::unique_ptr<CTexture> CreateTiledThumb(const std::vector<std::string>& files);
35 static bool ResizeTexture(
36 const std::string& image,
37 CTexture* texture,
38 uint32_t& dest_width,
39 uint32_t& dest_height,
40 uint8_t*& result,
41 size_t& result_size,
42 CPictureScalingAlgorithm::Algorithm scalingAlgorithm = CPictureScalingAlgorithm::NoAlgorithm);
43 static bool ResizeTexture(const std::string &image, uint8_t *pixels, uint32_t width, uint32_t height, uint32_t pitch,
44 uint32_t &dest_width, uint32_t &dest_height, uint8_t* &result, size_t& result_size,
45 CPictureScalingAlgorithm::Algorithm scalingAlgorithm = CPictureScalingAlgorithm::NoAlgorithm);
47 /*! \brief Cache a texture, resizing, rotating and flipping as needed, and saving as a JPG or PNG
48 \param texture a pointer to a CTexture
49 \param dest_width [in/out] maximum width in pixels of cached version - replaced with actual cached width
50 \param dest_height [in/out] maximum height in pixels of cached version - replaced with actual cached height
51 \param dest the output cache file
52 \return true if successful, false otherwise
54 static bool CacheTexture(
55 CTexture* texture,
56 uint32_t& dest_width,
57 uint32_t& dest_height,
58 const std::string& dest,
59 CPictureScalingAlgorithm::Algorithm scalingAlgorithm = CPictureScalingAlgorithm::NoAlgorithm);
60 static bool CacheTexture(uint8_t *pixels, uint32_t width, uint32_t height, uint32_t pitch, int orientation,
61 uint32_t &dest_width, uint32_t &dest_height, const std::string &dest,
62 CPictureScalingAlgorithm::Algorithm scalingAlgorithm = CPictureScalingAlgorithm::NoAlgorithm);
64 static void GetScale(unsigned int width, unsigned int height, unsigned int &out_width, unsigned int &out_height);
65 static bool ScaleImage(
66 uint8_t* in_pixels,
67 unsigned int in_width,
68 unsigned int in_height,
69 unsigned int in_pitch,
70 AVPixelFormat in_format,
71 uint8_t* out_pixels,
72 unsigned int out_width,
73 unsigned int out_height,
74 unsigned int out_pitch,
75 AVPixelFormat out_format,
76 CPictureScalingAlgorithm::Algorithm scalingAlgorithm = CPictureScalingAlgorithm::NoAlgorithm);
78 private:
79 static bool OrientateImage(std::unique_ptr<uint32_t[]>& pixels,
80 unsigned int& width,
81 unsigned int& height,
82 int orientation,
83 unsigned int& stridePixels);
85 static bool FlipHorizontal(std::unique_ptr<uint32_t[]>& pixels,
86 const unsigned int& width,
87 const unsigned int& height,
88 const unsigned int& stridePixels);
89 static bool FlipVertical(std::unique_ptr<uint32_t[]>& pixels,
90 const unsigned int& width,
91 const unsigned int& height,
92 const unsigned int& stridePixels);
93 static bool Rotate90CCW(std::unique_ptr<uint32_t[]>& pixels,
94 unsigned int& width,
95 unsigned int& height,
96 unsigned int& stridePixels);
97 static bool Rotate270CCW(std::unique_ptr<uint32_t[]>& pixels,
98 unsigned int& width,
99 unsigned int& height,
100 unsigned int& stridePixels);
101 static bool Rotate180CCW(std::unique_ptr<uint32_t[]>& pixels,
102 const unsigned int& width,
103 const unsigned int& height,
104 const unsigned int& stridePixels);
105 static bool Transpose(std::unique_ptr<uint32_t[]>& pixels,
106 unsigned int& width,
107 unsigned int& height,
108 unsigned int& width_aligned);
109 static bool TransposeOffAxis(std::unique_ptr<uint32_t[]>& pixels,
110 unsigned int& width,
111 unsigned int& height,
112 unsigned int& stridePixels);
115 //this class calls CreateThumbnailFromSurface in a CJob, so a png file can be written without halting the render thread
116 class CThumbnailWriter : public CJob
118 public:
119 //WARNING: buffer is deleted from DoWork()
120 CThumbnailWriter(unsigned char* buffer, int width, int height, int stride, const std::string& thumbFile);
121 ~CThumbnailWriter() override;
122 bool DoWork() override;
124 private:
125 unsigned char* m_buffer;
126 int m_width;
127 int m_height;
128 int m_stride;
129 std::string m_thumbFile;