LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Value is invalid or out of range

Hi, I have a problem during craeting bitmap. I receive NON_FATAL RUN_TIME ERROR that says "Value is invalid or out of range". At first I tried to use 24 bits pixel depth but I decreased it to 8 because I thought that it might solve this problem but it didn't. Could you help me to avoid this? And could you tell me what is maximum size of bitmap may be?

0 Kudos
Message 1 of 5
(3,068 Views)

How are you creating the bitmap? Can you post your code and highlight where the error arises?

 

If you are using CVI functions like NewBitmap () or so keep in mind this note that you can read in the help for the function (highlight is mine):

pixelDepth int Number of bits per pixel.

The valid values for the pixelDepth parameter are 1, 4, 8, 24, and 32. This depth determines how LabWindows/CVI interprets the data you pass in the bits parameter.

Regardless of the color depth that you specify, the new bitmap matches the color depth of the display screen.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 5
(3,034 Views)

Thank you for reply. My bitmap size changes dynamicly depending on parameters that I receive in funciton. I guess it depends on size of bitmap. Because with bytesPerRow = 26000 it works fine. But when bytesPerRow = 130000 I receive

this error. 

Here is the funciton: 

	// Bits per pixel in bitmap
	const int pixelDepth = 24;
	
	const int bitmapID;
	
	//
	// Finding max time to get size of array used for drawing 
	//
	double maxTime = findMaxTime(&receiver);
	
	// Size of array that used for drawing 
	// original signal array size is 1000 which means 1 ms 
	// so size of final signal should be 1000 * max but for better look we will increase it in 2 times
	const int drawSize = maxTime * 2 * array_size;
	
	// array that used for showing signals 
	double drawArray[drawSize];
	
	// size of bits array
	// amount of elements per line depends on pixelDepth
	// one element - one byte
	const int bitsSize = drawSize *  pixelDepth/8;
	
	
	const int bytesPerRow = drawSize * pixelDepth/8; 
	
	// bits array that contains info about each pixel in bitmap
	unsigned char bits[bitsSize];
	
	// max and min values from drawArray
	double maxVal, minVal;
	
	// indexes of max and min values
	int maxIndex, minIndex;
	
	int colors[256];
	
	for (int k = 0; k < 256; k++)
		colors[k] = 256 * k + 256 * 256 * k + k;
	
	// Calling function that counts final view of signals and assigning it to drawArray
	memcpy(drawArray, findDrawArray(&receiver), sizeof(drawArray));
	
	// Max and min values from drawArray
	MaxMin1D(drawArray, drawSize, &maxVal, &maxIndex, &minVal, &minIndex);
			
	NewBitmap(bytesPerRow, pixelDepth, drawSize, 1, colors, bits, NULL, &bitmapID);

This funciton I needs to draw in canvas array that was filled by previous steps. 

Thank you. 

0 Kudos
Message 3 of 5
(3,029 Views)

I suppose your 26000 and 130000 figures are approximated, since they would give a fractional value for DrawSize Smiley Happy

 

It's not clear to me how that error could arise, and you don't say us where you receive it. Anyway, since you are dealing with 24-bit images I would put away 'colors' and 'bytesPerRow' parameters from the call to NewBitmap: the first one is not used for such a resolution, while bytesPerRow can be changed to -1 without losses since your image is a single line of pixels.

Probably this won't solve your problem but the code will be cleaner and easier to follow/check.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 5
(3,020 Views)

Yes,  those values are approximately as each time function receive different values.

But such values I received during debugging. Everything I want to be done is for each value in array set exect color for pixel. 

	NewBitmap(bytesPerRow, pixelDepth, drawSize, 1, colors, bits, NULL, &bitmapID);
	
	for(int i = 0; i<drawSize; i++)
	{
		double percent;
		
		if(drawArray[i] < 0)
		{
		    percent = ((abs(minVal) - abs(drawArray[i])) * 100.0)/(abs(minVal) + maxVal); 
		}
		else
		{
			percent = ((abs(minVal) + drawArray[i]) *100.0)/(abs(minVal) + maxVal);
		}

		int color = (255 * percent)/100;
		
	
		bits[i] = color;
		bits[i+1] = color;
		bits[i+2] = color;
	}
SetBitmapData(bitmapID, bytesPerRow, 8, colors, bits, NULL);

This code works fine. But if size of  "drawArray" mentioned above become higher. I receive this error. This error points me to function NewBitmap and code after NewBitmap function don't execute. I will send you full function:

	// Bits per pixel in bitmap
	const int pixelDepth = 24;
	
	const int bitmapID = 1435;
	
	//
	// Finding max time to get size of array used for drawing 
	//
	double maxTime = findMaxTime(&receiver);
	
	// Size of array that used for drawing 
	// original signal array size is 1000 which means 1 ms 
	// so size of final signal should be 1000 * max but for better look we will increase it in 2 times
	const int drawSize = maxTime * 2 * array_size;
	
	// array that used for showing signals 
	double drawArray[drawSize];
	
	// size of bits array
	// amount of elements per line depends on pixelDepth
	// one element - one byte
	const int bitsSize = drawSize *  pixelDepth/8;
	
	
	const int bytesPerRow = drawSize * pixelDepth/8; 
	
	// bits array that contains info about each pixel in bitmap
	unsigned char bits[bitsSize];
	
	// max and min values from drawArray
	double maxVal, minVal;
	
	// indexes of max and min values
	int maxIndex, minIndex;
	
	int colors[256];
	
	for (int k = 0; k < 256; k++)
		colors[k] = 256 * k + 256 * 256 * k + k;
	
	// Calling function that counts final view of signals and assigning it to drawArray
	memcpy(drawArray, findDrawArray(&receiver), sizeof(drawArray));
	
	// Max and min values from drawArray
	MaxMin1D(drawArray, drawSize, &maxVal, &maxIndex, &minVal, &minIndex);
		
/*	for(int c = 0; c<255; c++)
	{
		colors[c].color = MakeColor(c, c, c);
		
		if(minVal + c * ((abs(minVal) + maxVal)/255) <= 0)
		{
			colors[c].dataValue.valDouble = minVal + c * ((abs(minVal) + maxVal)/255); 
		}
		else
		{
			colors[c].dataValue.valDouble = c * ((abs(minVal) + maxVal)/255) - abs(minVal);
		}
		
		#ifdef DEBUG 
			printf("color data val = %f \n", colors[c].dataValue.valDouble);
		#endif
		
	}
*/	

	//
	// !!!Soleve problem with bitmap size!!!
	//
	
	NewBitmap(bytesPerRow, pixelDepth, drawSize, 1, colors, bits, NULL, &bitmapID);
	
	for(int i = 0; i<drawSize; i++)
	{
		double percent;
		
		if(drawArray[i] < 0)
		{
		    percent = ((abs(minVal) - abs(drawArray[i])) * 100.0)/(abs(minVal) + maxVal); 
		}
		else
		{
			percent = ((abs(minVal) + drawArray[i]) *100.0)/(abs(minVal) + maxVal);
		}

		int color = (255 * percent)/100;
		
	
		bits[i] = color;
		bits[i+1] = color;
		bits[i+2] = color;
	}
	
	SetBitmapData(bitmapID, bytesPerRow, 8, colors, bits, NULL);

	CanvasDrawBitmap(tabPanelHandle_5, TABPANEL_5_CANVAS, bitmapID, VAL_ENTIRE_OBJECT, VAL_ENTIRE_OBJECT); 

Please tell me if you will need additional information

 

 

 

0 Kudos
Message 5 of 5
(3,016 Views)