ManjiriJ / indic-text-renderer

Automatically exported from code.google.com/p/indic-text-renderer
Other
0 stars 0 forks source link

How to produce more colors with Indic Text #9

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Rather than it is an issue,its just how to?
Right now I am able to produce two colors namely black and white
   @drawGlyph of EditIndicText
              int graylevel = glyphBitmap[i][j]  for white
              int graylevel =255- glyphBitmap[i][j] for black

Though,I am able to give other colors through modifying graylevel,but it 
doesn't come as crisp as white or black color.

So ,is there any way to produce other colors rather than just plain white and 
black.

Original issue reported on code.google.com by sant...@braindigit.com on 24 Jan 2013 at 8:22

GoogleCodeExporter commented 9 years ago
So bitmap masking does the work,but I don't know how it works so far
for yellow
graylevel = ((glyphBitmap[i][j] & 0x000000ff) << 8)
And maybe to produce other color we need to do bitwise shifting.

Original comment by sant...@braindigit.com on 25 Jan 2013 at 4:17

GoogleCodeExporter commented 9 years ago

folowing works for colors.

public void drawGlyph(int glyphBitmap[][], int x, int y) { 
  if (glyphBitmap == null) {                            
     return;                  
  }                  
  int height = glyphBitmap.length;                  
  if (height == 0) {
     return;                  
  }                  
  int width = glyphBitmap[0].length;                  
  Bitmap tempBitmap = Bitmap.createBitmap( width,  height, Bitmap.Config.ARGB_8888);

  int rVal = Color.red(m_nTextColor);
  int gVal = Color.green(m_nTextColor);
  int bVal = Color.blue(m_nTextColor);

  for (int i = 0; i < height; i++) {
     for (int j = 0; j < width; j++) {
       int bitmapValue = glyphBitmap[i][j];
       if (bitmapValue == 0)
           tempBitmap.setPixel(j, i, Color.TRANSPARENT);
       else {
         float bitmapFactor = ((float)(bitmapValue & 0xFF)) / 255.0f;
         tempBitmap.setPixel(j, i, Color.argb(255,
          (int)(bitmapFactor * rVal), (int)(bitmapFactor * gVal),
           (int)(bitmapFactor * bVal)));
       }
    }
  }

Original comment by rgubb...@gmail.com on 25 Jan 2013 at 3:52

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
@rgubb:
        Thanks a lot ,your method works greatly for adding colors to EditIndicText.
But I do have a question 
   on black background,the textColor seems to work fine
   but on white background,I couldn't see the same crispness of color as displayed on  black background.To work 
    For black background
    float bitmapFactor =((float)(bitmapValue& 0xFF)/255.0f
    And for white background I have done
    float bitmapFactor =((float)(bitmapValue& 0xFF);
 But the quality of color is not so vibrant as of text color displayed on black background.

Original comment by sant...@braindigit.com on 27 Jan 2013 at 9:28

Attachments:

GoogleCodeExporter commented 9 years ago
sant...,
I think the problem is same as what we faced early on. Check if the letters are 
hazy (or blurred) if you didn't do any color factoring. If so, try the 
following.

In the loop replace the first line
int bitmapValue = glyphBitmap[i][j];

by
int bitmapValue = 255 - glyphBitmap[i][j];

and do the rest as it is now. that might solve the problem.

Original comment by rgubb...@gmail.com on 27 Jan 2013 at 10:50

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
@rgubb:
           Yes the issue is same as you explained on http://code.google.com/p/indic-text-renderer/issues/detail?id=8 i.e. the text being fuzzy on white background. And I haven't done any color factoring,just followed the steps provided by you.And the solution you have provided 
    In the loop replace the first line
int bitmapValue = glyphBitmap[i][j];

by
int bitmapValue = 255 - glyphBitmap[i][j];

doesn't do any good i.e. the text comes in fuzzy manner

And last request to you,could you point me on how to learn bitmap masking,pixel 
concept and coloring to pixel,so that I might figure whole thing on my own

Original comment by sant...@braindigit.com on 28 Jan 2013 at 5:45

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
sant...
To learn pixels, their coloring etc. please refer to any basic tutorial or text 
book on image processing. I dont have any reference handy at this time.

On blurred chars displayed, please check to make sure your JNI is being built 
everytime you change the C file. Also try removing the following lines in the 
inner loop. This causes the black to become transparent and hence reflect the 
white background.

       if (bitmapValue == 0)
           tempBitmap.setPixel(j, i, Color.TRANSPARENT);

Original comment by rgubb...@gmail.com on 28 Jan 2013 at 7:43

GoogleCodeExporter commented 9 years ago
@rgubb
        I have done as you stated
        int textColor =Color.BLUE;
        //if (glyphBitmap[i][j] == 0) {
        //tempBitmap.setPixel(j, i, Color.WHITE);
       // } else {
                 int bitmapValue =glyphBitmap[i][j];
         float bitmapFactor = (float)((bitmapValue & 0xff))/255.0f;

         tempBitmap.setPixel(j, i, Color.argb(255,
                    (int) (bitmapFactor*redValue),
                    (int) (bitmapFactor*blueValue),
                    (int) (bitmapFactor*greenValue)));
                //}

And the text comes in desired blue color but with black background.Right now I 
am not changing any C (complex-script-rendering) file.

See first text
And when I do 
      int bitmapValue =255- glyphBitmap[i][j];
I see black text with blue background.(see second text)

Original comment by sant...@braindigit.com on 28 Jan 2013 at 8:32

Attachments: