Page MenuHomePhabricator

evas_convert: implement convert to binary image (1bpp)
Needs ReviewPublic

Authored by ali.alzyod on Sun, Aug 4, 10:47 AM.

Details

Summary

Implement convert to rgba32 to binary image (1bpp), this could be helpful for future use

Test Plan
#include <stdio.h>

#define R_VAL(p) (((DATA8 *)(p))[2])
#define G_VAL(p) (((DATA8 *)(p))[1])
#define B_VAL(p) (((DATA8 *)(p))[0])

typedef unsigned int DATA32;
typedef unsigned char DATA8;
void evas_common_convert_rgba_to_1bpp_gry_1_dith(DATA32 *src, DATA8 *dst, int src_jump, int dst_jump, int w, int h)
{
   DATA32 *src_ptr;
   DATA8 *dst_ptr;
   int x, y;
   DATA8 r, g, b;
   DATA32 gry8;
   const DATA32 threshold = 0x7f;

   dst_ptr = (DATA8 *) dst;
   src_ptr = src;

   for (y = 0; y < h; y++)
     {
         size_t dst_row_adv = y * (w + (dst_jump<<3));
         for (x = 0; x < w; x++)
           {
               r = (R_VAL(src_ptr));
               g = (G_VAL(src_ptr));
               b = (B_VAL(src_ptr));
               // Y = 0.299 * R + 0.587 * G + 0.114 * B;
               gry8 = ((r * 76) + (g * 150) + (b * 29)) >> 8;
               if (gry8 >= threshold)
                   dst_ptr[(dst_row_adv + x) >> 3] |= (DATA8)(0x80 >> (x % 8));
               src_ptr++;
           }
         src_ptr += src_jump;
     }
}

int main()
{
    DATA32 src[10] = {0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0,0,0,0,0xFFFFFFFF,0xFFFFFFFF};
    DATA8  dst[4] = {0};
    evas_common_convert_rgba_to_1bpp_gry_1_dith(src,dst,0,0,5,2);
    printf("%x %x %x %x",dst[0],dst[1],dst[2],dst[3]);
    return 0;
}

Diff Detail

Repository
rEFL core/efl
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 12558
Build 9057: arc lint + arc unit
ali.alzyod created this revision.Sun, Aug 4, 10:47 AM

It seems that this patch has no reviewers specified. If you are unsure who can review your patch, please check this wiki page and see if anyone can be added: https://phab.enlightenment.org/w/maintainers_reviewers/

ali.alzyod requested review of this revision.Sun, Aug 4, 10:47 AM
ali.alzyod edited the test plan for this revision. (Show Details)Sun, Aug 4, 10:49 AM
ali.alzyod edited the test plan for this revision. (Show Details)
ali.alzyod added reviewers: cedric, vtorri.
segfaultxavi requested changes to this revision.Mon, Aug 5, 12:10 AM
segfaultxavi added a subscriber: segfaultxavi.

r * 76 causes overflow.
Test case is very poor, and it should be a unit case, testing far more cases. Ideally a whole ramp.
EINA_UNUSED vars are actually used.

This revision now requires changes to proceed.Mon, Aug 5, 12:10 AM

@segfaultxavi Why do you think r * 76 causes overflow ?

Auto testing is hard to implement for this function since no path lead to this function, but we may need to use it in future.

ali.alzyod updated this revision to Diff 23883.Mon, Aug 5, 12:34 AM

remove UNUSED for used variables

@segfaultxavi Why do you think r * 76 causes overflow ?

Because r is a char, or what am, I missing?

ali.alzyod added a comment.EditedMon, Aug 5, 12:23 PM

@segfaultxavi Why do you think r * 76 causes overflow ?

Because r is a char, or what am, I missing?

If you multiply char with int compiler will autocast char to int, and result saved in int

segfaultxavi resigned from this revision.Mon, Aug 5, 12:28 PM

OK, I should not be doing reviews while on holidays :)