Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Windows Bitmaps, Continued!

SephirothSephiroth Fayetteville, NC, USAPosts: 1,035Member
Think I may have found the problem with the image. Say I have a 320x200 image. I would code my app to red pixels 0-319. Now when I store the bitmap's dimensions in the bitmap headers, should I store 319 or 320 for the width? Subtracting one from the width seems to fix the problem in some cases.

-[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

Comments

  • AsmGuru62AsmGuru62 Posts: 6,519Member
    : Think I may have found the problem with the image. Say I have a 320x200 image. I would code my app to red pixels 0-319. Now when I store the bitmap's dimensions in the bitmap headers, should I store 319 or 320 for the width? Subtracting one from the width seems to fix the problem in some cases.
    :
    : -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]
    :
    [blue]The width field in BMP headers must be the physical width (in your case 320). If making it 319 'fixes' something - you should get into debugger and see [b]why[/b] it 'fixes'? The problem is somewhere else. Can you explain what is it your doing? BMP editor of some kind? If so, just look in MSDN or www.wotsit.org - they should have better explanation of BMP format.[/blue]
  • SephirothSephiroth Fayetteville, NC, USAPosts: 1,035Member
    : [blue]The width field in BMP headers must be the physical width (in your case 320). If making it 319 'fixes' something - you should get into debugger and see [b]why[/b] it 'fixes'? The problem is somewhere else. Can you explain what is it your doing? BMP editor of some kind? If so, just look in MSDN or www.wotsit.org - they should have better explanation of BMP format.[/blue]
    :
    Actually I am looking into the old file format now. I noticed that some images have a recorded size less than the width * height - header. This is very odd, but here's a general run-down. Oh, and the reason that I am reading these as "sizeof(char[2])" is because the files are old 16bit byte-aligned files, and the vars are of the type "short".
    [code]
    void ConvertIMG(char *FileName)
    {
    ...
    fread(&(IMGHeader.XOffset), sizeof(char[2]), 1, pImageFile);
    fread(&(IMGHeader.YOffset), sizeof(char[2]), 1, pImageFile);
    fread(&(IMGHeader.Width), sizeof(char[2]), 1, pImageFile);
    fread(&(IMGHeader.Height), sizeof(char[2]), 1, pImageFile);
    fread(&(IMGHeader.Unused), sizeof(char[2]), 1, pImageFile);
    fread(&(IMGHeader.ImageSize), sizeof(char[2]), 1, pImageFile);
    ...
    return;
    }
    [/code]
    After that I just read in the linear bitmap. The linear bitmap is of type "char" and contains "IMGHeader.ImageSize" of them. Each has a value of 0-255 which points to an RGB triplet in a seperate palette file. I showed in my other post how I read/wrote the palette and new bitmap. The colors come out fine, but the image just won't for some reason, unless I subtract one from the width and set that in the bitmap headers. All of the vars I read into are 32bit "short int" vars. Any ideas?

    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

  • AsmGuru62AsmGuru62 Posts: 6,519Member
    : : [blue]The width field in BMP headers must be the physical width (in your case 320). If making it 319 'fixes' something - you should get into debugger and see [b]why[/b] it 'fixes'? The problem is somewhere else. Can you explain what is it your doing? BMP editor of some kind? If so, just look in MSDN or www.wotsit.org - they should have better explanation of BMP format.[/blue]
    : :
    : Actually I am looking into the old file format now. I noticed that some images have a recorded size less than the width * height - header. This is very odd, but here's a general run-down. Oh, and the reason that I am reading these as "sizeof(char[2])" is because the files are old 16bit byte-aligned files, and the vars are of the type "short".
    : [code]
    : void ConvertIMG(char *FileName)
    : {
    : ...
    : fread(&(IMGHeader.XOffset), sizeof(char[2]), 1, pImageFile);
    : fread(&(IMGHeader.YOffset), sizeof(char[2]), 1, pImageFile);
    : fread(&(IMGHeader.Width), sizeof(char[2]), 1, pImageFile);
    : fread(&(IMGHeader.Height), sizeof(char[2]), 1, pImageFile);
    : fread(&(IMGHeader.Unused), sizeof(char[2]), 1, pImageFile);
    : fread(&(IMGHeader.ImageSize), sizeof(char[2]), 1, pImageFile);
    : ...
    : return;
    : }
    : [/code]
    : After that I just read in the linear bitmap. The linear bitmap is of type "char" and contains "IMGHeader.ImageSize" of them. Each has a value of 0-255 which points to an RGB triplet in a seperate palette file. I showed in my other post how I read/wrote the palette and new bitmap. The colors come out fine, but the image just won't for some reason, unless I subtract one from the width and set that in the bitmap headers. All of the vars I read into are 32bit "short int" vars. Any ideas?
    :
    : -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]
    :
    :
    [blue]I am not sure, but I think that BMP file format was not modifed since Win 3.0 - just some features added, but never the structures defining it were altered in a way of 16-bit into 32-bit.

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_4v1h.asp

    Are you loading everything according to that ^^^?

    Also, if you want, of course, send me your image file to 'asmguru62@hotmail.com' - just make a ZIP out of it. I want to take a look. Maybe these images are some kind of proprietary format? And not real Windows BMPs?[/blue]
  • SephirothSephiroth Fayetteville, NC, USAPosts: 1,035Member
    : [blue]I am not sure, but I think that BMP file format was not modifed since Win 3.0 - just some features added, but never the structures defining it were altered in a way of 16-bit into 32-bit.
    :
    : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_4v1h.asp
    :
    : Are you loading everything according to that ^^^?
    :
    : Also, if you want, of course, send me your image file to 'asmguru62@hotmail.com' - just make a ZIP out of it. I want to take a look. Maybe these images are some kind of proprietary format? And not real Windows BMPs?[/blue]
    :
    Well the images I am converting are proprietary to Bethesda Softworks. They're .IMG format of their own design, but I'm converting them to bitmaps. I'll send you the source, an image or two, and let you see what's happening. Maybe we can figure it out together.

    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

  • AsmGuru62AsmGuru62 Posts: 6,519Member
    : : [blue]I am not sure, but I think that BMP file format was not modifed since Win 3.0 - just some features added, but never the structures defining it were altered in a way of 16-bit into 32-bit.
    : :
    : : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_4v1h.asp
    : :
    : : Are you loading everything according to that ^^^?
    : :
    : : Also, if you want, of course, send me your image file to 'asmguru62@hotmail.com' - just make a ZIP out of it. I want to take a look. Maybe these images are some kind of proprietary format? And not real Windows BMPs?[/blue]
    : :
    : Well the images I am converting are proprietary to Bethesda Softworks. They're .IMG format of their own design, but I'm converting them to bitmaps. I'll send you the source, an image or two, and let you see what's happening. Maybe we can figure it out together.
    :
    : -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]
    :
    :
    [blue]So, the question is: this Bethesda company - do they publish their .IMG format or you have to reverse-engineer it?[/blue]
  • SephirothSephiroth Fayetteville, NC, USAPosts: 1,035Member
    : [blue]So, the question is: this Bethesda company - do they publish their .IMG format or you have to reverse-engineer it?[/blue]
    :
    Bethesda never published it, but it's a widely known format. Reference here:

    http://www.m0use.net/~uesp/text.shtml?dagger/imgfrm.txt

    I am now emailing you a few images and my source. Expect it in about 10min if the net is laggy. I'm not though, 5.8mbps :D!

    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

Sign In or Register to comment.