X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fpixelstore.cpp;fp=source%2Fpixelstore.cpp;h=c32cf60964a30b43cf7946782fa2c5943231e710;hb=055f553b1a75f44e72f3c2b5a1c98c1e1e8f3f30;hp=0000000000000000000000000000000000000000;hpb=a533f857e7d319c6eff2b788bbad3a238468c4b2;p=libs%2Fgl.git diff --git a/source/pixelstore.cpp b/source/pixelstore.cpp new file mode 100644 index 00000000..c32cf609 --- /dev/null +++ b/source/pixelstore.cpp @@ -0,0 +1,62 @@ +#include +#include "gl.h" +#include "pixelformat.h" +#include "pixelstore.h" + +using namespace std; + +namespace Msp { +namespace GL { + +PixelStore::PixelStore(): + row_length(0), + image_height(0), + skip_pixels(0), + skip_rows(0), + skip_images(0), + alignment(4) +{ } + +PixelStore PixelStore::from_image(const Graphics::Image &img) +{ + PixelStore pstore; + unsigned stride = img.get_stride(); + unsigned ncomp = get_component_count(pixelformat_from_graphics(img.get_format())); + pstore.set_canvas_size(img.get_stride()/ncomp, 0); + pstore.set_alignment(min(stride&~(stride-1), 8U)); + return pstore; +} + +void PixelStore::set_canvas_size(unsigned w, unsigned h) +{ + row_length = w; + image_height = h; +} + +void PixelStore::set_origin(unsigned x, unsigned y, unsigned z) +{ + skip_pixels = x; + skip_rows = y; + skip_images = z; +} + +void PixelStore::set_alignment(unsigned a) +{ + alignment = a; +} + +void PixelStore::bind() const +{ + if(set_current(this)) + { + glPixelStorei(GL_UNPACK_ROW_LENGTH, row_length); + glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, image_height); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, skip_pixels); + glPixelStorei(GL_UNPACK_SKIP_ROWS, skip_rows); + glPixelStorei(GL_UNPACK_SKIP_IMAGES, skip_images); + glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); + } +} + +} // namespace GL +} // namespace Msp