| 1 |
/* |
| 2 |
* Copyright (C) 2005-2018 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#pragma once |
| 10 |
|
| 11 |
#include "pictures/PictureScalingAlgorithm.h" |
| 12 |
#include "utils/Job.h" |
| 13 |
|
| 14 |
#include <cstddef> |
| 15 |
#include <cstdint> |
| 16 |
#include <memory> |
| 17 |
#include <string> |
| 18 |
#include <vector> |
| 19 |
|
| 20 |
extern "C" |
| 21 |
{ |
| 22 |
#include <libavutil/pixfmt.h> |
| 23 |
} |
| 24 |
|
| 25 |
class CTexture; |
| 26 |
|
| 27 |
class CPicture |
| 28 |
{ |
| 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); |
| 32 |
|
| 33 |
static std::unique_ptr<CTexture> CreateTiledThumb(const std::vector<std::string>& files); |
| 34 |
|
| 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); |
| 46 |
|
| 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 |
| 53 |
*/ |
| 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); |
| 63 |
|
| 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); |
| 77 |
|
| 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); |
| 84 |
|
| 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); |
| 113 |
}; |
| 114 |
|
| 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 |
| 117 |
{ |
| 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; |
| 123 |
|
| 124 |
private: |
| 125 |
unsigned char* m_buffer; |
| 126 |
int m_width; |
| 127 |
int m_height; |
| 128 |
int m_stride; |
| 129 |
std::string m_thumbFile; |
| 130 |
}; |
| 131 |
|