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

Last change on this file since 2183 was 2183, checked in by sam, 7 years ago

build: fix the WTFPL site URL in all code comments.

  • Property svn:keywords set to Id
File size: 1.3 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://www.wtfpl.net/ for more details.
9//
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include "core.h"
16#include "../../image/image-private.h"
17
18using namespace std;
19
20namespace lol
21{
22
23/*
24 * Image implementation class
25 */
26
27DECLARE_IMAGE_LOADER(DummyImageData, 0)
28{
29public:
30    virtual bool Open(char const *);
31    virtual bool Close();
32
33    virtual void *GetData() const;
34
35private:
36    uint8_t *pixels;
37};
38
39/*
40 * Public Image class
41 */
42
43bool DummyImageData::Open(char const *path)
44{
45    size = ivec2(256);
46    format = Image::FORMAT_RGBA;
47    pixels = (uint8_t *)malloc(256 * 256 * 4 * sizeof(*pixels));
48    uint8_t *parser = pixels;
49    for (int j = 0; j < 256; j++)
50        for (int i = 0; i < 256; i++)
51        {
52            *parser++ = ((i ^ j) & 1) * 0xff;
53            *parser++ = (uint8_t)i;
54            *parser++ = (uint8_t)j;
55            *parser++ = (((i >> 4) ^ (j >> 4)) & 1) * 0xff;
56        }
57
58    return true;
59}
60
61bool DummyImageData::Close()
62{
63    free(pixels);
64
65    return true;
66}
67
68void * DummyImageData::GetData() const
69{
70    return pixels;
71}
72
73} /* namespace lol */
74
Note: See TracBrowser for help on using the repository browser.