Solved

setPixels(int[] inData)

Posted on 2004-10-04
8
232 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
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
LVL 92

Assisted Solution

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

Accepted Solution

by:
MogalManic earned 80 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

696 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