本文整理汇总了C++中PixelBuffer::to_format方法的典型用法代码示例。如果您正苦于以下问题:C++ PixelBuffer::to_format方法的具体用法?C++ PixelBuffer::to_format怎么用?C++ PixelBuffer::to_format使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PixelBuffer
的用法示例。
在下文中一共展示了PixelBuffer::to_format方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: create_bitmap_data
PixelBuffer IconSet_Impl::create_bitmap_data(const PixelBuffer &image)
{
// Convert pixel buffer to DIB compatible format:
PixelBuffer bmp_image = image.to_format(tf_bgra8);
// Note that the APIs use pre-multiplied alpha, which means that the red,
// green and blue channel values in the bitmap must be pre-multiplied with
// the alpha channel value. For example, if the alpha channel value is x,
// the red, green and blue channels must be multiplied by x and divided by
// 0xff prior to the call.
int w = bmp_image.get_width();
int h = bmp_image.get_height();
unsigned int *p = (unsigned int *) bmp_image.get_data();
for (int y = 0; y < h; y++)
{
int index = y * w;
unsigned int *line = p + index;
for (int x = 0; x < w; x++)
{
unsigned int a = ((line[x] >> 24) & 0xff);
unsigned int r = ((line[x] >> 16) & 0xff);
unsigned int g = ((line[x] >> 8) & 0xff);
unsigned int b = (line[x] & 0xff);
r = r * a / 255;
g = g * a / 255;
b = b * a / 255;
line[x] = (a << 24) + (r << 16) + (g << 8) + b;
}
}
// Flip image upside down
for (int y = 0; y < h/2; y++)
{
for (int x = 0; x < w; x++)
{
unsigned int l1 = p[y*w+x];
unsigned int l2 = p[(w-1-y)*w+x];
p[(w-1-y)*w+x] = l1;
p[y*w+x] = l2;
}
}
return bmp_image;
}
示例2: 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);
}
示例3: add_alphaclipped_frames_free
void CursorDescription::add_alphaclipped_frames_free(
const PixelBuffer &pixelbuffer,
int xpos, int ypos,
float trans_limit)
{
PixelBuffer alpha_buffer = pixelbuffer.to_format(tf_rgba8);
int width = alpha_buffer.get_width();
int height = alpha_buffer.get_height();
std::vector<int> explored_vector;
explored_vector.resize(width * height);
int *explored = &(explored_vector[0]);
memset(explored, 0, width * height * sizeof(int));
Vec4ub *data = alpha_buffer.get_data<Vec4ub>();
int x1, y1, x2, y2;
bool more;
for (int y = ypos; y < height; y++)
{
for (int x = xpos; x < width; x++)
{
if (explored[y*width + x] == 1) continue;
explored[y*width + x] = 1;
if (data[y*width + x].a <= trans_limit * 255)
continue;
// Initialize the bounding box to the current pixel
x1 = x2 = x;
y1 = y2 = y;
more = true;
while (more)
{
// Assume that there are NO opaque pixels around the current bounding box
more = false;
// Scan under the current bounding box and see if there any non-transparent pixels
for (int i = x1; i <= x2; i++)
{
if (y2 + 1 < height)
{
explored[(y2 + 1)*width + i] = 1;
if (data[(y2 + 1)*width + i].a > trans_limit * 255)
{
more = true;
y2 = y2 + 1;
}
}
}
// Now scan the left and right sides of the current bounding box
for (int j = y1; j <= y2; j++)
{
// Scan the right side
if (x2 + 1 < width)
{
explored[j*width + x2 + 1] = 1;
if (data[j*width + x2 + 1].a > trans_limit * 255)
{
more = true;
x2 = x2 + 1;
}
}
// Scan the left side
if (x1 - 1 >= 0)
{
explored[j*width + x1 - 1] = 1;
if (data[j*width + x1 - 1].a > trans_limit * 255)
{
more = true;
x1 = x1 - 1;
}
}
}
}
// Mark all pixels in the bounding box as being explored
for (int i = x1; i <= x2; i++)
{
for (int j = y1; j <= y2; j++)
{
explored[j*width + i] = 1;
}
}
impl->frames.push_back(CursorDescriptionFrame(pixelbuffer, Rect(x1, y1, x2, y2)));
}
}
}
示例4: add_alphaclipped_frames
void CursorDescription::add_alphaclipped_frames(
const PixelBuffer &pixelbuffer,
int xpos, int ypos,
float trans_limit)
{
PixelBuffer alpha_buffer = pixelbuffer.to_format(tf_rgba8);
int begin = 0;
bool prev_trans = true;
int alpha_width = alpha_buffer.get_width();
int alpha_height = alpha_buffer.get_height();
bool found_opaque = false;
bool found_trans = false;
std::vector<int> opaque_row_vector;
opaque_row_vector.resize(alpha_width);
int *opaque_row = &(opaque_row_vector[0]);
memset(opaque_row, 0, alpha_width*sizeof(int));
int cut_top = ypos;
int cut_bottom = alpha_height;
char *data = (char *)alpha_buffer.get_data();
for (int y = ypos; y < alpha_height; y++)
{
bool opaque_line = false;
Vec4ub *line = (Vec4ub *)(data + alpha_buffer.get_pitch()*y);
for (int x = 0; x < alpha_width; x++)
{
if (line[x].a > trans_limit * 255)
{
opaque_row[x] = 1;
opaque_line = true;
found_opaque = true;
}
}
if (opaque_line == false) // cut something of top or bottom
{
if (found_opaque)
{
cut_bottom--;
found_trans = true;
}
else
cut_top++;
}
else if (found_trans)
{
found_trans = false;
cut_bottom = alpha_height;
}
}
if (cut_top >= cut_bottom)
throw Exception("add_alphaclipped_frames: Image contained only alpha!");
for (int x = xpos; x < alpha_width; x++)
{
if (opaque_row[x] && prev_trans)
{
begin = x;
prev_trans = false;
}
else if (!opaque_row[x] && !prev_trans)
{
impl->frames.push_back(
CursorDescriptionFrame(pixelbuffer, Rect(begin, cut_top, x + 1, cut_bottom)));
prev_trans = true;
}
}
if (!prev_trans)
{
impl->frames.push_back(
CursorDescriptionFrame(pixelbuffer, Rect(begin, cut_top, alpha_width, cut_bottom)));
}
}