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; }