00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "Teddy/TeddyConfig.h"
00026 #include "Teddy/Graphics/Device.h"
00027 #include "Teddy/Graphics/Texture.h"
00028
00029
00030 namespace Teddy {
00031 namespace Graphics {
00032
00033
00035 void Texture::convert_to_a(){
00036 switch( work_data_pixel_format ){
00037 case GL_RGB: convert_rgb_to_a (); break;
00038 case GL_RGBA: convert_rgba_to_a(); break;
00039 default: break;
00040 }
00041
00042 work_data_pixel_format = GL_ALPHA;
00043 }
00044
00045
00047 void Texture::convert_to_rgb(){
00048 switch( work_data_pixel_format ){
00049 case GL_ALPHA: convert_a_to_rgb (); break;
00050 case GL_RGBA: convert_rgba_to_rgb(); break;
00051 default: break;
00052 }
00053
00054 work_data_pixel_format = GL_RGB;
00055 }
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00070 void Texture::convert_a_to_rgb(){
00071 unsigned char *in = work_data;
00072 unsigned char *out = new unsigned char[size[0]*size[1]];
00073 int x = 0;
00074 int y = 0;
00075 int a = 0;
00076
00077 for( y=0; y<size[1]; y++ ){
00078 for( x=0; x<size[0]; x++ ){
00079 a = in[y*size[0]+x];
00080 out[y*size[0]*3+x*3+0] = a;
00081 out[y*size[0]*3+x*3+1] = a;
00082 out[y*size[0]*3+x*3+2] = a;
00083 }
00084 }
00085
00086 setWorkData( out );
00087 }
00088
00089
00091 void Texture::convert_rgb_to_a(){
00092 unsigned char *in = work_data;
00093 unsigned char *out = new unsigned char[size[0]*size[1]];
00094 int x = 0;
00095 int y = 0;
00096 int r = 0;
00097 int g = 0;
00098 int b = 0;
00099 int a = 0;
00100
00101 for( y=0; y<size[1]; y++ ){
00102 for( x=0; x<size[0]; x++ ){
00103 r = in[y*size[0]*3+x*3+0];
00104 g = in[y*size[0]*3+x*3+1];
00105 b = in[y*size[0]*3+x*3+2];
00106 a = r;
00107 out[y*size[0]+x] = a;
00108 }
00109 }
00110
00111 setWorkData( out );
00112 }
00113
00114
00116 void Texture::convert_rgba_to_a(){
00117 unsigned char *in = work_data;
00118 unsigned char *out = new unsigned char[size[0]*size[1]];
00119 int x = 0;
00120 int y = 0;
00121 int r = 0;
00122 int g = 0;
00123 int b = 0;
00124 int a = 0;
00125
00126 for( y=0; y<size[1]; y++ ){
00127 for( x=0; x<size[0]; x++ ){
00128 r = in[y*size[0]*4+x*4+0];
00129 g = in[y*size[0]*4+x*4+1];
00130 b = in[y*size[0]*4+x*4+2];
00131 a = in[y*size[0]*4+x*4+2];
00132 out[y*size[0]+x] = a;
00133 }
00134 }
00135
00136 setWorkData( out );
00137 }
00138
00139
00141 void Texture::convert_rgba_to_rgb(){
00142 unsigned char *in = work_data;
00143 unsigned char *out = new unsigned char[int(size[0]*size[1])*3];
00144 int x = 0;
00145 int y = 0;
00146 int r = 0;
00147 int g = 0;
00148 int b = 0;
00149 int a = 0;
00150
00151 for( y=0; y<size[1]; y++ ){
00152 for( x=0; x<size[0]; x++ ){
00153 r = in[y*size[0]*4+x*4+0];
00154 g = in[y*size[0]*4+x*4+1];
00155 b = in[y*size[0]*4+x*4+2];
00156 a = in[y*size[0]*4+x*4+2];
00157 out[y*size[0]*3+x*3+0] = r;
00158 out[y*size[0]*3+x*3+1] = g;
00159 out[y*size[0]*3+x*3+2] = b;
00160 }
00161 }
00162
00163 setWorkData( out );
00164 }
00165
00166
00167 };
00168 };
00169