简体   繁体   English

运行时混合大图像(Java / JOGL /处理)

[英]Runtime blending large images (Java/JOGL/Processing)

I need to alpha blend 2700x1600 images at runtime. 我需要在运行时Alpha混合2700x1600图像。 It's essentially a slideshow, though with multiple "decks" running simultaneously. 它实际上是幻灯片,尽管同时运行多个“平台”。 Each column in this diagram represents a program state at any moment in time: 该图中的每一列代表随时的程序状态:

imageA1 <-blend-> imageA2 <-blend-> imageA3 ...
imageB1 <-blend-> imageB2 <-blend-> imageB3 ...
imageC1 <-blend-> imageC2 <-blend-> imageC3 ...
imageD1 <-blend-> imageD2 <-blend-> imageD3 ...
imageE1 <-blend-> imageE2 <-blend-> imageE3 ...
imageF1 <-blend-> imageF2 <-blend-> imageF3 ...

Not totally surprisingly, I'm having problems keeping my framerate up. 毫不奇怪,我在保持帧速率方面遇到问题。 I've tried doing the blending on an offscreen buffer, but that hasn't seemed to help much if any. 我曾尝试在屏幕外缓冲区上进行混合,但这似乎并没有太大帮助。 Are there any general strategies for working with images this large that might apply to this situation? 是否有适用于这种情况的处理大图像的通用策略? Something to leverage the graphics card as much as possible, perhaps? 也许有什么可以利用显卡的?

This is my basic strategy (very simplified code, Processing rather than Java) as of right now: 到目前为止,这是我的基本策略(非常简化的代码,处理而不是Java):

PImage a = loadImage("imageA.png");
PImage b = loadImage("imageB.png");
PGraphics buffer = createGraphics(width, height, OPENGL);

void draw () {
    buffer.beginDraw();
    buffer.tint(255, 200);
    buffer.image(a, 0, 0);
    buffer.tint(255, 100);
    buffer.image(b, 0, 0);
    buffer.endDraw();
    image(buffer, 0, 0);
}

I'm using Java/ Processing , but advice in raw JOGL is welcome. 我正在使用Java / Processing ,但是欢迎在原始JOGL中提供建议。

I'm also having a bit of trouble managing memory; 我在管理内存方面也遇到了麻烦; each of these images uncompressed is ~17MB (2700x1600x4 bytes), and there are a total of ~60 images I'll be blending (not all simultaneously!). 这些未压缩的图像中的每一个都是〜17MB(2700x1600x4字节),总共要混合约60张图像(不是同时全部!)。 I have strategies in mind for the memory issue that are outside the scope of this question, but I include it here in case there is a clever way to balance memory usage between the computer's memory and the graphics card's. 对于内存问题,我所考虑的策略不在此问题的范围内,但如果在计算机内存和图形卡之间找到平衡内存使用的巧妙方法,我将其包括在此处。

(Extra info, for those who care: My understanding is that Processing's image() calls (which draw image objects to the screen) uses JOGL for its underlying implementation. This understanding comes from looking at the source for Processing's PGraphics.imageImpl() method , which when using the PGraphicsOpenGL renderer (I am), ends up at native JOGL calls within PGraphicsOpenGL.rawPolys() .) (额外的信息,对于那些关心的人:我的理解是Processing的image()调用(将图像对象绘制到屏幕上)使用JOGL作为其基础实现。这种理解来自查看Processing的PGraphics.imageImpl()方法的源代码。 ,当使用PGraphicsOpenGL渲染器(我是)时,最终在PGraphicsOpenGL.rawPolys()中的本机JOGL调用中结束 。)

Your worst enemy will be disk I/O. 您最大的敌人将是磁盘I / O。 In the past, I have used a memory buffer which held all the images that needed to be processed. 在过去,我使用了一个内存缓冲区来保存所有需要处理的图像。 In your case, that buffer would be a slice of your 60 images... say a 10 image slice buffer. 在您的情况下,该缓冲区将是您的60张图像的一部分……比如说10张图像的切片缓冲区。

Producer Thread-1: 生产者线程1:

load image from disk--->|10 image Buffer|----->process image in a FIFO manner 从磁盘加载图像-> 10图像缓冲区|->以FIFO方式处理图像

Consumer Thread-2: image ready for display --->|Display buffer|----->paint image 使用者线程2:准备显示的图像---> |显示缓冲区| ----->绘制图像

Also, you could profile your code with JProfiler to see other bottlenecks. 另外,您可以使用JProfiler来分析代码,以查看其他瓶颈。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM