android studio cannot resolve symbol "ff" - android

I am trying to retrieve value of red, green,blue from pixel color value .So I need to perform some shift and multiply operation.But android studio notifying above error at following code.
clr=bm.getPixel(0,0);
cred=(clr & 0*ff)>>16;
tv.append((String.valueOf(clr)));
tv.append((String.valueOf(cred)));
ERROR:Cannot resolve Symbol ff at line no 2;

It should be 0xff and not 0*ff
cred=(clr & 0xff)>>16;
0*ff is multiplying 0 with unknown symbol ff (since you don't have any variable named ff in scope)
While above code will compile and resolve your error, it is not correct code for reading red color value from bitmap pixel. Correct code would be
cred = (clr >> 16) & 0xff;
But probably the easiest and safest way would be to use Color class.
int a = Color.alpha(clr);
int r = Color.red(clr);
int g = Color.green(clr);
int b = Color.blue(clr);

Related

Save Android color as int notation

I wand to Theme a app in the same Color like my CM Theme and the App only allow to use a color picker,after looking in the shard preference of the app i found something. That's the Story but not the question.
This is what i found:
<int name="color_main_window" value="-13162859" />
My question is how i can generate this int from rgb/hex and the absolutely needed way from rgb/hex to int ?
An int is a 32-bit signed integer. So, -13161859 = 0xFF372695. A color will be represented as an ARGB int, so
a = FF
r = 37
g = 26
b = 95
The Color class has utility methods that can convert int to rgb or argb and vice versa.

Convert XY Values to RGB

I am using the Android Philips Hue SDK and I am currently having an issue with converting the light bulbs XY value to RGB.
I have looked at this code provided in a forum on Philips Hue website and the code has been provided by someone from Hue Support.
I have the following function using this code from the forum:
public static int[] convertXYToRGB(float[] xy, String lightModel)
{
int color = PHUtilities.colorFromXY(xy, lightModel);
int r = Color.red(color);
int g = Color.green(color);
int b = Color.blue(color);
return new int[] {r, g, b};
}
And I am calling it like:
int hue = lightState.getHue();
float[] xy = PHUtilities.calculateXY(hue, item.light.getModelNumber());
int[] rgb = Utilities.convertXYToRGB(xy, item.light.getModelNumber());
Looking at the RGB value I get back it seems to be the wrong colour. For example, using the official app, I set one of my light bulbs to red. When I run my app, the RGB value that comes back is a pale yellow.
Has anyone else experienced this or know how to resolve this issue?
I had a similar issue while programming a desktop application using the same Java SDK (login required). Interestingly, a plain red turned into a fade yellow, exactly how you describe it. A possible solution is to use the xy-values directly instead of the conversion from hue-values. That finally solved the problem for me. You can get the xy-values from the PHLightState object using the methods .getX() and .getY(). After that, use colorFromXY as in your code to get the RGB-values (as android color value = int).
PHLightState s = light.getLastKnownLightState();
float xy[] = new float[] {s.getX(), s.getY()};
int combRGB = PHUtilities.colorFromXY(xy, light.getModelNumber());
On Android, convert combRGB as you already do. Make sure to include android.graphics.Color. If you are testing on non-Android systems you can use the following code:
Color theColor = new Color(combRGB);
int[] sepRGB = {theColor.getRed(), theColor.getGreen(), theColor.getBlue()};
Note: The lights can only address a certain color gamut depending on the type. This is explained into detail here. The 'normal' bulbs with a color gamut B have quite some limitations. For example: most greens turn into yellows and the blues contain a certain amount of red.
Example values: The following overall conversions are tested on my live system with LCT001-blubs. I used PHUtilities.calculateXYFromRGB() to convert the input, then I set the xy-values of the new light state with .setX() and .setY() and finally sent it to the bridge. The values are then extracted from the light cache in the application as soon as it gets the next update.
255 0 0 -> 254 0 0
0 255 0 -> 237 254 0
0 0 255 -> 90 0 254
200 0 200 -> 254 0 210
255 153 0 -> 254 106 0
255 153 153 -> 254 99 125

Unresolved inclusion: <algorithm> eclipse Android

Why is not in my NDK algoritmh.h???? how can i make my std::Sort???? of 1d array
/----------------------------------------------------------
Solved the 2nd question::
and 2. question:my other code started says this error:) SOlved!
Multiple markers at this line
- call of overloaded 'log(int)' is
ambiguous
- candidates are:
in this code:
int m = (int) (log (524288) / log (2));
OK this is solved
std::log has overloads that accept float, double or long double as parameters. The compiler doesn't know which function you are asking for.
Try:
int m = (int) (log (524288.) / log (2.));
Notice that the parameters to log() are now double, not int.

Understanding ImageProcessing code

I am new to android ndk.I have started learning through the image processing example by
ruckus and by IBM blog. I am not getting few lines below.Can any one please help me to understand the code snippet?`
static void brightness(AndroidBitmapInfo* info, void* pixels, float brightnessValue){
int xx, yy, red, green, blue;
uint32_t* line;
for(yy = 0; yy < info->height; yy++){
line = (uint32_t*)pixels;
for(xx =0; xx < info->width; xx++){
//extract the RGB values from the pixel
red = (int) ((line[xx] & 0x00FF0000) >> 16);
green = (int)((line[xx] & 0x0000FF00) >> 8);
blue = (int) (line[xx] & 0x00000FF );
//manipulate each value
red = rgb_clamp((int)(red * brightnessValue));
green = rgb_clamp((int)(green * brightnessValue));
blue = rgb_clamp((int)(blue * brightnessValue));
// set the new pixel back in
line[xx] =
((red << 16) & 0x00FF0000) |
((green << 8) & 0x0000FF00) |
(blue & 0x000000FF);
}
pixels = (char*)pixels + info->stride;
}
}
`
static int rgb_clamp(int value) {
if(value > 255) {
return 255;
}
if(value < 0) {
return 0;
}
return value;
}
How the RGB value are getting extracted and wht does this rgb_clamp do.Why are we setting new Pixell back and how does pixels = (char*)pixels + info->stride; works?
I am not a c/c++ guys and not having much knowledge of Image processing.
Thanks
At first lets talk about one pixel. As far as i can see, it is a composition of at least 3 channels: r,g and b, which are all stored in one uint32_t value and has the format 0x00RRGGBB(32bit / 4 channels = 8bit per channel and thus a value range from 0..255). So, to get the separated r, g and b-values you need to mask them out, which is done in the three lines below //extract the RGB values. For example the red component... With the mask 0x00FF0000 and the & operator, you set every bit to 0 except the bits that are set in the red channel. But when you just mask them out with 0x00RRGGBB & 0x00FF0000 = 0x00RR0000, you would get a very big number. To get a value between 0 and 255 you also have to shift the bits to the right and that is what is done with the >>-operator. So for the latter example: After applying the mask, you get 0x00RR0000, and shifting this 16 bit right (>> 16)gives you 0x000000RR, which is a number between 0 and 255. The same happens with the green channel, but with an 8bit right shift and since the blue value is already on the "right" bit position, there is no need to shift.
Second question: What rgb_clamp does is easy to explain. It ensures, that your r,g or b-value, multiplied with your brightness factor, never exceeds the value range 0..255.
After the multiplication with the brightness factor, the new values are written back into memory, which happens in the reverse order of the above described extraction, this time shifting them leftwards and removing bits, that we don't want with the mask.
After one line of your image is processed, the info->stride is added, since for optimization purposes, the memory probably is aligned to fill 32byte boundaries and thus a single line can be longer than only image width and thus the "rest" of bytes are added to the pointer.
First and foremost I suggest you read the C book here: http://publications.gbdirect.co.uk/c_book/
Next I'll go through your questions.
How are the RGB values extracted
line is set to point to pixels parameter:
line = (uint32_t*)pixels;
That is pixels is an array of 32 bit unsigned integers
Then for the height and width of the bitmap the RGB values are extracted using a combination of bitwise ANDing (&) and bit shifting right (>>).
Lets see how you get red:
red = (int) ((line[xx] & 0x00FF0000) >> 16);
Here we get the current line, then AND with 0x00FF0000 as mask, this gets the bits 24-16 from the line. So using RGB code #123456 as an example we will be left with 0x00120000 in the red variable. But it's still in the 24-16 bit position so we right shift 16 bits to shift the bits down to 0x00000012.
We do this for the green and blue values, adjusting the AND mask and number of bits to shift right.
More information on binary arithmetic can be found here: http://publications.gbdirect.co.uk/c_book/chapter2/expressions_and_arithmetic.html
What does rgb_clamp do
This function simply ensures the red, green, or blue values are 0 or above or 255 and below.
If the parameter to rbg_clamp is -20 the it will return 0, which will be used to set the RGB value. If the parameter is rbg_clamp is 270 it will return 255.
RGB values for each colour must not exceed 225 or be below 0. In this example 255 being the brightest and 0 being the darkest value.
Why are we setting pixel back
It appears we are changing the brightness of the pixel, and setting the value back ready to be displayed.
How does pixels = (char*)pixels + info->stride; work?
Without knowing the structure of info variable of AndroidBitmapInfo type, I would guess info->stride refers to the width of the bitmap in bytes so line will become the next line on the next loop iteration.
Hope that helps

How to create view cache by RGB565?

android 2.2, the default view cache is ARGB_8888,
How to create view's cache by RGB565?
Thanks!
The simplest way is to simply drop the least-significant bits.
Ie.
NewR = R >> 3;
NewG = G >> 2;
NewB = B >> 3;
However, I suppose a more thorough method might include some form of dithering, to minimise banding.

Categories

Resources