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
35 bool operator==(const CTextureDetails
&right
) const
37 return (id
== right
.id
&&
39 width
== right
.width
);
51 \brief Job class for caching textures
53 Handles loading and caching of textures.
55 class CTextureCacheJob
: public CJob
58 CTextureCacheJob(const std::string
&url
, const std::string
&oldHash
= "");
59 ~CTextureCacheJob() override
;
61 const char* GetType() const override
{ return kJobTypeCacheImage
; }
62 bool operator==(const CJob
*job
) const override
;
63 bool DoWork() override
;
65 /*! \brief retrieve a hash for the given image
66 Combines the size, ctime and mtime of the image file into a "unique" hash
67 \param url location of the image
68 \return a hash string for this image
70 bool CacheTexture(std::unique_ptr
<CTexture
>* texture
= nullptr);
72 static bool ResizeTexture(const std::string
&url
, uint8_t* &result
, size_t &result_size
);
75 std::string m_oldHash
;
76 CTextureDetails m_details
;
78 /*! \brief retrieve a hash for the given image
79 Combines the size, ctime and mtime of the image file into a "unique" hash
80 \param url location of the image
81 \return a hash string for this image
83 static std::string
GetImageHash(const std::string
&url
);
85 /*! \brief Check whether a given URL represents an image that can be updated
86 We currently don't check http:// and https:// URLs for updates, under the assumption that
87 a image URL is much more likely to be static and the actual image at the URL is unlikely
88 to change, so no point checking all the time.
89 \param url the url to check
90 \return true if the image given by the URL should be checked for updates, false otherwise
92 bool UpdateableURL(const std::string
&url
) const;
94 /*! \brief Decode an image URL to the underlying image, width, height and orientation
95 \param url wrapped URL of the image
96 \param width width derived from URL
97 \param height height derived from URL
98 \param scalingAlgorithm scaling algorithm derived from URL
99 \param additional_info additional information, such as "flipped" to flip horizontally
100 \return URL of the underlying image file.
102 static std::string
DecodeImageURL(const std::string
&url
, unsigned int &width
, unsigned int &height
, CPictureScalingAlgorithm::Algorithm
& scalingAlgorithm
, std::string
&additional_info
);
104 /*! \brief Load an image at a given target size and orientation.
106 Doesn't necessarily load the image at the desired size - the loader *may* decide to load it slightly larger
107 or smaller than the desired size for speed reasons.
109 \param image the URL of the image file.
110 \param width the desired maximum width.
111 \param height the desired maximum height.
112 \param additional_info extra info for loading, such as whether to flip horizontally.
113 \return a pointer to a CTexture object, NULL if failed.
115 static std::unique_ptr
<CTexture
> LoadImage(const std::string
& image
,
118 const std::string
& additional_info
,
119 bool requirePixels
= false);
121 std::string m_cachePath
;
124 /* \brief Job class for storing the use count of textures
126 class CTextureUseCountJob
: public CJob
129 explicit CTextureUseCountJob(const std::vector
<CTextureDetails
> &textures
);
131 const char* GetType() const override
{ return "usecount"; }
132 bool operator==(const CJob
*job
) const override
;
133 bool DoWork() override
;
136 std::vector
<CTextureDetails
> m_textures
;