本文整理汇总了C++中PixelBuffer::get_width方法的典型用法代码示例。如果您正苦于以下问题:C++ PixelBuffer::get_width方法的具体用法?C++ PixelBuffer::get_width怎么用?C++ PixelBuffer::get_width使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PixelBuffer
的用法示例。
在下文中一共展示了PixelBuffer::get_width方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: add_gridclipped_frames
void CursorDescription::add_gridclipped_frames(
const PixelBuffer &pixelbuffer,
int xpos, int ypos,
int width, int height,
int xarray, int yarray,
int array_skipframes,
int xspace, int yspace)
{
int ystart = ypos;
for (int y = 0; y < yarray; y++)
{
int xstart = xpos;
for (int x = 0; x < xarray; x++)
{
if (y == yarray - 1 && x >= xarray - array_skipframes)
break;
if (xstart + width > pixelbuffer.get_width() || ystart + height > pixelbuffer.get_height())
throw Exception("add_gridclipped_frames: Outside pixelbuffer bounds");
impl->frames.push_back(CursorDescriptionFrame(pixelbuffer, Rect(xstart, ystart, xstart + width, ystart + height)));
xstart += width + xspace;
}
ystart += height + yspace;
}
}
示例2: Point
Texture2D::Texture2D( GraphicContext &context, const std::string &filename, const FileSystem &fs, const ImageImportDescription &import_desc)
{
PixelBuffer pb = ImageProviderFactory::load(filename, fs, std::string());
pb = import_desc.process(pb);
*this = Texture2D(context, pb.get_width(), pb.get_height(), import_desc.is_srgb() ? tf_srgb8_alpha8 : tf_rgba8);
set_subimage(context, Point(0, 0), pb, Rect(pb.get_size()), 0);
impl->provider->set_wrap_mode(impl->wrap_mode_s, impl->wrap_mode_t);
}
示例3: 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);
}
示例4: sizeof
void X11Window::set_large_icon(const PixelBuffer &image)
{
unsigned int size = (image.get_width() * image.get_height()) + 2; // header is 2 ints
unsigned long* data = (unsigned long*)malloc(size * sizeof(unsigned long));
// set header
data[0] = image.get_width();
data[1] = image.get_height();
// icon data is expected as ARGB
PixelBuffer transformed_image = image.to_format(tf_bgra8);
// on 64bit systems, the destination buffer is 64 bit per pixel
// thus, we have to copy each pixel individually (no memcpy)
for (int y = 0; y < image.get_height(); ++y) {
const uint32_t* src = (const uint32_t*)transformed_image.get_line(y);
unsigned long* dst = &data[2 + (y * image.get_width())];
for (int x = 0; x < image.get_width(); ++x) {
dst[x] = src[x];
}
}
// set icon geometry
unsigned long* geom = (unsigned long*)malloc(4 * sizeof(unsigned long));
geom[0] = geom[1] = 0; // x, y
geom[2] = image.get_width();
geom[3] = image.get_height();
Atom propertyGeom = XInternAtom(handle.display, "_NET_WM_ICON_GEOMETRY", 0);
XChangeProperty(handle.display, handle.window, propertyGeom, XA_CARDINAL, 32, PropModeReplace, (unsigned char*)geom, 4);
// set icon data
Atom property = XInternAtom(handle.display, "_NET_WM_ICON", 0);
XChangeProperty(handle.display, handle.window, property, XA_CARDINAL, 32, PropModeReplace,
(unsigned char*)data, size);
}
示例5: Pointf
OutlineProviderBitmap_Impl::OutlineProviderBitmap_Impl(
const PixelBuffer &pbuf,
int alpha_limit,
bool get_insides)
:
data(0),
get_insides(get_insides),
alpha_limit(alpha_limit),
//double_precision(false),
//consecutive_left_turns(0),
//consecutive_right_turns(0),
alpha_pixel(3),
pb(pbuf),
last_point(0,0),
last_dir(DIR_LEFT)
{
if( pbuf.get_format() != tf_rgba8 )
{
// the image contains no alpha - add only a rectangle
Contour contour;
contour.get_points().push_back( Pointf(0.0f, 0.0f) );
contour.get_points().push_back( Pointf(0.0f, float(height)) );
contour.get_points().push_back( Pointf(float(width), float(height)) );
contour.get_points().push_back( Pointf(float(width), 0.0f) );
contours.push_back(contour);
return;
}
height = pbuf.get_height();
width = pbuf.get_width();
// allocate a grid of unsigned chars, this represents the corners between pixels.
// We will only use the first 4 bits of each char:
// (1 << 0) 0x1 : the pixel to the upper left
// (1 << 1) 0x2 : the pixel to the upper right
// (1 << 2) 0x4 : the pixel to the lower left
// (1 << 3) 0x8 : the pixel to the lower right
data = new unsigned char[(height+1)*(width+1)];
// The image part
for(int y = 0; y <= height; y++)
{
for(int x = 0; x <= width; x++)
{
get_corner(x,y) = 0x0;
if(is_opaque(x-1,y-1))
get_corner(x,y) |= 0x1;
if(is_opaque(x,y-1))
get_corner(x,y) |= 0x2;
if(is_opaque(x-1,y))
get_corner(x,y) |= 0x4;
if(is_opaque(x,y))
get_corner(x,y) |= 0x8;
}
}
find_contours();
}
示例6: 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);
//.........这里部分代码省略.........
示例7: 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
}
}
示例8: 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
//.........这里部分代码省略.........
示例9: add_frame
void CursorDescription::add_frame(const PixelBuffer &pixelbuffer)
{
impl->frames.push_back(CursorDescriptionFrame(pixelbuffer, Rect(0, 0, pixelbuffer.get_width(), pixelbuffer.get_height())));
}