Пример #1
0
int main()
{
    Bitmap bm;

    bm = bitmapCreate(10);
    if (!bm)
    {
        fprintf(stderr, "Failed to create bitmap.\n");
        return 1;
    }

    bitmapPrint(bm);

    bitmapSet(&bm, 3);
    bitmapSet(&bm, 0);
    bitmapSet(&bm, 8);

    bitmapPrint(bm);

    bitmapUnset(&bm, 3);

    bitmapPrint(bm);

    bitmapClear(&bm);
    
    bitmapPrint(bm);

    bitmapDestroy(&bm);

    printf("End\n");

    return 0;
}
Пример #2
0
/*
 * Funkce volaná ze skriptu
 */
LUA_FUNC createBitmap(lua_State* L)
{
    int width, height;
    if (bmp)
    {
        LUA_ERROR("bitmap is already created");
    }

    /* Kontrola počtu parametrů */
    NUMBER_OF_PARAMETERS(2);
    /* Kontrola typu parametrů */
    NUMBERP(1);
    NUMBERP(2);
    width = lua_tointeger(L, 1);
    height = lua_tointeger(L, 2);
    /* Kontrola hodnot parametrů */
    CHECK_RANGE(width, 0, MAX_BITMAP_WIDTH, "bitmap width is out of range");
    CHECK_RANGE(height, 0, MAX_BITMAP_HEIGHT, "bitmap height is out of range");
    /* Vše v pořádku - vytvoříme bitmapu */
    bmp = bitmapCreate(width, height);
    if (bmp == NULL)
    {
        LUA_ERROR("bitmapCreate failed");
    }
    return LUA_OK;
}
Пример #3
0
void windowInit(void) {
	s_pRestoreBuffer = bitmapCreate(
		WINDOW_WIDTH, WINDOW_HEIGHT,
		g_pMainBuffer->sCommon.pVPort->ubBPP, BMF_INTERLEAVED
	);
	s_pBg = bitmapCreateFromFile("data/commrade_bg.bm", 0);
	s_pButtons = bitmapCreateFromFile("data/commrade_buttons.bm", 0);
}
Пример #4
0
int unsortedSelectAll(void *_header, FILE *dataFp, struct bitmap **bmp, error *err) {
	
	columnHeaderUnsorted *header = (columnHeaderUnsorted *) _header;

	if (header->nEntries < 1) {
		ERROR(err, E_COLEMT);
		return 1;
	}

	if (bitmapCreate(header->nEntries, bmp, err)) {
		return 1;
	}

	bitmapMarkAll(*bmp);

	return 0;
}
Пример #5
0
void swap_bootstrap(void)
{

	int retval;
	struct stat a;
//	struct vnode *swap_vnode;

	retval = vfs_open(SWAP_DEVICE, O_RDWR, &swap_vnode);
	if(retval)
	{
		panic("could not open swap device\n")	;
	}

	VOP_STAT(swap_vnode, &a);
	swap_map = bitmapCreate(a.st_size / PAGE_SIZE);
	if(swap_map == NULL)
	{
		panic("could not create swap map\n")	;
	}

	vfs_close(swap_vnode);
}
Пример #6
0
int unsortedSelectRange(void *_header, FILE *dataFp, int low, int high, struct bitmap **bmp, error *err) {
	
	columnHeaderUnsorted *header = (columnHeaderUnsorted *) _header;

	if (header->nEntries < 1) {
		ERROR(err, E_COLEMT);
		return 1;
	}

	if (bitmapCreate(header->nEntries, bmp, err)) {
		return 1;
	}


	if (fseek(dataFp, 0, SEEK_SET) == -1) {
		ERROR(err, E_FSK);
		return 1;
	}

	int length = header->nEntries;
	for (int i = 0; i < length; i++) {
		int entry;

		if (fread(&entry, sizeof(int), 1, dataFp) < 1) {
			ERROR(err, E_FRD);
			return 1;
		}

		if (entry >= low && entry <= high) {
			if (bitmapMark(*bmp, i, err)) {
				return 1;
			}
		}
	} 

	return 0;
}
Пример #7
0
static int dbLoopJoin(joinArgs *args, response *res, error *err) {
	
	char *oldVar1 = args->oldVar1;
	char *oldVar2 = args->oldVar2;

	char *newVar1 = args->newVar1;
	char *newVar2 = args->newVar2;

	if (oldVar1 == NULL || oldVar2 == NULL ||
		newVar1 == NULL || newVar2 == NULL) {
		ERROR(err, E_BADARG);
		goto exit;
	}

	// Get the results from the old var names
	fetchResults *fResults1;
	fetchResults *fResults2;

	if (obtainResults(oldVar1, &fResults1, err) || obtainResults(oldVar2, &fResults2, err)) {
		goto exit;
	}

	int nResults1 = fResults1->nResultEntries;
	int nResults2 = fResults2->nResultEntries;

	if (nResults1 == 0 || nResults2 == 0) {
		ERROR(err, E_VAREMT);
		goto exit;
	}

	// Create bitmaps to store results of joins
	struct bitmap *bmp1;
	struct bitmap *bmp2;
	if (bitmapCreate(fResults1->nColumnEntries, &bmp1, err)) {
		goto exit;
	}
	if (bitmapCreate(fResults2->nColumnEntries, &bmp2, err)) {
		bitmapDestroy(bmp1);
		goto exit;
	}

	// Determine smaller and larger results
	fetchResults *smallerFResults;
	fetchResults *largerFResults;

	struct bitmap *smallerBmp;
	struct bitmap *largerBmp;

	char *smallerNewVar;
	char *largerNewVar;

	if (nResults1 < nResults2) {
		smallerFResults = fResults1;
		smallerBmp = bmp1;
		smallerNewVar = newVar1;

		largerFResults = fResults2;
		largerBmp = bmp2;
		largerNewVar = newVar2;
	} else {
		smallerFResults = fResults2;
		smallerBmp = bmp2;
		smallerNewVar = newVar2;

		largerFResults = fResults1;
		largerBmp = bmp1;
		largerNewVar = newVar1;
	}

	// Loop and fill bitmaps
	for (int i = 0; i < largerFResults->nResultEntries; i++) {
		for (int j = 0; j < smallerFResults->nResultEntries; j++) {
			if (largerFResults->results[i] == smallerFResults->results[j]) {
				if (bitmapMark(largerBmp, largerFResults->indices[i], err) ||
					bitmapMark(smallerBmp, smallerFResults->indices[j], err)) {
					goto cleanupBitmaps;
				}
			}
		}
	}

	// Add bitmaps to varmap using new var names
	if (varMapAddVar(smallerNewVar, VAR_BMP, smallerBmp, err) ||
		varMapAddVar(largerNewVar, VAR_BMP, largerBmp, err)) {
		goto cleanupBitmaps;
	}

	printf("Added variables '%s' and '%s'\n", smallerNewVar, largerNewVar);

	RESPONSE_SUCCESS(res);

	return 0;

cleanupBitmaps:
	bitmapDestroy(bmp1);
	bitmapDestroy(bmp2);
exit:
	return 1;
}