Solved

setPixels(int[] inData)

Posted on 2004-10-04
8
229 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
web services creation SOAP vs REST 5 80
Running JavaFX on JDeveloper 12C 1 76
Is there a simpler dropbox system? 10 44
spring maven example issues 3 38
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…
In this post we will learn different types of Android Layout and some basics of an Android App.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

740 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