本文整理汇总了C++中PixelBuffer类的典型用法代码示例。如果您正苦于以下问题:C++ PixelBuffer类的具体用法?C++ PixelBuffer怎么用?C++ PixelBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PixelBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: main
int main(int argc, const char* argv[]) {
if (argc < 2) {
std::cerr << "ERROR : Please specify a input file." << std::endl;
exit(1);
}
std::string filename = argv[1];
Scene scene(filename);
std::cout << filename << std::endl;
PixelBuffer buf = RayTracer::rayTrace(scene);
// file splitting code referenced form
// http://www.cplusplus.com/reference/string/string/find_last_of/
int index = filename.find_last_of("/\\");
std::string path = filename.substr(0,index);
std::string name = filename.substr(index+1);
std::stringstream ss;
ss << name;
std::string namebase;
std::getline(ss, namebase, '.');
buf.toFile(namebase);
return 0;
}
示例3: drawCachedGlyphBitmap
void Font::drawCachedGlyphBitmap(CachedGlyphInfo* glyph, int x, int y, uint8_t* bitmap,
uint32_t bitmapWidth, uint32_t bitmapHeight, Rect* bounds, const float* pos) {
int dstX = x + glyph->mBitmapLeft;
int dstY = y + glyph->mBitmapTop;
CacheTexture* cacheTexture = glyph->mCacheTexture;
PixelBuffer* pixelBuffer = cacheTexture->getPixelBuffer();
uint32_t formatSize = PixelBuffer::formatSize(pixelBuffer->getFormat());
uint32_t alpha_channel_offset = PixelBuffer::formatAlphaOffset(pixelBuffer->getFormat());
uint32_t cacheWidth = cacheTexture->getWidth();
uint32_t srcStride = formatSize * cacheWidth;
uint32_t startY = glyph->mStartY * srcStride;
uint32_t endY = startY + (glyph->mBitmapHeight * srcStride);
const uint8_t* cacheBuffer = pixelBuffer->map();
for (uint32_t cacheY = startY, bitmapY = dstY * bitmapWidth; cacheY < endY;
cacheY += srcStride, bitmapY += bitmapWidth) {
if (formatSize == 1) {
memcpy(&bitmap[bitmapY + dstX], &cacheBuffer[cacheY + glyph->mStartX], glyph->mBitmapWidth);
} else {
for (uint32_t i = 0; i < glyph->mBitmapWidth; ++i) {
bitmap[bitmapY + dstX + i] = cacheBuffer[cacheY + (glyph->mStartX + i)*formatSize + alpha_channel_offset];
}
}
}
}
示例4: PixelBuffer
void Filter::applyToBuffer(PixelBuffer* buffer, float newStrength[])
{
PixelBuffer* tempB;
tempB = new PixelBuffer(buffer->getWidth(), buffer->getHeight(), buffer->getBackgroundColor());
for (int h = 0; h < buffer->getHeight(); h++)
{
for (int w = 0; w < buffer->getWidth(); w++)
{
ColorData c = buffer->getPixel(w, h);
for (int mw = 0; mw < maskWidth; mw++)
{
for (int mh = 0; mh < maskHeight; mh++)
{
trans = mask[mw][mh];
ColorData maskC = buffer->getPixel((w - maskWidth/2 + mw), (h - maskHeight/2 + mh));
maskC = maskC * trans;
c = c + maskC;
}
}
c = c - buffer->getPixel(w, h);
tempB->setPixel(w, h, c);
}
}
buffer->copyPixelBuffer(tempB, buffer);
delete tempB;
}
示例5: outline_provider
CollisionOutline::CollisionOutline(
IODevice &file, const std::string &file_extension,
int alpha_limit,
OutlineAccuracy accuracy,
bool get_insides)
{
if( file_extension == "out" )
{
OutlineProviderFile outline_provider(file);
*this = CollisionOutline(outline_provider.get_contours(), outline_provider.get_size(), accuracy_raw );
}
else
{
PixelBuffer pbuf = ImageProviderFactory::load(file, file_extension);
if( pbuf.get_format() == tf_rgba8 )
{
OutlineProviderBitmap outline_provider(pbuf, alpha_limit, get_insides);
*this = CollisionOutline(outline_provider.get_contours(), outline_provider.get_size(), accuracy );
}
else
{
OutlineProviderBitmap outline_provider(pbuf, alpha_limit, get_insides);
*this = CollisionOutline(outline_provider.get_contours(), outline_provider.get_size(), accuracy_raw );
}
}
set_rotation_hotspot(origin_center);
}
示例6: main
int main(int argv, char **argc) {
Scene *scene = new Scene();
std::ifstream sceneFile("scene.txt");
if (!sceneFile)
return 123;
std::string s((std::istreambuf_iterator<char>(sceneFile)), std::istreambuf_iterator<char>());
JsonGroup json(s);
JsonArray objects(json.at("objects").Array());
JsonArray lights(json.at("lights").Array());
JsonGroup camera(json.at("camera").Group());
Camera cam = Camera(Vector3D(camera.at("position").Array().at(0).Float(), camera.at("position").Array().at(1).Float(), camera.at("position").Array().at(2).Float()), Vector3D(camera.at("target").Array().at(0).Float(), camera.at("target").Array().at(1).Float(), camera.at("target").Array().at(2).Float()), camera.at("roll").Float());
for (int i = 0; i < objects.size(); i++){
JsonGroup object = objects.at(i).Group();
if (object.at("type").String().compare("sphere") == 0){
scene->add(new SphereObject(Vector3D(object.at("position").Array().at(0).Float(), object.at("position").Array().at(1).Float(), object.at("position").Array().at(2).Float()),
object.at("radius").Float(), Color(object.at("color").Array().at(0).Integer(), object.at("color").Array().at(1).Integer(), object.at("color").Array().at(2).Integer()), object.at("reflection").Float(), object.at("refraction").Float(), object.at("ior").Float()));
}
if (object.at("type").String().compare("plane") == 0){
scene->add(new PlaneObject(Vector3D(object.at("position").Array().at(0).Float(), object.at("position").Array().at(1).Float(), object.at("position").Array().at(2).Float()),
Vector3D(object.at("normal").Array().at(0).Float(), object.at("normal").Array().at(1).Float(), object.at("normal").Array().at(2).Float()),
Color(object.at("color").Array().at(0).Array().at(0).Integer(), object.at("color").Array().at(0).Array().at(1).Integer(), object.at("color").Array().at(0).Array().at(2).Integer()),
Color(object.at("color").Array().at(1).Array().at(0).Integer(), object.at("color").Array().at(1).Array().at(1).Integer(), object.at("color").Array().at(1).Array().at(2).Integer()), object.at("reflection").Float(), object.at("refraction").Float(), object.at("ior").Float()));
}
if (object.at("type").String().compare("triangle") == 0){
scene->add(new TriangleObject(Vector3D(object.at("vertices").Array().at(0).Array().at(0).Integer(), object.at("vertices").Array().at(0).Array().at(1).Integer(), object.at("vertices").Array().at(0).Array().at(2).Integer()),
Vector3D(object.at("vertices").Array().at(1).Array().at(0).Integer(), object.at("vertices").Array().at(1).Array().at(1).Integer(), object.at("vertices").Array().at(1).Array().at(2).Integer()),
Vector3D(object.at("vertices").Array().at(2).Array().at(0).Integer(), object.at("vertices").Array().at(2).Array().at(1).Integer(), object.at("vertices").Array().at(2).Array().at(2).Integer()),
Color(object.at("color").Array().at(0).Integer(), object.at("color").Array().at(1).Integer(), object.at("color").Array().at(2).Integer()), object.at("reflection").Float(), object.at("refraction").Float(), object.at("ior").Float()));
}
}
for (int i = 0; i < lights.size(); i++){
JsonGroup light = lights.at(i).Group();
if (light.at("type").String().compare("point") == 0){
scene->add(new PointLight(Vector3D(light.at("position").Array().at(0).Float(), light.at("position").Array().at(1).Float(), light.at("position").Array().at(2).Float())));
}
if (light.at("type").String().compare("direction") == 0){
scene->add(new DirectionLight(Vector3D(light.at("direction").Array().at(0).Float(), light.at("direction").Array().at(1).Float(), light.at("direction").Array().at(2).Float())));
}
}
Renderer *renderer = new Renderer();
PixelBuffer *buffer = renderer->render(scene, &cam, camera.at("resolution").Array().at(0).Integer(), camera.at("resolution").Array().at(1).Integer(), camera.at("raydepth").Integer());
//buffer->savePPM("test.ppm");
buffer->saveBMP("image.bmp");
return 0;
}
示例7:
TransferTexture::TransferTexture(GraphicContext &gc, const PixelBuffer &pbuff, PixelBufferDirection direction, BufferUsage usage)
{
GraphicContextProvider *gc_provider = gc.get_provider();
PixelBufferProvider *provider = gc_provider->alloc_pixel_buffer();
*this = TransferTexture(provider);
provider->create(pbuff.get_data(), pbuff.get_size(), direction, pbuff.get_format(), usage);
}
示例8: batcher
HSVSprite::HSVSprite(Canvas &canvas, HSVSpriteBatch *batcher, const std::string &image_filename)
: batcher(batcher)
{
PixelBuffer image = ImageProviderFactory::load(image_filename);
Subtexture subtexture = batcher->alloc_sprite(canvas, image.get_size());
geometry = subtexture.get_geometry();
texture = subtexture.get_texture();
texture.set_subimage(canvas, geometry.get_top_left(), image, image.get_size());
}
示例9: 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);
}
示例10: PixelBuffer
Texture *NGE_SDL_Texture_Load(const char *path)
{
PixelBuffer *buf;
Texture *tex = NULL;
SDL_Surface *surface;
Sint32 i, j;
Uint8 *p, *q;
Uint8 r, g, b, a;
if(path) {
if((surface = IMG_Load(path))) {
//SDL_LockSurface(surface); -> peut poser des pb
buf = new PixelBuffer(surface->format->BytesPerPixel, surface->w, surface->h);
p = (Uint8 *) surface->pixels;
//for(i = 0; i < surface->h; i++) {
for(i = surface->h - 1; i >= 0; i--) {
q = buf->getPixelAddr(0, i);
for(j = 0; j < surface->w; j++) {
r = p[j * surface->format->BytesPerPixel + 0];
g = p[j * surface->format->BytesPerPixel + 1];
b = p[j * surface->format->BytesPerPixel + 2];
if(surface->format->BytesPerPixel == 4)
a = p[j * surface->format->BytesPerPixel + 3];
else;
q[j * surface->format->BytesPerPixel + 0] = r;
q[j * surface->format->BytesPerPixel + 1] = g;
q[j * surface->format->BytesPerPixel + 2] = b;
if(surface->format->BytesPerPixel == 4)
q[j * surface->format->BytesPerPixel + 3] = a;
else;
}
//p += surface->format->BytesPerPixel * surface->w;
p += surface->format->BytesPerPixel * surface->w;
}
tex = new Texture();
tex->setPixelBuffer(buf);
// tex->updateInGC();
//SDL_UnlockSurface(surface);
SDL_FreeSurface(surface);
}
else
printf("Texture \"%s\" not loaded: not found.\n", path);
}
else;
return tex;
}
示例11: drawGridGradientCircle
void drawGridGradientCircle(PixelBuffer& buf) {
float midX = buf.width() / 2.f;
float midY = buf.height() / 2.f;
float maxDistSquared = midX * midX + midY * midY;
for (int i=0; i < buf.width(); i++) {
for (int j=0; j < buf.height(); j++) {
float distX = (midX - i);
float distY = (midY - j);
float distSquared = distX * distX + distY * distY;
float t = 1 - distSquared / maxDistSquared;
if ( t < 0.90) {
if ( (i + j) % 2 == 0 ) {
buf.setPixel(i,j, t * .75, t * .75, t * .75);
} else {
buf.setPixel(i,j, t * .25, t * .25, t * .25);
}
} else {
if (fmod(t * 1000.f, 1.f) < .5) {
buf.setPixel(i,j, 0.8f,0.3f,0.1f);
} else {
buf.setPixel(i,j, 0.9,.51,.22);
}
}
}
}
}
示例12: 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);
}
示例13: m_numRows
App::App()
: m_numRows(1)
, m_numCols(1)
, m_drawType(kCircle)
, m_finalImage(0)
{
QmlDocument *qml = QmlDocument::create("main.qml");
qml->setContextProperty("cs", this);
AbstractPane *root = qml->createRootNode<AbstractPane>();
Application::setScene(root);
if (root != 0)
{
TextField* textField = root->findChild<TextField*>("numRows");
connect(textField, SIGNAL(touch(bb::cascades::TouchEvent*)), this, SLOT(onIntFieldTouched(bb::cascades::TouchEvent*)));
connect(textField, SIGNAL(textChanged(QString)), this, SLOT(onNumRowsChanged(QString)));
textField = root->findChild<TextField*>("numCols");
connect(textField, SIGNAL(touch(bb::cascades::TouchEvent*)), this, SLOT(onIntFieldTouched(bb::cascades::TouchEvent*)));
connect(textField, SIGNAL(textChanged(QString)), this, SLOT(onNumColsChanged(QString)));
// Four hard-coded buttons.
// Three select an image from the asset...
Button* button = root->findChild<Button*>("img1");
connect(button, SIGNAL(clicked()), this, SLOT(onImageSelected()));
button = root->findChild<Button*>("img2");
connect(button, SIGNAL(clicked()), this, SLOT(onImageSelected()));
button = root->findChild<Button*>("img3");
connect(button, SIGNAL(clicked()), this, SLOT(onImageSelected()));
// ...and two specify images to draw on demand
button = root->findChild<Button*>("circle");
connect(button, SIGNAL(clicked()), this, SLOT(onCircleSelected()));
button = root->findChild<Button*>("square");
connect(button, SIGNAL(clicked()), this, SLOT(onSquareSelected()));
m_finalImage = root->findChild<ImageView*>("finalImage");
// Set the image on the circle and the square
PixelBuffer pixelBuffer;
button = root->findChild<Button*>("circle");
pixelBuffer = drawCircle(QSize(50,50));
button->setImage(pixelBuffer.getBuffer());
button = root->findChild<Button*>("square");
pixelBuffer = drawSquare(QSize(50,50));
button->setImage(pixelBuffer.getBuffer());
}
示例14: Point
Texture2D::Texture2D(GraphicContext &context, const PixelBuffer &image, const Rect &src_rect, bool is_srgb)
{
*this = Texture2D(context, src_rect.get_width(), src_rect.get_height(), is_srgb ? tf_srgb8_alpha8 : tf_rgba8);
set_pixel_ratio(image.get_pixel_ratio());
set_subimage(context, Point(0, 0), image, src_rect, 0);
impl->provider->set_wrap_mode(impl->wrap_mode_s, impl->wrap_mode_t);
}
示例15: drawCachedGlyphBitmap
void Font::drawCachedGlyphBitmap(CachedGlyphInfo* glyph, int x, int y, uint8_t* bitmap,
uint32_t bitmapWidth, uint32_t bitmapHeight, Rect* bounds, const float* pos) {
int dstX = x + glyph->mBitmapLeft;
int dstY = y + glyph->mBitmapTop;
CacheTexture* cacheTexture = glyph->mCacheTexture;
uint32_t cacheWidth = cacheTexture->getWidth();
uint32_t startY = glyph->mStartY * cacheWidth;
uint32_t endY = startY + (glyph->mBitmapHeight * cacheWidth);
PixelBuffer* pixelBuffer = cacheTexture->getPixelBuffer();
const uint8_t* cacheBuffer = pixelBuffer->map();
for (uint32_t cacheY = startY, bitmapY = dstY * bitmapWidth; cacheY < endY;
cacheY += cacheWidth, bitmapY += bitmapWidth) {
memcpy(&bitmap[bitmapY + dstX], &cacheBuffer[cacheY + glyph->mStartX], glyph->mBitmapWidth);
}
}