Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
   Copyright (c) 2018 DIVIDE-Studio
   Copyright (c) 2009 Ionut Cava

   This file is part of DIVIDE Framework.

   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software
   and associated documentation files (the "Software"), to deal in the Software
   without restriction,
   including without limitation the rights to use, copy, modify, merge, publish,
   distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so,
   subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED,
   INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
   PARTICULAR PURPOSE AND NONINFRINGEMENT.
   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
   DAMAGES OR OTHER LIABILITY,
   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
   IN CONNECTION WITH THE SOFTWARE
   OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 */

#ifndef _UTILITY_IMAGETOOLS_H
#define _UTILITY_IMAGETOOLS_H

#include "Core/Math/Headers/MathVectors.h"
#include "Core/Headers/NonCopyable.h"
#include <mutex>

namespace Divide {
enum class GFXImageFormat : U32;
enum class TextureType : U32;

namespace ImageTools {

class ImageLayer {
   public:
    ImageLayer() : _size(0)
    {
        _dimensions.set(0, 0, 1);
    }

    inline void writeData(U8* data, U32 len) {
        _data.assign(data, data + len);
    }

    inline void writeData(F32* data, U32 len) {
        _dataf.assign(data, data + len);
    }
    /// the image data as it was read from the file / memory.
    size_t _size;
    vectorImpl<U8> _data;
    vectorImpl<F32> _dataf;
    /// with and height
    vec3<U16> _dimensions;
};

class ImageData : private NonCopyable {
   public:
     ImageData();
    ~ImageData();

    /// image origin information
    inline void flip(bool state) { _flip = state; }
    inline bool flip() const { return _flip; }
    /// set and get the image's actual data 
    inline const bufferPtr data(U32 mipLevel = 0) const { 
        bufferPtr data = nullptr;
        if (mipLevel < mipCount()) {
            // triple data-ception
            data = (bufferPtr)_data[mipLevel]._data.data();
        }

        return data;
    }

    inline const vectorImpl<ImageLayer>& imageLayers() const {
        return _data;
    }
    /// image width, height and depth
    inline const vec3<U16>& dimensions(U32 mipLevel = 0) const { 
        assert(mipLevel < mipCount());

        return _data[mipLevel]._dimensions;
    }
    /// set and get the image's compression state
    inline bool compressed() const { return _compressed; }
    /// get the number of pre-loaded mip maps
    inline U32 mipCount() const { return to_U32(_data.size()); }
    /// image transparency information
    inline bool alpha() const { return _alpha; }
    /// image depth information
    inline U8 bpp() const { return _bpp; }
    /// the filename from which the image is created
    inline const stringImpl& name() const { return _name; }
    /// the image format as given by STB/NV_DDS
    inline GFXImageFormat format() const { return _format; }
    /// get the texel colour at the specified offset from the origin
    UColour getColour(I32 x, I32 y, U32 mipLevel = 0) const;
    void getColour(I32 x, I32 y, U8& r, U8& g, U8& b, U8& a, U32 mipLevel = 0) const;

    void getRed(I32 x, I32 y, U8& r, U32 mipLevel = 0) const;
    void getGreen(I32 x, I32 y, U8& g, U32 mipLevel = 0) const;
    void getBlue(I32 x, I32 y, U8& b, U32 mipLevel = 0) const;
    void getAlpha(I32 x, I32 y, U8& a, U32 mipLevel = 0) const;

    inline TextureType compressedTextureType() const {
        return _compressedTextureType;
    }

  protected:
    friend class ImageDataInterface;
    /// creates this image instance from the specified data
    bool create(const stringImpl& fileName);
    bool loadDDS_IL(const stringImpl& filename);
    bool loadDDS_NV(const stringImpl& filename);

   private:
    //Each entry is a separate mip map.
    vectorImpl<ImageLayer> _data;
    /// is the image stored as a regular image or in a compressed format? (eg. DXT1 / DXT3 / DXT5)
    bool _compressed;
    /// should we flip the image's origin on load?
    bool _flip;
    /// does the image have transparency?
    bool _alpha;
    /// the image format
    GFXImageFormat _format;
    /// used by compressed images to load 2D/3D/cubemap textures etc
    TextureType _compressedTextureType;
    /// the actual image filename
    stringImpl _name;
    /// image's bits per pixel
    U8 _bpp;
};

class ImageDataInterface {
public:
    static void CreateImageData(const stringImpl& filename, ImageData& imgOut);
private:
    /// used to lock image loader in a sequential operating mode in a multithreaded environment
    static std::mutex _loadingMutex;
};

/// save a single file to TGA
I8 SaveToTGA(const stringImpl& filename, const vec2<U16>& dimensions, U8 pixelDepth,
    U8* imageData);
/// save a single file to tga using a sequential naming pattern
I8 SaveSeries(const stringImpl& filename, const vec2<U16>& dimensions, U8 pixelDepth,
    U8* imageData);

};  // namespace ImageTools
};  // namespace Divide

#endif

Commits for Divide-Framework/trunk/Source Code/Utility/Headers/ImageTools.h

Diff revisions: vs.
Revision Author Commited Message
1029 Diff Diff IonutCava picture IonutCava Tue 30 Jan, 2018 17:28:39 +0000

[Ionut]
- Update copyright notices

1004 Diff Diff IonutCava picture IonutCava Wed 20 Dec, 2017 17:16:32 +0000

[Ionut]
- More GUI cleanup (added multiple GUIButton events)
- Typedef vec4<U8> and vec4<F32> to UColour and FColour respectively for easier to read code.

905 Diff Diff IonutCava picture IonutCava Mon 26 Jun, 2017 15:56:21 +0000

[Ionut]
Untested code

- Rework RenderBin/RenderPass/RenderQueue system to allow per-bin type rendering decision
— Added to allow implementation of Weighted, Blended Order-Independent Transparency later on
- Better detection of transparency and translucency in textures and materials. Used to separate Alpha-Discard based geometry from OIT translucent geometry

895 Diff Diff IonutCava picture IonutCava Wed 21 Jun, 2017 21:10:26 +0000

[IonutCava]
- Reorder and cleanup OpenGL backend a bit.
- Small code cleanup
- Some small profile-guided optimizations

867 Diff Diff IonutCava picture IonutCava Mon 20 Feb, 2017 17:01:12 +0000

[IonutCava]
- Rename to_XNN and to_const_XNN functions to reflect the target data type they are converting to.
- Cleanup Angle namespace and remove all “inDegrees” parameters from rotation functions. Use aliases to differentiate between Degree and Radian parameters.
- Profile guided optimizations.

836 Diff Diff IonutCava picture IonutCava Fri 27 Jan, 2017 14:59:56 +0000

[IonutCava]
- Update copyright notice

832 Diff Diff IonutCava picture IonutCava Thu 26 Jan, 2017 17:23:11 +0000

[IonutCava]
- More path related work
- Initial code to centralize file I/O (does not compile yet)

759 Diff Diff IonutCava picture IonutCava Sun 07 Aug, 2016 18:34:32 +0000

[IonutCava]
- Add workaround for singlethreaded texture loading
- Small corrections to ImageTools image loading

721 Diff Diff IonutCava picture IonutCava Wed 08 Jun, 2016 15:47:49 +0000

[IonutCava]
- Spelling: change all references from our code of “color” to the PROPER British version of “colour” because it sounds 100x better

652 IonutCava picture IonutCava Thu 25 Feb, 2016 17:13:10 +0000

[IonutCava]
- More work on compressed texture loading (DXT1, DXT3, DXT5)