12 |
// |
// |
13 |
// $Id$ |
// $Id$ |
14 |
// $Log$ |
// $Log$ |
15 |
|
// Revision 1.3 2004/12/26 08:03:34 skunix |
16 |
|
// changed lambda::bind's to boost::binds |
17 |
|
// |
18 |
// Revision 1.2 2004/12/26 02:29:33 skunix |
// Revision 1.2 2004/12/26 02:29:33 skunix |
19 |
// Texture manager basics written, and texture-meta-parser added |
// Texture manager basics written, and texture-meta-parser added |
20 |
// |
// |
22 |
// started texture-related classes |
// started texture-related classes |
23 |
// |
// |
24 |
|
|
25 |
|
#include <boost/scoped_array.hpp> |
26 |
|
|
27 |
#include <GL/gl.h> |
#include <iostream> |
28 |
#include <GL/glu.h> |
#include <GL/glew.h> |
|
|
|
29 |
#include "texture.hpp" |
#include "texture.hpp" |
30 |
#include "texture-meta.hpp" |
#include "texture-meta.hpp" |
|
|
|
31 |
#include <Magick++.h> |
#include <Magick++.h> |
32 |
|
|
33 |
namespace usata |
namespace usata |
34 |
{ |
{ |
35 |
|
|
36 |
TextureMeta::TextureMeta(const std::string& fn) |
|
37 |
: filename(fn) |
namespace |
38 |
{ |
{ |
39 |
|
|
40 |
|
struct PixmapType |
41 |
|
{ |
42 |
|
|
43 |
}; |
}; |
44 |
|
|
45 |
|
class Pixmap |
46 |
|
{ |
47 |
|
unsigned Width; |
48 |
|
unsigned Height; |
49 |
|
unsigned Depth; |
50 |
|
std::string Format; |
51 |
|
boost::scoped_array<unsigned char> pixels; |
52 |
|
|
53 |
|
public: |
54 |
|
Pixmap(unsigned, unsigned, unsigned char, std::string &type); |
55 |
|
unsigned width() const { return Width; } |
56 |
|
unsigned height() const { return Height; } |
57 |
|
const std::string& |
58 |
|
format() const {return Format;} |
59 |
|
unsigned char*get_pixels(){ return pixels.get();} |
60 |
|
}; |
61 |
|
|
62 |
|
} |
63 |
|
Pixmap::Pixmap(unsigned w, unsigned h, unsigned char d, std::string &type) |
64 |
|
: Width(w), |
65 |
|
Height(h), |
66 |
|
Format(type), |
67 |
|
pixels( new unsigned char[w*h*(d/8)]) |
68 |
|
{ |
69 |
|
|
70 |
|
} |
71 |
|
|
72 |
|
|
73 |
|
TextureMeta::TextureMeta(const boost::filesystem::path& p) |
74 |
|
: filepath(p) |
75 |
|
{ |
76 |
|
|
77 |
|
} |
78 |
Texture::Texture (const TextureMeta* meta) |
Texture::Texture (const TextureMeta* meta) |
79 |
{ |
{ |
80 |
|
Magick::Image XI(meta->filepath.native_file_string()); |
81 |
|
std::cout << XI.columns() << "x" <<XI.rows() <<std::endl; |
82 |
|
Magick::ImageType image_type = XI.type(); |
83 |
|
unsigned Depth; |
84 |
|
std::string Type; |
85 |
|
switch (image_type) |
86 |
|
{ |
87 |
|
case Magick::TrueColorType: |
88 |
|
case Magick::PaletteType: |
89 |
|
{ |
90 |
|
Type="RGB"; |
91 |
|
Depth = 24; |
92 |
|
break; |
93 |
|
} |
94 |
|
|
95 |
|
case Magick::TrueColorMatteType: |
96 |
|
case Magick::PaletteMatteType: |
97 |
|
{ |
98 |
|
Type="RGBA"; |
99 |
|
Depth = 32; |
100 |
|
break; |
101 |
|
} |
102 |
|
|
103 |
|
case Magick::GrayscaleType: |
104 |
|
{ |
105 |
|
std::cout << "Grey" << std::endl; |
106 |
|
return; |
107 |
|
} |
108 |
|
|
109 |
|
default: |
110 |
|
{ |
111 |
|
throw std::runtime_error("Unsupported image pixel layout"); |
112 |
|
} |
113 |
|
|
114 |
|
} |
115 |
|
|
116 |
|
Pixmap pb(XI.columns(),XI.rows(),Depth,Type); |
117 |
|
XI.write(0,0,pb.width(), pb.height(), pb.format(),Magick::CharPixel,pb.get_pixels()); |
118 |
|
|
119 |
|
|
120 |
|
|
121 |
return; |
return; |
122 |
} |
} |
123 |
|
|
124 |
|
Texture::~Texture() |
125 |
|
{ |
126 |
|
} |
127 |
|
|
128 |
} |
} |