Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Trapezoid!  (Read 1248 times)
0 Members and 1 Guest are viewing this topic.
Offline counterp

Senior Member


Medals: 11



« Posted 2012-11-20 00:48:11 »

I was wondering if there are any fast algorithms out there for taking an image and morphing it into the shape of a trapezoid (trapezium).

I found this method:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
   private final float A = W * 0.08f;
   private final float B = W * (1f - 0.08f);

   private final void createTrapezium(BufferedImage src, BufferedImage out) {
      int[] pix = ((DataBufferInt) src.getRaster().getDataBuffer()).getData();
      int[] pix2 = ((DataBufferInt) out.getRaster().getDataBuffer()).getData();
      Arrays.fill(pix2, 0);
      for (int y = 0; y < HEIGHT; y++) {
         int yw = y * W;
         float y_to_h = y / (float) HEIGHT;
         float C_A_offset = A * (1 - y_to_h);
         float trapeziumLine = -C_A_offset + B + (W - B) * y_to_h;
         float k = trapeziumLine / W;
         for (int x = 0; x < W; x++) {
            int destX = (int) (C_A_offset + x * k);
            pix2[yw + destX] = pix[yw + x];
         }
      }
   }


But it's pretty CPU intensive (using this in real-time for a changing background image at 30 FPS)... Is there an alternative to using JAI?
Offline sproingie

JGO Kernel


Medals: 201



« Reply #1 - Posted 2012-11-20 01:18:11 »

You mention JAI, so I assume you've seen the thread at http://stackoverflow.com/questions/2500489/fast-perspective-transform-in-java-advanced-imaging-api ... unfortunately you're not going to get anywhere with an Affine transform, so you're kinda out of luck as built-in features go. 

If you're looking to do a transition, like screens swiping from one to the next, you could always pre-render them and just animate through those.  Otherwise the only really viable alternative that'll get you any reasonable quality at decent speed is to go 3d and use OpenGL.
Offline counterp

Senior Member


Medals: 11



« Reply #2 - Posted 2012-11-22 22:51:51 »

It seems that JAI has to be installed, that's why I don't want to use it.. Is there a version that you can just bundle with a project (with native libs)?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline sproingie

JGO Kernel


Medals: 201



« Reply #3 - Posted 2012-11-22 23:13:20 »

You could try ImageMagick bindings, I'm pretty sure that has a perspective transform in it.  There's also JavaCV, which should be able to do anything you imagine once you figure it out.  Neither of those are going to be real-time either.


Offline counterp

Senior Member


Medals: 11



« Reply #4 - Posted 2012-11-23 01:57:58 »

Ugh. Would it be possible to have a 3D background and a 2D foreground if I switch to OpenGL? Time to look up tutorials.

Thanks!
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (24 views)
2014-07-24 01:59:36

Riven (22 views)
2014-07-23 21:16:32

Riven (18 views)
2014-07-23 21:07:15

Riven (21 views)
2014-07-23 20:56:16

ctomni231 (49 views)
2014-07-18 06:55:21

Zero Volt (45 views)
2014-07-17 23:47:54

danieldean (36 views)
2014-07-17 23:41:23

MustardPeter (39 views)
2014-07-16 23:30:00

Cero (54 views)
2014-07-16 00:42:17

Riven (54 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!