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
/*
   Copyright (c) 2016 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 setData(U8* data, U32 len) {
        _data.assign(data, data + len);
    }

    inline void setData(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_uint(_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
    vec4<U8> 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;

    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
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 Diff Diff IonutCava picture IonutCava Thu 25 Feb, 2016 17:13:10 +0000

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

651 Diff Diff IonutCava picture IonutCava Wed 24 Feb, 2016 16:54:46 +0000

[IonutCava]
- Improved component access speed
- Added update flags to SceneNodes
— Currently used to flag bounding box update
- SceneNode bounds are only updated in the sceneUpdate call. BOUNDS_CHANGED flag can be set at any time.
- Changed SceneNode->SceneGraphNode BB update system to use the new SceneNode flag system
- Added initial code for compressed texture support (formats, containers, etc)
- Added STB libraries for future use

648 Diff Diff IonutCava picture IonutCava Sun 21 Feb, 2016 16:32:52 +0000

[IonutCava]
- Update copyright notice
- Move BoundingBox and BoundingSphere to a new BoundsComponent
— Add a temp hack in SceneGraphNode to update these

604 Diff Diff IonutCava picture IonutCava Sun 13 Dec, 2015 19:04:57 +0000

[IonutCava]
- New post processing system:
— Simplified operators
— PostFX is always enabled. Individual operators are toggles on or off
— Fixed Bloom and adaptive exposure
- Reworked texture creation and resizing
— Saved TextureDescriptor as part of the texture state

542 Diff Diff IonutCava picture IonutCava Thu 29 Oct, 2015 23:44:59 +0000

[IonutCava]
- Improved multi-threaded culling
- Increased nodeBuffer size to avoid different render stages to override each-other’s data and wait for locks
- Added a indirect command buffer per render stage

457 Diff Diff IonutCava picture IonutCava Mon 01 Jun, 2015 21:45:52 +0000

[Ionut]
- Windows build fix for previous commit

405 IonutCava picture IonutCava Mon 20 Apr, 2015 15:57:24 +0000

[Ionut]
- Moved SceneAnimator instances from the SkinnedSubMesh instance to the parent Mesh instance (if it has the SKINNING flag)
— Will allow a single bone buffer per mesh (instead of one per submesh) and better syncing of playback times
- Cleaned the SceneAnimator class a bit:
— Removed the hashmaps that were put in place to speed up bone lookup as the bone count is low and a find_if in a vector of bones isn’t a bottleneck. Reduces memory consumption as well.
— Moving the SceneAnimator class allowed parsing of all available ASSIMP meshes at once in a tight loop.
- Modified texture loading a bit for better compatibility.