jzimagepng.cpp

来自「君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图」· C++ 代码 · 共 664 行 · 第 1/2 页

CPP
664
字号
            a1 = 255 - a;
            src = (unsigned char *)&ptar[j];
            if(a == 255)
            {
                line[j*4 + 0] = row_pointers[dx*4 + 0];
                line[j*4 + 1] = row_pointers[dx*4 + 1];
                line[j*4 + 2] = row_pointers[dx*4 + 2];
            }else if(a == 0)
            {
                line[j*4 + 0] = src[2];
                line[j*4 + 1] = src[1];
                line[j*4 + 2] = src[0];
            }else
            {
                line[j*4 + 0] = (a1 * src[2] + a * row_pointers[dx*4 + 0])>>8;
                line[j*4 + 1] = (a1 * src[1] + a * row_pointers[dx*4 + 1])>>8;
                line[j*4 + 2] = (a1 * src[0] + a * row_pointers[dx*4 + 2])>>8;
            }
            break;
        }

        case 24:
        {
            line[j*4 + 0] = row_pointers[dx*3 + 0];
            line[j*4 + 1] = row_pointers[dx*3 + 1];
            line[j*4 + 2] = row_pointers[dx*3 + 2];
            break;
        }

    }
}
#endif


void CJzImagePng::deflate(DWORD wBpp)
{
    DWORD i, j;
    int dx, dy;
    unsigned int a,a1;
    unsigned int r1,g1,b1;
    unsigned int r2,g2,b2;
    unsigned char *src;
    //info.dwEffWidth = pScr->w*4;
    info.dwEffWidth = info.dwimaWidth*4;

    //ivscale = (int)( ((float)info.dwimaWidth/info_ptr->width)*128.0+1 );
    //if( ivscale > 128 ) ivscale = 128;

    BYTE *line = info.pImage;
    //BYTE ivCenter = (cinfo.output_height-info.dwimaHeight)/2*info.dwimaWidth 

        printf(" ********info.dwimaWidth: %d, info.dwimaHeight: %d\n", info.dwimaWidth, info.dwimaHeight );
        printf(" ************info_ptr->height: %d\n", info_ptr->height );
        printf("*********** pixel_depth: %d, wBpp: %d\n", pixel_depth, wBpp );
        printf("*********** ivscale: %d\n", ivscale );
    unsigned int *ptar = pScr->buffer;//for test
    dy = 0;
    for( j = 0; j < info.dwimaHeight; j++ )
    {
        while( ivscale*dy/128 <= j )
        {
            png_read_row(png_ptr, row_pointers, NULL);
            dy++;
        }

        //////////// row
        memset(line, 0, info.dwimaWidth * 4);
        dx = 0;
        for( i = 0; i < info.dwimaWidth; i++ )
        {
            while( ivscale*dx/128 < i ) dx++;

         ///////////////////////////////////
            switch(pixel_depth)
            {
                case 32:
                {
                    a = row_pointers[dx*4 + 3];
                    a1 = 255 - a;
                    src = (unsigned char *)&ptar[j];
                    if(a == 255)
                    {
                        line[i*4 + 0] = row_pointers[dx*4 + 0];
                        line[i*4 + 1] = row_pointers[dx*4 + 1];
                        line[i*4 + 2] = row_pointers[dx*4 + 2];
                    }else if(a == 0)
                    { 
                        line[i*4 + 0] = src[2];
                        line[i*4 + 1] = src[1];
                        line[i*4 + 2] = src[0];
                    }else
                    {
                        line[i*4 + 0] = (a1 * src[2] + a * row_pointers[dx*4 + 0])>>8;
                        line[i*4 + 1] = (a1 * src[1] + a * row_pointers[dx*4 + 1])>>8;
                        line[i*4 + 2] = (a1 * src[0] + a * row_pointers[dx*4 + 2])>>8;
                    }
                    break;
                }

                case 24:
                {
                    line[i*4 + 0] = row_pointers[dx*3 + 0];
                    line[i*4 + 1] = row_pointers[dx*3 + 1];
                    line[i*4 + 2] = row_pointers[dx*3 + 2];
                    break;
                }


            }//end switch(pixel_depth)

        } //end for i
        ///////////

        //memcpy( (void *)ptar, line, info.dwEffWidth );
        //ptar += pScr->w;
        line = line + info.dwEffWidth;


    }
    
    
    //test
/*
    if(cinfo.output_scanline >=cinfo.output_height)
    {
        printf("=========== notice extract jpg ==============\n");
        return;
    }

*/
    while(  dy < info_ptr->height  )
    {
        png_read_row(png_ptr, row_pointers, NULL);
        dy++;
    }
}





#if 0
void CJzImagePng::deflate(DWORD wBpp)
{
	unsigned char *line = (unsigned char *)malloc(info.dwimaWidth * 4);
	int dx,dy, lineflag, verflag;
	unsigned int *ptar = pScr->buffer;
        unsigned char c;
	unsigned int a,a1;
	unsigned int r1,g1,b1;
	unsigned int r2,g2,b2;
	unsigned char *src;			
        int newfxscale; 
        int newfyscale;

	if( pScr->w < info_ptr->width )
            newfxscale = (int)(fxscale*128.0);
        else
            newfxscale = 128;

        if(pScr->h < info_ptr->height )
            newfyscale = (int)(fyscale*128.0);
        else
            newfyscale = 128;
        printf("newfyscal, newfxscal,= %d, %d\n", newfyscale, newfxscale );

        printf("wBpp = %d , pixel_depth = %d \n", wBpp, pixel_depth ); 							
         dy = 0;
	for(DWORD i = 0;i < info.dwimaHeight ;i++)
	{	
		memset(line,0,info.dwimaWidth * 4);
                verflag = 0; 
		while(newfyscale*dy/128 <= i)
		{
	            png_read_row(png_ptr, row_pointers, NULL);
		    if( verflag == 0 )
                    {

	                dx = 0;
			for(DWORD j = 0; j < info.dwimaWidth; j++)
			{
                                    lineflag = 0;
				while(newfxscale*dx/128 <= j )
				{
                                    if( lineflag == 0 )
                                    {
				  	switch(pixel_depth)//wBpp)
					{
					case 32:
						a = row_pointers[dx*4 + 3];
						a1 = 255 - a;
						src = (unsigned char *)&ptar[j]; 
						if(a == 255)
						{
							line[j*4 + 0] = row_pointers[dx*4 + 0];
							line[j*4 + 1] = row_pointers[dx*4 + 1];
							line[j*4 + 2] = row_pointers[dx*4 + 2];
						}else if(a == 0)
						{
							line[j*4 + 0] = src[2];
							line[j*4 + 1] = src[1];
							line[j*4 + 2] = src[0];
						}else
						{
						line[j*4 + 0] = (a1 * src[2] + a * row_pointers[dx*4 + 0])>>8;
						line[j*4 + 1] = (a1 * src[1] + a * row_pointers[dx*4 + 1])>>8;
						line[j*4 + 2] = (a1 * src[0] + a * row_pointers[dx*4 + 2])>>8;
						}
						break;
					case 24:
						line[j*4 + 0] = row_pointers[dx*3 + 0];
						line[j*4 + 1] = row_pointers[dx*3 + 1];
						line[j*4 + 2] = row_pointers[dx*3 + 2];
						break;
					case 16:
						//break;
					case 8:
						{
							c = row_pointers[dx];
							a = pRgb[c].rgbReserved;
							a1 = 255 - a;
							r1 = (unsigned int)pRgb[c].rgbRed;
							g1 = (unsigned int)pRgb[c].rgbGreen;
							b1 = (unsigned int)pRgb[c].rgbBlue;
							src = (unsigned char *)&ptar[j]; 
							b2 = (unsigned int)src[0];
							g2 = (unsigned int)src[1];
							r2 = (unsigned int)src[2];
							if(a == 255)
							{
								line[j*3 + 0] = r1;
								line[j*3 + 1] = g1;
								line[j*3 + 2] = b1;
							}else if(a == 0)
							{
								line[j*3 + 0] = r2;
								line[j*3 + 1] = g2;
								line[j*3 + 2] = b2;
							}else
							{
								line[j*3 + 0] = (a1 * r2 + a * r1)>>8;
								line[j*3 + 1] = (a1 * g2 + a * g1)>>8;
								line[j*3 + 2] = (a1 * b2 + a * b1)>>8;
							}
							c = c >> pixel_depth;
						}
						break;
					case 4:
						{
							unsigned char mask;
							mask = (8 / pixel_depth) - 1;
							
							if((dx & (pixel_depth - 1)) == 0)
								c = row_pointers[dx / (8 / pixel_depth)];
							a = pRgb[c& mask].rgbReserved;
							a1 = 255 - a;
							r1 = (unsigned int)pRgb[c & mask].rgbRed;
							g1 = (unsigned int)pRgb[c& mask].rgbGreen;
							b1 = (unsigned int)pRgb[c& mask].rgbBlue;
							src = (unsigned char *)&ptar[j]; 
							b2 = (unsigned int)src[0];
							g2 = (unsigned int)src[1];
							r2 = (unsigned int)src[2];
							if(a == 255)
							{
								line[j*3 + 0] = r1;
								line[j*3 + 1] = g1;
								line[j*3 + 2] = b1;
							}else if(a == 0)
							{
								line[j*3 + 0] = r2;
								line[j*3 + 1] = g2;
								line[j*3 + 2] = b2;
							}else
							{
								line[j*3 + 0] = (a1 * r2 + a * r1)>>8;
								line[j*3 + 1] = (a1 * g2 + a * g1)>>8;
								line[j*3 + 2] = (a1 * b2 + a * b1)>>8;
							}
							c = c >> pixel_depth;
						}
						break;
					case 1:

						break;
					    }//end switch(pixel_depth)

                                            lineflag = 1;
                                        }//end if lineflag
					dx++;
				}
			   }//for(DWORD j = 0; j < info.dwimaWidth; j++)

                            memcpy((void *)ptar, (void *)line,info.dwimaWidth * 4 );
                            ptar += pScr->w;
                            verflag = 1;
                            //printf("dy = %d \n",dy);
                        }//endif verflag
                        //printf("info_ptr->height, dy = %d, %d  \n",info_ptr->height, dy);
                        dy++;
                        if( dy >= info_ptr->height )
                        {
                             free(line);
                             return ;
                        }
			
		}
/*
		for(DWORD j = 0;j < info.dwimaWidth;j++)
		{
			int av = 1;
			ptar[j] = SETRGB(line[j * 3 + 0] / av, line[j * 3 + 1] / av,line[j * 3 + 2] / av); 
		}
*/              //memcpy((void *)ptar, (void *)line,info.dwimaWidth * 4 );
	        //ptar += pScr->w; 
	  

	}
	/*
	if(info_ptr->height - head.biHeight > 0)
	{
		for(int i = 0; i < info_ptr->height - head.biHeight * scale;i++)
			png_read_row(png_ptr, row_pointers, NULL);	
	}	
    */
	free(line);
		
}

#endif

⌨️ 快捷键说明

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