digitalmars.D.learn - How do I read data with ByChunk?
- Craig Dillabaugh (22/22) Mar 18 2011 Hi,
- Zirneklis (12/34) Mar 18 2011 File.byChunk is designed to be used with a foreach loop, you could try:
- Craig Dillabaugh (12/54) Mar 18 2011 values (images have the
Hi, I have two binary files containing image data, and I want to go through them pixel by pixel and read the image data into arrays and compare the pixel values (images have the exact same dimensions but one is unsigned 1 byte per pixel, and the other signed 2 bytes per pixel). I am trying to read the data in using the following loop: for(int i = 0; i < num_blocks; i++) { auto resampbytes = resampFile.byChunk( resamp_buffer_size ); auto normbytes = normalFile.byChunk( normal_buffer_size ); ubyte[] resamp = cast(ubyte[]) resampbytes; short[] normaldata = cast(short[]) normbytes; //Process the data ... } However, when I attempt to compile this I get the following errors: Error: cannot cast from ByChunk to ubyte[] Error: cannot cast from ByChunk to short[] Oddly, the example for ByChunk in the documentation seems to do exactly what I think I am trying here, but apparently I am missing something. Any help would be appreciated (also if there is a better way of doing what I am trying to do any pointers on that would be appreciated too!) Regards, Craig
Mar 18 2011
On 18/03/2011 14:35, Craig Dillabaugh wrote:Hi, I have two binary files containing image data, and I want to go through them pixel by pixel and read the image data into arrays and compare the pixel values (images have the exact same dimensions but one is unsigned 1 byte per pixel, and the other signed 2 bytes per pixel). I am trying to read the data in using the following loop: for(int i = 0; i< num_blocks; i++) { auto resampbytes = resampFile.byChunk( resamp_buffer_size ); auto normbytes = normalFile.byChunk( normal_buffer_size ); ubyte[] resamp = cast(ubyte[]) resampbytes; short[] normaldata = cast(short[]) normbytes; //Process the data ... } However, when I attempt to compile this I get the following errors: Error: cannot cast from ByChunk to ubyte[] Error: cannot cast from ByChunk to short[] Oddly, the example for ByChunk in the documentation seems to do exactly what I think I am trying here, but apparently I am missing something. Any help would be appreciated (also if there is a better way of doing what I am trying to do any pointers on that would be appreciated too!) Regards, CraigFile.byChunk is designed to be used with a foreach loop, you could try: ubyte[] resamp = new ubyte[resamp_buffer_size]; short[] normaldata = new short[normal_buffer_size]; for(int i = 0; i < num_blocks; i++) { resampFile.rawRead(resamp); normaldata.rawRead(normaldata); //Process the data ... } -- Aku MoD.
Mar 18 2011
== Quote from Zirneklis (avoi dingspam.cc)'s articleOn 18/03/2011 14:35, Craig Dillabaugh wrote:through them pixel byHi, I have two binary files containing image data, and I want to govalues (images have thepixel and read the image data into arrays and compare the pixelthe other signed 2 bytesexact same dimensions but one is unsigned 1 byte per pixel, and( resamp_buffer_size );per pixel). I am trying to read the data in using the following loop: for(int i = 0; i< num_blocks; i++) { auto resampbytes = resampFile.byChunk( normal_buffer_size );auto normbytes = normalFile.byChunkerrors:ubyte[] resamp = cast(ubyte[]) resampbytes; short[] normaldata = cast(short[]) normbytes; //Process the data ... } However, when I attempt to compile this I get the followingexactly what I think IError: cannot cast from ByChunk to ubyte[] Error: cannot cast from ByChunk to short[] Oddly, the example for ByChunk in the documentation seems to dodoing what I am tryingam trying here, but apparently I am missing something. Any help would be appreciated (also if there is a better way oftry:to do any pointers on that would be appreciated too!) Regards, CraigFile.byChunk is designed to be used with a foreach loop, you couldubyte[] resamp = new ubyte[resamp_buffer_size]; short[] normaldata = new short[normal_buffer_size]; for(int i = 0; i < num_blocks; i++) { resampFile.rawRead(resamp); normaldata.rawRead(normaldata); //Process the data ... }Thanks, that did the trick! Craig
Mar 18 2011