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