[filesystem][SpecialProtocol] Removed assert from GetPath
[xbmc.git] / xbmc / pictures / Picture.h
blobee5a270d868c71e61aadf08ad5bb122f62b29518
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 <string>
17 #include <vector>
19 extern "C"
21 #include <libavutil/pixfmt.h>
24 class CTexture;
26 class CPicture
28 public:
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,
40 CTexture* texture,
41 uint32_t& dest_width,
42 uint32_t& dest_height,
43 uint8_t*& result,
44 size_t& result_size,
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(
58 CTexture* texture,
59 uint32_t& dest_width,
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(
69 uint8_t* in_pixels,
70 unsigned int in_width,
71 unsigned int in_height,
72 unsigned int in_pitch,
73 AVPixelFormat in_format,
74 uint8_t* out_pixels,
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);
81 private:
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
102 public:
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;
108 private:
109 unsigned char* m_buffer;
110 int m_width;
111 int m_height;
112 int m_stride;
113 std::string m_thumbFile;