Is it safe to update individual areas of BufferedImage in separate threads?

I have a collection of instances BufferedImage, one main image and some subimages created by a call getSubImageon the main image. Subjects do not overlap. I also make changes to the subimage, and I want to split it into several threads, one for each prototype.

From my understanding of how they work BufferedImage, Rasterand DataBuffer, this should be safe, because:

  • Each instance BufferedImage(and its corresponding WritableRasterand SampleModel) is available from only one thread.
  • General ColorModelis unchanged
  • DataBuffer It has no fields that can be changed (the only thing that can change is the elements of the support array).
  • Changing disjoint array segments in separate threads is safe.

However, I cannot find anything in the documentation that says it is definitely safe. Can I take it safe? I know that you can work with copies of a child Raster, but I would prefer to avoid this because of memory limitations.

Otherwise, is it possible to make the operation thread safe without copying areas of the parent image?

+5
source share
4 answers

JAI "" ? , , BufferedImage, subImage BufferedImage. JAI : JAI README

TiledImage, RenderedImage ( BufferedImage). JAI:

. .

RenderedImage BufferedImage, BufferedImage . JAI , .

+4

, . , . , - , , , . , : "BufferedImage " - , .

, , unit test, ConTest. , concurrency. BufferedImage , , .

+2

BufferedImage, , , :

, , . , .

, , .

:   

        W1       W2      W3
Img1 |-------|-------|-------|
        W1 W2 W3
Img2 | ------- | ------- | ------- |
To:
        W1 W1 W1
Img1 | ------- | ------- | ------- |
        W2 W2 W2
Img2 | ------- | ------- | ------- |
    
+1
source

If none of these answers satisfies (enough), you can do something that finally resolves the issue at a heavy (?) Price.

Explore the source for BufferedImage, DataBuffer, Raster, etc. This is the only way.

0
source

All Articles