mirror of https://github.com/adamdruppe/arsd.git
experimental direct image access
This commit is contained in:
parent
bdf89ec6d1
commit
84832e6f86
|
@ -112,7 +112,7 @@ struct Pen {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class Image {
|
final class Image {
|
||||||
this(int width, int height) {
|
this(int width, int height) {
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
|
@ -128,7 +128,7 @@ class Image {
|
||||||
impl.dispose();
|
impl.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
void putPixel(int x, int y, Color c) {
|
final void putPixel(int x, int y, Color c) {
|
||||||
if(x < 0 || x >= width)
|
if(x < 0 || x >= width)
|
||||||
return;
|
return;
|
||||||
if(y < 0 || y >= height)
|
if(y < 0 || y >= height)
|
||||||
|
@ -137,7 +137,7 @@ class Image {
|
||||||
impl.setPixel(x, y, c);
|
impl.setPixel(x, y, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
void opIndexAssign(Color c, int x, int y) {
|
final void opIndexAssign(Color c, int x, int y) {
|
||||||
putPixel(x, y, c);
|
putPixel(x, y, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,6 +150,39 @@ class Image {
|
||||||
return where;
|
return where;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: make properly cross platform by getting rgba right
|
||||||
|
|
||||||
|
/// warning: this is not portable across platforms because the data format can change
|
||||||
|
ubyte* getDataPointer() {
|
||||||
|
return impl.rawData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// for use with getDataPointer
|
||||||
|
final int bytesPerLine() const pure @safe nothrow {
|
||||||
|
version(Windows)
|
||||||
|
return ((cast(int) width * 3 + 3) / 4) * 4;
|
||||||
|
else version(X11)
|
||||||
|
return 4 * width;
|
||||||
|
else version(OSXCocoa)
|
||||||
|
return 4 * width;
|
||||||
|
else version(html5)
|
||||||
|
return 4 * width;
|
||||||
|
else static assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// for use with getDataPointer
|
||||||
|
final int bytesPerPixel() const pure @safe nothrow {
|
||||||
|
version(Windows)
|
||||||
|
return 3;
|
||||||
|
else version(X11)
|
||||||
|
return 4;
|
||||||
|
else version(OSXCocoa)
|
||||||
|
return 4;
|
||||||
|
else version(html5)
|
||||||
|
return 4;
|
||||||
|
else static assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
immutable int width;
|
immutable int width;
|
||||||
immutable int height;
|
immutable int height;
|
||||||
private:
|
private:
|
||||||
|
@ -320,7 +353,7 @@ class Sprite {
|
||||||
infoheader.bmiHeader.biBitCount = 24;
|
infoheader.bmiHeader.biBitCount = 24;
|
||||||
infoheader.bmiHeader.biCompression = BI_RGB;
|
infoheader.bmiHeader.biCompression = BI_RGB;
|
||||||
|
|
||||||
byte* rawData;
|
ubyte* rawData;
|
||||||
|
|
||||||
// FIXME: this should prolly be a device dependent bitmap...
|
// FIXME: this should prolly be a device dependent bitmap...
|
||||||
handle = enforce(CreateDIBSection(
|
handle = enforce(CreateDIBSection(
|
||||||
|
@ -937,7 +970,7 @@ version(Windows) {
|
||||||
|
|
||||||
mixin template NativeImageImplementation() {
|
mixin template NativeImageImplementation() {
|
||||||
HBITMAP handle;
|
HBITMAP handle;
|
||||||
byte* rawData;
|
ubyte* rawData;
|
||||||
|
|
||||||
void setPixel(int x, int y, Color c) {
|
void setPixel(int x, int y, Color c) {
|
||||||
auto itemsPerLine = ((cast(int) width * 3 + 3) / 4) * 4;
|
auto itemsPerLine = ((cast(int) width * 3 + 3) / 4) * 4;
|
||||||
|
@ -1198,14 +1231,14 @@ version(X11) {
|
||||||
|
|
||||||
mixin template NativeImageImplementation() {
|
mixin template NativeImageImplementation() {
|
||||||
XImage* handle;
|
XImage* handle;
|
||||||
byte* rawData;
|
ubyte* rawData;
|
||||||
|
|
||||||
void createImage(int width, int height) {
|
void createImage(int width, int height) {
|
||||||
auto display = XDisplayConnection.get();
|
auto display = XDisplayConnection.get();
|
||||||
auto screen = DefaultScreen(display);
|
auto screen = DefaultScreen(display);
|
||||||
|
|
||||||
// This actually needs to be malloc to avoid a double free error when XDestroyImage is called
|
// This actually needs to be malloc to avoid a double free error when XDestroyImage is called
|
||||||
rawData = cast(byte*) malloc(width * height * 4);
|
rawData = cast(ubyte*) malloc(width * height * 4);
|
||||||
|
|
||||||
handle = XCreateImage(
|
handle = XCreateImage(
|
||||||
display,
|
display,
|
||||||
|
@ -1807,7 +1840,7 @@ XImage *XCreateImage(
|
||||||
uint /* depth */,
|
uint /* depth */,
|
||||||
int /* format */,
|
int /* format */,
|
||||||
int /* offset */,
|
int /* offset */,
|
||||||
byte* /* data */,
|
ubyte* /* data */,
|
||||||
uint /* width */,
|
uint /* width */,
|
||||||
uint /* height */,
|
uint /* height */,
|
||||||
int /* bitmap_pad */,
|
int /* bitmap_pad */,
|
||||||
|
|
Loading…
Reference in New Issue