⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bitmap_def.c.svn-base

📁 A Flash Player with ActionScript support. Write in C and C++. It have two part, one is Player and an
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
// Just init JPEG object and read JPEG Tablesint readJpegTables(struct JPEGTable *JTable) {    //	struct my_error_mgr jerr;    int rVal;#ifdef PRINT_DG    printf("flash: readJpegTables !\n");#endif    /**/    if (haveTables) {        //it has already been initialized        return 0;    }    /**/    // Setup error handler    jpegObject.err = jpeg_std_error(&jpegErrorMgr.pub);    jpegErrorMgr.pub.error_exit = my_error_exit;    if (setjmp(jpegErrorMgr.setjmp_buffer)) {        // JPEG data Error        jpeg_destroy_decompress(&jpegObject);        assert(0);    }    // Set current stream pointer to stream    inputData = JTable->JPEGTables;    // Here it's Ok    jpeg_create_decompress(&jpegObject);    // Setup source manager structure    jpegSourceManager.init_source = initSource;    jpegSourceManager.fill_input_buffer = fillInputBuffer;    jpegSourceManager.skip_input_data = skipInputData;    jpegSourceManager.resync_to_restart = resyncToRestart;    jpegSourceManager.term_source = termSource;    jpegSourceManager.next_input_byte = NULL; /* until buffer loaded */    // Set default source manager    jpegObject.src = &jpegSourceManager;    rVal = jpeg_read_header(&jpegObject, FALSE);    assert(rVal ==JPEG_HEADER_OK||rVal ==JPEG_HEADER_TABLES_ONLY);#ifdef PRINT_DG    printf("flash: readJpegTables jpeg_read_header : %d\n",rVal);#endif    haveTables = 1;    return 0;}int buildFromZlibData(unsigned char *buffer, int width, int height, int format, int tableSize, int tableHasAlpha,struct DefineBitsLossless2* outStruct) {    z_stream	stream;    int		status;    unsigned char  *data;    int		elementSize;    long		 depth=0;    long		 nbColors=0;#ifdef PRINT_DG    printf("flash: loading with zlib\n");#endif    if (tableHasAlpha) {        elementSize = 4;	// Cmap is RGBA    } else {        elementSize = 3;	// Cmap is RGB    }    stream.next_in = buffer;    stream.avail_in = 1;    stream.zalloc = Z_NULL;    stream.zfree = Z_NULL;    tableSize++;    outStruct->Width = width;    outStruct->Height = height;    outStruct->Bpl = width;    // Uncompress struct RGBA Table    if (format == 3) {        unsigned char *colorTable;        long n;        // Ajust width for 32 bit padding        width = (width+3)/4*4;        outStruct->Width = width;        outStruct->Bpl = width;        depth = 1;        colorTable = (unsigned char*)malloc(tableSize*elementSize);        assert(colorTable != NULL);        stream.next_out = colorTable;        stream.avail_out = tableSize*elementSize;        inflateInit(&stream);        while (1) {            status = inflate(&stream, Z_SYNC_FLUSH);            if (status == Z_STREAM_END) {                break;            }            if (status != Z_OK) {                printf("Zlib cmap error : %s\n", stream.msg);                assert(0);            }            stream.avail_in = 1;            // Colormap if full            if (stream.avail_out == 0) {                break;            }        }        nbColors = tableSize;        outStruct->ColormapP = (struct RGBA*)malloc(nbColors*sizeof(struct RGBA));        if (outStruct->ColormapP == NULL) {            free(colorTable);            assert(0);        }        for(n=0; n < nbColors; n++) {            outStruct->ColormapP[n].Red = colorTable[n*elementSize+0];            outStruct->ColormapP[n].Green = colorTable[n*elementSize+1];            outStruct->ColormapP[n].Blue = colorTable[n*elementSize+2];            if (tableHasAlpha) {                outStruct->ColormapP[n].Alpha = colorTable[n*elementSize+3];            }        }        free(colorTable);    } else if (format == 4) {        depth = 2;        width = (width+1)/2*2;        outStruct->Bpl = width;    } else if (format == 5) {        depth = 4;    }    data = (unsigned char*)malloc(depth*width*height);    if (data == NULL) {        if (outStruct->ColormapP)            free(outStruct->ColormapP);        assert(0);    }    stream.next_out = data;    stream.avail_out = depth*width*height;    if (format != 3) {        status = inflateInit(&stream);    }    while (1) {        status = inflate(&stream, Z_SYNC_FLUSH) ;        if (status == Z_STREAM_END) {            break;        }        if (status != Z_OK) {            printf("Zlib data error : %s\n", stream.msg);            free(data);            assert(0);        }        stream.avail_in = 1;    }    inflateEnd(&stream);    outStruct->PixelsP = (unsigned char *)malloc(height*width);    if (outStruct->PixelsP == NULL) {        if (outStruct->ColormapP)            free(outStruct->ColormapP);        free(data);        assert(0);    }    if (format != 3) {        int n,c;        unsigned char r,g,b,a;        unsigned char *ptr;        r = g = b = a = 0; /* to supress warnings */        nbColors = 0;        outStruct->ColormapP = (struct RGBA*)malloc(256*sizeof(struct RGBA));        if (outStruct->ColormapP == NULL) {            free(data);            free(outStruct->PixelsP);            assert(0);        }        memset(outStruct->ColormapP, 0, 256 * sizeof(struct RGBA));        ptr = outStruct->PixelsP;        for(n=0; n < width*height*depth; n+=depth,ptr++) {            switch (format) {            case 4:                a = 1;                r = (data[n] & 0x78)<<1;                g = ((data[n] & 0x03)<<6) | (data[n+1] & 0xc0)>>2;                b = (data[n+1] & 0x1e)<<3;                break;            case 5:                a = data[n];                // Reduce color dynamic range                r = data[n+1]&0xe0;                g = data[n+2]&0xe0;                b = data[n+3]&0xe0;                break;            }            for(c=0; c < nbColors; c++) {                if (r == outStruct->ColormapP[c].Red                        &&  g == outStruct->ColormapP[c].Green                        &&  b == outStruct->ColormapP[c].Blue) {                    *ptr = c;                    break;                }            }            if (c == nbColors) {                if (nbColors == 256)                    continue;                nbColors++;                if (nbColors == 256) {                    //printf("Colormap entries exhausted. After %d scanned pixels\n", n/4);                }                outStruct->ColormapP[c].Alpha = a;                outStruct->ColormapP[c].Red   = r;                outStruct->ColormapP[c].Green = g;                outStruct->ColormapP[c].Blue  = b;                *ptr = c;            }        }    } else {        memcpy(outStruct->PixelsP, data, width*height);        if (tableHasAlpha) {            int n;            unsigned char *ptr, *alpha;            outStruct->Alpha_bufP = (unsigned char *)malloc(width*height);            ptr = data;            alpha = outStruct->Alpha_bufP;            for(n=0; n < width*height; n++, ptr++, alpha++) {                *alpha = outStruct->ColormapP[*ptr].Alpha;            }        }    }    outStruct->Colors = nbColors;    assert(outStruct->PixelsP != 0);    free(data);#ifdef PRINT_DG    printf("flash: loading with zlib finished!\n");#endif    return 0;}int bmp_makebmp(struct DefineCharacter* InStruct,swf_file_t *swf_p) {    struct DefineBits* InBitsStruct;    struct DefineBitsJPEG* InJPEGStruct;    struct DefineBitsLossless2* InBitsLossless2Struct;    int rc = 0;#ifdef PRINT_DG    printf("flash: enter BitmapCache !\n");    printf("flash: InStruct->CharacterType : %d\n",InStruct->CharacterType);#endif    if(InStruct->CharacterType == (UI8)CharBitsOne) {        InBitsStruct = (struct DefineBits*)InStruct;        readJpegTables(swf_p->JPEGTableP);#ifdef PRINT_DG        printf("flash: InBitsStruct->JPEGDataLength : %d\n",InBitsStruct->JPEGDataLength);#endif        rc = buildFromJpegAbbreviatedData(&InBitsStruct->JPEGData[0],InBitsStruct);        if(rc) {            assert(0);        }    } else if(InStruct->CharacterType ==(UI8)CharBitsJPEG) {        InJPEGStruct = (struct DefineBitsJPEG*)InStruct;#ifdef PRINT_DG        printf("flash: InJPEGStruct->JPEGDataLength : %d\n",InJPEGStruct->JPEGDataLength);        printf("flash: InJPEGStruct->AlphaDataLength : %d\n",InJPEGStruct->AlphaDataLength);        /*        	for(j=0;j<20;j++)        		printf(" %x ",InJPEGStruct->JPEGData[j]);        	printf("\n");        	for(i=InJPEGStruct->JPEGDataLength-20;i<InJPEGStruct->JPEGDataLength;i++)        		printf(" %x ",InJPEGStruct->JPEGData[i]);        	printf("\n");        */#endif        if(InJPEGStruct->AlphaDataLength) {            rc = buildFromJpegInterchangeData(1,InJPEGStruct->JPEGDataLength,InJPEGStruct);        } else {            rc = buildFromJpegInterchangeData(0,0,InJPEGStruct);        }        if(rc) {            assert(0);        }    } else if(InStruct->CharacterType == (UI8)CharBitsLosslessOne) {        InBitsLossless2Struct = (struct DefineBitsLossless2*)InStruct;#ifdef PRINT_DG        printf("flash: InBitsLossless2Struct->ZlibBitmapDataLength : %d\n",InBitsLossless2Struct->ZlibBitmapDataLength);#endif        rc = buildFromZlibData(InBitsLossless2Struct->ZlibBitmapData,                               InBitsLossless2Struct->BitmapWidth,InBitsLossless2Struct->BitmapHeight, InBitsLossless2Struct->BitmapFormat,                               InBitsLossless2Struct->BitmapColorTableSize, 0,InBitsLossless2Struct);        if(rc) {            assert(0);        }    } else if(InStruct->CharacterType == (UI8)CharBitsLosslessTwo) {        InBitsLossless2Struct = (struct DefineBitsLossless2*)InStruct;#ifdef PRINT_DG        printf("flash: InBitsLossless2Struct->ZlibBitmapDataLength : %d\n",InBitsLossless2Struct->ZlibBitmapDataLength);#endif        rc = buildFromZlibData(InBitsLossless2Struct->ZlibBitmapData,                               InBitsLossless2Struct->BitmapWidth,InBitsLossless2Struct->BitmapHeight, InBitsLossless2Struct->BitmapFormat,                               InBitsLossless2Struct->BitmapColorTableSize, 1,InBitsLossless2Struct);        if(rc) {            assert(0);        }    }    assert(((struct DefineBits*)(InStruct))->PixelsP != 0);#ifdef PRINT_DG    printf("flash: enter BitmapCache finished !\n");#endif    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -