How do I read data with ByChunk?
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
Re: How do I read data with ByChunk?
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, Craig File.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.
Re: How do I read data with ByChunk?
== Quote from Zirneklis (a...@dingspam.cc)'s article 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, Craig File.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 ... } Thanks, that did the trick! Craig