Exemple #1
0
uint32_t  freetype2_setfontcolor(PFont pfont, uint32_t color)
{
	PFontFreetype pf = (PFontFreetype) pfont;
	uint32_t last_color;
	switch(pf->disp)
	{
		case DISPLAY_PIXEL_FORMAT_5551:
			last_color = MAKE_RGBA_5551(pf->r,pf->g,pf->b,pf->a);
			GET_RGBA_5551(color,pf->r,pf->g,pf->b,pf->a);
			break;
		case DISPLAY_PIXEL_FORMAT_4444:
			last_color = MAKE_RGBA_4444(pf->r,pf->g,pf->b,pf->a);
			GET_RGBA_4444(color,pf->r,pf->g,pf->b,pf->a);
			break;
		case DISPLAY_PIXEL_FORMAT_565:
			last_color = MAKE_RGBA_565(pf->r,pf->g,pf->b,pf->a);
			GET_RGBA_565(color,pf->r,pf->g,pf->b,pf->a);
			break;
//		case DISPLAY_PIXEL_FORMAT_8888:
	default:
			last_color = MAKE_RGBA_8888(pf->r,pf->g,pf->b,pf->a);
			GET_RGBA_8888(color,pf->r,pf->g,pf->b,pf->a);
			break;
	}
	freetype2_calcalphatable(pfont);
	return last_color;
}
void scale_col (uint8 *sdata, uint32 sw, uint8 *ddata, uint32 dw,uint32 dh, uint32 u, line_contrib_type *contrib,uint32 dpitch,uint32 dtype)
{ 
    uint32 y, i;
	uint8 r,g,b,a,sr,sb,sg,sa;
	uint32 left,right;
	uint32 *src32,*dst32;
	uint16 *src16,*dst16;
	src32 = (uint32*)sdata;
	dst32 = (uint32*)ddata;
	src16 = (uint16*)sdata;
	dst16 = (uint16*)ddata;

	for (y = 0; y < dh; y++) 
    {    // Loop through column
        left  = contrib->contrib_row[y].left;    // Retrieve left boundries
        right = contrib->contrib_row[y].right;  // Retrieve right boundries
		r = 0,g = 0,b = 0,a = 0;
        for (i = left; i <= right; i++)
        {   // Scan between boundries
            // Accumulate weighted effect of each neighboring pixel
			if(dtype == DISPLAY_PIXEL_FORMAT_8888){
				GET_RGBA_8888(src32[i * sw + u],sr,sg,sb,sa);
			}
			else if(dtype == DISPLAY_PIXEL_FORMAT_4444){ 
				GET_RGBA_4444(src16[i * sw + u],sr,sg,sb,sa);
			}
			else if(dtype == DISPLAY_PIXEL_FORMAT_5551){ 
				GET_RGBA_5551(src16[i * sw + u],sr,sg,sb,sa);
			}
			else if(dtype == DISPLAY_PIXEL_FORMAT_565){ 
				GET_RGBA_565(src16[i * sw + u],sr,sg,sb,sa);
			}

			if(sa==0)
				continue;
            r += (uint8)(contrib->contrib_row[y].weights[i-left] * (double)(sr)); 
            g += (uint8)(contrib->contrib_row[y].weights[i-left] * (double)(sg)); 
            b += (uint8)(contrib->contrib_row[y].weights[i-left] * (double)(sb));
			a += (uint8)(contrib->contrib_row[y].weights[i-left] * (double)(sa));
        }
		if(dtype == DISPLAY_PIXEL_FORMAT_8888)
			dst32[y*dpitch+u] = MAKE_RGBA_8888(r,g,b,a);   // Place result in destination pixel
		else if(dtype == DISPLAY_PIXEL_FORMAT_4444)
			dst16[y*dpitch+u] = MAKE_RGBA_4444(r,g,b,a);   // Place result in destination pixel
		else if(dtype == DISPLAY_PIXEL_FORMAT_5551)
			dst16[y*dpitch+u] = MAKE_RGBA_5551(r,g,b,a);   // Place result in destination pixel
		else if(dtype == DISPLAY_PIXEL_FORMAT_565)
			dst16[y*dpitch+u] = MAKE_RGBA_565(r,g,b,a);   // Place result in destination pixel
    }
} 
void scale_row (uint8 *sdata, uint32 sw,uint8 *ddata, uint32 dw, uint32 u, line_contrib_type *contrib,uint32 spitch,uint32 dtype)  
{
    uint32 x, i;
	uint32 *src32, *dst32;
	uint16 *src16, *dst16;
	uint8 sr, sg, sb, sa,r = 0,g = 0,b = 0,a = 0;
	src32 = (uint32*)sdata+u*spitch;
	dst32 = (uint32*)ddata+u*dw;
	src16 = (uint16*)sdata+u*spitch;
	dst16 = (uint16*)ddata+u*dw;
    for (x = 0; x < dw; x++) 
    {   // Loop through row
        int left  = contrib->contrib_row[x].left;    // Retrieve left boundries
        int right = contrib->contrib_row[x].right;  // Retrieve right boundries
		r = 0,g = 0,b = 0,a = 0;
        for (i = left; i <= right; i++)
        {   // Scan between boundries
            // Accumulate weighted effect of each neighboring pixel			
			if(dtype == DISPLAY_PIXEL_FORMAT_8888){
				GET_RGBA_8888(src32[i],sr,sg,sb,sa);
			}
			else if(dtype == DISPLAY_PIXEL_FORMAT_4444){
				GET_RGBA_4444(src16[i],sr,sg,sb,sa);
			}
			else if(dtype == DISPLAY_PIXEL_FORMAT_5551){
				GET_RGBA_5551(src16[i],sr,sg,sb,sa);
			}
			else{
				GET_RGBA_565(src16[i],sr,sg,sb,sa);
			}
				
			if(sa==0)
				continue;
			r += (uint8)(contrib->contrib_row[x].weights[i-left] * (double)(sr)); 
            g += (uint8)(contrib->contrib_row[x].weights[i-left] * (double)(sg)); 
            b += (uint8)(contrib->contrib_row[x].weights[i-left] * (double)(sb));
			a += (uint8)(contrib->contrib_row[x].weights[i-left] * (double)(sa));
        } 
        if(dtype == DISPLAY_PIXEL_FORMAT_8888)
			dst32[x] = MAKE_RGBA_8888(r,g,b,a); // Place result in destination pixel
		else if(dtype == DISPLAY_PIXEL_FORMAT_4444)
			dst16[x] = MAKE_RGBA_4444(r,g,b,a);
		else if(dtype == DISPLAY_PIXEL_FORMAT_5551)
			dst16[x] = MAKE_RGBA_5551(r,g,b,a);
		else if(dtype == DISPLAY_PIXEL_FORMAT_565)
			dst16[x] = MAKE_RGBA_565(r,g,b,a);
    } 
}
Exemple #4
0
image_p image_load_jpg_buf(const char* mbuf,int bsize, int displaymode)
{
	image_p pimage = NULL;
	struct jpeg_decompress_struct	cinfo;
	struct jpeg_error_mgr jerr;
	uint8 *rawdata,*scanline, *p,*data = NULL;
	int	rawsize,texw,texh,width,height,bpb=2,size;
	int r,g,b,x;
	uint32* p32;
	uint16* p16;
	uint16 color16;
	uint32 color32;

	if(mbuf == NULL||bsize==0)
		return 0;
	memset(&cinfo,0,sizeof(struct jpeg_decompress_struct));
	memset(&jerr,0,sizeof(struct jpeg_error_mgr));

	rawsize = bsize;
	rawdata = (uint8*)mbuf;

	if (rawdata[6] != 'J' || rawdata[7] != 'F' || rawdata[8] != 'I' || rawdata[9] != 'F')
	{
		return 0;
	}

	cinfo.err = jpeg_std_error(&jerr);
	jpeg_create_decompress(&cinfo);

	jpeg_mem_src(&cinfo, rawdata, rawsize);

	jpeg_read_header(&cinfo, 1);

	jpeg_start_decompress(&cinfo);

	if(cinfo.output_components != 3 && cinfo.output_components != 4)
	{
		jpeg_destroy_decompress(&cinfo);
		return 0;
	}
	texw = roundpower2(cinfo.output_width);
	texh = roundpower2(cinfo.output_height);
	width = cinfo.output_width;
	height = cinfo.output_height;

	if(displaymode == DISPLAY_PIXEL_FORMAT_8888){
		bpb = 4;
	}
	size = texw * texh * bpb;
	data = (uint8*)malloc(size);
	memset(data,0,size);
	scanline = (uint8*)malloc(cinfo.output_width * 3);
	if(!scanline){
		jpeg_destroy_decompress(&cinfo);
		SAFE_FREE (data);
		return 0;
	}
	p32 = (uint32*)data;
	p16 = (uint16*) p32;

	while(cinfo.output_scanline < cinfo.output_height){
		jpeg_read_scanlines(&cinfo, &scanline, 1);
		p = (uint8*)scanline;
		for(x=0; x<(int)cinfo.output_width; x++){

			r = p[0];
			g = p[1];
			b = p[2];
			switch (displaymode){
				case DISPLAY_PIXEL_FORMAT_565:
					color16 = MAKE_RGBA_565(r,g,b,0xff);
					*(p16+x) = color16;
					break;
				case DISPLAY_PIXEL_FORMAT_5551:
					color16 = MAKE_RGBA_5551(r,g,b,0xff);
					*(p16+x) = color16;
					break;
				case DISPLAY_PIXEL_FORMAT_4444:
					color16 = MAKE_RGBA_4444(r,g,b,0xff);
					*(p16+x) = color16;
					break;
				case DISPLAY_PIXEL_FORMAT_8888:
					color32 = MAKE_RGBA_8888(r,g,b,0xff);
					*(p32+x) = color32;
					break;
			}
			p+=3;
		}
		p32 += texw;
		p16 += texw;
	}
	SAFE_FREE(scanline);
	jpeg_finish_decompress(&cinfo);
	jpeg_destroy_decompress(&cinfo);
	pimage = (image_p)malloc(sizeof(image_t));
	memset(pimage,0,sizeof(image_t));
	pimage->data = (uint8 *)data;
	pimage->w    = width;
	pimage->h    = height;
	pimage->texw = texw;
	pimage->texh = texh;
	pimage->bpb  = bpb;
	pimage->dtype = displaymode;
	pimage->rcentrex = pimage->w*1.0f/2;
	pimage->rcentrey = pimage->h*1.0f/2;
	pimage->mode = GET_PSM_COLOR_MODE(displaymode);
	pimage->mask = CreateColor(255,255,255,255,displaymode);
	pimage->texid = image_tid++;
	return pimage;
}
Exemple #5
0
static void draw_one_word(PFontFreetype pf,FT_Bitmap* bitmap,image_p pimage,int x,int y)
{
	int height = bitmap->rows;
	int width = bitmap->width;
	int i,j;
	uint32_t* cpbegin32;
	uint16_t* cpbegin16;
	unsigned char *buf = bitmap->buffer;
	if(y + height > (int)pimage->h)
		height = pimage->h - y;
	if(x + width > (int)pimage->w)
		width = pimage->w - x;

	if(height <= 0 || width <= 0)
		return;
		
	switch(pimage->dtype) {
		case DISPLAY_PIXEL_FORMAT_8888:
			cpbegin32 = (uint32_t*)pimage->data + y * pimage->texw + x;
			if(y < 0) {
				cpbegin32 -= y * pimage->texw;
				buf -= y * bitmap->width;
				j = -y;
			}
			else
				j = 0;
			for(; j < height; j++){
				if(x < 0) {
					cpbegin32 -= x;
					buf -= x;
					i = -x;
				}
				else
					i = 0;
				for(; i < width; i++)
					*(cpbegin32++) = MAKE_RGBA_8888(pf->r, pf->g, pf->b, pf->alpha_table[*(buf++)]);
				cpbegin32 += pimage->texw - width;
				buf += bitmap->width - width;
			}
			break;
		case DISPLAY_PIXEL_FORMAT_4444:
			cpbegin16 = (uint16_t*)pimage->data + y * pimage->texw + x;
			if(y < 0) {
				cpbegin16 -= y * pimage->texw;
				buf -= y * bitmap->width;
				j = -y;
			}
			else
				j = 0;
			for(; j < height; j++){
				if(x < 0) {
					cpbegin16 -= x;
					buf -= x;
					i = -x;
				}
				else
					i = 0;
				for(; i < width; i++)
					*(cpbegin16++) = MAKE_RGBA_4444(pf->r, pf->g, pf->b, pf->alpha_table[*(buf++)]);
				cpbegin16 += pimage->texw - width;
				buf += bitmap->width - width;
			}
			break;
		case DISPLAY_PIXEL_FORMAT_5551:
			cpbegin16 = (uint16_t*)pimage->data + y * pimage->texw + x;
			if(y < 0) {
				cpbegin16 -= y * pimage->texw;
				buf -= y * bitmap->width;
				j = -y;
			}
			else
				j = 0;
			for(; j < height; j++){
				if(x < 0) {
					cpbegin16 -= x;
					buf -= x;
					i = -x;
				}
				else
					i = 0;
				for(; i < width; i++)
					*(cpbegin16++) = MAKE_RGBA_5551(pf->r, pf->g, pf->b, (pf->a&(*(buf++)))?255:0);
				cpbegin16 += pimage->texw - width;
				buf += bitmap->width - width;
			}
			break;
		case DISPLAY_PIXEL_FORMAT_565:
			cpbegin16 = (uint16_t*)pimage->data + y * pimage->texw + x;
			if(y < 0) {
				cpbegin16 -= y * pimage->texw;
				buf -= y * bitmap->width;
				j = -y;
			}
			else
				j = 0;
			for(; j < height; j++){
				if(x < 0) {
					cpbegin16 -= x;
					buf -= x;
					i = -x;
				}
				else
					i = 0;
				for(; i < width; i++)
					if(*(buf++))
						*(cpbegin16++) = MAKE_RGBA_565(pf->r, pf->g, pf->b, 0);
					else
						*(cpbegin16++) = 0;
				cpbegin16 += pimage->texw - width;
				buf += bitmap->width - width;
			}
			break;
		default:
			break;
	}
}
Exemple #6
0
//image conv
image_p image_conv(image_p src, int dtype)
{
	image_p dst;
	uint32_t i,j;
	uint32_t *src32, *dst32;
	uint16_t *src16, *dst16;
	uint8_t r,g,b,a;

	if(src->dtype == (uint32_t)dtype)
		return image_clone(src);

	CHECK_AND_UNSWIZZLE(src);
	dst = image_create(src->w, src->h, dtype);

	src32 = (uint32_t*)src->data;
	dst32 = (uint32_t*)dst->data;
	src16 = (uint16_t*)src->data;
	dst16 = (uint16_t*)dst->data;

	for(i = 0; i < src->h; i++)
	{
		for (j = 0; j<src->w; j++)
		{
			if(dtype == DISPLAY_PIXEL_FORMAT_8888){
				if(src->dtype == DISPLAY_PIXEL_FORMAT_4444){
					GET_RGBA_4444(src16[i*src->texw+j],r,g,b,a);
					dst32[i*dst->texw+j] = MAKE_RGBA_8888(r,g,b,a);
				}
				else if(src->dtype == DISPLAY_PIXEL_FORMAT_5551){
					GET_RGBA_5551(src16[i*src->texw+j],r,g,b,a);
					dst32[i*dst->texw+j] = MAKE_RGBA_8888(r,g,b,a);
				}
				else if(src->dtype == DISPLAY_PIXEL_FORMAT_565){
					GET_RGBA_565(src16[i*src->texw+j],r,g,b,a);
					dst32[i*dst->texw+j] = MAKE_RGBA_8888(r,g,b,a);
				}
			}
			else if(dtype == DISPLAY_PIXEL_FORMAT_4444){
				if(src->dtype == DISPLAY_PIXEL_FORMAT_8888){
					GET_RGBA_8888(src32[i*src->texw+j],r,g,b,a);
					dst16[i*dst->texw+j] = MAKE_RGBA_4444(r,g,b,a);
				}
				else if(src->dtype == DISPLAY_PIXEL_FORMAT_5551){
					GET_RGBA_5551(src16[i*src->texw+j],r,g,b,a);
					dst16[i*dst->texw+j] = MAKE_RGBA_4444(r,g,b,a);
				}
				else if(src->dtype == DISPLAY_PIXEL_FORMAT_565){
					GET_RGBA_565(src16[i*src->texw+j],r,g,b,a);
					dst16[i*dst->texw+j] = MAKE_RGBA_4444(r,g,b,a);
				}
			}
			else if(dtype == DISPLAY_PIXEL_FORMAT_5551){
				if(src->dtype == DISPLAY_PIXEL_FORMAT_8888){
					GET_RGBA_8888(src32[i*src->texw+j],r,g,b,a);
					dst16[i*dst->texw+j] = MAKE_RGBA_5551(r,g,b,a);
				}
				else if(src->dtype == DISPLAY_PIXEL_FORMAT_4444){
					GET_RGBA_4444(src16[i*src->texw+j],r,g,b,a);
					dst16[i*dst->texw+j] = MAKE_RGBA_5551(r,g,b,a);
				}
				else if(src->dtype == DISPLAY_PIXEL_FORMAT_565){
					GET_RGBA_565(src16[i*src->texw+j],r,g,b,a);
					dst16[i*dst->texw+j] = MAKE_RGBA_5551(r,g,b,a);
				}
			}
			else if(dtype == DISPLAY_PIXEL_FORMAT_565){
				if(src->dtype == DISPLAY_PIXEL_FORMAT_8888){
					GET_RGBA_8888(src32[i*src->texh+j],r,g,b,a);
					dst16[i*dst->texh+j] = MAKE_RGBA_565(r,g,b,a);
				}
				else if(src->dtype == DISPLAY_PIXEL_FORMAT_4444){
					GET_RGBA_4444(src16[i*src->texh+j],r,g,b,a);
					dst16[i*dst->texh+j] = MAKE_RGBA_565(r,g,b,a);
				}
				else if(src->dtype == DISPLAY_PIXEL_FORMAT_5551){
					GET_RGBA_5551(src16[i*src->texh+j],r,g,b,a);
					dst16[i*dst->texh+j] = MAKE_RGBA_565(r,g,b,a);
				}
			}
		}
	}
	dst->swizzle = 1;
	swizzle_swap(dst);
	CHECK_AND_SWIZZLE(src);
	return dst;
}
Exemple #7
0
int get_saturation_brightness_color(int dtype, int scol,int saturation, int brightness)
{
	int r, g, b, a, mincol, maxcol;
	switch(dtype)
	{
	case DISPLAY_PIXEL_FORMAT_8888:
		GET_RGBA_8888(scol, r, g, b, a);
		break;
	case DISPLAY_PIXEL_FORMAT_4444:
		GET_RGBA_4444(scol, r, g, b, a);
		break;
	case DISPLAY_PIXEL_FORMAT_5551:
		GET_RGBA_5551(scol, r, g, b, a);
		break;
	case DISPLAY_PIXEL_FORMAT_565:
		GET_RGBA_565(scol, r, g, b, a);
		break;
	default:
		return 0;
	}
	// 处理饱和度
	if(saturation!=0)
	{
		maxcol = r>g ? (r>b?r:b):g;
		mincol = r>g ? (g>b?b:g):r;
		if(saturation>0)
		{
			if(maxcol == 0xff)
			{
				goto cont001;
			}
		}
		else
		{
			if(maxcol == 0)
			{
				goto cont001;
			}
		}
		r += mincol + (r - mincol)*(100 + saturation)/100;
		g = mincol + (g - mincol)*(100 + saturation)/100;
		b = mincol + (b - mincol)*(100 + saturation)/100;
		if(r>0xff)r=0xff;
		if(g>0xff)g=0xff;
		if(b>0xff)b=0xff;
		if(r<0)r=0;
		if(g<0)g=0;
		if(b<0)b=0;
	}
cont001:
	// 处理亮度
	if(brightness!=0)
	{
		//gcol = ((r + g + b) / 3) & 0xff;
		//maxcol = r>g ? (r>b?r:b):g;
		mincol = r>g ? (g>b?b:g):r;
		r += (0xff-mincol) * (brightness)/100;
		g += (0xff-mincol) * (brightness)/100;
		b += (0xff-mincol) * (brightness)/100;
		if(r>0xff)r=0xff;
		if(g>0xff)g=0xff;
		if(b>0xff)b=0xff;
		if(r<0)r=0;
		if(g<0)g=0;
		if(b<0)b=0;
	}

	// 输出
	switch(dtype)
	{
		case DISPLAY_PIXEL_FORMAT_8888:
			return MAKE_RGBA_8888(r, g, b, a);
			break;
		case DISPLAY_PIXEL_FORMAT_4444:
			return MAKE_RGBA_4444(r, g, b, a);
			break;
		case DISPLAY_PIXEL_FORMAT_5551:
			return MAKE_RGBA_5551(r, g, b, a);
			break;
		case DISPLAY_PIXEL_FORMAT_565:
			return MAKE_RGBA_565(r, g, b, a);
			break;
	}

	return 0;
}
Exemple #8
0
int get_gray_color(int dtype, int scol, int gray)
{
	int gcol = 0, r = 0, g = 0, b = 0, a = 0;
	if(gray==0)
		return scol;
	switch(dtype)
	{
	case DISPLAY_PIXEL_FORMAT_8888:
		GET_RGBA_8888(scol, r, g, b, a);
		break;
	case DISPLAY_PIXEL_FORMAT_4444:
		GET_RGBA_4444(scol, r, g, b, a);
		break;
	case DISPLAY_PIXEL_FORMAT_5551:
		GET_RGBA_5551(scol, r, g, b, a);
		break;
	case DISPLAY_PIXEL_FORMAT_565:
		GET_RGBA_565(scol, r, g, b, a);
		break;
	}

	gcol = ((r + g + b) / 3) & 0xff;
	if(gray==100)
	{
		switch(dtype)
		{
			case DISPLAY_PIXEL_FORMAT_8888:
				return MAKE_RGBA_8888(gcol, gcol, gcol, a);
				break;
			case DISPLAY_PIXEL_FORMAT_4444:
				return MAKE_RGBA_4444(gcol, gcol, gcol, a);
				break;
			case DISPLAY_PIXEL_FORMAT_5551:
				return MAKE_RGBA_5551(gcol, gcol, gcol, a);
				break;
			case DISPLAY_PIXEL_FORMAT_565:
				return MAKE_RGBA_565(gcol, gcol, gcol, a);
				break;
		}
	}
	r += ((gcol - r) * gray / 100) & 0xff;
	g += ((gcol - g) * gray / 100) & 0xff;
	b += ((gcol - b) * gray / 100) & 0xff;

	switch(dtype)
	{
		case DISPLAY_PIXEL_FORMAT_8888:
			return MAKE_RGBA_8888(r, g, b, a);
			break;
		case DISPLAY_PIXEL_FORMAT_4444:
			return MAKE_RGBA_4444(r, g, b, a);
			break;
		case DISPLAY_PIXEL_FORMAT_5551:
			return MAKE_RGBA_5551(r, g, b, a);
			break;
		case DISPLAY_PIXEL_FORMAT_565:
			return MAKE_RGBA_565(r, g, b, a);
			break;
	}

	return 0;
}
image_p image_conv(image_p src, int dtype)
{
	image_p dst;
	uint8 recover = 0;
	uint32 i,j;
	uint32 *src32, *dst32;
	uint16 *src16, *dst16;
	uint8 r,g,b,a;

	if(src->dtype == dtype)
		return image_clone(src);

	if(src->swizzle ==1){
		unswizzle_swap(src);
		recover = 1;
	}
	dst = image_create(src->w, src->h, dtype);

	src32 = (uint32*)src->data;
	dst32 = (uint32*)dst->data;
	src16 = (uint16*)src->data;
	dst16 = (uint16*)dst->data;
	
	for(i = 0; i < src->h; i++)
	{
		for (j = 0; j<src->w; j++)
		{
			if(dtype == DISPLAY_PIXEL_FORMAT_8888){
				if(src->dtype == DISPLAY_PIXEL_FORMAT_4444){
					GET_RGBA_4444(src16[i*src->texw+j],r,g,b,a);
					dst32[i*dst->texw+j] = MAKE_RGBA_8888(r,g,b,a);
				}
				else if(src->dtype == DISPLAY_PIXEL_FORMAT_5551){
					GET_RGBA_5551(src16[i*src->texw+j],r,g,b,a);
					dst32[i*dst->texw+j] = MAKE_RGBA_8888(r,g,b,a);
				}
				else if(src->dtype == DISPLAY_PIXEL_FORMAT_565){
					GET_RGBA_565(src16[i*src->texw+j],r,g,b,a);
					dst32[i*dst->texw+j] = MAKE_RGBA_8888(r,g,b,a);
				}
			}
			else if(dtype == DISPLAY_PIXEL_FORMAT_4444){
				if(src->dtype == DISPLAY_PIXEL_FORMAT_8888){
					GET_RGBA_8888(src32[i*src->texw+j],r,g,b,a);
					dst16[i*dst->texw+j] = MAKE_RGBA_4444(r,g,b,a);
				}
				else if(src->dtype == DISPLAY_PIXEL_FORMAT_5551){
					GET_RGBA_5551(src16[i*src->texw+j],r,g,b,a);
					dst16[i*dst->texw+j] = MAKE_RGBA_4444(r,g,b,a);
				}
				else if(src->dtype == DISPLAY_PIXEL_FORMAT_565){
					GET_RGBA_565(src16[i*src->texw+j],r,g,b,a);
					dst16[i*dst->texw+j] = MAKE_RGBA_4444(r,g,b,a);
				}
			}
			else if(dtype == DISPLAY_PIXEL_FORMAT_5551){
				if(src->dtype == DISPLAY_PIXEL_FORMAT_8888){
					GET_RGBA_8888(src32[i*src->texw+j],r,g,b,a);
					dst16[i*dst->texw+j] = MAKE_RGBA_5551(r,g,b,a);
				}
				else if(src->dtype == DISPLAY_PIXEL_FORMAT_4444){
					GET_RGBA_4444(src16[i*src->texw+j],r,g,b,a);
					dst16[i*dst->texw+j] = MAKE_RGBA_5551(r,g,b,a);
				}
				else if(src->dtype == DISPLAY_PIXEL_FORMAT_565){
					GET_RGBA_565(src16[i*src->texw+j],r,g,b,a);
					dst16[i*dst->texw+j] = MAKE_RGBA_5551(r,g,b,a);
				}
			}
			else if(dtype == DISPLAY_PIXEL_FORMAT_565){
				if(src->dtype == DISPLAY_PIXEL_FORMAT_8888){
					GET_RGBA_8888(src32[i*src->texh+j],r,g,b,a);
					dst16[i*dst->texh+j] = MAKE_RGBA_565(r,g,b,a);
				}
				else if(src->dtype == DISPLAY_PIXEL_FORMAT_4444){
					GET_RGBA_4444(src16[i*src->texh+j],r,g,b,a);
					dst16[i*dst->texh+j] = MAKE_RGBA_565(r,g,b,a);
				}
				else if(src->dtype == DISPLAY_PIXEL_FORMAT_5551){
					GET_RGBA_5551(src16[i*src->texh+j],r,g,b,a);
					dst16[i*dst->texh+j] = MAKE_RGBA_565(r,g,b,a);
				}
			}
		}
	}
	swizzle_swap(dst);
	if(recover)
		swizzle_swap(src);
	return dst;
}
image_p image_rot(image_p src,float angel)
{
	image_p dst;
	uint8 recover = 0;
	double sx,rs0,rs1,sy;
	double rangel;
	pointf d0,d1,d2,d3,d4;
	float x1,x2,y1,y2;
	sint16 xo, yo, wo, ho;
	uint32 i,j;
	uint32 *src32, *dst32;
	uint16 *src16, *dst16;
	uint16 r,g,b,a;
	uint16 r2,g2,b2,a2;
	uint8 smc;
	float xbx;

	while(angel > 360.0f)
		angel-=360.0f;

	while(angel<0)
		angel+=360.0f;

	if(angel == 0)
		return image_clone(src);
	
	if(src->swizzle ==1){
		unswizzle_swap(src);
		recover = 1;
	}

	rangel = angel*3.1415926f/180.0f;
	sx = cos(rangel);
	rs0 = sin(rangel);
	rs1 = -sin(rangel);
	sy = cos(rangel);

	d0.x = 0;
	d0.y = 0;
	d1 = image_rot_pointf(d0, sx, sy, rs0, rs1);
	d0.x = src->w;
	d2 = image_rot_pointf(d0, sx, sy, rs0, rs1);
	d0.y = src->h;
	d3 = image_rot_pointf(d0, sx, sy, rs0, rs1);
	d0.x = 0;
	d4 = image_rot_pointf(d0, sx, sy, rs0, rs1);

	x1 = min(d1.x, min(d2.x, min(d3.x, d4.x)));
	x2 = max(d1.x, max(d2.x, max(d3.x, d4.x)));
	y1 = min(d1.y, min(d2.y, min(d3.y, d4.y)));
	y2 = max(d1.y, max(d2.y, max(d3.y, d4.y)));

	xo = x1;
	yo = y1;
	wo = x2 - xo;
	ho = y2 - yo;

	dst = image_create(wo, ho, src->dtype);
	
	src32 = (uint32*)src->data;
	dst32 = (uint32*)dst->data;
	src16 = (uint16*)src->data;
	dst16 = (uint16*)dst->data;
	
	for(i = 0; i < dst->h; i++)
	{
		for (j = 0; j<dst->w; j++)
		{
			d0.x = j;
			d0.y = i;
			d0 = image_rot_pointf(d0, sx, sy, rs0, rs1);
			// easy way
			smc = 1;
			r2 = 0; g2 = 0; b2 = 0; a2 = 0;
			if(src->dtype == DISPLAY_PIXEL_FORMAT_8888){
				if((int)d0.y-yo < src->texh && (int)d0.x-xo < src->texw){
					//dst16[i*dst->texw+j] = src16[((int)d0.y-yo)*src->texw+(int)d0.x-xo];
					GET_RGBA_8888(src32[((int)d0.y-yo)*src->texw+(int)d0.x-xo], r, g, b, a);
					xbx = 1.0f - ((d0.y-yo) - (int)(d0.y-yo));
					r2 = r * xbx;
					g2 = g * xbx;
					b2 = b * xbx;
					a2 = a * xbx;

					if((int)d0.y-yo+1 < src->texh){
						smc++;
						xbx = 1.0f - xbx;
						GET_RGBA_8888(src32[((int)d0.y-yo+1)*src->texw+(int)d0.x-xo], r, g, b, a);
						r2 += r * xbx;
						g2 += g * xbx;
						b2 += b * xbx;
						a2 += a * xbx;
					}

					r = min(r2, 255);
					g = min(g2, 255);
					b = min(b2, 255);
					a = min(a2, 255);
					dst32[i*dst->texw+j] = MAKE_RGBA_8888(r,g,b,a);
				}
			}
			else if(src->dtype == DISPLAY_PIXEL_FORMAT_4444){
				if((int)d0.y-yo < src->texh && (int)d0.x-xo < src->texw){
					//dst16[i*dst->texw+j] = src16[((int)d0.y-yo)*src->texw+(int)d0.x-xo];
					GET_RGBA_4444(src16[((int)d0.y-yo)*src->texw+(int)d0.x-xo], r, g, b, a);
					xbx = 1.0f - ((d0.y-yo) - (int)(d0.y-yo));
					r2 = r * xbx;
					g2 = g * xbx;
					b2 = b * xbx;
					a2 = a * xbx;

					if((int)d0.y-yo+1 < src->texh){
						smc++;
						xbx = 1.0f - xbx;
						GET_RGBA_4444(src16[((int)d0.y-yo+1)*src->texw+(int)d0.x-xo], r, g, b, a);
						r2 += r * xbx;
						g2 += g * xbx;
						b2 += b * xbx;
						a2 += a * xbx;
					}

					r = min(r2, 255);
					g = min(g2, 255);
					b = min(b2, 255);
					a = min(a2, 255);
					dst16[i*dst->texw+j] = MAKE_RGBA_4444(r,g,b,a);
				}
			}
			else if(src->dtype == DISPLAY_PIXEL_FORMAT_5551){
				if((int)d0.y-yo < src->texh && (int)d0.x-xo < src->texw){
					//dst16[i*dst->texw+j] = src16[((int)d0.y-yo)*src->texw+(int)d0.x-xo];
					GET_RGBA_5551(src16[((int)d0.y-yo)*src->texw+(int)d0.x-xo], r, g, b, a);
					xbx = 1.0f - ((d0.y-yo) - (int)(d0.y-yo));
					r2 = r * xbx;
					g2 = g * xbx;
					b2 = b * xbx;
					a2 = a * xbx;

					if((int)d0.y-yo+1 < src->texh){
						smc++;
						xbx = 1.0f - xbx;
						GET_RGBA_5551(src16[((int)d0.y-yo+1)*src->texw+(int)d0.x-xo], r, g, b, a);
						r2 += r * xbx;
						g2 += g * xbx;
						b2 += b * xbx;
						a2 += a * xbx;
					}

					r = min(r2, 255);
					g = min(g2, 255);
					b = min(b2, 255);
					a = min(a2, 255);
					dst16[i*dst->texw+j] = MAKE_RGBA_5551(r,g,b,a);
				}
			}
			else{
				if((int)d0.y-yo < src->texh && (int)d0.x-xo < src->texw){
					//dst16[i*dst->texw+j] = src16[((int)d0.y-yo)*src->texw+(int)d0.x-xo];
					GET_RGBA_565(src16[((int)d0.y-yo)*src->texw+(int)d0.x-xo], r, g, b, a);
					xbx = 1.0f - ((d0.y-yo) - (int)(d0.y-yo));
					r2 = r * xbx;
					g2 = g * xbx;
					b2 = b * xbx;
					a2 = a * xbx;

					if((int)d0.y-yo+1 < src->texh){
						smc++;
						xbx = 1.0f - xbx;
						GET_RGBA_565(src16[((int)d0.y-yo+1)*src->texw+(int)d0.x-xo], r, g, b, a);
						r2 += r * xbx;
						g2 += g * xbx;
						b2 += b * xbx;
						a2 += a * xbx;
					}

					r = min(r2, 255);
					g = min(g2, 255);
					b = min(b2, 255);
					a = min(a2, 255);
					dst16[i*dst->texw+j] = MAKE_RGBA_565(r,g,b,a);
				}
			}
		}
	}
	
	swizzle_swap(dst);
	if(recover)
		swizzle_swap(src);
	return dst;
}
Exemple #11
0
image_p image_load_bmp_buf(const char* mbuf,int bsize, int displaymode)
{
	image_p pimage = NULL;
	uint8_t *pdata,*data,*line;
	int dsize,w,h,texw,texh,bpb,size,x,y,done = 0;
	uint32_t* p32;
	uint16_t* p16;
	uint16_t color16;
	uint32_t color32;
	PBITMAPFILEHEADER pbfh = (PBITMAPFILEHEADER)mbuf;
	PBITMAPINFOHEADER pbih;

	if(pbfh->bfType !=0x4d42){
		nge_print("not bmp file\n");
		return 0;
	}
	pbih = (PBITMAPINFOHEADER)(mbuf+sizeof(BITMAPFILEHEADER));
	dsize = sizeof(BITMAPFILEHEADER)+pbih->biSize;
	pdata =  (uint8_t*)mbuf+dsize;
	w = pbih->biWidth;
	h = pbih->biHeight;
	texw = roundpower2(w);
	texh = roundpower2(h);
	bpb  = 4;
	if(displaymode != DISPLAY_PIXEL_FORMAT_8888){
		bpb = 2;
	}
	//int biSizeImage = ((((pbih->biWidth * pbih->biBitCount) + 31) & ~31) / 8) * pbih->biHeight;
	size = texw * texh * bpb;
	data = (uint8_t*)malloc(size);
	memset(data,0,size);
	p32 = (uint32_t*)data;
	p16 = (uint16_t*) p32;
	line = NULL;
	if(pbih->biBitCount == 24){
		for (y = h;y>0;y--){
			line = pdata+(y-1)*w*3;
			for (x=0;x<w;x++){
				switch(displaymode)
				{
				case DISPLAY_PIXEL_FORMAT_8888:
					color32 = MAKE_RGBA_8888(line[2],line[1],line[0],0xff);
					*(p32+x) = color32;
					break;
				case DISPLAY_PIXEL_FORMAT_565:
					color16 = MAKE_RGBA_565(line[2],line[1],line[0],0xff);
					*(p16+x) = color16;
					break;
				case DISPLAY_PIXEL_FORMAT_5551:
					color16 = MAKE_RGBA_5551(line[2],line[1],line[0],0xff);
					*(p16+x) = color16;
					break;
				case DISPLAY_PIXEL_FORMAT_4444:
					color16 = MAKE_RGBA_4444(line[2],line[1],line[0],0xff);
					*(p16+x) = color16;
					break;
				}
				line+=3;
			}
			p32 += texw;
			p16 += texw;
		}
		done = 1;
	}
	else if(pbih->biBitCount == 32){
		for (y = h;y>0;y--){
			line = pdata+(y-1)*w*4;
			for (x=0;x<w;x++){
				switch(displaymode)
				{
				case DISPLAY_PIXEL_FORMAT_8888:
					color32 = MAKE_RGBA_8888(line[2],line[1],line[0],0xff);
					*(p32+x) = color32;
					break;
				case DISPLAY_PIXEL_FORMAT_565:
					color16 = MAKE_RGBA_565(line[2],line[1],line[0],0xff);
					*(p16+x) = color16;
					break;
				case DISPLAY_PIXEL_FORMAT_5551:
					color16 = MAKE_RGBA_5551(line[2],line[1],line[0],0xff);
					*(p16+x) = color16;
					break;
				case DISPLAY_PIXEL_FORMAT_4444:
					color16 = MAKE_RGBA_4444(line[2],line[1],line[0],0xff);
					*(p16+x) = color16;
					break;
				}
				line+=4;
			}
			p32 += texw;
			p16 += texw;
		}
		done = 1;
	}

	if (done){
		pimage = (image_p)malloc(sizeof(image_t));
		memset(pimage,0,sizeof(image_t));
		pimage->data = (uint8_t *)data;
		pimage->w    = w;
		pimage->h    = h;
		pimage->texw = texw;
		pimage->texh = texh;
		pimage->bpb  = bpb;
		pimage->dtype = displaymode;
		pimage->rcentrex = pimage->w*1.0f/2;
		pimage->rcentrey = pimage->h*1.0f/2;
		pimage->mode = GET_PSM_COLOR_MODE(displaymode);
		pimage->mask = CreateColor(255,255,255,255,displaymode);
		pimage->texid = image_tid++;
	}
	return pimage;
}