Exemple #1
0
/**
 * Resize bitmap
 *
 * @v bitmap		Bitmap
 * @v new_length	New length of bitmap, in bits
 * @ret rc		Return status code
 */
int bitmap_resize ( struct bitmap *bitmap, unsigned int new_length ) {
	unsigned int old_num_blocks;
	unsigned int new_num_blocks;
	size_t new_size;
	bitmap_block_t *new_blocks;

	old_num_blocks = BITMAP_INDEX ( bitmap->length + BITMAP_BLKSIZE - 1 );
	new_num_blocks = BITMAP_INDEX ( new_length + BITMAP_BLKSIZE - 1 );

	if ( old_num_blocks != new_num_blocks ) {
		new_size = ( new_num_blocks * sizeof ( bitmap->blocks[0] ) );
		new_blocks = realloc ( bitmap->blocks, new_size );
		if ( ! new_blocks ) {
			DBGC ( bitmap, "Bitmap %p could not resize to %d "
			       "bits\n", bitmap, new_length );
			return -ENOMEM;
		}
		bitmap->blocks = new_blocks;
	}
	bitmap->length = new_length;

	while ( old_num_blocks < new_num_blocks ) {
		bitmap->blocks[old_num_blocks++] = 0;
	}

	DBGC ( bitmap, "Bitmap %p resized to %d bits\n", bitmap, new_length );
	return 0;
}
Exemple #2
0
bool SaveARGB(const char *fileName, BYTE *data, int width, int height)
{
    bool result = false;
    if (!data)
        return result;

    ARGBPixel *input = (ARGBPixel *)data;
    BitmapPixel *output = new BitmapPixel[BITMAP_SIZE(width, height)];
    memset(output, 0, BITMAP_SIZE(width, height) * sizeof(BitmapPixel));

    for(int row = 0; row < height; ++row)
    {
        for(int col = 0; col < width; ++col)
        {
            int outputIdx = BITMAP_INDEX(col, row, width);
            int inputIdx = ((height - row - 1) * width) + col;

            output[outputIdx].red = input[inputIdx].red;
            output[outputIdx].green = input[inputIdx].green;
            output[outputIdx].blue = input[inputIdx].blue;
        }
    }

    result = SaveBitmap(fileName, (BYTE *)output, width, height);

    delete [] output;

    return result;
}
Exemple #3
0
bool SaveBGR(const char *fileName, BYTE *data, int width, int height)
{
    bool result = false;

    if (!data)
        return false;
    RGBPixel *input = (RGBPixel *)data;
    BitmapPixel *output = new BitmapPixel[BITMAP_SIZE(width, height)];

    // Pad bytes need to be set to zero, it's easier to just set the entire chunk of memory
    memset(output, 0, BITMAP_SIZE(width, height) * sizeof(BitmapPixel));

    for(int row = 0; row < height; ++row)
    {
        for(int col = 0; col < width; ++col)
        {
            // In a bitmap (0,0) is at the bottom left, in the frame buffer it is the top left.
            int outputIdx = BITMAP_INDEX(col, row, width);
            int inputIdx = ((height - row - 1) * width) + col;

            output[outputIdx].red = input[inputIdx].blue;
            output[outputIdx].green = input[inputIdx].green;
            output[outputIdx].blue = input[inputIdx].red;
        }
    }

    result = SaveBitmap(fileName, (BYTE *)output, width, height);

    delete [] output;

    return result;
}
Exemple #4
0
static inline int
bb_table_lookup(bb_table_t *table, uint addr)
{
    byte *bm = table->bm;
    PRINT(5, "lookup "PFX" in bb table "PFX"\n",
          (ptr_uint_t)addr, (ptr_uint_t)table);
    /* We see this and it seems to be erroneous data from the pdb,
     * xref drsym_enumerate_lines() from drsyms.
     */
    if (table->size <= addr)
        return BB_TABLE_ENTRY_INVALID;
    if (bm[BITMAP_INDEX(addr)] == 0xff ||
        TEST(BITMAP_MASK(BITMAP_OFFSET(addr)), bm[BITMAP_INDEX(addr)]))
        return BB_TABLE_ENTRY_SET;
    return BB_TABLE_ENTRY_CLEAR;
}
Exemple #5
0
bool SaveRGBPlanar(const char *fileName, BYTE *data, int width, int height)
{
    if (!data)
        return false;

    const char *nameExt[] = {"red", "green", "blue"};
    BitmapPixel *output = new BitmapPixel[BITMAP_SIZE(width, height)];
    memset(output, 0, BITMAP_SIZE(width, height) * sizeof(BitmapPixel));

    for(int color = 0; color < 3; ++color)
    {
        for(int row = 0; row < height; ++row)
        {
            for(int col = 0; col < width; ++col)
            {   
                int outputIdx = BITMAP_INDEX(col, row, width);
                int inputIdx = ((height - row - 1) * width) + col;

                output[outputIdx].blue = 0;
                output[outputIdx].green = 0;
                output[outputIdx].red = 0;

                switch(color)
                {
                case 0:
                    output[outputIdx].red = data[inputIdx];
                    break;

                case 1:
                    output[outputIdx].green = data[inputIdx + (width * height)];
                    break;

                case 2:
                    output[outputIdx].blue = data[inputIdx + 2 * (width * height)];
                    break;

                default:
                    break;
                }
            }
        }

        std::string outputFile = fileName;
        size_t find = outputFile.find_last_of(".");

        outputFile.insert(find, "-");
        outputFile.insert(find+1, nameExt[color]);

        if(!SaveBitmap(outputFile.c_str(), (BYTE *)output, width, height))
        {
            delete [] output;
            return false;
        }
    }

    delete [] output;

    return true;
}
Exemple #6
0
/**
 * Test bit in bitmap
 *
 * @v bitmap		Bitmap
 * @v bit		Bit index
 * @ret is_set		Bit is set
 */
int bitmap_test ( struct bitmap *bitmap, unsigned int bit ) {
	unsigned int index = BITMAP_INDEX ( bit );
        bitmap_block_t mask = BITMAP_MASK ( bit );

	if ( bit >= bitmap->length )
		return 0;
	return ( bitmap->blocks[index] & mask );
}
Exemple #7
0
static inline bool
bb_table_add(bb_table_t *table, bb_entry_t *entry)
{
    byte *bm;
    uint idx, offs, addr_end, idx_end, offs_end, i;
    if (table == BB_TABLE_IGNORE)
        return false;
    if (table->size <= entry->start + entry->size) {
        WARN(3, "Wrong range "PFX"-"PFX" or table size "PFX" for table "PFX"\n",
             (ptr_uint_t)entry->start,
             (ptr_uint_t)entry->start + entry->size,
             (ptr_uint_t)table->size,
             (ptr_uint_t)table);
        return false;
    }
    bm  = table->bm;
    idx = BITMAP_INDEX(entry->start);
    /* we assume that the whole bb is seen if its start addr is seen */
    if (bm[idx] == BB_TABLE_RANGE_SET)
        return false;
    offs = BITMAP_OFFSET(entry->start);
    if (TEST(BITMAP_MASK(offs), bm[idx]))
        return false;
    /* now we add a new bb */
    PRINT(6, "Add "PFX"-"PFX" in table "PFX"\n",
          (ptr_uint_t)entry->start,
          (ptr_uint_t)entry->start + entry->size,
          (ptr_uint_t)table);
    addr_end = entry->start + entry->size - 1;
    idx_end  = BITMAP_INDEX(addr_end);
    offs_end = (idx_end > idx) ? BITS_PER_BYTE-1 : BITMAP_OFFSET(addr_end);
    /* first byte in the bitmap */
    bm[idx] |= bitmap_set[offs][offs_end];
    /* set all the middle byte */
    for (i = idx + 1; i < idx_end; i++)
        bm[i] = BB_TABLE_RANGE_SET;
    /* last byte in the bitmap */
    if (idx_end > idx) {
        offs_end = BITMAP_OFFSET(addr_end);
        bm[idx_end] |= bitmap_set[0][offs_end];
    }
    return true;
}
Exemple #8
0
/**
 * Set bit in bitmap
 *
 * @v bitmap		Bitmap
 * @v bit		Bit index
 */
void bitmap_set ( struct bitmap *bitmap, unsigned int bit ) {
	unsigned int index = BITMAP_INDEX ( bit );
        bitmap_block_t mask = BITMAP_MASK ( bit );

	DBGC ( bitmap, "Bitmap %p setting bit %d\n", bitmap, bit );

	/* Update bitmap */
	bitmap->blocks[index] |= mask;

	/* Update first gap counter */
	while ( bitmap_test ( bitmap, bitmap->first_gap ) ) {
		bitmap->first_gap++;
	}
}
Exemple #9
0
bool SaveYUV(const char *fileName, BYTE *data, int width, int height)
{
    if (!data)
        return false;

    int hWidth = width >> 1;
    int hHeight = height >> 1;
    size_t find = -1;
    std::string outputFile;

    BitmapPixel *luma = new BitmapPixel[BITMAP_SIZE(width, height)];
    BitmapPixel *chrom = new BitmapPixel[BITMAP_SIZE(width, height)];

    memset(luma, 0, BITMAP_SIZE(width, height) * sizeof(BitmapPixel));
    memset(chrom, 0, BITMAP_SIZE(hWidth, hHeight) * sizeof(BitmapPixel));

    for(int row = 0; row < height; ++row)
    {
        for(int col = 0; col < width; ++col)
        {
            int outputIdx = BITMAP_INDEX(col, row, width);
            int inputIdx = ((height - row - 1) * width) + col;

            luma[outputIdx].red = data[inputIdx];
            luma[outputIdx].green = data[inputIdx];
            luma[outputIdx].blue = data[inputIdx];
        }
    }

    data += width * height;

    outputFile = fileName;
    find = outputFile.find_last_of(".");

    outputFile.insert(find, "-");
    outputFile.insert(find+1, "y");

    if(!SaveBitmap(outputFile.c_str(), (BYTE *)luma, width, height))
    {
        delete [] luma;
        delete [] chrom;
        return false;
    }

    for(int row = 0; row < hHeight; ++row)
    {
        for(int col = 0; col < hWidth; ++col)
        {
            int outputIdx = BITMAP_INDEX(col, row, hWidth);
            int inputIdx = ((hHeight - row - 1) * hWidth) + col;

            chrom[outputIdx].red = data[inputIdx];
            chrom[outputIdx].green = 255 - data[inputIdx];
            chrom[outputIdx].blue = 0;
        }
    }

    data += hWidth * hHeight;

    outputFile = fileName;
    find = outputFile.find_last_of(".");

    outputFile.insert(find, "-");
    outputFile.insert(find+1, "u");

    if(!SaveBitmap(outputFile.c_str(), (BYTE *)chrom, hWidth, hHeight))
    {
        delete [] luma;
        delete [] chrom;
        return false;
    }

    for(int row = 0; row < hHeight; ++row)
    {
        for(int col = 0; col < hWidth; ++col)
        {
            int outputIdx = BITMAP_INDEX(col, row, hWidth);
            int inputIdx = ((hHeight - row - 1) * hWidth) + col;

            chrom[outputIdx].red = 0;
            chrom[outputIdx].green = 255 - data[inputIdx];
            chrom[outputIdx].blue = data[inputIdx];
        }
    }

    data += hWidth * hHeight;

    outputFile = fileName;
    find = outputFile.find_last_of(".");

    outputFile.insert(find, "-");
    outputFile.insert(find+1, "v");

    if(!SaveBitmap(outputFile.c_str(), (BYTE *)chrom, hWidth, hHeight))
    {
        delete [] luma;
        delete [] chrom;
        return false;
    }

    delete [] luma;
    delete [] chrom;
    return true;
}