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"
19 #include <libavutil/pixfmt.h>
27 static bool GetThumbnailFromSurface(const unsigned char* buffer
, int width
, int height
, int stride
, const std::string
&thumbFile
, uint8_t* &result
, size_t& result_size
);
28 static bool CreateThumbnailFromSurface(const unsigned char* buffer
, int width
, int height
, int stride
, const std::string
&thumbFile
);
30 /*! \brief Create a tiled thumb of the given files
31 \param files the files to create the thumb from
32 \param thumb the filename of the thumb
34 static bool CreateTiledThumb(const std::vector
<std::string
> &files
, const std::string
&thumb
);
36 static bool ResizeTexture(
37 const std::string
& image
,
40 uint32_t& dest_height
,
43 CPictureScalingAlgorithm::Algorithm scalingAlgorithm
= CPictureScalingAlgorithm::NoAlgorithm
);
44 static bool ResizeTexture(const std::string
&image
, uint8_t *pixels
, uint32_t width
, uint32_t height
, uint32_t pitch
,
45 uint32_t &dest_width
, uint32_t &dest_height
, uint8_t* &result
, size_t& result_size
,
46 CPictureScalingAlgorithm::Algorithm scalingAlgorithm
= CPictureScalingAlgorithm::NoAlgorithm
);
48 /*! \brief Cache a texture, resizing, rotating and flipping as needed, and saving as a JPG or PNG
49 \param texture a pointer to a CTexture
50 \param dest_width [in/out] maximum width in pixels of cached version - replaced with actual cached width
51 \param dest_height [in/out] maximum height in pixels of cached version - replaced with actual cached height
52 \param dest the output cache file
53 \return true if successful, false otherwise
55 static bool CacheTexture(
58 uint32_t& dest_height
,
59 const std::string
& dest
,
60 CPictureScalingAlgorithm::Algorithm scalingAlgorithm
= CPictureScalingAlgorithm::NoAlgorithm
);
61 static bool CacheTexture(uint8_t *pixels
, uint32_t width
, uint32_t height
, uint32_t pitch
, int orientation
,
62 uint32_t &dest_width
, uint32_t &dest_height
, const std::string
&dest
,
63 CPictureScalingAlgorithm::Algorithm scalingAlgorithm
= CPictureScalingAlgorithm::NoAlgorithm
);
65 static void GetScale(unsigned int width
, unsigned int height
, unsigned int &out_width
, unsigned int &out_height
);
66 static bool ScaleImage(
68 unsigned int in_width
,
69 unsigned int in_height
,
70 unsigned int in_pitch
,
71 AVPixelFormat in_format
,
73 unsigned int out_width
,
74 unsigned int out_height
,
75 unsigned int out_pitch
,
76 AVPixelFormat out_format
,
77 CPictureScalingAlgorithm::Algorithm scalingAlgorithm
= CPictureScalingAlgorithm::NoAlgorithm
);
80 static bool OrientateImage(uint32_t *&pixels
, unsigned int &width
, unsigned int &height
, int orientation
);
82 static bool FlipHorizontal(uint32_t*& pixels
,
83 const unsigned int& width
,
84 const unsigned int& height
);
85 static bool FlipVertical(uint32_t*& pixels
,
86 const unsigned int& width
,
87 const unsigned int& height
);
88 static bool Rotate90CCW(uint32_t *&pixels
, unsigned int &width
, unsigned int &height
);
89 static bool Rotate270CCW(uint32_t *&pixels
, unsigned int &width
, unsigned int &height
);
90 static bool Rotate180CCW(uint32_t*& pixels
,
91 const unsigned int& width
,
92 const unsigned int& height
);
93 static bool Transpose(uint32_t *&pixels
, unsigned int &width
, unsigned int &height
);
94 static bool TransposeOffAxis(uint32_t *&pixels
, unsigned int &width
, unsigned int &height
);
97 //this class calls CreateThumbnailFromSurface in a CJob, so a png file can be written without halting the render thread
98 class CThumbnailWriter
: public CJob
101 //WARNING: buffer is deleted from DoWork()
102 CThumbnailWriter(unsigned char* buffer
, int width
, int height
, int stride
, const std::string
& thumbFile
);
103 ~CThumbnailWriter() override
;
104 bool DoWork() override
;
107 unsigned char* m_buffer
;
111 std::string m_thumbFile
;