Vasco,

Did you also change what is written out to disk?  If so, we’ll have to figure 
out a backwards compatible encoding flag or always write out wastefully but 
keep it efficient in memory.

Longer term for ebm, dsp, it would probably be good to allow an arbitrary image 
encoding or binunif object, instead of very specific encoded formats.

Cheers!
Sean


> On Nov 1, 2017, at 6:48 AM, vasco_costa--- via brlcad-commits 
> <brlcad-comm...@lists.sourceforge.net> wrote:
> 
> Revision: 70379
>          http://sourceforge.net/p/brlcad/code/70379
> Author:   vasco_costa
> Date:     2017-11-01 10:48:50 +0000 (Wed, 01 Nov 2017)
> Log Message:
> -----------
> Pack EBM data into bitmap. Fits same data into 1/8th the memory. e.g. a 
> 512x512 bitmap uses 32KB instead of 256KB RAM.
> 
> Modified Paths:
> --------------
>    brlcad/trunk/src/librt/primitives/ebm/ebm.c
>    brlcad/trunk/src/librt/primitives/ebm/ebm_shot.cl
> 
> Modified: brlcad/trunk/src/librt/primitives/ebm/ebm.c
> ===================================================================
> --- brlcad/trunk/src/librt/primitives/ebm/ebm.c    2017-10-30 19:23:02 UTC 
> (rev 70378)
> +++ brlcad/trunk/src/librt/primitives/ebm/ebm.c    2017-11-01 10:48:50 UTC 
> (rev 70379)
> @@ -132,11 +132,15 @@
>         (struct rt_ebm_specific *)stp->st_specific;
>     struct clt_ebm_specific *args;
> 
> -    const size_t nbytes =
> -    (ebm->ebm_i.xdim+BIT_XWIDEN*2)*(ebm->ebm_i.ydim+BIT_YWIDEN*2);
> +    struct rt_ebm_internal *eip = &ebm->ebm_i;
> +    unsigned int x, y, id;
> +
> +    const size_t npixels =
> +    (eip->xdim+BIT_XWIDEN*2)*(eip->ydim+BIT_YWIDEN*2);
> +    const size_t nbytes = ((npixels/8+1)/8)*8+8;
>     size_t size = sizeof(*args);
> 
> -    size += (nbytes/8)*8+8;
> +    size += nbytes;
>     args = (struct clt_ebm_specific*)bu_pool_alloc(pool, 1, size);
> 
>     VMOVE(args->ebm_xnorm, ebm->ebm_xnorm);
> @@ -147,10 +151,19 @@
>     VMOVE(args->ebm_large, ebm->ebm_large);
>     MAT_COPY(args->ebm_mat, ebm->ebm_mat);
> 
> -    args->tallness = ebm->ebm_i.tallness;
> -    args->xdim = ebm->ebm_i.xdim;
> -    args->ydim = ebm->ebm_i.ydim;
> -    memcpy(args->apbuf, ebm->ebm_i.mp->apbuf, nbytes);
> +    args->tallness = eip->tallness;
> +    args->xdim = eip->xdim;
> +    args->ydim = eip->ydim;
> +    memset(args->apbuf, 0, nbytes);
> +
> +    for (y = 0; y < eip->ydim; y++) {
> +    for (x = 0; x < eip->xdim; x++) {
> +        if (BIT(eip, x, y) != 0) {
> +        id = (y+BIT_YWIDEN)*(eip->xdim + BIT_XWIDEN*2)+x+BIT_XWIDEN; 
> +        args->apbuf[(id >> 3)] |= (1 << (id & 7));
> +        }
> +    }
> +    }
>     return size;
> }
> 
> 
> Modified: brlcad/trunk/src/librt/primitives/ebm/ebm_shot.cl
> ===================================================================
> --- brlcad/trunk/src/librt/primitives/ebm/ebm_shot.cl    2017-10-30 19:23:02 
> UTC (rev 70378)
> +++ brlcad/trunk/src/librt/primitives/ebm/ebm_shot.cl    2017-11-01 10:48:50 
> UTC (rev 70379)
> @@ -13,7 +13,7 @@
>     double tallness;        /**< @brief Z dimension (mm) */
>     uint xdim;            /**< @brief X dimension (w cells) */
>     uint ydim;            /**< @brief Y dimension (n cells) */
> -    uchar apbuf[16];
> +    uchar apbuf[8];
> };
> 
> 
> @@ -25,8 +25,10 @@
>  */
> #define BIT_XWIDEN 2
> #define BIT_YWIDEN 2
> -#define BIT(_eip, _x, _y) \
> -    
> (((_eip)->apbuf))[((_y)+BIT_YWIDEN)*((_eip)->xdim+BIT_XWIDEN*2)+(_x)+BIT_XWIDEN]
> +static inline uint BIT(global const struct ebm_specific *eip, uint x, uint 
> y) {
> +    uint id = (y+BIT_YWIDEN)*(eip->xdim + BIT_XWIDEN*2)+x+BIT_XWIDEN;
> +    return ((eip->apbuf[(id >> 3)] & (1 << (id & 7))));
> +}
> 
> /*
>  * Codes to represent surface normals.  In a bitmap, there are only 4
> 
> This was sent by the SourceForge.net collaborative development platform, the 
> world's largest Open Source development site.
> 
> 
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> BRL-CAD Source Commits mailing list
> brlcad-comm...@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/brlcad-commits

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
BRL-CAD Developer mailing list
brlcad-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-devel

Reply via email to