How do I read data with ByChunk?

Craig Dillabaugh cdillaba at nrcan.gc.ca
Fri Mar 18 07:35:03 PDT 2011


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



More information about the Digitalmars-d-learn mailing list