2 * Copyright (c) 2021 - 2022 Samsung Electronics Co., Ltd. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 #include "tvgLoader.h"
25 #include "tvgJpgLoader.h"
27 /************************************************************************/
28 /* Internal Class Implementation */
29 /************************************************************************/
31 void JpgLoader::clear()
34 if (freeData) free(data);
41 /************************************************************************/
42 /* External Class Implementation */
43 /************************************************************************/
46 JpgLoader::~JpgLoader()
49 if (freeData) free(data);
54 bool JpgLoader::open(const string& path)
59 decoder = jpgdHeader(path.c_str(), &width, &height);
60 if (!decoder) return false;
62 w = static_cast<float>(width);
63 h = static_cast<float>(height);
69 bool JpgLoader::open(const char* data, uint32_t size, bool copy)
74 this->data = (char *) malloc(size);
75 if (!this->data) return false;
76 memcpy((char *)this->data, data, size);
79 this->data = (char *) data;
84 decoder = jpgdHeader(this->data, size, &width, &height);
85 if (!decoder) return false;
87 w = static_cast<float>(width);
88 h = static_cast<float>(height);
95 bool JpgLoader::read()
97 if (!decoder || w <= 0 || h <= 0) return false;
99 TaskScheduler::request(this);
105 bool JpgLoader::close()
113 unique_ptr<Surface> JpgLoader::bitmap()
117 if (!image) return nullptr;
119 auto surface = static_cast<Surface*>(malloc(sizeof(Surface)));
120 surface->buffer = (uint32_t*)(image);
124 surface->cs = SwCanvas::ARGB8888;
126 return unique_ptr<Surface>(surface);
130 void JpgLoader::run(unsigned tid)
136 image = jpgdDecompress(decoder);