Solved

setPixels(int[] inData)

Posted on 2004-10-04
8
222 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
  • 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
 
LVL 92

Expert Comment

by:objects
ID: 12221984
0
 
LVL 92

Assisted Solution

by:objects
objects earned 70 total points
ID: 12222002
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Securing Jmx Console and web console 2 65
mockito example issue 8 62
eclipse java  build path 6 45
eclipse apache tomcat admin console 52 66
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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 will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to implement Singleton Design Pattern in Java.

896 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now