source: trunk/src/image/codec/dummy-image.cpp @ 955

Last change on this file since 955 was 955, checked in by sam, 11 years ago

core: implement dynamic registration of image loaders.

  • Property svn:keywords set to Id
File size: 1.4 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include <cmath>
16
17#include "core.h"
18#include "image/image-private.h"
19
20using namespace std;
21
22namespace lol
23{
24
25/*
26 * Image implementation class
27 */
28
29DECLARE_IMAGE_LOADER(DummyImageData, 0)
30{
31public:
32    virtual bool Open(char const *);
33    virtual bool Close();
34
35    virtual void *GetData() const;
36
37private:
38    uint8_t *pixels;
39};
40
41/*
42 * Public Image class
43 */
44
45bool DummyImageData::Open(char const *path)
46{
47    size = 256;
48    format = Image::FORMAT_RGBA;
49    pixels = (uint8_t *)malloc(256 * 256 * 4 * sizeof(*pixels));
50    uint8_t *parser = pixels;
51    for (int j = 0; j < 256; j++)
52        for (int i = 0; i < 256; i++)
53        {
54            *parser++ = ((i ^ j) & 1) * 0xff;
55            *parser++ = (uint8_t)i;
56            *parser++ = (uint8_t)j;
57            *parser++ = (((i >> 4) ^ (j >> 4)) & 1) * 0xff;
58        }
59
60    return true;
61}
62
63bool DummyImageData::Close()
64{
65    free(pixels);
66
67    return true;
68}
69
70void * DummyImageData::GetData() const
71{
72    return pixels;
73}
74
75} /* namespace lol */
76
Note: See TracBrowser for help on using the repository browser.