Subversion Repositories tpanel

Rev

Rev 361 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 361 Rev 365
Line 22... Line 22...
22
#include <include/core/SkImageGenerator.h>
22
#include <include/core/SkImageGenerator.h>
23
#include <include/core/SkStream.h>
23
#include <include/core/SkStream.h>
24
#include <include/core/SkFont.h>
24
#include <include/core/SkFont.h>
25
#include <include/core/SkTypeface.h>
25
#include <include/core/SkTypeface.h>
26
#include <include/core/SkColorSpace.h>
26
#include <include/core/SkColorSpace.h>
-
 
27
#include <include/codec/SkCodec.h>
27
 
28
 
28
#include <iconv.h>
29
#include <iconv.h>
29
#include <libgen.h>
30
#include <libgen.h>
30
 
31
 
31
#include <sys/types.h>
32
#include <sys/types.h>
Line 230... Line 231...
230
    return SkString(path);
231
    return SkString(path);
231
}
232
}
232
 
233
 
233
bool DecodeDataToBitmap(sk_sp<SkData> data, SkBitmap* dst)
234
bool DecodeDataToBitmap(sk_sp<SkData> data, SkBitmap* dst)
234
{
235
{
-
 
236
    DECL_TRACER("DecodeDataToBitmap(sk_sp<SkData> data, SkBitmap* dst)");
-
 
237
 
235
    if (!data || !dst)
238
    if (!data || !dst)
236
        return false;
239
        return false;
237
 
240
 
238
    std::unique_ptr<SkImageGenerator> gen(SkImageGenerator::MakeFromEncoded(std::move(data)));
241
//    std::unique_ptr<SkImageGenerator> gen(SkImageGenerators::MakeFromEncoded(std::move(data)));
239
    return gen && dst->tryAllocPixels(gen->getInfo()) &&
242
//    return gen && dst->tryAllocPixels(gen->getInfo()) &&
240
            gen->getPixels(gen->getInfo().makeColorSpace(nullptr), dst->getPixels(), dst->rowBytes());
243
//           gen->getPixels(gen->getInfo().makeColorSpace(nullptr), dst->getPixels(), dst->rowBytes());
-
 
244
 
-
 
245
 
-
 
246
    std::unique_ptr<SkCodec> codec = SkCodec::MakeFromData(std::move(data));
-
 
247
 
-
 
248
    if (!codec)
-
 
249
        return false;
-
 
250
 
-
 
251
    SkImageInfo info = codec->getInfo();
-
 
252
 
-
 
253
    if(dst->tryAllocPixels(info))
-
 
254
    {
-
 
255
        if(codec->getPixels(info, dst->getPixels(), dst->rowBytes()) == SkCodec::kSuccess)
-
 
256
            return true;
-
 
257
    }
-
 
258
 
-
 
259
    return false;
241
}
260
}
242
 
261
 
243
std::unique_ptr<SkStreamAsset> GetResourceAsStream(const char* resource, _RESOURCE_TYPE rs)
262
std::unique_ptr<SkStreamAsset> GetResourceAsStream(const char* resource, _RESOURCE_TYPE rs)
244
{
263
{
245
    sk_sp<SkData> data = GetResourceAsData(resource, rs);
264
    sk_sp<SkData> data = GetResourceAsData(resource, rs);
Line 247... Line 266...
247
    : nullptr;
266
    : nullptr;
248
}
267
}
249
 
268
 
250
sk_sp<SkData> GetResourceAsData(const char* resource, _RESOURCE_TYPE rs)
269
sk_sp<SkData> GetResourceAsData(const char* resource, _RESOURCE_TYPE rs)
251
{
270
{
-
 
271
    DECL_TRACER("GetResourceAsData(const char* resource, _RESOURCE_TYPE rs)");
-
 
272
 
252
    SkString str = GetResourcePath(resource, rs);
273
    SkString str = GetResourcePath(resource, rs);
253
 
274
 
254
    sk_sp<SkData> data = SkData::MakeFromFileName(str.c_str());
275
    sk_sp<SkData> data = SkData::MakeFromFileName(str.c_str());
255
 
276
 
256
    if (data)
277
    if (data)
Line 273... Line 294...
273
 * Read the image from a file and save it into a data buffer. This is the base
294
 * Read the image from a file and save it into a data buffer. This is the base
274
 * to convert the image.
295
 * to convert the image.
275
 */
296
 */
276
sk_sp<SkData> readImage(const string& fname)
297
sk_sp<SkData> readImage(const string& fname)
277
{
298
{
-
 
299
    DECL_TRACER("readImage(const string& fname)");
-
 
300
 
278
    sk_sp<SkData> data = GetResourceAsData(fname.c_str());
301
    sk_sp<SkData> data = GetResourceAsData(fname.c_str());
279
 
302
 
280
    if (!data)
303
    if (!data)
281
    {
304
    {
282
        MSG_ERROR("readImage: Error loading the image " << fname);
305
        MSG_ERROR("readImage: Error loading the image " << fname);