Пример #1
0
static int depthfirst_map_one (flux_t *h, const char *key, int dirskip,
                               restart_map_f cb, void *arg)
{
    flux_jobid_t id;
    flux_future_t *f;
    const char *eventlog;
    struct job *job = NULL;
    char path[64];
    int rc = -1;

    if (strlen (key) <= dirskip) {
        errno = EINVAL;
        return -1;
    }
    if (fluid_decode (key + dirskip + 1, &id, FLUID_STRING_DOTHEX) < 0)
        return -1;
    if (flux_job_kvs_key (path, sizeof (path), id, "eventlog") < 0) {
        errno = EINVAL;
        return -1;
    }
    if (!(f = flux_kvs_lookup (h, NULL, 0, path)))
        goto done;
    if (flux_kvs_lookup_get (f, &eventlog) < 0)
        goto done;
    if (!(job = job_create_from_eventlog (id, eventlog)))
        goto done;
    if (cb (job, arg) < 0)
        goto done;
    rc = 1;
done:
    flux_future_destroy (f);
    job_decref (job);
    return rc;
}
Пример #2
0
static void loadImage(HWND hWnd, LPWSTR fileName)
{
	char *data;
	int size;
	data = readFile(fileName, &size);
	if (data == nullptr)
	{
		MessageBoxW(hWnd, L"Cannot read file content!", L"Critical", MB_ICONERROR | MB_OK);
		return;
	}

	int width, height;
	char *decoded = fluid_decode(data, size, &width, &height);
	free(data);
	if (decoded == nullptr)
	{
		MessageBoxW(hWnd, L"Decode image file failed.", L"Critical", MB_ICONERROR | MB_OK);
		return;
	}

	/* ARGB -> BGRA, Premultiply alpha */
	unsigned char *r = (unsigned char *) decoded;
	for (int i = 0; i < height; i++)
		for (int j = 0; j < width; j++)
		{
			unsigned char t = r[0];
			r[0] = r[2];
			r[2] = t;

			/* Premultiply (for display) */
			r[0] = r[0] * r[3] / 255 + (255 - r[3]);
			r[1] = r[1] * r[3] / 255 + (255 - r[3]);
			r[2] = r[2] * r[3] / 255 + (255 - r[3]);

			r += 4;
		}

	if (bitmap)
		DeleteObject(bitmap);
	bitmapWidth = width;
	bitmapHeight = height;

	BITMAPINFO bmi;
	bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	bmi.bmiHeader.biWidth = width;
	bmi.bmiHeader.biHeight = -height;
	bmi.bmiHeader.biPlanes = 1;
	bmi.bmiHeader.biBitCount = 32;
	bmi.bmiHeader.biCompression = BI_RGB;
	bmi.bmiHeader.biSizeImage = width * height * 4;
	HDC hdc = GetDC(hWnd);
	bitmap = CreateDIBitmap(hdc, &bmi.bmiHeader, CBM_INIT, decoded, &bmi, DIB_RGB_COLORS);
	ReleaseDC(hWnd, hdc);
	SendMessageW(hWnd, WM_PAINT, 0, 0);
	free(decoded);
}