Example #1
0
ILBM_ColorMap *ILBM_generateGrayscaleColorMap(const ILBM_Image *image)
{
    ILBM_ColorMap *colorMap = ILBM_createColorMap();
    
    if(colorMap != NULL)
    {
        unsigned int numOfColors = ILBM_calculateNumOfColors(image->bitMapHeader);
        unsigned int i;
    
        for(i = 0; i < numOfColors; i++)
        {
            ILBM_ColorRegister *colorRegister = ILBM_addColorRegisterInColorMap(colorMap);
            unsigned int value = i * 0xff / (numOfColors - 1);
            
            colorRegister->red = value;
            colorRegister->green = value;
            colorRegister->blue = value;
        }
    }
    
    return colorMap;
}
Example #2
0
IFF_Form *ILBM_createTestForm()
{
    ILBM_BitMapHeader *bitMapHeader;
    ILBM_ColorRegister *colorRegister;
    ILBM_ColorMap *colorMap;
    ILBM_CMYKRegister *cmykRegister;
    ILBM_CMYKMap *cmykMap;
    ILBM_ColorNames *colorNames;
    ILBM_Viewport *viewport;
    ILBM_DPIHeader *dpiHeader;
    ILBM_Point2D *point2d;
    ILBM_Sprite *sprite;
    ILBM_ColorRange *colorRange;
    ILBM_DRange *drange;
    ILBM_DIndex *dindex;
    ILBM_CycleInfo *cycleInfo;

    unsigned int rowSize;
    IFF_Long bodyChunkSize;
    IFF_UByte *bodyChunkData;
    IFF_RawChunk *body;
    ILBM_Image *image;
    unsigned int count = 0;
    unsigned int i;
    IFF_Form *form;

    /* Define bitmap header */
    bitMapHeader = ILBM_createBitMapHeader();
    
    bitMapHeader->w = 160;
    bitMapHeader->h = 120;
    bitMapHeader->x = 0;
    bitMapHeader->y = 0;
    bitMapHeader->nPlanes = 2;
    bitMapHeader->masking = ILBM_MSK_NONE;
    bitMapHeader->compression = ILBM_CMP_NONE;
    bitMapHeader->xAspect = 20;
    bitMapHeader->yAspect = 22;
    bitMapHeader->pageWidth = 320;
    bitMapHeader->pageHeight = 200;
    
    /* Add some RGB colors */
    colorMap = ILBM_createColorMap();
    
    colorRegister = ILBM_addColorRegisterInColorMap(colorMap);
    colorRegister->red = 0;
    colorRegister->green = 0;
    colorRegister->blue = 0;
    
    colorRegister = ILBM_addColorRegisterInColorMap(colorMap);
    colorRegister->red = 0xf0;
    colorRegister->green = 0;
    colorRegister->blue = 0;
    
    colorRegister = ILBM_addColorRegisterInColorMap(colorMap);
    colorRegister->red = 0;
    colorRegister->green = 0xf0;
    colorRegister->blue = 0;
    
    colorRegister = ILBM_addColorRegisterInColorMap(colorMap);
    colorRegister->red = 0;
    colorRegister->green = 0;
    colorRegister->blue = 0xf0;
    
    /* Add some CYMK colors */
    cmykMap = ILBM_createCMYKMap();
    
    cmykRegister = ILBM_addCMYKRegisterInCMYKMap(cmykMap);
    cmykRegister->cyan = 0xff;
    cmykRegister->magenta = 0;
    cmykRegister->yellow = 0;
    cmykRegister->black = 0;
    
    cmykRegister = ILBM_addCMYKRegisterInCMYKMap(cmykMap);
    cmykRegister->cyan = 0;
    cmykRegister->magenta = 0xff;
    cmykRegister->yellow = 0;
    cmykRegister->black = 0;
    
    cmykRegister = ILBM_addCMYKRegisterInCMYKMap(cmykMap);
    cmykRegister->cyan = 0;
    cmykRegister->magenta = 0;
    cmykRegister->yellow = 0xff;
    cmykRegister->black = 0;
    
    cmykRegister = ILBM_addCMYKRegisterInCMYKMap(cmykMap);
    cmykRegister->cyan = 0;
    cmykRegister->magenta = 0;
    cmykRegister->yellow = 0;
    cmykRegister->black = 0xff;
    
    /* Add some color names */
    colorNames = ILBM_createColorNames();
    colorNames->startingColor = 0;
    colorNames->endingColor = 3;
    
    ILBM_addColorName(colorNames, "black");
    ILBM_addColorName(colorNames, "red");
    ILBM_addColorName(colorNames, "green");
    ILBM_addColorName(colorNames, "blue");
    
    /* Set viewport */
    
    viewport = ILBM_createViewport();
    viewport->viewportMode = 0x4;
    
    /* Define DPI header */
    
    dpiHeader = ILBM_createDPIHeader();
    dpiHeader->dpiX = 100;
    dpiHeader->dpiY = 100;
    
    /* Define grab */
    
    point2d = ILBM_createGrab();
    point2d->x = 10;
    point2d->y = 20;
    
    /* Define sprite */
    
    sprite = ILBM_createSprite();
    sprite->spritePrecedence = 1;
    
    /* Define a color range */
    
    colorRange = ILBM_createColorRange();
    colorRange->rate = 8192;
    colorRange->active = 1;
    colorRange->low = 0;
    colorRange->high = 3;
    
    /* Define a dynamic range */
    
    drange = ILBM_createDRange(0);
    drange->min = 0;
    drange->max = 3;
    drange->rate = 8192;
    drange->flags = ILBM_RNG_ACTIVE;
    
    dindex = ILBM_addDIndexToDRange(drange);
    dindex->cell = 0;
    dindex->index = 0;
    
    dindex = ILBM_addDIndexToDRange(drange);
    dindex->cell = 1;
    dindex->index = 2;
    
    dindex = ILBM_addDIndexToDRange(drange);
    dindex->cell = 2;
    dindex->index = 1;
    
    dindex = ILBM_addDIndexToDRange(drange);
    dindex->cell = 3;
    dindex->index = 3;
    
    /* Define a cycle info range */
    
    cycleInfo = ILBM_createCycleInfo();
    cycleInfo->direction = 1;
    cycleInfo->start = 0;
    cycleInfo->end = 3;
    cycleInfo->seconds = 0;
    cycleInfo->microSeconds = 100;
    
    /* Create image */
    image = ILBM_createImage("ILBM");
    
    image->bitMapHeader = bitMapHeader;
    image->colorMap = colorMap;
    image->cmykMap = cmykMap;
    image->colorNames = colorNames;
    image->viewport = viewport;
    image->point2d = point2d;
    image->dpiHeader = dpiHeader;
    image->sprite = sprite;
    
    ILBM_addColorRangeToImage(image, colorRange);
    ILBM_addDRangeToImage(image, drange);
    ILBM_addCycleInfoToImage(image, cycleInfo);
    
    /* Set pixel data */
    
    /* Create a red scanline block */
    
    rowSize = ILBM_calculateRowSize(image) * bitMapHeader->nPlanes;
    bodyChunkSize = rowSize * bitMapHeader->h;
    bodyChunkData = (IFF_UByte*)malloc(bodyChunkSize * sizeof(IFF_UByte));
    body = IFF_createRawChunk("BODY");
    
    for(i = 0; i < 39; i++)
    {
	memcpy(bodyChunkData + count, redScanLine, rowSize * sizeof(IFF_UByte));
	count += rowSize;
    }
    
    /* Add black scanline */
    
    memcpy(bodyChunkData + count, blackScanLine, rowSize * sizeof(IFF_UByte));
    count += rowSize;
    
    /* Create a green scanline block */
    
    for(i = 40; i < 79; i++)
    {
	memcpy(bodyChunkData + count, greenScanLine, rowSize * sizeof(IFF_UByte));
	count += rowSize;
    }
    
    /* Add black scanline */
    
    memcpy(bodyChunkData + count, blackScanLine, rowSize * sizeof(IFF_UByte));
    count += rowSize;
    
    /* Create a blue scanline block */
    
    for(i = 80; i < 119; i++)
    {
	memcpy(bodyChunkData + count, blueScanLine, rowSize * sizeof(IFF_UByte));
	count += rowSize;
    }
    
    /* Add black scanline */
    memcpy(bodyChunkData + count, blackScanLine, rowSize * sizeof(IFF_UByte));
    count += rowSize;
    
    /* Attach data to the body chunk */
    IFF_setRawChunkData(body, bodyChunkData, bodyChunkSize);
    
    /* Attach body the image */
    image->body = body;
    
    /* Convert image to form */
    form = ILBM_convertImageToForm(image);
    
    /* Free stuff */
    ILBM_freeImage(image);
    
    /* Return generated form */
    return form;
}
int main(int argc, char *argv[])
{
    ILBM_BitMapHeader *bitMapHeader;
    ILBM_ColorRegister *colorRegister;
    ILBM_ColorMap *colorMap;
    ILBM_Viewport *viewport;
    ILBM_Point2D *point2d;
    ILBM_Sprite *sprite;
    ILBM_ColorRange *colorRange;
    ILBM_DRange *drange;
    ILBM_DIndex *dindex;
    ILBM_CycleInfo *cycleInfo;

    unsigned int rowSize; 
    IFF_Long bodyChunkSize;
    IFF_UByte *bodyChunkData;
    IFF_RawChunk *body;
    ILBM_Image *image;
    IFF_Form *form;
    
    unsigned int i;
    unsigned int count = 0;
    int status = 0;
    
    /* Define bitmap header */
    bitMapHeader = ILBM_createBitMapHeader();
    
    bitMapHeader->w = 161;
    bitMapHeader->h = 120;
    bitMapHeader->x = 0;
    bitMapHeader->y = 0;
    bitMapHeader->nPlanes = 2;
    bitMapHeader->masking = ILBM_MSK_NONE;
    bitMapHeader->compression = ILBM_CMP_NONE;
    bitMapHeader->xAspect = 20;
    bitMapHeader->yAspect = 22;
    bitMapHeader->pageWidth = 320;
    bitMapHeader->pageHeight = 200;
    
    /* Add some colors */
    colorMap = ILBM_createColorMap();
    
    colorRegister = ILBM_addColorRegisterInColorMap(colorMap);
    colorRegister->red = 0;
    colorRegister->green = 0;
    colorRegister->blue = 0;
    
    colorRegister = ILBM_addColorRegisterInColorMap(colorMap);
    colorRegister->red = 0xf0;
    colorRegister->green = 0;
    colorRegister->blue = 0;
    
    colorRegister = ILBM_addColorRegisterInColorMap(colorMap);
    colorRegister->red = 0;
    colorRegister->green = 0xf0;
    colorRegister->blue = 0;
    
    colorRegister = ILBM_addColorRegisterInColorMap(colorMap);
    colorRegister->red = 0;
    colorRegister->green = 0;
    colorRegister->blue = 0xf0;
    
    /* Set viewport */
    
    viewport = ILBM_createViewport();
    viewport->viewportMode = 0x4;
    
    /* Define grab */
    
    point2d = ILBM_createGrab();
    point2d->x = 10;
    point2d->y = 20;
    
    /* Define sprite */
    
    sprite = ILBM_createSprite();
    sprite->spritePrecedence = 1;
    
    /* Define a color range */
    
    colorRange = ILBM_createColorRange();
    colorRange->rate = 8192;
    colorRange->active = 1;
    colorRange->low = 0;
    colorRange->high = 3;
    
    /* Define a dynamic range */
    
    drange = ILBM_createDRange(0);
    drange->min = 0;
    drange->max = 3;
    drange->rate = 8192;
    drange->flags = ILBM_RNG_ACTIVE;
    
    dindex = ILBM_addDIndexToDRange(drange);
    dindex->cell = 0;
    dindex->index = 0;
    
    dindex = ILBM_addDIndexToDRange(drange);
    dindex->cell = 1;
    dindex->index = 2;
    
    dindex = ILBM_addDIndexToDRange(drange);
    dindex->cell = 2;
    dindex->index = 1;
    
    dindex = ILBM_addDIndexToDRange(drange);
    dindex->cell = 3;
    dindex->index = 3;
    
    /* Define a cycle info range */
    
    cycleInfo = ILBM_createCycleInfo();
    cycleInfo->direction = 1;
    cycleInfo->start = 0;
    cycleInfo->end = 3;
    cycleInfo->seconds = 0;
    cycleInfo->microSeconds = 100;
    
    /* Create image */
    image = ILBM_createImage("ILBM");
    
    image->bitMapHeader = bitMapHeader;
    image->colorMap = colorMap;
    image->viewport = viewport;
    image->point2d = point2d;
    image->sprite = sprite;
    
    ILBM_addColorRangeToImage(image, colorRange);
    ILBM_addDRangeToImage(image, drange);
    ILBM_addCycleInfoToImage(image, cycleInfo);
    
    /* Set pixel data */
    
    /* Create a red scanline block */
    
    body = IFF_createRawChunk("BODY");
    rowSize = ILBM_calculateRowSize(image) * bitMapHeader->nPlanes;
    bodyChunkSize = rowSize * bitMapHeader->h;
    bodyChunkData = (IFF_UByte*)malloc(bodyChunkSize * sizeof(IFF_UByte));
    
    for(i = 0; i < 39; i++)
    {
	memcpy(bodyChunkData + count, redScanLine, rowSize * sizeof(IFF_UByte));
	count += rowSize;
    }
    
    /* Add black scanline */
    
    memcpy(bodyChunkData + count, blackScanLine, rowSize * sizeof(IFF_UByte));
    count += rowSize;
    
    /* Create a green scanline block */
    
    for(i = 40; i < 79; i++)
    {
	memcpy(bodyChunkData + count, greenScanLine, rowSize * sizeof(IFF_UByte));
	count += rowSize;
    }
    
    /* Add black scanline */
    
    memcpy(bodyChunkData + count, blackScanLine, rowSize * sizeof(IFF_UByte));
    count += rowSize;
    
    /* Create a blue scanline block */
    
    for(i = 80; i < 119; i++)
    {
	memcpy(bodyChunkData + count, blueScanLine, rowSize * sizeof(IFF_UByte));
	count += rowSize;
    }
    
    /* Add black scanline */
    memcpy(bodyChunkData + count, blackScanLine, rowSize * sizeof(IFF_UByte));
    count += rowSize;
    
    /* Attach data to the body chunk */
    IFF_setRawChunkData(body, bodyChunkData, bodyChunkSize);
    
    /* Attach body the image */
    image->body = body;
    
    /* Convert image to form */
    form = ILBM_convertImageToForm(image);
    
    /* Write the form */
    
    if(!ILBM_write("bars-padded.ILBM", (IFF_Chunk*)form))
    {
	fprintf(stderr, "Error writing ILBM file!\n");
	status = 1;
    }
    
    /* Free stuff */
    
    ILBM_freeImage(image);
    ILBM_free((IFF_Chunk*)form);
    
    return status;
}
Example #4
0
IFF_Form *ILBM_createTestForm()
{
    ILBM_BitMapHeader *bitMapHeader;
    ILBM_ColorMap *colorMap;
    
    IFF_Long bodyChunkSize;
    IFF_UByte *bodyChunkData;
    IFF_RawChunk *body;
    ILBM_Image *image;
    IFF_Form *form;
    
    unsigned int i;
    unsigned int count = 0;
    unsigned int rowSize;

    /* Define bitmap header */
    bitMapHeader = ILBM_createBitMapHeader();
    
    bitMapHeader->w = 320;
    bitMapHeader->h = 240;
    bitMapHeader->x = 0;
    bitMapHeader->y = 0;
    bitMapHeader->nPlanes = 8;
    bitMapHeader->masking = ILBM_MSK_NONE;
    bitMapHeader->compression = ILBM_CMP_NONE;
    bitMapHeader->xAspect = 20;
    bitMapHeader->yAspect = 22;
    bitMapHeader->pageWidth = 320;
    bitMapHeader->pageHeight = 240;
    
    /* Add some colors */
    colorMap = ILBM_createColorMap();
    
    for(i = 0; i < 64; i++)
    {
	ILBM_ColorRegister *colorRegister = ILBM_addColorRegisterInColorMap(colorMap);
	
	colorRegister->red = i * 4;
	colorRegister->green = i * 2;
	colorRegister->blue = i * 2;
    }
    
    for(i = 64; i < 128; i++)
    {
	ILBM_ColorRegister *colorRegister = ILBM_addColorRegisterInColorMap(colorMap);
	
	colorRegister->red = i;
	colorRegister->green = i * 2;
	colorRegister->blue = i / 2;
    }
    
    for(i = 128; i < 192; i++)
    {
	ILBM_ColorRegister *colorRegister = ILBM_addColorRegisterInColorMap(colorMap);
	
	colorRegister->red = i / 4;
	colorRegister->green = i / 2;
	colorRegister->blue = i;
    }
    
    for(i = 192; i < 256; i++)
    {
	ILBM_ColorRegister *colorRegister = ILBM_addColorRegisterInColorMap(colorMap);
	
	colorRegister->red = i;
	colorRegister->green = i;
	colorRegister->blue = i;
    }
    
    /* Create image */
    
    image = ILBM_createImage("PBM ");
    image->bitMapHeader = bitMapHeader;
    image->colorMap = colorMap;
    
    /* Set pixel data */
    
    rowSize = ILBM_calculateRowSize(image);
    bodyChunkSize = bitMapHeader->w * bitMapHeader->h; 
    bodyChunkData = (IFF_UByte*)malloc(bodyChunkSize * sizeof(IFF_UByte));
    body = IFF_createRawChunk("BODY");
    
    /* Each scanline has a new color from the palette */
    for(i = 0; i < bitMapHeader->h; i++)
    {
	memset(bodyChunkData + count, i, bitMapHeader->w);
	count += rowSize;
    }
    
    /* Attach data to the body chunk */
    IFF_setRawChunkData(body, bodyChunkData, bodyChunkSize);
    
    /* Attach body the image */
    image->body = body;
    
    /* Convert image to form */
    form = ILBM_convertImageToForm(image);

    /* Free stuff */
    ILBM_freeImage(image);

    return form;
}
Example #5
0
IFF_Form *ILBM_createTestForm()
{
    ILBM_BitMapHeader *bitMapHeader;
    ILBM_ColorRegister *colorRegister;
    ILBM_ColorMap *colorMap;
    ILBM_Viewport *viewport;

    unsigned int bitplaneSize, offset;
    IFF_Long bitplanesChunkSize;
    IFF_UByte *bitplanesChunkData;
    IFF_RawChunk *bitplanes;
    ILBM_Image *image;
    IFF_Form *form;

    /* Define bitmap header */
    bitMapHeader = ILBM_createBitMapHeader();
    
    bitMapHeader->w = 320;
    bitMapHeader->h = 200;
    bitMapHeader->x = 0;
    bitMapHeader->y = 0;
    bitMapHeader->nPlanes = 2;
    bitMapHeader->masking = ILBM_MSK_NONE;
    bitMapHeader->compression = ILBM_CMP_NONE;
    bitMapHeader->xAspect = 20;
    bitMapHeader->yAspect = 22;
    bitMapHeader->pageWidth = 320;
    bitMapHeader->pageHeight = 200;
    
    /* Add some colors */
    colorMap = ILBM_createColorMap();
    
    colorRegister = ILBM_addColorRegisterInColorMap(colorMap);
    colorRegister->red = 0xf0;
    colorRegister->green = 0;
    colorRegister->blue = 0;
    
    colorRegister = ILBM_addColorRegisterInColorMap(colorMap);
    colorRegister->red = 0;
    colorRegister->green = 0;
    colorRegister->blue = 0xf0;
    
    colorRegister = ILBM_addColorRegisterInColorMap(colorMap);
    colorRegister->red = 0x50;
    colorRegister->green = 0;
    colorRegister->blue = 0;
    
    colorRegister = ILBM_addColorRegisterInColorMap(colorMap);
    colorRegister->red = 0;
    colorRegister->green = 0;
    colorRegister->blue = 0x50;
    
    /* Set viewport */
    viewport = ILBM_createViewport();
    viewport->viewportMode = 0x4;
    
    /* Create image */
    image = ILBM_createImage("ACBM");
    
    image->bitMapHeader = bitMapHeader;
    image->colorMap = colorMap;
    image->viewport = viewport;
    
    /* Set pixel data */
    bitplaneSize = ILBM_calculateRowSize(image) * bitMapHeader->h;
    bitplanesChunkSize = bitplaneSize * bitMapHeader->nPlanes;
    bitplanesChunkData = (IFF_UByte*)malloc(bitplanesChunkSize * sizeof(IFF_UByte));
    bitplanes = IFF_createRawChunk("ABIT");
    
    /* Compose first bitplane that uses 0 for odd pixels and 1 for even pixels */
    memset(bitplanesChunkData, 0x5, bitplaneSize);
    offset = bitplaneSize;
    
    /* The second plane has an upperhalf that consists of 0s and a lowerhalf that consists of 1s */
    memset(bitplanesChunkData + offset, 0, bitplaneSize / 2);
    offset += bitplaneSize / 2;
    memset(bitplanesChunkData + offset, 0xff, bitplaneSize / 2);
    
    /* Attach data to the body chunk */
    IFF_setRawChunkData(bitplanes, bitplanesChunkData, bitplanesChunkSize);
    
    /* Attach bitplanes to the image */
    image->bitplanes = bitplanes;
    
    /* Convert image to form */
    form = ILBM_convertImageToForm(image);
    
    /* Free stuff */
    ILBM_freeImage(image);
    
    /* Return generated form */
    return form;
}