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.
11 #include "pictures/PictureScalingAlgorithm.h"
12 #include "utils/Job.h"
22 #include <libavutil/pixfmt.h>
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
,
39 uint32_t& dest_height
,
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(
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(
67 unsigned int in_width
,
68 unsigned int in_height
,
69 unsigned int in_pitch
,
70 AVPixelFormat in_format
,
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
);
79 static bool OrientateImage(std::unique_ptr
<uint32_t[]>& pixels
,
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
,
96 unsigned int& stridePixels
);
97 static bool Rotate270CCW(std::unique_ptr
<uint32_t[]>& pixels
,
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
,
107 unsigned int& height
,
108 unsigned int& width_aligned
);
109 static bool TransposeOffAxis(std::unique_ptr
<uint32_t[]>& pixels
,
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
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
;
125 unsigned char* m_buffer
;
129 std::string m_thumbFile
;