techyian / MMALSharp

C# wrapper to Broadcom's MMAL with an API to the Raspberry Pi camera.
MIT License
195 stars 33 forks source link

Unnecessary file output to post-process still captures #188

Open MV10 opened 4 years ago

MV10 commented 4 years ago

This is another spinoff from PR #175.

While testing those changes, I was surprised to see my "jpg" file on ramdisk briefly jump to the raw data's 3.5MB size, then drop to the 200K JPEG size.

This is due to ImageStreamCaptureHandler and the underlying stream base class writing image data to the stream in Process, then copying it back to memory in PostProcess to invoke OnManipulate. The initial output seems like unnecessary overhead. It's trivial in my ramdisk scenario, but it would make a bigger difference on slower physical media (especially SD cards).

It seems to me that if Manipulate is called with a target ImageFormat, we need sort of a hybrid of InMemoryCaptureHandler Process to accumulate image data in memory, and the output stage of StreamCaptureHandler PostProcess to invoke manipulation and write the results to a pathname. (In fact, maybe it should work the same way even when ImageFormat is null. Then you'd be storing a raw file.)

I'm not sure of the best way to resolve this, but after thinking about it more, it didn't really belong in that PR.