Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I understood correctly, you store each individual pixel in one <code>Stream</code> element, and this can be inefficient. What you can do is create your custom <code>LazyRaster</code> class which contains lazy references to blocks of the image of some size (for instance, 20x20). The first time some block is written, its corresponding array is initialized, and from there on changing a pixel means writing to that array.</p> <p>This is more work, but may result in better performance. Furthermore, if you wish to support stacking of image operations (e.g. do a map - take - map), and then evaluating the image in "one-go", the implementation could get tricky - stream implementation is the best evidence for this.</p> <p>Another thing one can do is ensure that the old <code>Stream</code>s are being <a href="https://stackoverflow.com/questions/4132924/functional-processing-of-scala-streams-without-outofmemory-errors">properly garbage collected</a>. I suspect <code>image</code> object in your example is a wrapper for your streams. If you wish to stack multiple image operations (like mapping) together and be able to gc the references you no longer need, you have to make sure that you don't hold any references to a stream - note that this is not ensured if:</p> <ol> <li>you have a reference to your image on the stack (<code>image</code> in the example)</li> <li>your <code>Image</code> wrapper contains such a reference.</li> </ol> <p>Without knowing more about the exact use cases, its hard to say more.</p> <p>Personally, I would avoid <code>Stream</code>s altogether, and simply use some immutable array-based data structure which is both space-efficient and avoids boxing. The only place where I potentially see <code>Stream</code>s being used is in iterative image transformations, like convolution or applying a stack of filters. You wouldn't have a <code>Stream</code> of pixels, but a <code>Stream</code> of images, instead. This could be a nice way to express a sequence of transformations - in this case, the comments about gc in the link given above apply.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload