aboutsummaryrefslogtreecommitdiff
path: root/dep/g3dlite/source/Image1.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'dep/g3dlite/source/Image1.cpp')
-rw-r--r--dep/g3dlite/source/Image1.cpp123
1 files changed, 56 insertions, 67 deletions
diff --git a/dep/g3dlite/source/Image1.cpp b/dep/g3dlite/source/Image1.cpp
index a61f7faa633..ed125adad18 100644
--- a/dep/g3dlite/source/Image1.cpp
+++ b/dep/g3dlite/source/Image1.cpp
@@ -1,21 +1,23 @@
/**
- @file Image1.cpp
+ \file G3D/Image1.cpp
- @maintainer Morgan McGuire, http://graphics.cs.williams.edu
+ \maintainer Morgan McGuire, http://graphics.cs.williams.edu
- @created 2007-01-31
- @edited 2007-01-31
+ \created 2007-01-31
+ \edited 2012-12-25
*/
#include "G3D/Image1.h"
-#include "G3D/Image1uint8.h"
-#include "G3D/GImage.h"
+#include "G3D/Image1unorm8.h"
+#include "G3D/Image.h"
#include "G3D/Color4.h"
-#include "G3D/Color4uint8.h"
+#include "G3D/Color4unorm8.h"
#include "G3D/Color1.h"
-#include "G3D/Color1uint8.h"
+#include "G3D/Color1unorm8.h"
#include "G3D/ImageFormat.h"
+#include "G3D/PixelTransferBuffer.h"
+#include "G3D/CPUPixelTransferBuffer.h"
namespace G3D {
@@ -24,30 +26,12 @@ Image1::Image1(int w, int h, WrapMode wrap) : Map2D<Color1, Color1>(w, h, wrap)
}
-Image1::Ref Image1::fromGImage(const GImage& im, WrapMode wrap) {
- switch (im.channels()) {
- case 1:
- return fromArray(im.pixel1(), im.width(), im.height(), wrap);
-
- case 3:
- return fromArray(im.pixel3(), im.width(), im.height(), wrap);
-
- case 4:
- return fromArray(im.pixel4(), im.width(), im.height(), wrap);
-
- default:
- debugAssertM(false, "Input GImage must have 1, 3, or 4 channels.");
- return NULL;
- }
-}
-
-
-Image1::Ref Image1::fromImage1uint8(const ReferenceCountedPointer<Image1uint8>& im) {
+Image1::Ref Image1::fromImage1unorm8(const shared_ptr<Image1unorm8>& im) {
Ref out = createEmpty(static_cast<WrapMode>(im->wrapMode()));
out->resize(im->width(), im->height());
int N = im->width() * im->height();
- const Color1uint8* src = reinterpret_cast<Color1uint8*>(im->getCArray());
+ const Color1unorm8* src = reinterpret_cast<Color1unorm8*>(im->getCArray());
for (int i = 0; i < N; ++i) {
out->data[i] = Color1(src[i]);
}
@@ -57,7 +41,7 @@ Image1::Ref Image1::fromImage1uint8(const ReferenceCountedPointer<Image1uint8>&
Image1::Ref Image1::createEmpty(int width, int height, WrapMode wrap) {
- return new Type(width, height, wrap);
+ return Image1::Ref(new Type(width, height, wrap));
}
@@ -66,20 +50,49 @@ Image1::Ref Image1::createEmpty(WrapMode wrap) {
}
-Image1::Ref Image1::fromFile(const std::string& filename, WrapMode wrap, GImage::Format fmt) {
+Image1::Ref Image1::fromFile(const std::string& filename, WrapMode wrap) {
Ref out = createEmpty(wrap);
- out->load(filename, fmt);
+ out->load(filename);
return out;
}
-void Image1::load(const std::string& filename, GImage::Format fmt) {
- copyGImage(GImage(filename, fmt));
+void Image1::load(const std::string& filename) {
+ shared_ptr<Image> image = Image::fromFile(filename);
+ if (image->format() != ImageFormat::L32F()) {
+ image->convertToL8();
+ }
+
+ switch (image->format()->code)
+ {
+ case ImageFormat::CODE_L8:
+ copyArray(static_cast<const Color1unorm8*>(image->toPixelTransferBuffer()->buffer()), image->width(), image->height());
+ break;
+ case ImageFormat::CODE_L32F:
+ copyArray(static_cast<const Color1*>(image->toPixelTransferBuffer()->buffer()), image->width(), image->height());
+ break;
+ case ImageFormat::CODE_RGB8:
+ copyArray(static_cast<const Color3unorm8*>(image->toPixelTransferBuffer()->buffer()), image->width(), image->height());
+ break;
+ case ImageFormat::CODE_RGB32F:
+ copyArray(static_cast<const Color3*>(image->toPixelTransferBuffer()->buffer()), image->width(), image->height());
+ break;
+ case ImageFormat::CODE_RGBA8:
+ copyArray(static_cast<const Color4unorm8*>(image->toPixelTransferBuffer()->buffer()), image->width(), image->height());
+ break;
+ case ImageFormat::CODE_RGBA32F:
+ copyArray(static_cast<const Color4*>(image->toPixelTransferBuffer()->buffer()), image->width(), image->height());
+ break;
+ default:
+ debugAssertM(false, "Trying to load unsupported image format");
+ break;
+ }
+
setChanged(true);
}
-Image1::Ref Image1::fromArray(const class Color3uint8* ptr, int w, int h, WrapMode wrap) {
+Image1::Ref Image1::fromArray(const class Color3unorm8* ptr, int w, int h, WrapMode wrap) {
Ref out = createEmpty(wrap);
out->copyArray(ptr, w, h);
return out;
@@ -93,7 +106,7 @@ Image1::Ref Image1::fromArray(const class Color1* ptr, int w, int h, WrapMode wr
}
-Image1::Ref Image1::fromArray(const class Color1uint8* ptr, int w, int h, WrapMode wrap) {
+Image1::Ref Image1::fromArray(const class Color1unorm8* ptr, int w, int h, WrapMode wrap) {
Ref out = createEmpty(wrap);
out->copyArray(ptr, w, h);
return out;
@@ -107,7 +120,7 @@ Image1::Ref Image1::fromArray(const class Color3* ptr, int w, int h, WrapMode wr
}
-Image1::Ref Image1::fromArray(const class Color4uint8* ptr, int w, int h, WrapMode wrap) {
+Image1::Ref Image1::fromArray(const class Color4unorm8* ptr, int w, int h, WrapMode wrap) {
Ref out = createEmpty(wrap);
out->copyArray(ptr, w, h);
return out;
@@ -120,24 +133,7 @@ Image1::Ref Image1::fromArray(const class Color4* ptr, int w, int h, WrapMode wr
return out;
}
-void Image1::copyGImage(const GImage& im) {
- switch (im.channels()) {
- case 1:
- copyArray(im.pixel1(), im.width(), im.height());
- break;
-
- case 3:
- copyArray(im.pixel3(), im.width(), im.height());
- break;
-
- case 4:
- copyArray(im.pixel4(), im.width(), im.height());
- break;
- }
-}
-
-
-void Image1::copyArray(const Color3uint8* src, int w, int h) {
+void Image1::copyArray(const Color3unorm8* src, int w, int h) {
resize(w, h);
int N = w * h;
@@ -149,7 +145,7 @@ void Image1::copyArray(const Color3uint8* src, int w, int h) {
}
-void Image1::copyArray(const Color4uint8* src, int w, int h) {
+void Image1::copyArray(const Color4unorm8* src, int w, int h) {
resize(w, h);
int N = w * h;
@@ -181,7 +177,7 @@ void Image1::copyArray(const Color4* src, int w, int h) {
}
-void Image1::copyArray(const Color1uint8* src, int w, int h) {
+void Image1::copyArray(const Color1unorm8* src, int w, int h) {
resize(w, h);
int N = w * h;
@@ -203,17 +199,10 @@ void Image1::copyArray(const Color3* src, int w, int h) {
}
-/** Saves in any of the formats supported by G3D::GImage. */
-void Image1::save(const std::string& filename, GImage::Format fmt) {
- GImage im(width(), height(), 1);
-
- int N = im.width() * im.height();
- Color1uint8* dst = im.pixel1();
- for (int i = 0; i < N; ++i) {
- dst[i] = Color1uint8(data[i]);
- }
-
- im.save(filename, fmt);
+void Image1::save(const std::string& filename) {
+ // To avoid saving as floating point image. FreeImage cannot convert floating point to L8.
+ Image1unorm8::Ref unorm8 = Image1unorm8::fromImage1(dynamic_pointer_cast<Image1>(shared_from_this()));
+ unorm8->save(filename);
}