[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

setPixels(int[] inData)

Posted on 2004-10-04
8
Medium Priority
?
235 Views
Last Modified: 2010-03-31
Hello!

Does anybody have any idea what this function does?
++++++++++++++++++++++++++++++++++++

   void setPixels(int[] inData){
        if(debugFlag){
            System.out.println("DicomFile.setPixels(int[]):");
        }
        pixel = new int[width * height];
        int index = 0;
        int red = 0;
        int green = 0;
        int blue = 0;
        for (int y = 0; y < height; y++) {
            //int red = (y * 255) / (height - 1);
            for (int x = 0; x < width; x++) {
                //green = (x * 255) / (width - 1);
                if (data!=null){
                    red = (inData[index]>>>16) & 0xFF;
                    green = (inData[index]>>>8) & 0xFF;
                    blue = (inData[index]) & 0xFF;
                }
                pixel[index++] = (255 << 24) | (red << 16) | (green <<8) | blue;
            }
        }
    }
+++++++++++++++++
0
Comment
Question by:dkim18
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 92

Expert Comment

by:objects
ID: 12221881
its copying an array of pixels, setting the alpha bits to 255.
 
0
 

Author Comment

by:dkim18
ID: 12221968
Objects,

what does this line do?
 red = (inData[index]>>>16) & 0xFF;

can you explain more in detail? or show me helpful links? I am not familiar with this pixels thing...

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 92

Assisted Solution

by:objects
objects earned 280 total points
ID: 12222002
0
 
LVL 21

Accepted Solution

by:
MogalManic earned 320 total points
ID: 12222667
I'll break this  down one step at a time:
inData[index] represents an index to the array of int (each int is 32 bits)
>>> is an unsigned shift right
(inData[index]>>>16) means to take the 2nd 16 bits of data and move it into the 1st 16 bits
  (e.g 10101010101010101111111111111111 becomes 00000000000000001010101010101010101010101010101)
(inData[index]>>>16) & 0xFF means keep the 1st 16 bits and discard the rest
red = (inData[index]>>>16) & 0xFF;
   means grab the 2nd set of 16 bits (counting from the right hand side) and discard the rest and store it in the variable red

green = (inData[index]>>>8) & 0xFF;
   means grab the bits between 8 and 21
blue = (inData[index]) & 0xFF;
   means grab the 1st 16 bits
0
 

Author Comment

by:dkim18
ID: 12223744
another quick question. Is '0xFF' compact way to specify byte values?
why do we use this format?
0
 
LVL 92

Expert Comment

by:objects
ID: 12223753
they are hex values, and are handy when dealing with byte and word values.
0
 
LVL 21

Expert Comment

by:MogalManic
ID: 12225044
Each hex character represents 4 binary characters.  So to know which bits are effected by an operation, just memorize this table (or tape it to your monitor):
Hex      binary
1      0001
2      0010
3      0011
4      0100
5      0101
6      0110
7      0111
8      1000
9      1001
A      1010
B      1011
C      1100
D      1101
E      1110
F      1111

So you are right, 0xFF is a compact way of specifying 11111111
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question