Results 1 to 7 of 7
  1. #1
    TacoManStan is offline Member
    Join Date
    Sep 2011
    Posts
    50
    Rep Power
    0

    Default How does the ColorModel class work?

    Hey everyone,

    I am working on a fairly basic 2D game, and I need some help modifying individual pixel data of a BufferedImage. The problem is, I don't quite understand how the BufferedImage organizes it's data into making the image appear.

    I know that there are two primary components, the ColorModel and the Raster. I have looked all over the internet for a basic introduction on how they work, but I can find none. Everything I find assumes that I already know how arrays of bytes are used to form colors, which I don't. All I really know about colors are the RGB and some ARGB color scheme, the 0 - 255 model.

    Some specific questions I have are:

    1) How does the IndexColorModel class work? What does it mean (in the constructor) by the size of the arrays vs. the number of bits each pixel occupies?

    2) Does the IndexColorModel specify an array of pixels the same way a Raster does, or does it contain a list of colors to be referenced by the Raster?

    3) What are "bands" and "banks" in terms of the ColorModel?

    4) What does the SampleModel do?

    5) What does it mean by having a Raster (or WritableRaster) that is compatable with a ColorModel?

    Any help would be greatly appreciated.

    PS: One more thing. The other day a friend reminded me that older games, and even some newer, have say 16 colors allowed in one sprite, which I'm assuming has something to do with the size of a bit/byte. This would then form a color pallet in which the Raster would take it's data from, to save time and memory. Is that what the ColorModel is? If so, how would I work it? If not, how is it done? Sorry, I have a lot of questions, if you have an answer or ANY website that will answe any of these questions, I would be very greatful.

    Thanks.

    PSS: Sorry for any spelling, grammer, etc errors, I wrote this rather fast with no spellcheck.

  2. #2
    TacoManStan is offline Member
    Join Date
    Sep 2011
    Posts
    50
    Rep Power
    0

    Default Re: How does the ColorModel class work?

    Really need help with this one. If anyone could point me to a website where I could start learning this myself that would also be very much appreciated. Anything where I can start.

    Thanks.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default Re: How does the ColorModel class work?

    If you want to know how a ColorModel is used, read the API.

    If you want to know how it works, read the source code.

    Why is this knowledge important to you?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    TacoManStan is offline Member
    Join Date
    Sep 2011
    Posts
    50
    Rep Power
    0

    Default Re: How does the ColorModel class work?

    Thanks for the quick response.

    It isn't the java that i'm interested in. Well it is, but I need to know how rasters communicate with the colormodels. I have no idea how pixels in general work, and I wouldn't know where to go to ask, so I made a thread here. The API is useful, but once again it assumes that I already know a lot about how pixels use arrays of primitives and what not, which I don't.

    And as for why the information is important, I am going to be implementing 2D particle emitters, shadows, lighting, and other things that will require modifying pixel data.

    Thanks for any help anyone can provide, and sorry if I'm not being clear... I really don't understand how these things work. If there is a better way to do this please tell me, but I still want to learn this stuff, it is going to be important especially when I try to write my own engine. (no time soon, probably when I go to college)

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default Re: How does the ColorModel class work?

    I need to know how rasters communicate with the colormodels
    The only way I know to approach that kind of knowledge gathering is to trace through the source code execution. you can do this by spending sleepless nights reading the JDK sources, or you can throw a test rig together and use a debugger. Each approach has its merits and demerits.

    ... things that will require modifying pixel data.
    I still don't see why that requires an in-depth understanding of how these classes work. What they do -- the API they expose -- is all you can make use of.

    Unless of course you want to write your own replacements for the JDK classes, aka reinventing the wheel.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    TacoManStan is offline Member
    Join Date
    Sep 2011
    Posts
    50
    Rep Power
    0

    Default Re: How does the ColorModel class work?

    Lol I feel stupid... I literally don't understand how the classes work. I have no desire to understand how the data is converted into the raster, I just want to know what the arrays mean.

    For example, a raster of 16 bytes of red, green, and blue can define a raster of 200x200. I don't understand how or why that works, or what the arrays are doing. I think my question is a lot simpler than you think, all I want to know is what the ColorModel does to the raster.

    Thanks, and sorry if I wasted your time or anything, or if I worded my question poorly.

  7. #7
    TacoManStan is offline Member
    Join Date
    Sep 2011
    Posts
    50
    Rep Power
    0

    Default Re: How does the ColorModel class work?

    No one has any more advice? Sill looking for help on this one...

Similar Threads

  1. Replies: 12
    Last Post: 08-16-2011, 10:25 AM
  2. Replies: 6
    Last Post: 02-24-2011, 10:35 PM
  3. How can I make this Java class work
    By ruchir123 in forum New To Java
    Replies: 2
    Last Post: 12-10-2010, 11:53 PM
  4. class that wont work out properly.
    By vampire-elf in forum New To Java
    Replies: 7
    Last Post: 09-07-2010, 01:39 AM
  5. repaint class doesnt work anymore... dunno why..
    By Addez in forum New To Java
    Replies: 9
    Last Post: 11-07-2009, 09:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •