8
\$\begingroup\$

I am generating a heightmap for every quad in my quadtree in openCL. The way I was creating the image is as follows:

DataBufferInt dataBuffer = (DataBufferInt)img.getRaster().getDataBuffer(); int data[] = dataBuffer.getData(); //img is a bufferedimage inputImageMem = CL.clCreateImage2D( context, CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR, new cl_image_format[]{imageFormat}, size, size, size * Sizeof.cl_uint, Pointer.to(data), null); 

This works ok but the major issue is that as the quads get smaller and smaller the 8-bit format of the buffered image starts to cause intolerable "stepping" issues as seen below:

enter image description here

I was wondering if there was an alternate way I could go about doing this?

Thanks for the time.

\$\endgroup\$
7
  • \$\begingroup\$ Is this the "stepping" you're talking about? i.imgur.com/Sx9egmm.png?1 \$\endgroup\$ Commented Aug 11, 2013 at 0:20
  • \$\begingroup\$ Yes, that it is. \$\endgroup\$ Commented Aug 11, 2013 at 1:39
  • \$\begingroup\$ Can you change the title to something more related to your question? I was trying to come up with something but didn't want to misinterpret your question. \$\endgroup\$ Commented Aug 11, 2013 at 5:10
  • \$\begingroup\$ Oh yea definitely \$\endgroup\$ Commented Aug 11, 2013 at 16:12
  • \$\begingroup\$ Why do you have to use a BufferedImage? What format are your input images? \$\endgroup\$ Commented Aug 12, 2013 at 4:58

1 Answer 1

1
\$\begingroup\$

Are you using texture filtering when reading the height map? I'd expect that a bilinear filter would smooth things out a bit.

If you still need better precision then change the image format to something like CL_UNORM_INT16 or CL_FLOAT - see http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/cl_image_format.html

I'm not quite sure how you do that from Java though.

\$\endgroup\$
5
  • \$\begingroup\$ Yea that's the issue: I can't figure out how to use anything other than 8-bit integer with a BufferedImage. \$\endgroup\$ Commented Aug 11, 2013 at 21:48
  • \$\begingroup\$ Since Java doesn't have native OpenCL support, it might help to know which library you're using. The other option would be to use a double width image, and decode it on the GPU as say (pixel[x]/256.0 + pixel[x+1]). \$\endgroup\$ Commented Aug 12, 2013 at 19:51
  • \$\begingroup\$ I tried using bilinear interpolation with no luck... I am just using Java OpenCL (JOCL) \$\endgroup\$ Commented Aug 13, 2013 at 2:08
  • \$\begingroup\$ The Java version of OpenCL seems to support these formats as well. cl_image_format has a image_channel_data_type member that can be used to specify the data format (eg. CL_FLOAT etc.) \$\endgroup\$ Commented Aug 13, 2013 at 7:37
  • 2
    \$\begingroup\$ docs.oracle.com/javase/7/docs/api/java/awt/image/… says BufferedImage supports TYPE_USHORT_GREY which is 16-bit. \$\endgroup\$ Commented Aug 13, 2013 at 8:31

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.