GX texture problem March 20, 2009 05:49PM | Registered: 15 years ago Posts: 703 |
void CMD2Model::cv_bmp_24_to_32bit(unsigned char* b,int scaled_width, int scaled_height ) { //expected 32 bit data u8* s = b; u8* tmp_32 = new u8[scaled_width * scaled_height * 4]; u8* n = tmp_32; for(int ty=0;ty<scaled_height;ty++) { for(int tx=0;tx<scaled_width;tx++) { *n++ = 255; // a *n++ = s[0]; //r *n++ = s[1]; // g *n++ = s[2]; // b s+=3; } } texture_buffer = new u8[scaled_width * scaled_height * 4];//(u8*)memalign(32, scaled_width * scaled_height ); if (!texture_buffer) return; u8* scaled = tmp_32; u8* pos = (u8 *)texture_buffer; for (int y = 0; y < scaled_height; y +=4) { u8* row1 = (u8 *)&(scaled[scaled_width * (y + 0)]); u8* row2 = (u8 *)&(scaled[scaled_width * (y + 1)]); u8* row3 = (u8 *)&(scaled[scaled_width * (y + 2)]); u8* row4 = (u8 *)&(scaled[scaled_width * (y + 3)]); for (int x = 0; x < scaled_width; x += 4) { u8 AR[32]; u8 GB[32]; for (int i = 0; i < 4; i++) { u8* ptr1 = &(row1[(x + i) * 4]); u8* ptr2 = &(row2[(x + i) * 4]); u8* ptr3 = &(row3[(x + i) * 4]); u8* ptr4 = &(row4[(x + i) * 4]); AR[(i * 2) + 0] = ptr1[0]; AR[(i * 2) + 1] = ptr1[3]; AR[(i * 2) + 8] = ptr2[0]; AR[(i * 2) + 9] = ptr2[3]; AR[(i * 2) + 16] = ptr3[0]; AR[(i * 2) + 17] = ptr3[3]; AR[(i * 2) + 24] = ptr4[0]; AR[(i * 2) + 25] = ptr4[3]; GB[(i * 2) + 0] = ptr1[2]; GB[(i * 2) + 1] = ptr1[1]; GB[(i * 2) + 8] = ptr2[2]; GB[(i * 2) + 9] = ptr2[1]; GB[(i * 2) + 16] = ptr3[2]; GB[(i * 2) + 17] = ptr3[1]; GB[(i * 2) + 24] = ptr4[2]; GB[(i * 2) + 25] = ptr4[1]; } memcpy(pos, AR, sizeof(AR)); pos += sizeof(AR); memcpy(pos, GB, sizeof(GB)); pos += sizeof(GB); } } GX_InitTexObj(&tex_skin, texture_buffer, scaled_width, scaled_height, GX_TF_RGBA8, GX_REPEAT, GX_REPEAT, GX_FALSE); DCFlushRange(texture_buffer,scaled_width*scaled_height*4); //temp 32bit buffer delete [] tmp_32; tmp_32 = 0; } bool CMD2Model::LoadSkin( const char *filename ) { FILE* f = 0; f = fopen(filename,"rb"); if (!f) return false; BITMAPINFOHEADER bih; BITMAPFILEHEADER bfh; fread(&bfh,14,1,f); fread(&bih,40,1,f); bih.biWidth = int4_swap(bih.biWidth); bih.biHeight = int4_swap(bih.biHeight); bih.biSizeImage = int4_swap(bih.biSizeImage); bih.biBitCount = 24; unsigned char* buf = 0; buf = new unsigned char[bih.biSizeImage]; if (!buf) return false; fread(buf,bih.biSizeImage,1,f); fclose(f); cv_bmp_24_to_32bit(buf,bih.biWidth,bih.biHeight); //convert 24bit to 32bit delete [] buf; buf = 0; return true; }
Re: GX texture problem March 21, 2009 10:34AM | Registered: 15 years ago Posts: 62 |
Re: GX texture problem March 21, 2009 12:21PM | Registered: 16 years ago Posts: 22 |
Re: GX texture problem March 21, 2009 06:41PM | Registered: 16 years ago Posts: 265 |
Re: GX texture problem March 21, 2009 07:45PM | Registered: 15 years ago Posts: 703 |
Re: GX texture problem March 21, 2009 11:34PM | Registered: 15 years ago Posts: 703 |
Re: GX texture problem March 22, 2009 02:00AM | Registered: 15 years ago Posts: 703 |