2 * Copyright (C) 2012-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"
24 \brief Simple class for passing texture detail around
29 bool operator==(const CTextureDetails
&right
) const
31 return (id
== right
.id
&&
33 width
== right
.width
);
39 unsigned int width
{0};
40 unsigned int height
{0};
41 bool updateable
{false};
42 bool hashRevalidated
{false};
47 \brief Job class for caching textures
49 Handles loading and caching of textures.
51 class CTextureCacheJob
: public CJob
54 CTextureCacheJob(const std::string
&url
, const std::string
&oldHash
= "");
55 ~CTextureCacheJob() override
;
57 const char* GetType() const override
{ return kJobTypeCacheImage
; }
58 bool operator==(const CJob
*job
) const override
;
59 bool DoWork() override
;
61 /*! \brief retrieve a hash for the given image
62 Combines the size, ctime and mtime of the image file into a "unique" hash
63 \param url location of the image
64 \return a hash string for this image
66 bool CacheTexture(std::unique_ptr
<CTexture
>* texture
= nullptr);
68 static bool ResizeTexture(const std::string
&url
, uint8_t* &result
, size_t &result_size
);
71 std::string m_oldHash
;
72 CTextureDetails m_details
;
74 /*! \brief retrieve a hash for the given image
75 Combines the size, ctime and mtime of the image file into a "unique" hash
76 \param url location of the image
77 \return a hash string for this image
79 static std::string
GetImageHash(const std::string
&url
);
81 /*! \brief Decode an image URL to the underlying image, width, height and orientation
82 \param url wrapped URL of the image
83 \param width width derived from URL
84 \param height height derived from URL
85 \param scalingAlgorithm scaling algorithm derived from URL
86 \param additional_info additional information, such as "flipped" to flip horizontally
87 \return URL of the underlying image file.
89 static std::string
DecodeImageURL(const std::string
&url
, unsigned int &width
, unsigned int &height
, CPictureScalingAlgorithm::Algorithm
& scalingAlgorithm
, std::string
&additional_info
);
91 /*! \brief Load an image at a given target size and orientation.
93 Doesn't necessarily load the image at the desired size - the loader *may* decide to load it slightly larger
94 or smaller than the desired size for speed reasons.
96 \param image the URL of the image file.
97 \param width the desired maximum width.
98 \param height the desired maximum height.
99 \param additional_info extra info for loading, such as whether to flip horizontally.
100 \return a pointer to a CTexture object, NULL if failed.
102 static std::unique_ptr
<CTexture
> LoadImage(const std::string
& image
,
105 const std::string
& additional_info
,
106 bool requirePixels
= false);
108 std::string m_cachePath
;
111 /* \brief Job class for storing the use count of textures
113 class CTextureUseCountJob
: public CJob
116 explicit CTextureUseCountJob(const std::vector
<CTextureDetails
> &textures
);
118 const char* GetType() const override
{ return "usecount"; }
119 bool operator==(const CJob
*job
) const override
;
120 bool DoWork() override
;
123 std::vector
<CTextureDetails
> m_textures
;