Solved

setPixels(int[] inData)

Posted on 2004-10-04
8
221 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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…

705 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

18 Experts available now in Live!

Get 1:1 Help Now