From: Samuel Dorrell on
I've made an algorithm to do image (video) segmentation on a dm6437evm. However, looking at the code (see below) I've noticed some inefficiencies in the way that the video is handled and want to create my own source code for these functions. There seem to be a number of ways of approaching this and I'm not really sure which to do, so to prevent going to far down any blind alley I thought I'd pose the question first.

Some approached that I've thought about are:
- use 'right click - generate s-function' (for the subsystem then modify the source code), but then I can't see a way to inline this into the generated code and having seperate source files means that the source files must be on the matlab and ide path and seems to pose various other constraints on how I configure my model.
- Write the source files from scratch and use the legacy code tool to generate the s-function interface (is it possible to specify when using an ert target?)
- Try specifying the code replacement via a target function library (but then will Simulink try and replace every selector function with my function?)
- Something else??

I'm a bit confused about how to move forward on this so any suggestions much appreciated.

Best Regards
Sam Dorrell

----------------------------------------------------------------------------------------------------------------
Specifically in the generated code I have a selector block which selects the luminance pixels from the YCbCr 4:2:2 (UYVY) image like so:
/* Selector: '<S16>/Selector1' */
> for (i = 0; i < 480; i++) {
> for (tmp = 0; tmp < 720; tmp++) {
> dm64_captureSegmentAndDispaly_B.Selector1[tmp + 720 * i] = capFrmPtr[((tmp << 1) + 1) + 1440 * i];
> }
> }

But I think that a faster implementation would be this:
> for (i = 0, j=0; i < 480*720; i++, j+=2) {
> dm64_captureSegmentAndDispaly_B.Selector1[i] = capFrmPtr[j];
> }