[fitsbits] Processor cache friendly processing of RGB FITS image.

David C. Partridge david.partridge at perdrix.co.uk
Thu Feb 13 07:13:27 EST 2020


Assume that I load the entire image into storage - I have plenty.

If I want to access the RGB tuple for location 1,1, there's a problem as
assuming (e.g.) a 30MB image, the Red Pixel will be a location 0 in the
buffer, the Green and +10MB, and the Blue at +20MB.

So if my C code (massively simplified) looks like:



		double fRed = 0.0, fGreen = 0.0, fBlue = 0.0;
		unsigned long greenOffset = m_lWidth * m_lHeight;
// index into buffer of the green image
		unsigned long blueOffset = 2 * greenOffset;
// index into buffer of the blue image

		for (long row = 0; row < m_lHeight; ++row)
		{
			for (long col = 0; col < m_lWidth; ++col)
			{
				long index = col + (row * m_lWidth);	//
index into the image for this plane

				:
				: omitted
				:

				switch (datatype)
				{
				case TBYTE:
					fRed = byteBuff[index];
					fGreen = byteBuff[greenOffset +
index];
					fBlue = byteBuff[blueOffset +
index];
					break;

which works fine but totally trashes the processor cache on each of the
three assignments.

I do need all three pixel values at the same time to populate my own
internal image representation.

Can anyone suggest a better way?

Many thanks
David

			




More information about the fitsbits mailing list