void App::read_write_pixel_buffer(clan::Canvas &canvas, clan::PixelBuffer &pbuff) { clan::ubyte64 time_now = clan::System::get_time(); pbuff.lock(canvas, clan::access_read_write); if (pbuff.get_format() != clan::tf_rgba8) throw clan::Exception("Expected the format to be RGBA8"); unsigned char *dptr = (unsigned char *) pbuff.get_data(); // Only write to a portion of the pixel buffer - To keep up the example speed const int write_fraction = 2; const int box_width = pbuff.get_width() / write_fraction; const int box_height = pbuff.get_height() / write_fraction; int next_line = (pbuff.get_width() - box_width) * pbuff.get_bytes_per_pixel(); dptr += pbuff.get_bytes_per_pixel() * pbuff.get_width() * ( (pbuff.get_height() - box_height) / 2); dptr += pbuff.get_bytes_per_pixel() * (pbuff.get_width() - box_width) / 2; for (int ycnt = 0; ycnt < box_height; ycnt++) { for (int xcnt = 0; xcnt < box_width; xcnt++) { unsigned char blue = dptr[0]; unsigned char red = dptr[1]; unsigned char green = dptr[2]; blue = red + xcnt + (time_now / 10); green = red + xcnt*ycnt/512 + (time_now / 20); *(dptr++) = blue; *(dptr++) = red; *(dptr++) = green; *(dptr++) = 0xFF; } dptr += next_line; } pbuff.unlock(); }
void App::upload_pixel_buffer(clan::Canvas &canvas, clan::PixelBuffer &pbuff_source, clan::PixelBuffer &pbuff_dest) { pbuff_source.lock(canvas, clan::access_read_only); pbuff_dest.upload_data(canvas, clan::Rect(0,0, pbuff_source.get_size()), pbuff_source.get_data()); pbuff_source.unlock(); }