Looking for help streaming data from bitmap files 
Author Message
 Looking for help streaming data from bitmap files

I actually posted this one about a week ago, but it seems to have expired
rather quickly.

I'm looking for some help streaming in data from a bitmap file.

My problems are occuring with 8-bit bitmaps that do not have height and
width dimensions that are multiples of 8. It seems that the pixel data, when
placed in a 2D array of the same dimensions as the image, is askew. The
image has literally been shifted so the whole thing looks sheared. I can't
figure out what's going on here. Is it a pointer problem? Should I be
offsetting my pointer to account for the fact that the dimensions aren't
some multiple of 8?

I think I need to pad the memory I'm storing the array in, but I really have
no clue how to do this.

Any help is appreciated.

Thanks.

Ian C.
--
----------
In the end it all piles up to one big nothing
One big nothing at all

Ian R. Chesal

http://www.*-*-*.com/ ~chesal



Thu, 24 Aug 2000 03:00:00 GMT  
 Looking for help streaming data from bitmap files

Quote:

> I actually posted this one about a week ago, but it seems to have expired
> rather quickly.

> I'm looking for some help streaming in data from a bitmap file.

> My problems are occuring with 8-bit bitmaps that do not have height and
> width dimensions that are multiples of 8. It seems that the pixel data, when
> placed in a 2D array of the same dimensions as the image, is askew. The
> image has literally been shifted so the whole thing looks sheared. I can't
> figure out what's going on here. Is it a pointer problem? Should I be
> offsetting my pointer to account for the fact that the dimensions aren't
> some multiple of 8?

> I think I need to pad the memory I'm storing the array in, but I really have
> no clue how to do this.

Hrmph, this hasn't much to do with Ansi C or C++.

The lines of bitmaps are often zero padded to make their bytelengths
multiples of whatever is convenient. So you get more bytes you actually
expect regarding the width of the image.

It would help if you stated the fileformat though



Fri, 25 Aug 2000 03:00:00 GMT  
 Looking for help streaming data from bitmap files

The problem is probably that you're not allowing for the fact that in the .BMP
format, the line size is always rounded up so that its a multiple of 8  - so
that lines always lie on dword boundaries I think.

something like:
  if((linelength & 3) != 0) {
    linelength |= 3;
    linelength++;
  }
should work.

manuel.

Quote:

> I actually posted this one about a week ago, but it seems to have expired
> rather quickly.

> I'm looking for some help streaming in data from a bitmap file.

> My problems are occuring with 8-bit bitmaps that do not have height and
> width dimensions that are multiples of 8. It seems that the pixel data, when
> placed in a 2D array of the same dimensions as the image, is askew. The
> image has literally been shifted so the whole thing looks sheared. I can't
> figure out what's going on here. Is it a pointer problem? Should I be
> offsetting my pointer to account for the fact that the dimensions aren't
> some multiple of 8?

> I think I need to pad the memory I'm storing the array in, but I really have
> no clue how to do this.

> Any help is appreciated.

> Thanks.

> Ian C.
> --
> ----------
> In the end it all piles up to one big nothing
> One big nothing at all

> Ian R. Chesal

> http://www.ecf.toronto.edu/~chesal



Fri, 25 Aug 2000 03:00:00 GMT  
 Looking for help streaming data from bitmap files

Quote:

> My problems are occuring with 8-bit bitmaps that do not have height and
> width dimensions that are multiples of 8. It seems that the pixel data, when
> placed in a 2D array of the same dimensions as the image, is askew. The
> image has literally been shifted so the whole thing looks sheared.

I sounds like the bug is in the routine that reads the image from
file into an array. If this routine is written in standard C, please
post it here in comp.lang.c (if it is very long, please post only
cruzial part). If it OTOH not written in standard C, please do not
cross post any more to c.l.c.

Stephan
(initiator of the campaign against grumpiness in c.l.c)



Fri, 25 Aug 2000 03:00:00 GMT  
 Looking for help streaming data from bitmap files

Quote:
>I sounds like the bug is in the routine that reads the image from
>file into an array. If this routine is written in standard C, please
>post it here in comp.lang.c (if it is very long, please post only
>cruzial part). If it OTOH not written in standard C, please do not
>cross post any more to c.l.c.

No problem. I should have mentioned that...I just figured it was implied
having posted in a C-language group and all...

Here's the relevant stuff...

/*****************************************
 * Create the array in memory dynamically *
 *****************************************/

 // Test for exceptions in case of memory errors
 try
 {
  dataArray = new DWORD*[rowSize];  // Set up the rows
  for (int i = 0; i < rowSize; i++)
  dataArray[i] = new DWORD[columnSize];  // Set up the columns

 }
 catch (xalloc)  // ENTER THIS BLOCK ONLY IF xalloc IS THROWN.
 {
  cout << "Could not allocate array.  Terminating.  Bye ...\n\n";
  exit(-1);
 }

 // Jump to data in bitmap file (should actually be there already)
 fseek(fpBmpIn, bitmapHead.Header.Offset, SEEK_SET);

 // Start streaming data into array, converting to bin numbers at same time
 for(countRow = 0 ; countRow < rowSize; ++countRow)
 {
  for(countColumn =0; countColumn < columnSize; ++countColumn)
  {
   dataArray [countRow][countColumn] = chooseBinNumber(GetByte(fpBmpIn));
  }
 }

This is the GetByte function for reference:

BYTE GetByte(FILE *fp)
{
static BYTE w;

 w=fgetc(fp)&0xff;
 return(w);

Quote:
}

And my definition for a DWORD is unsigned long. BYTE is simple unsigned
char.

Actually, I think I may have just seen my mistake...by putting 8-bit data
into the unsigned long spaces in the array, am I creating conversion
headaches for myself?

Thanks for the help...and advice. Sorry to have offended anyone with my lack
of c-specific information in my post.

Ian C.



Sat, 26 Aug 2000 03:00:00 GMT  
 Looking for help streaming data from bitmap files

|>I sounds like the bug is in the routine that reads the image from
|>file into an array. If this routine is written in standard C, please
|>post it here in comp.lang.c (if it is very long, please post only
|>cruzial part). If it OTOH not written in standard C, please do not
|>cross post any more to c.l.c.
|
|
|No problem. I should have mentioned that...I just figured it was implied
|having posted in a C-language group and all...
|
|Here's the relevant stuff...

throw wrong_newsgroup;

Oh, my! This is hardly relevant stuff.  The '//' comments are not
part of C as of ISO 9899:1990, but the real tip off is
try { /* buggy stuff */ }
catch { /* errors I shouldn't have written */ }
and
trying to shift left the unidentified identifier cout
by an amount specified by a string.  Using a
non-standard argument to exit() is, however,
common enough to "C" programmers.

When you have identified an actual C++ problem,
and have read their FAQs,
try {
   post_to("comp.lang.c++");

Quote:
}

catch {
   hell_if("post not topical or answered in FAQ");

Quote:
}

|
|/*****************************************
| * Create the array in memory dynamically *
| *****************************************/
|
| // Test for exceptions in case of memory errors
| try
| {
|  dataArray = new DWORD*[rowSize];  // Set up the rows
|  for (int i = 0; i < rowSize; i++)
|  dataArray[i] = new DWORD[columnSize];  // Set up the columns
|
| }
| catch (xalloc)  // ENTER THIS BLOCK ONLY IF xalloc IS THROWN.
| {
|  cout << "Could not allocate array.  Terminating.  Bye ...\n\n";
|  exit(-1);
| }
|
| // Jump to data in bitmap file (should actually be there already)
| fseek(fpBmpIn, bitmapHead.Header.Offset, SEEK_SET);
|
| // Start streaming data into array, converting to bin numbers at same time
| for(countRow = 0 ; countRow < rowSize; ++countRow)
| {
|  for(countColumn =0; countColumn < columnSize; ++countColumn)
|  {
|   dataArray [countRow][countColumn] = chooseBinNumber(GetByte(fpBmpIn));
|  }
| }
|
|This is the GetByte function for reference:
|
|BYTE GetByte(FILE *fp)
|{
|static BYTE w;
|
| w=fgetc(fp)&0xff;
| return(w);
|}
|
|And my definition for a DWORD is unsigned long. BYTE is simple unsigned
|char.
|
|Actually, I think I may have just seen my mistake...by putting 8-bit data
|into the unsigned long spaces in the array, am I creating conversion
|headaches for myself?
|
|Thanks for the help...and advice. Sorry to have offended anyone with my
lack
|of c-specific information in my post.
|
|Ian C.
|
|


Sat, 26 Aug 2000 03:00:00 GMT  
 Looking for help streaming data from bitmap files


: >I sounds like the bug is in the routine that reads the image from
: >file into an array. If this routine is written in standard C, please
: >post it here in comp.lang.c (if it is very long, please post only
: >cruzial part). If it OTOH not written in standard C, please do not
: >cross post any more to c.l.c.

: No problem. I should have mentioned that...I just figured it was implied
: having posted in a C-language group and all...
[...]

Well, it may have been implied, but it was wrong; you are using C++,
not C.  Although your compiler may well be able to handle both, they
are very different languages, and you need to ask questions on C++
in comp.lang.c++.

Will



Sat, 26 Aug 2000 03:00:00 GMT  
 Looking for help streaming data from bitmap files

Fine.

Quote:


>: >I sounds like the bug is in the routine that reads the image from
>: >file into an array. If this routine is written in standard C, please
>: >post it here in comp.lang.c (if it is very long, please post only
>: >cruzial part). If it OTOH not written in standard C, please do not
>: >cross post any more to c.l.c.

>: No problem. I should have mentioned that...I just figured it was implied
>: having posted in a C-language group and all...
>[...]

>Well, it may have been implied, but it was wrong; you are using C++,
>not C.  Although your compiler may well be able to handle both, they
>are very different languages, and you need to ask questions on C++
>in comp.lang.c++.

>Will




Sun, 27 Aug 2000 03:00:00 GMT  
 Looking for help streaming data from bitmap files

Ian R. Chesal wrote in a message to All:

Quote:
>If this routine is written in standard C, please post it here in
>comp.lang.c

 IRC> No problem. I should have mentioned that...I just figured it was
 IRC> implied having posted in a C-language group and all...

Just what exactly did you imply ? That try, new, definition in for loop
initialiser, catch, xalloc, cout are standard C ? In that case I'm
afraid your implication is entirely wrong. It may be (and probably is)
valid standard C++ though.

 IRC> BYTE GetByte(FILE *fp)
 IRC> {
 IRC> static BYTE w;
 IRC> w=fgetc(fp)&0xff;
 IRC> return(w);
 IRC> }

You don't gain anything here by making w static. You only need to do
this in some cases where you have to return a pointer to an array (or
sometimes even struct), although personally I don't like the method.
The standard library does it (e.g. localtime), but then again the
standard library also has gets().

greetings,
Tom



Sun, 27 Aug 2000 03:00:00 GMT  
 Looking for help streaming data from bitmap files

*.bmp files DWORD align every scanline

Quote:

>I actually posted this one about a week ago, but it seems to have expired
>rather quickly.

>I'm looking for some help streaming in data from a bitmap file.

>My problems are occuring with 8-bit bitmaps that do not have height and
>width dimensions that are multiples of 8. It seems that the pixel data,
when
>placed in a 2D array of the same dimensions as the image, is askew. The
>image has literally been shifted so the whole thing looks sheared. I can't
>figure out what's going on here. Is it a pointer problem? Should I be
>offsetting my pointer to account for the fact that the dimensions aren't
>some multiple of 8?

>I think I need to pad the memory I'm storing the array in, but I really
have
>no clue how to do this.

>Any help is appreciated.

>Thanks.

>Ian C.
>--
>----------
>In the end it all piles up to one big nothing
>One big nothing at all

>Ian R. Chesal

>http://www.ecf.toronto.edu/~chesal



Sun, 03 Sep 2000 03:00:00 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Need help streaming data from BMP file

2. Capturing frames from a data stream into bitmap format

3. Data Streams and File Pointers

4. can you remove data from data streams???

5. create bitmap from a dialog box with data from .RC file

6. HELP: bitmap data structure!!

7. Help on offset of a file (stream):

8. c file (stream) input buffer problem help PLEASE!

9. Changing a FD to a FILE Stream........HELP!

10. HELP ME: Files and Streams

11. Bitmap to stream, how come only 0x0000

12. Streaming PDF data into browser

 

 
Powered by phpBB® Forum Software