Beispiel #1
0
/// <summary>
/// Main processing function
/// </summary>
void Direct2DWindow::Update()
{
    m_cdmap->RefreshField();
    const ColorField color_ref(m_cdmap->GetColorFieldRef());
	BYTE *bytearray = const_cast<BYTE*>(color_ref.GetColorArray());
    m_pDrawDepth->Draw(bytearray,
                       color_ref.GetFieldArea() * color_ref.GetBytesPerPixel());
}
Beispiel #2
0
int32
ColorField::_UpdateThread(void *data)
{
	// initialization

	ColorField *colorField = (ColorField *)data;
	BLooper *looper = colorField->Looper();

	if (looper)
		looper->Lock();

	BBitmap* bitmap = colorField->fBgBitmap[0];
	BView* view = colorField->fBgView[0];

	port_id port = colorField->fUpdatePort;

	if (looper)
		looper->Unlock();

	// draw

	float h, s, v, r, g, b;
	int R, G, B;

	int32 msg_code;
	char msg_buffer;

	while (true) {
		port_info info;
		do {
			read_port(port, &msg_code, &msg_buffer, sizeof(msg_buffer));
			get_port_info(port, &info);
		} while (info.queue_count);

		if (looper)
			looper->Lock();
	
		uint colormode = colorField->fColorMode;
		float fixedvalue = colorField->fFixedValue;

		if (looper)
			looper->Unlock();

		bitmap->Lock();
		view->BeginLineArray(256 * 256);

		switch (colormode)
		{
			case R_SELECTED:
			{
				R = round(fixedvalue * 255);
				for (int G = 0; G < 256; ++G)
					for (int B = 0; B < 256; ++B)
						DrawColorPoint(BPoint(G, 255.0 - B), R, G, B);
				break;
			}

			case G_SELECTED:
			{
				G = round(fixedvalue * 255);
				for (int R = 0; R < 256; ++R)
					for (int B = 0; B < 256; ++B)
						DrawColorPoint(BPoint(R, 255.0 - B), R, G, B);
				break;
			}

			case B_SELECTED:
			{
				B = round(fixedvalue * 255);
				for (int R = 0; R < 256; ++R)
					for (int G = 0; G < 256; ++G)
						DrawColorPoint(BPoint(R, 255.0 - G), R, G, B);
				break;
			}

			case H_SELECTED:
			{
				h = fixedvalue;
				for (int x = 0; x < 256; ++x) {
					s = (float)x / 255.0;
					for (int y = 0; y < 256; ++y) {
						v = (float)y / 255.0;
						HSV_to_RGB(h, s, v, r, g, b);
						DrawColorPoint(BPoint(x, 255.0 - y), round(r * 255.0),
							round(g * 255.0), round(b * 255.0));
					}
				}
				break;
			}

			case S_SELECTED:
			{
				s = fixedvalue;
				for (int x = 0; x < 256; ++x) {
					h = 6.0 / 255 * x;
					for (int y = 0; y<256; ++y) {
						v = (float)y / 255.0;
						HSV_to_RGB(h, s, v, r, g, b);
						DrawColorPoint(BPoint(x, 255.0 - y), round(r * 255.0),
							round(g * 255.0), round(b * 255.0));
					}
				}
				break;
			}

			case V_SELECTED:
			{
				v = fixedvalue;
				for (int x = 0; x < 256; ++x) {
					h = 6.0 / 255 * x;
					for (int y = 0; y < 256; ++y) {
						s = (float)y / 255.0;
						HSV_to_RGB(h, s, v, r, g, b);
						DrawColorPoint(BPoint(x, 255.0 - y), round(r * 255.0),
							round(g * 255.0), round(b * 255.0));
					}
				}
				break;
			}
		}

		view->EndLineArray();
		view->Sync();

		bitmap->Unlock();

		looper = colorField->Looper();
		if (looper && looper->Lock()) {
			colorField->Update(2);
			looper->Unlock();
		}
	}

	return 0;
}
Beispiel #3
0
// _UpdateThread
int32
ColorField::_UpdateThread(void* data)
{
	// initializing
	ColorField* colorField = (ColorField *)data;
	
	bool looperLocked = colorField->LockLooper();

	BBitmap* bitmap = colorField->fBgBitmap[0];
	port_id	port = colorField->fUpdatePort;
	orientation orient = colorField->fOrientation;

	if (looperLocked)
		colorField->UnlockLooper();
	
	float h, s, v, r, g, b;
	int R, G, B;
		
	// drawing

    int32 msg_code;
    char msg_buffer;

	while (true) {

		port_info info;

		do {

			read_port(port, &msg_code, &msg_buffer, sizeof(msg_buffer));
			get_port_info(port, &info);
			
		} while (info.queue_count);
		
		if (colorField->LockLooper()) {
		
			uint 	colormode = colorField->fMode;
			float	fixedvalue = colorField->fFixedValue;
		
			int width = (int)colorField->Width();
			int height = (int)colorField->Height();
		     
			colorField->UnlockLooper();
		
			bitmap->Lock();
	//bigtime_t now = system_time();
			uint8* bits = (uint8*)bitmap->Bits();
			uint32 bpr = bitmap->BytesPerRow();
			// offset 2 pixels from top and left
			bits += 2 * 4 + 2 * bpr;
			
			switch (colormode) {
				
				case R_SELECTED: {
					R = round(fixedvalue * 255);
					for (int y = height; y >= 0; y--) {
						uint8* bitsHandle = bits;
						int B = y / height * 255;
						for (int x = 0; x <= width; ++x) {
							int G = x / width * 255;
							set_bits(bitsHandle, R, G, B);
							bitsHandle += 4;
						}
						bits += bpr;
					}
				}; break;
				
				case G_SELECTED: {
					G = round(fixedvalue * 255);
					for (int y = height; y >= 0; y--) {
						uint8* bitsHandle = bits;
						int B = y / height * 255;
						for (int x = 0; x <= width; ++x) {
							int R = x / width * 255;
							set_bits(bitsHandle, R, G, B);
							bitsHandle += 4;
						}
						bits += bpr;
					}
				}; break;
				
				case B_SELECTED: {
					B = round(fixedvalue * 255);
					for (int y = height; y >= 0; y--) {
						uint8* bitsHandle = bits;
						int G = y / height * 255;
						for (int x = 0; x <= width; ++x) {
							int R = x / width * 255;
							set_bits(bitsHandle, R, G, B);
							bitsHandle += 4;
						}
						bits += bpr;
					}
				}; break;
				
				case H_SELECTED: {
					h = fixedvalue;
					if (orient == B_VERTICAL) {
						for (int y = 0; y <= height; ++y) {
							v = (float)(height - y) / height;
							uint8* bitsHandle = bits;
							for (int x = 0; x <= width; ++x) {
								s = (float)x / width;
								HSV_to_RGB( h, s, v, r, g, b );
								set_bits(bitsHandle, round(r * 255.0), round(g * 255.0), round(b * 255.0));
								bitsHandle += 4;
							}
							bits += bpr;
						}
					} else {
						for (int y = 0; y <= height; ++y) {
							s = (float)y / height;
							uint8* bitsHandle = bits;
							for (int x = 0; x <= width; ++x) {
								v = (float)(width - x) / width;
								HSV_to_RGB( h, s, v, r, g, b );
								set_bits(bitsHandle, round(r * 255.0), round(g * 255.0), round(b * 255.0));
								bitsHandle += 4;
							}
							bits += bpr;
						}
					}
				}; break;
				
				case S_SELECTED: {
					s = fixedvalue;
					for (int y = 0; y <= height; ++y) {
						v = (float)(height - y) / height;
						uint8* bitsHandle = bits;
						for (int x = 0; x <= width; ++x) {
							h = 6.0 / width * x;
							HSV_to_RGB( h, s, v, r, g, b );
							set_bits(bitsHandle, round(r * 255.0), round(g * 255.0), round(b * 255.0));
							bitsHandle += 4;
						}
						bits += bpr;
					}
				}; break;
				
				case V_SELECTED: {
					v = fixedvalue;
					for (int y = 0; y <= height; ++y) {
						s = (float)(height - y) / height;
						uint8* bitsHandle = bits;
						for (int x = 0; x <= width; ++x) {
							h = 6.0 / width * x;
							HSV_to_RGB( h, s, v, r, g, b );
							set_bits(bitsHandle, round(r * 255.0), round(g * 255.0), round(b * 255.0));
							bitsHandle += 4;
						}
						bits += bpr;
					}
				}; break;
			}
	
	//printf("color field update: %lld\n", system_time() - now);
			bitmap->Unlock();
	
			if (colorField->LockLooper()) {
				colorField->Update(2);
				colorField->UnlockLooper();
			}
		}
	}
}