CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 4 1234 LastLast
Results 1 to 15 of 46
  1. #1
    Join Date
    Apr 2008
    Posts
    214

    [RESOLVED] C++ bitmap - why?

    Edited from some code I found, but don't know why it works. Palette doesn't get used ever again after this code, but still gets applied to the image when compiled and ran?

    Code:
    bmp.palette =(RGBQUAD*) ((BYTE*)bmp.bitmapInfo + sizeof(BITMAPINFOHEADER));
    if(!fread(bmp.palette, sizeof(RGBQUAD), bmp.nColors, file))

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: C++ bitmap - why?

    Quote Originally Posted by zaryk View Post
    Edited from some code I found, but don't know why it works. Palette doesn't get used ever again
    What do you mean by "doesn't get used ever again"?
    but still gets applied to the image when compiled and ran?
    So you expect anyone to know what your entire program is doing, with the loops, functions, assignments, etc. that are being done, by posting only 2 lines of code?

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Apr 2008
    Posts
    214

    Re: C++ bitmap - why?

    Look, if you would think about the question, it means exactly what I am saying. It never gets used again; no where in the code is it used after that; ctrl-F, palette, nothing afterwards (3 entries) where it is declared and those two;

    And if you don't know what 'applied' means?
    well, no where in the code do you set bitmapInfo.bmiColors = palette, for example. WOW, you learned something today. Good Job!

    There is nothing else that is related to the palette. So, I expect people to think, and not ask stupid questions when not even I understand. Unlike when I first started, I am pretty capable of finding out what codes to use and why it works or doesn't; your lucky I ask at all. It means that I am confident there is someone who actually thinks things through before asking questions, but no, Im always let down. The other code is irrelevant.

    I have been looking over different examples of reading bitmapinfo and displaying the pic, and every example I find never actually used the palette; just read the palette in a for loop or similar to the code below. The palette on some may use it to printf() the rgb colors to the console, but nothing.

    When I didnt use the code, already displayed, I got the myprog3.gif.
    Then I added the code, already displayed, I got the myprog4.gif. Voila! It Works!

    And this is besides the fact that most of the other code I looked at, once you comment out those lines of code that copy the palette from the image; when you run the program; it crashes OR doesn't display an image at all.

    Go do some research and come back to me when your actually thinking.

    You can start with this one:
    http://www.cplusplus.com/files/winbmp.zip

    I edited the line from it because I couldn't find any better, and easiest to change around while testing why mine was showing a irregular image.
    Code:
       bmp.palette =(RGBQUAD*) ((BYTE*)bmp.bitmapInfo + sizeof(BITMAPINFOHEADER));
    Attached Images Attached Images

  4. #4
    Join Date
    Apr 2009
    Posts
    598

    Re: C++ bitmap - why?

    The palette is useful only for screens displaying no more than 256 colors. They are quite rare nowadays. Usually, we have 32 bits per pixel, or more.
    The BMP file format might contain a palette. But nowadays, images are rarely created with a palette anymore.

  5. #5
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Re: C++ bitmap - why?

    Quote Originally Posted by zaryk View Post
    Edited from some code I found, but don't know why it works. Palette doesn't get used ever again after this code, but still gets applied to the image when compiled and ran?

    Code:
    bmp.palette =(RGBQUAD*) ((BYTE*)bmp.bitmapInfo + sizeof(BITMAPINFOHEADER));
    if(!fread(bmp.palette, sizeof(RGBQUAD), bmp.nColors, file))
    So ... what exactly is bmp and what do you do with it afterwards? Do you write it to a .bmp file or maybe use it create a bitmap in memory? In which case, why would you not expect the pallette to be applied when you display the bitmap with the pallette in it?

    Quote Originally Posted by zaryk View Post
    Look, if you would think about the question, it means exactly what I am saying.
    Quote Originally Posted by zaryk View Post
    And if you don't know what 'applied' means?
    Quote Originally Posted by zaryk View Post
    So, I expect people to think, and not ask stupid questions when not even I understand.
    Quote Originally Posted by zaryk View Post
    your lucky I ask at all.
    Quote Originally Posted by zaryk View Post
    Im always let down.
    Quote Originally Posted by zaryk View Post
    Go do some research and come back to me when your actually thinking.
    Wow ... just wow.

    Grabs pop-corn and waits for Paul McKenzie to return.
    My hobby projects:
    www.rclsoftware.org.uk

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: C++ bitmap - why?

    Quote Originally Posted by Zaccheus View Post
    ...
    Wow ... just wow.

    Grabs pop-corn and waits for Paul McKenzie to return.
    Victor Nijegorodov

  7. #7
    Join Date
    Apr 2008
    Posts
    214

    Re: C++ bitmap - why?

    *sigh*

    Zacc:
    This really isn't about my code, it's about every code I have looked at, including the one I provided, but if it makes you feel better, bmp is a struct. And its drawn to a window, just a plain gray window. bmp.bitmapinfo.bmColors isn't equal to anything, so unless your saying that it reads in automatically, then I might have a better understanding, but that doesn't explain when you add those lines that read in the palette, it makes the image correct.

    Code:
    struct BMP
        {
            int nColors;
            RGBQUAD *palette;
            BYTE *bitmapImage;
            BITMAPINFO * bitmapInfo;
            BITMAPFILEHEADER fileHeader;
            BITMAPINFOHEADER infoHeader;
        };
        BMP bmp;
    And this is in a class.

    You want to see how the infoHeader is read in too?

    Why don't you all open up the example, make a project from the .cpp and comment/uncomment out these lines:

    Code:
    //Palette=(RGBQUAD*)((char*)pbmi+sizeof(BITMAPINFOHEADER));
    //bmpfile.read ((char*)Palette,sizeof (RGBQUAD) * (1<<BPP));

    the example image it provides, turns black when you comment out those lines
    the example image displays correctly when you uncomment out those lines

    Here have tux bitmap:
    the tux image turns irregular when you comment out those lines
    the tux image displays correctly when you uncomment out those lines

    Edit: Maybe, its a compiler problem, so fyi I use codeblocks.
    Attached Images Attached Images
    Last edited by zaryk; November 8th, 2010 at 02:54 PM.

  8. #8
    Join Date
    Feb 2002
    Posts
    4,640

    Re: C++ bitmap - why?

    Quote Originally Posted by zaryk View Post
    Look, if you would think about the question, it means exactly what I am saying. It never gets used again; no where in the code is it used after that; ctrl-F, palette, nothing afterwards (3 entries) where it is declared and those two;

    And if you don't know what 'applied' means?
    well, no where in the code do you set bitmapInfo.bmiColors = palette, for example. WOW, you learned something today. Good Job!

    There is nothing else that is related to the palette. So, I expect people to think, and not ask stupid questions when not even I understand. Unlike when I first started, I am pretty capable of finding out what codes to use and why it works or doesn't; your lucky I ask at all. It means that I am confident there is someone who actually thinks things through before asking questions, but no, Im always let down. The other code is irrelevant.

    I have been looking over different examples of reading bitmapinfo and displaying the pic, and every example I find never actually used the palette; just read the palette in a for loop or similar to the code below. The palette on some may use it to printf() the rgb colors to the console, but nothing.

    When I didnt use the code, already displayed, I got the myprog3.gif.
    Then I added the code, already displayed, I got the myprog4.gif. Voila! It Works!

    And this is besides the fact that most of the other code I looked at, once you comment out those lines of code that copy the palette from the image; when you run the program; it crashes OR doesn't display an image at all.

    Go do some research and come back to me when your actually thinking.

    You can start with this one:
    http://www.cplusplus.com/files/winbmp.zip

    I edited the line from it because I couldn't find any better, and easiest to change around while testing why mine was showing a irregular image.
    Code:
       bmp.palette =(RGBQUAD*) ((BYTE*)bmp.bitmapInfo + sizeof(BITMAPINFOHEADER));
    Wow, good way to get help from someone who has a lot of experience here (22000+ posts, and "reputation beyond repute (3000+)").

    Viggy

  9. #9
    Join Date
    Apr 2008
    Posts
    214

    Re: C++ bitmap - why?

    Even I can ask 3000+ stupid questions in 22k posts, and become reputable. So, I don't judge that meter as a comparison for intelligence or experience.

  10. #10
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: C++ bitmap - why?

    Quote Originally Posted by zaryk View Post
    Even I can ask 3000+ stupid questions in 22k posts, and become reputable. So, I don't judge that meter as a comparison for intelligence or experience.
    Well, then try it! And we all will see how fast you'll achieve it!
    Victor Nijegorodov

  11. #11
    Join Date
    Apr 2008
    Posts
    214

    Re: C++ bitmap - why?

    Wait till I'm about 80yrs old, when my brain is too old to think about the questions.

  12. #12
    Join Date
    Feb 2002
    Posts
    4,640

    Re: C++ bitmap - why?

    Quote Originally Posted by zaryk View Post
    Even I can ask 3000+ stupid questions in 22k posts, and become reputable. So, I don't judge that meter as a comparison for intelligence or experience.
    You don't gain a reputation for asking questions, only answering them.

    Viggy

  13. #13
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: C++ bitmap - why?

    Quote Originally Posted by zaryk View Post
    Wait till I'm about 80yrs old,
    Well, you are an optimist!
    Victor Nijegorodov

  14. #14
    Join Date
    Apr 2008
    Posts
    214

    Re: C++ bitmap - why?

    Wow, I learned something! I am so glad you cleared that up. I wish I could tell the difference, tho.

  15. #15
    Join Date
    Apr 1999
    Posts
    27,449

    Re: C++ bitmap - why?

    Quote Originally Posted by zaryk View Post
    Look, if you would think about the question, it means exactly what I am saying. It never gets used again; no where in the code is it used after that;
    Programming is an exact science. Terms such as "never gets used" means nothing without a full explanation of what you are referring to. That could mean anything from a pointer to this palette not being referenced anymore, to some loop that gets only done once, to who knows whatever. We are not mind readers or psychic.

    The point is this -- you need to learn to ask questions with more detail, so that others who have no idea what you mean can understand fully. Posting two lines of code and asking "what's happening?" is not the way to ask a serious question in any programming forum, not just CodeGuru. It is, if not amatuerish, unprofessional to formulate a question like that and then insult others (which is against forum rules to do so) who are asking you for more details. It is no different than someone posting this:
    Code:
    int i = 0;
    i += 1;
    and asking why their program only adds 1 to i only once and "never gets used", insults anyone asking for details, and then goes on about how their program has loops, while statements, function calls, ad nauseam.

    As to my experience, try 30 years of programming, and currently in the business of imaging and graphics, so I could have helped you, but I guess not. So next time, formulate a question that explains in detail what is the problem you're having, and not expect us to use divining rods and a crystal ball to figure out what you're talking about.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; November 8th, 2010 at 09:20 PM.

Page 1 of 4 1234 LastLast

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured