本文整理汇总了C++中PixelBuffer::get_pitch方法的典型用法代码示例。如果您正苦于以下问题:C++ PixelBuffer::get_pitch方法的具体用法?C++ PixelBuffer::get_pitch怎么用?C++ PixelBuffer::get_pitch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PixelBuffer
的用法示例。
在下文中一共展示了PixelBuffer::get_pitch方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: draw_image
void SWRenderDisplayWindowProvider::draw_image(const Rect &dest, const PixelBuffer &image, const Rect &src)
{
XImage ximage;
memset(&ximage, 0, sizeof(ximage));
ximage.width = image.get_width();
ximage.height = image.get_height();
ximage.format = ZPixmap;
ximage.data = (char *) image.get_data();
ximage.byte_order = LSBFirst;
int image_pitch = image.get_pitch();
int image_bpp = image.get_bytes_per_pixel();
if (image_bpp == 1)
{
ximage.bitmap_unit = 8;
}
else if (image_bpp == 2)
{
ximage.bitmap_unit = 16;
}
else if (image_bpp == 3)
{
ximage.bitmap_unit = 24;
}
else ximage.bitmap_unit = 32;
ximage.bitmap_pad = ximage.bitmap_unit;
ximage.bitmap_bit_order = LSBFirst;
ximage.depth = 24;
ximage.bytes_per_line = image_pitch;
ximage.bits_per_pixel = image_bpp * 8;
ximage.red_mask = 0x00ff0000;
ximage.green_mask = 0x0000ff00;
ximage.blue_mask = 0x000000ff;
if (!XInitImage(&ximage))
{
throw Exception("Cannot initialise image");
}
GC xgc = XCreateGC(window.get_display(), window.get_window(), 0, NULL);
XPutImage(window.get_display(), window.get_window(), xgc, &ximage, src.left, src.top, dest.left, dest.top, src.get_width(), src.get_height());
XFreeGC(window.get_display(), xgc);
}
示例2: Exception
GameTerrain::GameTerrain(
GraphicContext &gc,
const std::string &heightmap_png,
const std::string &texture_png,
const std::string &areas_png,
const std::string &borders_png,
int area_count,
float vertical_scale)
: num_vertices(0)
{
color_areas = PNGProvider::load(areas_png).to_format(tf_r8);
PixelBuffer pb = PNGProvider::load(heightmap_png).to_format(tf_rgba8);
int width = pb.get_width()-1;
int height = pb.get_height()-1;
num_vertices = width*height*3*4 /*+ width*6*2 + height*6*2 + 6*/;
vertex_buffer = VertexArrayBuffer(gc, num_vertices*sizeof(Vertex));
vertex_buffer.lock(cl_access_write_only);
Vertex *vertex_data = reinterpret_cast<Vertex *>(vertex_buffer.get_data());
int pitch = pb.get_pitch();
unsigned char *data = reinterpret_cast<unsigned char *>(pb.get_data());
for (int y = 0; y < height; y++)
{
unsigned int *line1 = reinterpret_cast<unsigned int *>(data + y*pitch);
unsigned int *line2 = reinterpret_cast<unsigned int *>(data + (y+1)*pitch);
Vertex *vertex_line = vertex_data + 3*4*width*y;
for (int x = 0; x < width; x++)
{
float height1 = (line1[x] >> 24) * vertical_scale;
float height2 = (line1[x+1] >> 24) * vertical_scale;
float height3 = (line2[x] >> 24) * vertical_scale;
float height4 = (line2[x+1] >> 24) * vertical_scale;
float height5 = (height1 + height2 + height3 + height4) / 4.0f;
Vertex *vertex_quad = vertex_line + x*3*4;
Vec3f positions[12] =
{
Vec3f(x+0.0f, height1, y+0.0f),
Vec3f(x+1.0f, height2, y+0.0f),
Vec3f(x+0.5f, height5, y+0.5f),
Vec3f(x+1.0f, height2, y+0.0f),
Vec3f(x+1.0f, height4, y+1.0f),
Vec3f(x+0.5f, height5, y+0.5f),
Vec3f(x+1.0f, height4, y+1.0f),
Vec3f(x+0.0f, height3, y+1.0f),
Vec3f(x+0.5f, height5, y+0.5f),
Vec3f(x+0.0f, height3, y+1.0f),
Vec3f(x+0.0f, height1, y+0.0f),
Vec3f(x+0.5f, height5, y+0.5f)
};
for (int i = 0; i < 12; i++)
vertex_quad[i].position = positions[i];
Vec3f normal1 = calc_normal(x, y, data, width, height, pitch);
Vec3f normal2 = calc_normal(x+1, y, data, width, height, pitch);
Vec3f normal3 = calc_normal(x, y+1, data, width, height, pitch);
Vec3f normal4 = calc_normal(x+1, y+1, data, width, height, pitch);
Vec3f normal5 = (normal1+normal2+normal3+normal4)/4.0f;
vertex_quad[0].normal = normal1;
vertex_quad[1].normal = normal2;
vertex_quad[2].normal = normal5;
vertex_quad[3].normal = normal2;
vertex_quad[4].normal = normal4;
vertex_quad[5].normal = normal5;
vertex_quad[6].normal = normal4;
vertex_quad[7].normal = normal3;
vertex_quad[8].normal = normal5;
vertex_quad[9].normal = normal3;
vertex_quad[10].normal = normal1;
vertex_quad[11].normal = normal5;
}
}
vertex_data += width*height*3*4;
/*
for (int y = 0; y < height; y++)
{
unsigned int *line1 = reinterpret_cast<unsigned int *>(data + y*pitch);
unsigned int *line2 = reinterpret_cast<unsigned int *>(data + (y+1)*pitch);
float scale = 0.4f;
float height1 = (line1[0] >> 24)*scale;
float height2 = (line2[0] >> 24)*scale;
float height3 = (line1[width] >> 24)*scale;
float height4 = (line2[width] >> 24)*scale;
vertex_data[y*6*2+0].position = Vec3f(0, -0.1f, (float)y);
vertex_data[y*6*2+1].position = Vec3f(0, (float)height1, (float)y);
vertex_data[y*6*2+2].position = Vec3f(0, (float)height2, (float)y+1);
vertex_data[y*6*2+3].position = Vec3f(0, (float)height2, (float)y+1);
vertex_data[y*6*2+4].position = Vec3f(0, -0.1f, (float)y+1);
vertex_data[y*6*2+5].position = Vec3f(0, -0.1f, (float)y);
vertex_data[y*6*2+11].position = Vec3f((float)width+1, -0.1f, (float)y);
//.........这里部分代码省略.........
示例3: pitch
PerlinNoise_PixelWriter_RGB8(PixelBuffer &pbuff)
: pitch(pbuff.get_pitch()),
current_ptr((uint8_t *) pbuff.get_data()),
line_start_ptr(current_ptr)
{
}
示例4: state_tracker
void GL1TextureProvider::set_texture_image3d(
GLuint target,
PixelBuffer &image,
int image_depth,
int level)
{
throw_if_disposed();
GL1TextureStateTracker state_tracker(texture_type, handle);
GLint gl_internal_format;
GLenum gl_pixel_format;
to_opengl_textureformat(image.get_format(), gl_internal_format, gl_pixel_format);
// check out if the original texture needs or doesn't need an alpha channel
bool needs_alpha = image.has_transparency();
GLenum format;
GLenum type;
bool conv_needed = !to_opengl_pixelformat(image, format, type);
// also check for the pitch (GL1 can only skip pixels, not bytes)
if (!conv_needed)
{
const int bytesPerPixel = image.get_bytes_per_pixel();
if (image.get_pitch() % bytesPerPixel != 0)
conv_needed = true;
}
// no conversion needed
if (!conv_needed)
{
// Upload to GL1:
// change alignment
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
const int bytesPerPixel = image.get_bytes_per_pixel();
#ifndef __ANDROID__
glPixelStorei(GL_UNPACK_ROW_LENGTH, image.get_pitch() / bytesPerPixel);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
#endif
char *data = (char *) image.get_data();
int image_width = image.get_width();
int image_height = image.get_height() / image_depth;
glTexImage3D(
target, // target
level, // level
gl_internal_format, // internalformat
image_width, // width
image_height, // height
image_depth, // depth
0, // border
format, // format
type, // type
data); // texels
}
// conversion needed
else
{
bool big_endian = Endian::is_system_big();
PixelBuffer buffer(
image.get_width(), image.get_height(),
needs_alpha ? tf_rgba8 : tf_rgb8);
buffer.set_image(image);
format = needs_alpha ? GL_RGBA : GL_RGB;
// Upload to OpenGL:
// change alignment
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
const int bytesPerPixel = buffer.get_bytes_per_pixel();
#ifndef __ANDROID__
glPixelStorei(GL_UNPACK_ROW_LENGTH, buffer.get_pitch() / bytesPerPixel);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
#endif
int image_width = image.get_width();
int image_height = image.get_height() / image_depth;
// upload
glTexImage3D(
target, // target
level, // level
gl_internal_format, // internalformat
image_width, // width
image_height, // height
image_depth, // depth
0, // border
format, // format
GL_UNSIGNED_BYTE, // type
buffer.get_data()); // texels
}
}
示例5: Exception
void GL1TextureProvider::copy_from(GraphicContext &gc, int x, int y, int slice, int level, const PixelBuffer &ximage, const Rect &src_rect)
{
OpenGL::set_active(gc);
PixelBuffer image = ximage;
if (src_rect.left < 0 || src_rect.top < 0 || src_rect.right > image.get_width() || src_rect.bottom > image.get_height())
throw Exception("Rectangle out of bounds");
throw_if_disposed();
GL1TextureStateTracker state_tracker(texture_type, handle);
// check out if the original texture needs or doesn't need an alpha channel
bool needs_alpha = image.has_transparency();
GLenum format;
GLenum type;
bool conv_needed = !to_opengl_pixelformat(image, format, type);
// also check for the pitch (GL1 can only skip pixels, not bytes)
if (!conv_needed)
{
const int bytesPerPixel = image.get_bytes_per_pixel();
if (image.get_pitch() % bytesPerPixel != 0)
conv_needed = true;
}
// no conversion needed
if (!conv_needed)
{
// change alignment
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
const int bytesPerPixel = image.get_bytes_per_pixel();
#ifndef __ANDROID__
glPixelStorei(GL_UNPACK_ROW_LENGTH, image.get_pitch() / bytesPerPixel);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, src_rect.left);
glPixelStorei(GL_UNPACK_SKIP_ROWS, src_rect.top);
#endif
}
// conversion needed
else
{
bool big_endian = Endian::is_system_big();
PixelBuffer buffer(
src_rect.get_width(), src_rect.get_height(),
needs_alpha ? tf_rgba8 : tf_rgb8);
buffer.set_subimage(image, Point(0, 0), src_rect);
format = needs_alpha ? GL_RGBA : GL_RGB;
// Upload to GL1:
glBindTexture(GL_TEXTURE_2D, handle);
// change alignment
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
const int bytesPerPixel = buffer.get_bytes_per_pixel();
#ifndef __ANDROID__
glPixelStorei(GL_UNPACK_ROW_LENGTH, buffer.get_pitch() / bytesPerPixel);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
#endif
type = GL_UNSIGNED_BYTE;
image = buffer;
}
// upload
glTexSubImage2D(
GL_TEXTURE_2D, // target
level, // level
x, y, // xoffset, yoffset
src_rect.get_width(), // width
src_rect.get_height(), // height
format, // format
type, // type
image.get_data()); // texels
if (!power_of_two_texture)
{
// TODO: This needs corrected.It should be optimised and currently it does not write to the lower right quadrant
// Check extend the right edge
int right_edge = x + image.get_width();
if ( right_edge >= width )
{
char *edge_data = (char *) image.get_data();
edge_data += image.get_bytes_per_pixel() * (width-1);
for(int edge_cnt = right_edge; edge_cnt < pot_width; edge_cnt++)
{
glTexSubImage2D(
GL_TEXTURE_2D, // target
level, // level
edge_cnt, y, // xoffset, yoffset
1, // width
src_rect.get_height(), // height
format, // format
//.........这里部分代码省略.........