Пример #1
0
void image::decodeFrame(unsigned char SOFmarker)
{
	switch(SOFmarker)
	{
	case SOF0:
		{
			SOF0::processSOF0();
			break;
		}
	case SOF1:
	case SOF2:
	case SOF3:
	case SOF5:
	case SOF6:
	case SOF7:
	case SOF9:
	case SOFA:
	case SOFB:
	case SOFD:
	case SOFE:
	case SOFF:
		{
			printError(1,"\nerror: found unsupported SOF marker..this mode of encoding not supported right now\n");
			break;
		}
	default:printError(1,"\nerror: found invalid frame marker\n");
	}

	unsigned char nextMarker;
	nextMarker = getNextMarker();
	while(nextMarker!=SOS)
		{    // keep processing markers until you see SOS marker
			processTablenMisc(nextMarker);
			nextMarker = getNextMarker();
		}
		decodeScan();
}
Пример #2
0
/****************************************************************************
DESCRIPTION:
Locates the specified bitmap file and loads it into a device context.

HEADER:
mgraph.h

PARAMETERS:
dc          - Device context to load bitmap into
f           - Pointer to opened bitmap file
dwSize      - Size of the bitmap file
dwOffset    - Offset into the file
dstLeft     - Left coordinate to place bitmap at
dstTop      - Top coordinate to place bitmap at
loadPalette - Should we load the palette values as well?

RETURNS:
True if the bitmap was successfully loaded.

REMARKS:
This function is the same as MGL_loadBitmapIntoDC, however it works with a
previously opened file. This allows you to create your own large files with
multiple files embedded in them.

SEE ALSO:
MGL_loadBitmapIntoDC
****************************************************************************/
ibool MGLAPI MGL_loadBitmapIntoDCExt(
    MGLDC *dc,
    FILE *f,
    ulong dwOffset,
    ulong dwSize,
    int dstLeft,
    int dstTop,
    ibool loadPalette)
{
    bitmap_t            bmh;
    palette_t           pal[256];         /* Temporary space for palette    */
    pixel_format_t      pf;
    int                 i,palSize,height;
    ibool               oldCheckId,isRLE;

    /* Read bitmap header */
    if (!readBitmapHeaderExt(&bmh,pal,&palSize,&pf,f,dwOffset,loadPalette,&isRLE))
        return false;

    /* Allocate a temporary bitmap to convert the scanlines */
    bmh.pal = pal;
    bmh.pf = &pf;
    if ((bmh.surface = PM_malloc(bmh.bytesPerLine)) == NULL) {
        FATALERROR(grNoMem);
        return false;
        }
    oldCheckId = MGL_checkIdentityPalette(false);

    /* Store the palette in the destination DC */
    if (loadPalette && (bmh.bitsPerPixel == 4 || bmh.bitsPerPixel == 8)) {
        MGL_setPalette(dc,pal,palSize / sizeof(palette_t),0);
        if (MGL_getVisualPage(dc) == MGL_getActivePage(dc))
            MGL_realizePalette(dc,palSize / sizeof(palette_t),0,false);
        }
    else if (loadPalette && ((dc->mi.modeFlags & MGL_IS_COLOR_INDEX) && bmh.bitsPerPixel > 8)) {
        MGL_getHalfTonePalette(pal);
        MGL_setPalette(dc,pal,MGL_getPaletteSize(dc),0);
        if (MGL_getVisualPage(dc) == MGL_getActivePage(dc))
            MGL_realizePalette(dc,MGL_getPaletteSize(dc),0,false);
        }

    /* Now read in the bits in the bitmap, by reading the data a scanline
     * at a time into our temporary memory DC, and then blting this to
     * the destination DC. We need to handle both cases of bottom up and
     * top down DIB's, plus RLE decoding.
     */
    height = bmh.height;
    if (isRLE) {
        /* Decode RLE bottom up DIB via MGL scratch buffer */
        bufStart = (uchar*)_MGL_buf;
        bufSize = _MGL_bufSize;
        readChunk(f);
        gcount = gdata = 0;
        bmh.height = 1;
        for (i = height-1; i >= 0; i--) {
            decodeScan(f,bmh.surface,bmh.bytesPerLine);
            MGL_putBitmap(dc,dstLeft,dstTop+i,&bmh,MGL_REPLACE_MODE);
            }
        }
    else if (height < 0) {
        /* Top down DIB */
        height = -bmh.height;
        bmh.height = 1;
        for (i = 0; i < height; i++) {
            __MGL_fread(bmh.surface,1,bmh.bytesPerLine,f);
            MGL_putBitmap(dc,dstLeft,dstTop+i,&bmh,MGL_REPLACE_MODE);
            }
        }
    else {
        /* Bottom up DIB */
        bmh.height = 1;
        for (i = height-1; i >= 0; i--) {
            __MGL_fread(bmh.surface,1,bmh.bytesPerLine,f);
            MGL_putBitmap(dc,dstLeft,dstTop+i,&bmh,MGL_REPLACE_MODE);
            }
        }
    PM_free(bmh.surface);
    MGL_checkIdentityPalette(oldCheckId);
    (void)dwSize;
    return true;
}
Пример #3
0
/****************************************************************************
DESCRIPTION:
Locates an open bitmap and loads it into memory from an open file.

HEADER:
mgraph.h

PARAMETERS:
f           - Open binary file to read data from
dwOffset    - Offset to start of bitmap in file
dwSize      - Size of the file
loadPalette - Should we load the palette values as well?

RETURNS:
Pointer to the loaded bitmap file

REMARKS:
This function is the same as MGL_loadBitmap, however it loads the file from a
previously open file. This allows you to create your own large files with
multiple files embedded in them.

SEE ALSO:
MGL_loadBitmap, MGL_loadBitmapIntoDC
****************************************************************************/
bitmap_t * MGLAPI MGL_loadBitmapExt(
    FILE *f,
    ulong dwOffset,
    ulong dwSize,
    ibool loadPalette)
{
    bitmap_t            bmh,*bitmap;
    palette_t           pal[256];       /* Temporary space for palette  */
    pixel_format_t      pf;
    long                size;
    int                 i,palSize;
    uchar               *p;
    ibool               isRLE;

    /* Open the bitmap header */
    if (!readBitmapHeaderExt(&bmh,pal,&palSize,&pf,f,dwOffset,loadPalette,&isRLE))
        return NULL;

    /* Allocate memory for the bitmap */
    if (!loadPalette && bmh.bitsPerPixel <= 8)
        palSize = 0;
    size = (long)bmh.bytesPerLine * bmh.height + palSize;
    if ((bitmap = PM_malloc(sizeof(bitmap_t)+size)) == NULL) {
        FATALERROR(grNoMem);
        return NULL;
        }
    *bitmap = bmh;

    size = sizeof(bitmap_t);
    if (bitmap->bitsPerPixel <= 8) {
        if (loadPalette) {
            bitmap->pal = (palette_t*)((uchar*)bitmap + size);
            memcpy(bitmap->pal,pal,palSize);
            }
        else
            bitmap->pal = NULL;
        bitmap->pf = NULL;
        }
    else {
        bitmap->pf = (pixel_format_t*)((uchar*)bitmap + size);
        *bitmap->pf = pf;
        bitmap->pal = NULL;
        }
    size += palSize;
    bitmap->surface = (uchar*)bitmap + size;

    /* Now read in the bits in the bitmap. We need to handle both cases
     * of bottom up and top down DIB's. We can also decode RLE bitmaps
     * (which are always bottom up DIB format) via MGL scratch buffer.
     */
    if (isRLE) {
        bufStart = (uchar*)_MGL_buf;
        bufSize = _MGL_bufSize;
        readChunk(f);
        gcount = gdata = 0;
        p = (uchar *)bitmap->surface + (long)bitmap->bytesPerLine * (bitmap->height-1);
        for (i = 0; i < bitmap->height; i++, p -= bitmap->bytesPerLine) {
            decodeScan(f,(uchar*)p,bitmap->bytesPerLine);
            }
        }
    else if (bitmap->height < 0) {
        bitmap->height = -bitmap->height;
        p = bitmap->surface;
        for (i = 0; i < bitmap->height; i++, p += bitmap->bytesPerLine) {
            __MGL_fread(p,1,bitmap->bytesPerLine,f);
            }
        }
    else {
        p = (uchar *)bitmap->surface + (long)bitmap->bytesPerLine * (bitmap->height-1);
        for (i = 0; i < bitmap->height; i++, p -= bitmap->bytesPerLine) {
            __MGL_fread(p,1,bitmap->bytesPerLine,f);
            }
        }
    (void)dwSize;
    return bitmap;
}