[ExecString] combine SplitParameters with identical function of CUtil
[xbmc.git] / xbmc / TextureCacheJob.h
blob8d7b764cd8327cfee8a41df3ceb203d00f581713
1 /*
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.
7 */
9 #pragma once
11 #include "pictures/PictureScalingAlgorithm.h"
12 #include "utils/Job.h"
14 #include <cstddef>
15 #include <memory>
16 #include <stdint.h>
17 #include <string>
18 #include <vector>
20 class CTexture;
22 /*!
23 \ingroup textures
24 \brief Simple class for passing texture detail around
26 class CTextureDetails
28 public:
29 bool operator==(const CTextureDetails &right) const
31 return (id == right.id &&
32 file == right.file &&
33 width == right.width );
36 int id{-1};
37 std::string file;
38 std::string hash;
39 unsigned int width{0};
40 unsigned int height{0};
41 bool updateable{false};
42 bool hashRevalidated{false};
45 /*!
46 \ingroup textures
47 \brief Job class for caching textures
49 Handles loading and caching of textures.
51 class CTextureCacheJob : public CJob
53 public:
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);
70 std::string m_url;
71 std::string m_oldHash;
72 CTextureDetails m_details;
73 private:
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,
103 unsigned int width,
104 unsigned int height,
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
115 public:
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;
122 private:
123 std::vector<CTextureDetails> m_textures;