PageRenderTime 85ms CodeModel.GetById 44ms RepoModel.GetById 1ms app.codeStats 0ms

/GT-I5700/gles20/src/pixel.cpp

https://github.com/DE-NISkA/cm_android_vendor_spica
C++ | 1357 lines | 1019 code | 185 blank | 153 comment | 101 complexity | db1278e9766886b8b36b77e26deb9259 MD5 | raw file
  1. /*
  2. *******************************************************************************
  3. *
  4. * SAMSUNG INDIA SOFTWARE OPERATIONS
  5. * Copyright(C) 2006
  6. * ALL RIGHTS RESERVED
  7. *
  8. * This program is proprietary to Samsung India Software Operations Pvt. Ltd.,
  9. * and is protected under International Copyright Act as an unpublished work.Its
  10. * use and disclosure is limited by the terms and conditions of a license agree-
  11. * -ment. It may not be copied or otherwise reproduced or disclosed to persons
  12. * outside the licensee's organization except in accordance with the terms and
  13. * conditions of such an agreement. All copies and reproductions shall be the
  14. * property of Samsung India Software Operations Pvt. Ltd. and must bear this
  15. * notice in its entirety.
  16. *
  17. *******************************************************************************
  18. */
  19. /*
  20. ***************************************************************************//*!
  21. *
  22. * \file pixel.cpp
  23. * \author Sandeep Kakarlapudi (s.kakarla@samsung.com)
  24. * \brief Pixel Conversion functions & encoding/decoding function definitions
  25. *
  26. *//*---------------------------------------------------------------------------
  27. * NOTES:
  28. *
  29. *//*---------------------------------------------------------------------------
  30. * HISTORY:
  31. *
  32. * 03.04.2007 Sandeep Kakarlapudi Initial Version
  33. *
  34. * 20.06.2007 Sandeep kakarlapudi Bug-Fix for color expansion
  35. *
  36. *******************************************************************************
  37. */
  38. #include "pixel.h"
  39. #include "platform.h"
  40. //#include <vector>
  41. #include "ustl.h"
  42. enum { R, G, B, A};
  43. #define TYPE2B enum{numBytes=2}; typedef unsigned short PixType
  44. #define TYPE4B enum{numBytes=4}; typedef unsigned int PixType
  45. //The following types are typically not used!
  46. #define TYPE1B enum{numBytes=1}; typedef unsigned char PixType
  47. #define TYPE3B enum{numBytes=3}; typedef unsigned int PixType
  48. //Debug functions
  49. void printBits(unsigned int a)
  50. {
  51. //LOGMSG("%x ",a);
  52. ustl::string s;
  53. do
  54. {
  55. s.insert(0,(a&1)?"1":"");
  56. a>>=1;
  57. }while(a);
  58. LOGMSG("%s ",s.c_str());
  59. }
  60. void printPix(int a,int b,int c,int d, unsigned int val)
  61. {
  62. unsigned int x=val&((1<<a)-1);
  63. val>>=a;
  64. unsigned int y = val&(( 1<<b)-1);
  65. val>>=b;
  66. unsigned int z = val&(( 1<<c)-1);
  67. val>>=c;
  68. unsigned int w = val&(( 1<<d)-1);
  69. val>>=d;
  70. LOGMSG("[ ");
  71. printBits(w);
  72. printBits(z);
  73. printBits(y);
  74. printBits(x);
  75. LOGMSG("]\n");
  76. }
  77. #define DEFPRINT static void print(PixType s) { printPix(Bx,By,Bz,Bw,s); }
  78. /* REFERENCE:
  79. [2:0] Mode used in Frame Buffer Color
  80. 000b = 555, RGB, 16-bit (top bit written as register alpha[7])
  81. 001b = 565, RGB, 16-bit
  82. 010b = 4444, RGB, 16-bit
  83. 011b = 1555, ARGB, 16-bit
  84. 100b = 0888, RGB, 32-bit(top byte written as register alpha)
  85. 101b = 8888, ARGB, 32-bit
  86. 110 ~ 111b = reserved
  87. */
  88. #define FMT(f) enum { Fmt = (f) }
  89. #define ORDER(a,b,c,d) enum { X=(d), Y=(c), Z=(b), W=(a) }
  90. #define BITS(a,b,c,d) enum {Bx=(d), By=(c), Bz=(b), Bw=(a) }
  91. //ORDER, First component is writen at LSBs
  92. // X,Y,Z,W is the order in which bits are "popped off" the LSBS are the top of the "stack"
  93. // => X corresponds to the LSBs, W corresponds to MSBs
  94. struct PxARGB8 { FMT(E_ARGB8); ORDER(A,R,G,B); BITS(8,8,8,8); TYPE4B; DEFPRINT };
  95. struct PxARGB0888 { FMT(E_ARGB0888); ORDER(A,R,G,B); BITS(0,8,8,8); TYPE4B; DEFPRINT };
  96. struct PxRGB8 { FMT(E_RGB8); ORDER(A,R,G,B); BITS(0,8,8,8); TYPE3B; DEFPRINT };
  97. struct PxARGB4 { FMT(E_ARGB4); ORDER(A,R,G,B); BITS(4,4,4,4); TYPE2B; DEFPRINT };
  98. struct PxRGB565{ FMT(E_RGB565); ORDER(A,R,G,B); BITS(0,5,6,5); TYPE2B; DEFPRINT };
  99. struct PxRGB5 { FMT(E_RGB5); ORDER(A,R,G,B); BITS(0,5,5,5); TYPE2B; DEFPRINT };
  100. struct PxARGB1555 { FMT(E_ARGB1555); ORDER(A,R,G,B); BITS(1,5,5,5); TYPE2B; DEFPRINT };
  101. struct PxLUMINANCE8 { FMT(E_LUMINANCE8); ORDER(A,R,G,B); BITS(0,8,0,0); TYPE1B; DEFPRINT };
  102. struct PxLUMINANCE_ALPHA88 { FMT(E_LUMINANCE_ALPHA88); ORDER(A,R,G,B); BITS(8,8,0,0); TYPE2B; DEFPRINT };
  103. struct PxLUMINANCE_ALPHA80 { FMT(E_LUMINANCE_ALPHA80); ORDER(A,R,G,B); BITS(0,8,0,0); TYPE2B; DEFPRINT };
  104. struct PxLUMINANCE_ALPHA08 { FMT(E_LUMINANCE_ALPHA08); ORDER(A,R,G,B); BITS(8,0,0,0); TYPE2B; DEFPRINT };
  105. struct PxABGR8 {FMT(E_ABGR8); ORDER(A,B,G,R); BITS(8,8,8,8); TYPE4B; DEFPRINT };
  106. struct PxBGR8{FMT(E_BGR8); ORDER(A,B,G,R); BITS(0,8,8,8); TYPE3B; DEFPRINT};
  107. struct PxRGBA4{FMT(E_RGBA4); ORDER(R,G,B,A); BITS(4,4,4,4); TYPE2B; DEFPRINT};
  108. struct PxRGBA5551{FMT(E_RGBA5551); ORDER(R,G,B,A); BITS(5,5,5,1); TYPE2B; DEFPRINT};
  109. struct PxALPHA_LIMUNANCE88 { FMT(E_ALPHA_LUMINANCE88); ORDER(A,R,G,B); BITS(8,8,0,0); TYPE2B; DEFPRINT };
  110. struct PxALPHA8 { FMT(E_ALPHA8); ORDER(A,R,G,B); BITS(8,0,0,0); TYPE1B; DEFPRINT };
  111. // RGB565 & ARGB8 ALREADY DFINED
  112. /*
  113. *******************************************************************************
  114. * Component level encoder / decoder
  115. *******************************************************************************
  116. */
  117. //Scaffolding to help with function specialization
  118. template <typename S, unsigned char component, unsigned char bits>
  119. struct _pixPopHelper //Handles bits in [4,8]
  120. {
  121. static inline void popBits(typename S::PixType& s, PxRGBAData& d)
  122. {
  123. //This implemetation gives accurate results for "bits" in range [4,8]
  124. const unsigned char srcVal = (s&((1<<bits)-1));
  125. d.c[component] = ( srcVal<<(8-bits) ) | (srcVal>>(2*bits-8));
  126. //Old implementation:
  127. // MASK SHIFT UP set LSBs to 1
  128. //d.c[component] = ( (s&((1<<bits)-1))<< (8-bits) ) | ( ((1<<(8-bits))-1) );
  129. s >>= bits;
  130. //LOGMSG("d.[%d] = %x \n",component,d.val );
  131. //LOGMSG("s = %x \n",s );
  132. }
  133. };
  134. template <typename S, unsigned char component>
  135. struct _pixPopHelper<S,component,0> //Handles bits = 0
  136. {
  137. static inline void popBits(typename S::PixType& s, PxRGBAData& d)
  138. {
  139. d.c[component] = 0xFF;
  140. //s>>= bits;
  141. }
  142. };
  143. template <typename S, unsigned char component>
  144. struct _pixPopHelper<S,component,1> //Handles bits = 1
  145. {
  146. static inline void popBits(typename S::PixType& s, PxRGBAData& d)
  147. {
  148. d.c[component] = (s&1)? 0xFF : 0;
  149. s>>= 1;//bits;
  150. }
  151. };
  152. template <typename S, unsigned char component>
  153. struct _pixPopHelper<S,component,2> //Handles bits = 2
  154. {
  155. static inline void popBits(typename S::PixType& s, PxRGBAData& d)
  156. {
  157. unsigned char tmp = s&0x3;
  158. tmp |= (tmp<<2);
  159. d.c[component] = (tmp<<4)|tmp;
  160. s>>= 2;
  161. }
  162. };
  163. template <typename S, unsigned char component>
  164. struct _pixPopHelper<S,component,3> //Handles bits = 3
  165. {
  166. static inline void popBits(typename S::PixType& s, PxRGBAData& d)
  167. {
  168. unsigned char tmp = s&0x7;
  169. d.c[component] = (tmp<<5)|(tmp<<2)|(tmp>>1);
  170. s>>= 3;
  171. }
  172. };
  173. template <unsigned char component, typename D, unsigned char bits>
  174. struct _pixPushHelper
  175. {
  176. static inline void pushBits(typename D::PixType& d, const PxRGBAData& s)
  177. {
  178. d<<=bits;
  179. d|= s.c[component]>>(8-bits);
  180. }
  181. };
  182. template <unsigned char component>
  183. struct _pixPushHelper<component,PxARGB0888,0>
  184. {
  185. static inline void pushBits(PxARGB0888::PixType& d, const PxRGBAData& s)
  186. {
  187. //d<<=8; Not required since A is the first component!
  188. d |= 0xFF;
  189. }
  190. };
  191. template <>
  192. //When copying to PxLUMINANCE_ALPHA80, we make alpha as 0xff to aid hardware and to conform to GL.
  193. struct _pixPushHelper<A,PxLUMINANCE_ALPHA80,0>
  194. {
  195. static inline void pushBits(PxLUMINANCE_ALPHA80::PixType& d, const PxRGBAData& s)
  196. {
  197. //d<<=8; Not required since A is the first component!
  198. d |= 0xFF;
  199. }
  200. };
  201. template <>
  202. //When copying to PxLUMINANCE_ALPHA80, we make alpha as 0xff to aid hardware and to conform to GL.
  203. struct _pixPushHelper<R,PxLUMINANCE_ALPHA08,0>
  204. {
  205. static inline void pushBits(PxLUMINANCE_ALPHA08::PixType& d, const PxRGBAData& s)
  206. {
  207. d<<=8; //Not required since A is the first component!
  208. d |= 0xFF; //to test
  209. }
  210. };
  211. /*
  212. *******************************************************************************
  213. * Main encode/decode functions
  214. *******************************************************************************
  215. */
  216. template <typename D, unsigned char component, unsigned char bits>
  217. inline void pushBits(typename D::PixType& d, const PxRGBAData& s)
  218. {
  219. // d<<=bits;
  220. // d|= s.c[component]>>(8-bits);
  221. _pixPushHelper<component,D,bits>::pushBits(d,s);
  222. }
  223. template <typename S, unsigned char component, unsigned char bits>
  224. inline void popBits(typename S::PixType& s, PxRGBAData& d)
  225. {
  226. _pixPopHelper<S,component,bits>::popBits(s,d);
  227. }
  228. /*
  229. *******************************************************************************
  230. * Pixel converter templates
  231. *******************************************************************************
  232. */
  233. template <typename D>
  234. inline typename D::PixType
  235. convertFromRGBAData(PxRGBAData s)
  236. {
  237. typename D::PixType d=0;
  238. pushBits<D, D::W, D::Bw>(d, s);
  239. pushBits<D, D::Z, D::Bz>(d, s);
  240. pushBits<D, D::Y, D::By>(d, s);
  241. pushBits<D, D::X, D::Bx>(d, s);
  242. return d;
  243. }
  244. template <typename S>
  245. inline PxRGBAData
  246. convertToRGBAData(typename S::PixType s)
  247. {
  248. PxRGBAData d;
  249. popBits<S, S::X, S::Bx>(s, d);
  250. popBits<S, S::Y, S::By>(s, d);
  251. popBits<S, S::Z, S::Bz>(s, d);
  252. popBits<S, S::W, S::Bw>(s, d);
  253. return d;
  254. }
  255. template<typename S>
  256. inline void genMipMapCore( void* pIn, void* pOut,GLsizei widthOut, GLsizei heightOut,GLsizei widthIn, GLsizei heightIn)
  257. {
  258. typename S::PixType* srcTmp = (typename S::PixType*)pIn;
  259. typename S::PixType* dstTmp = (typename S::PixType*)pOut;
  260. typename S::PixType srcT ;
  261. PxRGBAData d1,d2,d3,d4 ;
  262. if(heightIn == 1)
  263. widthIn =0;
  264. int flag = 0;
  265. if(widthIn == 1)
  266. flag = 2;
  267. //handle win ==1 AND hin ==1 case
  268. for (int y = 0; y < heightOut ; ++y)
  269. for(int x =0; x< widthOut; ++x)
  270. {
  271. srcT = srcTmp[2*x + 2*y * widthIn];
  272. popBits<S, S::X, S::Bx>(srcT, d1);
  273. popBits<S, S::Y, S::By>(srcT, d1);
  274. popBits<S, S::Z, S::Bz>(srcT, d1);
  275. popBits<S, S::W, S::Bw>(srcT, d1);
  276. srcT = srcTmp[ 2*x+1 + 2*y * widthIn];
  277. popBits<S, S::X, S::Bx>(srcT, d2);
  278. popBits<S, S::Y, S::By>(srcT, d2);
  279. popBits<S, S::Z, S::Bz>(srcT, d2);
  280. popBits<S, S::W, S::Bw>(srcT, d2);
  281. srcT = srcTmp[ 2*x + (2*y + 1) * widthIn];
  282. popBits<S, S::X, S::Bx>(srcT, d3);
  283. popBits<S, S::Y, S::By>(srcT, d3);
  284. popBits<S, S::Z, S::Bz>(srcT, d3);
  285. popBits<S, S::W, S::Bw>(srcT, d3);
  286. srcT = srcTmp[ (2*x+1) + (2*y +1) * widthIn - flag];
  287. popBits<S, S::X, S::Bx>(srcT, d4);
  288. popBits<S, S::Y, S::By>(srcT, d4);
  289. popBits<S, S::Z, S::Bz>(srcT, d4);
  290. popBits<S, S::W, S::Bw>(srcT, d4);
  291. d1.c[0] = (d1.c[0] + d2.c[0] + d3.c[0] + d4.c[0])>>2;
  292. d1.c[1] = (d1.c[1] + d2.c[1] + d3.c[1] + d4.c[1])>>2;
  293. d1.c[2] = (d1.c[2] + d2.c[2] + d3.c[2] + d4.c[2])>>2;
  294. d1.c[3] = (d1.c[3] + d2.c[3] + d3.c[3] + d4.c[3])>>2;
  295. pushBits<S, S::W, S::Bw>(dstTmp[x + y* widthOut], d1);
  296. pushBits<S, S::Z, S::Bz>(dstTmp[x + y* widthOut], d1);
  297. pushBits<S, S::Y, S::By>(dstTmp[x + y* widthOut], d1);
  298. pushBits<S, S::X, S::Bx>(dstTmp[x + y* widthOut], d1);
  299. }
  300. }
  301. void genMipMaps(PxFmt fmt, void* pIn, void* pOut, GLsizei widthOut, GLsizei heightOut, GLsizei widthIn, GLsizei heightIn)
  302. {
  303. switch(fmt)
  304. {
  305. case E_ARGB8: return genMipMapCore<PxARGB8>( pIn, pOut, widthOut, heightOut, widthIn, heightIn);
  306. case E_ARGB0888: return genMipMapCore<PxARGB0888>( pIn, pOut, widthOut, heightOut, widthIn, heightIn);
  307. case E_RGB8: return genMipMapCore<PxRGB8>(pIn, pOut, widthOut, heightOut, widthIn, heightIn);
  308. case E_ARGB4: return genMipMapCore<PxARGB4>(pIn, pOut, widthOut, heightOut, widthIn, heightIn);
  309. case E_RGB565: return genMipMapCore<PxRGB565>(pIn, pOut,widthOut, heightOut, widthIn, heightIn);
  310. case E_RGB5: return genMipMapCore<PxRGB5>(pIn, pOut,widthOut, heightOut, widthIn, heightIn);
  311. case E_ARGB1555: return genMipMapCore<PxARGB1555>(pIn, pOut,widthOut, heightOut, widthIn, heightIn);
  312. case E_LUMINANCE8: return genMipMapCore<PxLUMINANCE8>(pIn, pOut,widthOut, heightOut, widthIn, heightIn);
  313. case E_LUMINANCE_ALPHA88: return genMipMapCore<PxLUMINANCE_ALPHA88>(pIn, pOut,widthOut, heightOut, widthIn, heightIn);
  314. case E_LUMINANCE_ALPHA80: return genMipMapCore<PxLUMINANCE_ALPHA80>(pIn, pOut,widthOut, heightOut, widthIn, heightIn);
  315. case E_LUMINANCE_ALPHA08: return genMipMapCore<PxLUMINANCE_ALPHA08>(pIn, pOut,widthOut, heightOut, widthIn, heightIn);
  316. //added for new format
  317. case E_ABGR8: return genMipMapCore<PxABGR8>( pIn, pOut, widthOut, heightOut, widthIn, heightIn);
  318. case E_BGR8: return genMipMapCore<PxBGR8>(pIn, pOut, widthOut, heightOut, widthIn, heightIn);
  319. case E_RGBA4: return genMipMapCore<PxRGBA4>(pIn, pOut, widthOut, heightOut, widthIn, heightIn);
  320. case E_RGBA5551: return genMipMapCore<PxRGBA5551>(pIn, pOut,widthOut, heightOut, widthIn, heightIn);
  321. case E_ALPHA_LUMINANCE88: return genMipMapCore<PxALPHA_LIMUNANCE88>(pIn, pOut,widthOut, heightOut, widthIn, heightIn);
  322. case E_ALPHA8: return genMipMapCore<PxALPHA8>( pIn, pOut, widthOut, heightOut, widthIn, heightIn);
  323. // default:
  324. LOGMSG("ERROR: unknown/unsupported destination pixel format: %d\n",fmt);
  325. }
  326. }
  327. /*
  328. *******************************************************************************
  329. * Main Converters
  330. *******************************************************************************
  331. */
  332. unsigned int convertFromRGBA(PxFmt dFmt, float rval, float gval, float bval, float aval)
  333. {
  334. PxRGBAData s;
  335. //gAssert((0.0<=rval)&&(rval<=1.0));
  336. s.c[R] = (unsigned char)(rval*255.0f);
  337. s.c[G] = (unsigned char)(gval*255.0f);
  338. s.c[B] = (unsigned char)(bval*255.0f);
  339. s.c[A] = (unsigned char)(aval*255.0f);
  340. return convertFromRGBA(dFmt, s);
  341. }
  342. unsigned int convertFromRGBA(PxFmt dFmt, unsigned char rval, unsigned char gval, unsigned char bval, unsigned char aval)
  343. {
  344. PxRGBAData s;
  345. s.c[R] = rval;
  346. s.c[G] = gval;
  347. s.c[B] = bval;
  348. s.c[A] = aval;
  349. return convertFromRGBA(dFmt, s);
  350. }
  351. unsigned int convertFromRGBA(PxFmt dFmt, PxRGBAData s)
  352. {
  353. switch(dFmt)
  354. {
  355. case E_ARGB8: return convertFromRGBAData<PxARGB8>(s);
  356. case E_ARGB0888: return convertFromRGBAData<PxARGB0888>(s);
  357. case E_RGB8: return convertFromRGBAData<PxRGB8>(s);
  358. case E_ARGB4: return convertFromRGBAData<PxARGB4>(s);
  359. case E_RGB565: return convertFromRGBAData<PxRGB565>(s);
  360. case E_RGB5: return convertFromRGBAData<PxRGB5>(s);
  361. case E_ARGB1555: return convertFromRGBAData<PxARGB1555>(s);
  362. //added for new format
  363. case E_ABGR8: return convertFromRGBAData<PxABGR8>(s);
  364. case E_BGR8: return convertFromRGBAData<PxBGR8>(s);
  365. case E_RGBA4: return convertFromRGBAData<PxRGBA4>(s);
  366. case E_RGBA5551: return convertFromRGBAData<PxRGBA5551>(s);
  367. // default:
  368. LOGMSG("ERROR: unknown/unsupported destination pixel format: %d\n",dFmt);
  369. }
  370. return 0;
  371. }
  372. template<typename D, typename S>
  373. inline void
  374. convertPixelsCore(void* dstPixels, GLsizei dstWidth, GLsizei dstHeight, GLsizei dstDepth,
  375. GLuint dstX, GLuint dstY, GLuint dstZ,
  376. const void* srcPixels, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth,
  377. GLuint srcX, GLuint srcY, GLuint srcZ,
  378. GLsizei cpyWidth, GLsizei cpyHeight, GLsizei cpyDepth , GLint dstPad, GLint srcPad, GLint dir)
  379. {
  380. GLubyte *src = NULL, *dst = NULL;
  381. typename S::PixType srcTmp ;
  382. typename D::PixType dstTmp = 0;
  383. //GLuint pixelSize = 0;
  384. int i = 0, j = 0, k = 0;
  385. // Special consideration for 2D where 0 depth is passed
  386. if(cpyDepth == 0) {
  387. cpyDepth = 1;
  388. }
  389. GLuint dstPixSize ,srcPixSize;
  390. srcPixSize = S::numBytes;
  391. dstPixSize = D::numBytes;
  392. //src = ((GLubyte*)srcPixels) + srcZ * srcWidth * srcHeight * srcPixSize + srcY * srcWidth * srcPixSize + srcX * srcPixSize;
  393. src = ((GLubyte*)srcPixels) + srcZ * srcWidth * srcHeight * srcPixSize + ( ( (1-dir)>>1)*(srcHeight-1) + (dir*srcY) ) * srcWidth * srcPixSize + srcX * srcPixSize;
  394. dst = ((GLubyte*)dstPixels) + dstZ * dstWidth * dstHeight * dstPixSize + dstY * dstWidth * dstPixSize + dstX * dstPixSize;
  395. PxRGBAData dTmp;
  396. for(k = 0; k < cpyDepth; k++) {
  397. for(j = 0; j < cpyHeight; j++) {
  398. for(i = 0; i < cpyWidth; i++){
  399. //typename S::PixType& srcTmp = *( (typename S::PixType*)src );
  400. //typename D::PixType& dstTmp = *( (typename D::PixType*)dst );
  401. //srcTmp = 0;
  402. dstTmp = 0;
  403. Plat::memcpy( &srcTmp,src,srcPixSize);
  404. //dstTmp = (typename D::PixType*)dst;
  405. popBits<S, S::X, S::Bx>(srcTmp, dTmp);
  406. popBits<S, S::Y, S::By>(srcTmp, dTmp);
  407. popBits<S, S::Z, S::Bz>(srcTmp, dTmp);
  408. popBits<S, S::W, S::Bw>(srcTmp, dTmp);
  409. pushBits<D, D::W, D::Bw>(dstTmp, dTmp);
  410. pushBits<D, D::Z, D::Bz>(dstTmp, dTmp);
  411. pushBits<D, D::Y, D::By>(dstTmp, dTmp);
  412. pushBits<D, D::X, D::Bx>(dstTmp, dTmp);
  413. Plat::memcpy( dst,&dstTmp,dstPixSize);
  414. dst += dstPixSize;
  415. src += srcPixSize;
  416. }
  417. src =src + dir * ( ( srcWidth - (dir*cpyWidth) ) * srcPixSize + srcPad );
  418. dst += (dstWidth - cpyWidth) * dstPixSize + dstPad;
  419. }
  420. src += ((srcHeight - cpyHeight) * (srcWidth + srcPad) ) * srcPixSize;
  421. dst += ((dstHeight - cpyHeight) * (dstWidth + dstPad) ) * dstPixSize;
  422. }
  423. }
  424. template<typename S>
  425. inline void
  426. convertPixelsFrom( PxFmt dstFmt, void* dstPixels, GLsizei dstWidth, GLsizei dstHeight, GLsizei dstDepth,
  427. GLuint dstX, GLuint dstY, GLuint dstZ,
  428. const void* srcPixels, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth,
  429. GLuint srcX, GLuint srcY, GLuint srcZ,
  430. GLsizei cpyWidth, GLsizei cpyHeight, GLsizei cpyDepth , GLint dstPad, GLint srcPad, GLint dir)
  431. {
  432. switch(dstFmt)
  433. {
  434. case E_ARGB8:
  435. convertPixelsCore<PxARGB8,S>(dstPixels,dstWidth,dstHeight,dstDepth,
  436. dstX, dstY, dstZ,
  437. srcPixels,srcWidth,srcHeight,srcDepth,
  438. srcX, srcY, srcZ,
  439. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad, dir);
  440. break;
  441. case E_ARGB0888:
  442. convertPixelsCore<PxARGB0888,S>(dstPixels,dstWidth,dstHeight,dstDepth,
  443. dstX, dstY, dstZ,
  444. srcPixels,srcWidth,srcHeight,srcDepth,
  445. srcX, srcY, srcZ,
  446. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad, dir);
  447. break;
  448. case E_RGB8:
  449. convertPixelsCore<PxRGB8,S>(dstPixels,dstWidth,dstHeight,dstDepth,
  450. dstX, dstY, dstZ,
  451. srcPixels,srcWidth,srcHeight,srcDepth,
  452. srcX, srcY, srcZ,
  453. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad, dir);
  454. break;
  455. case E_ARGB4:
  456. convertPixelsCore<PxARGB4,S>(dstPixels,dstWidth,dstHeight,dstDepth,
  457. dstX, dstY, dstZ,
  458. srcPixels,srcWidth,srcHeight,srcDepth,
  459. srcX, srcY, srcZ,
  460. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad, dir);
  461. break;
  462. case E_RGB565:
  463. convertPixelsCore<PxRGB565,S>(dstPixels,dstWidth,dstHeight,dstDepth,
  464. dstX, dstY, dstZ,
  465. srcPixels,srcWidth,srcHeight,srcDepth,
  466. srcX, srcY, srcZ,
  467. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad, dir);
  468. break;
  469. case E_RGB5:
  470. convertPixelsCore<PxRGB5,S>(dstPixels,dstWidth,dstHeight,dstDepth,
  471. dstX, dstY, dstZ,
  472. srcPixels,srcWidth,srcHeight,srcDepth,
  473. srcX, srcY, srcZ,
  474. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad, dir);
  475. break;
  476. case E_ARGB1555:
  477. convertPixelsCore<PxARGB1555,S>(dstPixels,dstWidth,dstHeight,dstDepth,
  478. dstX, dstY, dstZ,
  479. srcPixels,srcWidth,srcHeight,srcDepth,
  480. srcX, srcY, srcZ,
  481. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad, dir);
  482. break;
  483. case E_LUMINANCE8:
  484. convertPixelsCore<PxLUMINANCE8,S>(dstPixels,dstWidth,dstHeight,dstDepth,
  485. dstX, dstY, dstZ,
  486. srcPixels,srcWidth,srcHeight,srcDepth,
  487. srcX, srcY, srcZ,
  488. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad, dir);
  489. break;
  490. case E_LUMINANCE_ALPHA88:
  491. convertPixelsCore<PxLUMINANCE_ALPHA88,S>(dstPixels,dstWidth,dstHeight,dstDepth,
  492. dstX, dstY, dstZ,
  493. srcPixels,srcWidth,srcHeight,srcDepth,
  494. srcX, srcY, srcZ,
  495. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad, dir);
  496. break;
  497. case E_LUMINANCE_ALPHA80:
  498. convertPixelsCore<PxLUMINANCE_ALPHA80,S>(dstPixels,dstWidth,dstHeight,dstDepth,
  499. dstX, dstY, dstZ,
  500. srcPixels,srcWidth,srcHeight,srcDepth,
  501. srcX, srcY, srcZ,
  502. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad, dir);
  503. break;
  504. case E_LUMINANCE_ALPHA08:
  505. convertPixelsCore<PxLUMINANCE_ALPHA08,S>(dstPixels,dstWidth,dstHeight,dstDepth,
  506. dstX, dstY, dstZ,
  507. srcPixels,srcWidth,srcHeight,srcDepth,
  508. srcX, srcY, srcZ,
  509. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad, dir);
  510. break;
  511. // added shariq
  512. case E_ABGR8:
  513. convertPixelsCore<PxABGR8,S>(dstPixels,dstWidth,dstHeight,dstDepth,
  514. dstX, dstY, dstZ,
  515. srcPixels,srcWidth,srcHeight,srcDepth,
  516. srcX, srcY, srcZ,
  517. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad, dir);
  518. break;
  519. case E_BGR8:
  520. convertPixelsCore<PxBGR8,S>(dstPixels,dstWidth,dstHeight,dstDepth,
  521. dstX, dstY, dstZ,
  522. srcPixels,srcWidth,srcHeight,srcDepth,
  523. srcX, srcY, srcZ,
  524. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad, dir);
  525. break;
  526. case E_RGBA4:
  527. convertPixelsCore<PxRGBA4,S>(dstPixels,dstWidth,dstHeight,dstDepth,
  528. dstX, dstY, dstZ,
  529. srcPixels,srcWidth,srcHeight,srcDepth,
  530. srcX, srcY, srcZ,
  531. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad, dir);
  532. break;
  533. case E_RGBA5551:
  534. convertPixelsCore<PxRGBA5551,S>(dstPixels,dstWidth,dstHeight,dstDepth,
  535. dstX, dstY, dstZ,
  536. srcPixels,srcWidth,srcHeight,srcDepth,
  537. srcX, srcY, srcZ,
  538. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad, dir);
  539. break;
  540. case E_ALPHA_LUMINANCE88:
  541. convertPixelsCore<PxALPHA_LIMUNANCE88,S>(dstPixels,dstWidth,dstHeight,dstDepth,
  542. dstX, dstY, dstZ,
  543. srcPixels,srcWidth,srcHeight,srcDepth,
  544. srcX, srcY, srcZ,
  545. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad, dir);
  546. break;
  547. case E_ALPHA8:
  548. convertPixelsCore<PxALPHA8,S>(dstPixels,dstWidth,dstHeight,dstDepth,
  549. dstX, dstY, dstZ,
  550. srcPixels,srcWidth,srcHeight,srcDepth,
  551. srcX, srcY, srcZ,
  552. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad, dir);
  553. break;
  554. // default:
  555. LOGMSG("ERROR: unknown/unsupported destination pixel format: %d\n",dstFmt);
  556. }
  557. }
  558. extern GLuint GetPixSize(GLenum TextureFormat);
  559. static void convertPixels_BGR2ARGB(void* dst, const void* src, GLsizei width, GLsizei height)
  560. {
  561. GLsizei i;
  562. unsigned char* pS = (unsigned char*) src;
  563. unsigned int* pD = (unsigned int*) dst;
  564. for( i=0 ; i<height*width ; i++ )
  565. {
  566. *pD = 0xff000000 | (*(pS))<<16 | (*(pS+1))<<8 | (*(pS+2)) ;
  567. pD++;
  568. pS+=3;
  569. }
  570. }
  571. static void convertPixels_ABGR2ARGB(void* dst, const void* src, GLsizei width, GLsizei height)
  572. {
  573. GLsizei i;
  574. unsigned char* pS = (unsigned char*) src;
  575. unsigned int* pD = (unsigned int*) dst;
  576. for( i=0 ; i<height*width ; i++ )
  577. {
  578. *pD = (*(pS+3))<<24 | (*(pS))<<16 | (*(pS+1))<<8 | (*(pS+2)) ;
  579. pD++;
  580. pS+=4;
  581. }
  582. }
  583. static void convertPixelsSubTexture_BGR2ARGB(void* dstPixels, const void* srcPixels, GLuint uiXOffset, GLuint uiYOffset, GLsizei SrcWidth, GLsizei SrcHeight, GLsizei DstWidth, GLsizei DstHeight)
  584. {
  585. GLuint i, j;
  586. GLint * pDst = (GLint *)dstPixels;
  587. GLubyte * pSrc = (GLubyte *)srcPixels;
  588. pDst += DstWidth*uiYOffset + uiXOffset;
  589. for(i = 0; i < SrcHeight; i++)
  590. {
  591. for(j = 0; j < SrcWidth; j++)
  592. {
  593. *pDst = 0xff000000 | (*(pSrc))<<16 | (*(pSrc+1))<<8 | (*(pSrc+2)) ;
  594. pDst++;
  595. pSrc += 3;
  596. }
  597. pDst += DstWidth - SrcWidth;
  598. }
  599. }
  600. static void convertPixelsSubTexture_ABGR2ARGB(void* dstPixels, const void* srcPixels, GLuint uiXOffset, GLuint uiYOffset, GLsizei SrcWidth, GLsizei SrcHeight, GLsizei DstWidth, GLsizei DstHeight)
  601. {
  602. GLuint i, j;
  603. GLint * pDst = (GLint *)dstPixels;
  604. GLubyte * pSrc = (GLubyte *)srcPixels;
  605. pDst += DstWidth*uiYOffset + uiXOffset;
  606. for(i = 0; i < SrcHeight; i++)
  607. {
  608. for(j = 0; j < SrcWidth; j++)
  609. {
  610. *pDst = (*(pSrc+3))<<24 | (*(pSrc))<<16 | (*(pSrc+1))<<8 | (*(pSrc+2)) ;
  611. pDst++;
  612. pSrc += 4;
  613. }
  614. pDst += DstWidth - SrcWidth;
  615. }
  616. }
  617. void convertPixelsTexure( PxFmt dstFmt, void* dstPixels, GLsizei width, GLsizei height,
  618. PxFmt srcFmt,const void* srcPixels)
  619. {
  620. if( dstFmt==srcFmt )
  621. {
  622. Plat::memcpy(dstPixels,srcPixels,width*height * GetPixSize(dstFmt) ); // imbumoh 20090105
  623. }
  624. else if( dstFmt==E_ARGB8 && (srcFmt==E_BGR8 || srcFmt==E_ABGR8 ) )
  625. {
  626. if( srcFmt==E_BGR8 )
  627. convertPixels_BGR2ARGB(dstPixels,srcPixels,width,height);
  628. else
  629. //_gl_asm_convertPixels_ABGR2ARGB(dstPixels,srcPixels,width*height);
  630. convertPixels_ABGR2ARGB(dstPixels,srcPixels,width,height);
  631. }
  632. else
  633. {
  634. convertPixels(dstFmt, dstPixels, width, height, 0,0,0,0,
  635. srcFmt, srcPixels, width, height, 0,0,0,0, width, height, 0,0,0,0);
  636. }
  637. }
  638. void convertPixels( PxFmt dstFmt, void* dstPixels, GLsizei dstWidth, GLsizei dstHeight, GLsizei dstDepth,
  639. GLuint dstX, GLuint dstY, GLuint dstZ,
  640. PxFmt srcFmt,const void* srcPixels, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth,
  641. GLuint srcX, GLuint srcY, GLuint srcZ,
  642. GLsizei cpyWidth, GLsizei cpyHeight, GLsizei cpyDepth , GLint dstPad, GLint srcPad,GLint dir)
  643. {
  644. switch(srcFmt)
  645. {
  646. case E_ARGB8:
  647. convertPixelsFrom<PxARGB8>(dstFmt,dstPixels,dstWidth,dstHeight,dstDepth,
  648. dstX, dstY, dstZ,
  649. srcPixels,srcWidth,srcHeight,srcDepth,
  650. srcX, srcY, srcZ,
  651. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad,dir);
  652. break;
  653. case E_ARGB0888:
  654. convertPixelsFrom<PxARGB0888>(dstFmt,dstPixels,dstWidth,dstHeight,dstDepth,
  655. dstX, dstY, dstZ,
  656. srcPixels,srcWidth,srcHeight,srcDepth,
  657. srcX, srcY, srcZ,
  658. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad,dir);
  659. break;
  660. case E_RGB8:
  661. convertPixelsFrom<PxRGB8>(dstFmt,dstPixels,dstWidth,dstHeight,dstDepth,
  662. dstX, dstY, dstZ,
  663. srcPixels,srcWidth,srcHeight,srcDepth,
  664. srcX, srcY, srcZ,
  665. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad,dir);
  666. break;
  667. case E_ARGB4:
  668. convertPixelsFrom<PxARGB4>(dstFmt,dstPixels,dstWidth,dstHeight,dstDepth,
  669. dstX, dstY, dstZ,
  670. srcPixels,srcWidth,srcHeight,srcDepth,
  671. srcX, srcY, srcZ,
  672. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad,dir);
  673. break;
  674. case E_RGB565:
  675. convertPixelsFrom<PxRGB565>(dstFmt,dstPixels,dstWidth,dstHeight,dstDepth,
  676. dstX, dstY, dstZ,
  677. srcPixels,srcWidth,srcHeight,srcDepth,
  678. srcX, srcY, srcZ,
  679. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad,dir);
  680. break;
  681. case E_RGB5:
  682. convertPixelsFrom<PxRGB5>(dstFmt,dstPixels,dstWidth,dstHeight,dstDepth,
  683. dstX, dstY, dstZ,
  684. srcPixels,srcWidth,srcHeight,srcDepth,
  685. srcX, srcY, srcZ,
  686. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad,dir);
  687. break;
  688. case E_ARGB1555:
  689. convertPixelsFrom<PxARGB1555>(dstFmt,dstPixels,dstWidth,dstHeight,dstDepth,
  690. dstX, dstY, dstZ,
  691. srcPixels,srcWidth,srcHeight,srcDepth,
  692. srcX, srcY, srcZ,
  693. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad,dir);
  694. break;
  695. case E_LUMINANCE8:
  696. convertPixelsFrom<PxLUMINANCE8>(dstFmt,dstPixels,dstWidth,dstHeight,dstDepth,
  697. dstX, dstY, dstZ,
  698. srcPixels,srcWidth,srcHeight,srcDepth,
  699. srcX, srcY, srcZ,
  700. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad,dir);
  701. break;
  702. case E_LUMINANCE_ALPHA88:
  703. convertPixelsFrom<PxLUMINANCE_ALPHA88>(dstFmt,dstPixels,dstWidth,dstHeight,dstDepth,
  704. dstX, dstY, dstZ,
  705. srcPixels,srcWidth,srcHeight,srcDepth,
  706. srcX, srcY, srcZ,
  707. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad,dir);
  708. break;
  709. case E_LUMINANCE_ALPHA80:
  710. convertPixelsFrom<PxLUMINANCE_ALPHA80>(dstFmt,dstPixels,dstWidth,dstHeight,dstDepth,
  711. dstX, dstY, dstZ,
  712. srcPixels,srcWidth,srcHeight,srcDepth,
  713. srcX, srcY, srcZ,
  714. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad,dir);
  715. break;
  716. case E_LUMINANCE_ALPHA08:
  717. convertPixelsFrom<PxLUMINANCE_ALPHA08>(dstFmt,dstPixels,dstWidth,dstHeight,dstDepth,
  718. dstX, dstY, dstZ,
  719. srcPixels,srcWidth,srcHeight,srcDepth,
  720. srcX, srcY, srcZ,
  721. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad,dir);
  722. break;
  723. // added shariq
  724. case E_ABGR8:
  725. convertPixelsFrom<PxABGR8>(dstFmt,dstPixels,dstWidth,dstHeight,dstDepth,
  726. dstX, dstY, dstZ,
  727. srcPixels,srcWidth,srcHeight,srcDepth,
  728. srcX, srcY, srcZ,
  729. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad,dir);
  730. break;
  731. case E_BGR8:
  732. convertPixelsFrom<PxBGR8>(dstFmt,dstPixels,dstWidth,dstHeight,dstDepth,
  733. dstX, dstY, dstZ,
  734. srcPixels,srcWidth,srcHeight,srcDepth,
  735. srcX, srcY, srcZ,
  736. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad,dir);
  737. break;
  738. case E_RGBA4:
  739. convertPixelsFrom<PxRGBA4>(dstFmt,dstPixels,dstWidth,dstHeight,dstDepth,
  740. dstX, dstY, dstZ,
  741. srcPixels,srcWidth,srcHeight,srcDepth,
  742. srcX, srcY, srcZ,
  743. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad,dir);
  744. break;
  745. case E_RGBA5551:
  746. convertPixelsFrom<PxRGBA5551>(dstFmt,dstPixels,dstWidth,dstHeight,dstDepth,
  747. dstX, dstY, dstZ,
  748. srcPixels,srcWidth,srcHeight,srcDepth,
  749. srcX, srcY, srcZ,
  750. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad,dir);
  751. break;
  752. case E_ALPHA_LUMINANCE88:
  753. convertPixelsFrom<PxALPHA_LIMUNANCE88>(dstFmt,dstPixels,dstWidth,dstHeight,dstDepth,
  754. dstX, dstY, dstZ,
  755. srcPixels,srcWidth,srcHeight,srcDepth,
  756. srcX, srcY, srcZ,
  757. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad,dir);
  758. break;
  759. case E_ALPHA8:
  760. convertPixelsFrom<PxALPHA8>(dstFmt,dstPixels,dstWidth,dstHeight,dstDepth,
  761. dstX, dstY, dstZ,
  762. srcPixels,srcWidth,srcHeight,srcDepth,
  763. srcX, srcY, srcZ,
  764. cpyWidth,cpyHeight,cpyDepth , dstPad, srcPad,dir);
  765. break;
  766. //default:
  767. LOGMSG("ERROR: unknown/unsupported source pixel format: %d\n",srcFmt);
  768. }
  769. }
  770. void convertPixelsSubTexture( PxFmt dstFmt, void* dstPixels, GLsizei DstWidth, GLsizei DstHeight,GLuint uiXOffset, GLuint uiYOffset, PxFmt srcFmt,const void* srcPixels, GLsizei SrcWidth, GLsizei SrcHeight)
  771. {
  772. GLuint i;
  773. GLuint uiDstPixSize = pixelSize(dstFmt);
  774. GLuint uiSrcPixSize = pixelSize(srcFmt);
  775. GLuint uiDstStride = DstWidth*uiDstPixSize;
  776. GLuint uiSrcStride = SrcWidth*uiSrcPixSize;
  777. GLubyte * pDst = (GLubyte *)dstPixels;
  778. GLubyte * pSrc = (GLubyte *)srcPixels;
  779. pDst += DstWidth*uiYOffset*uiDstPixSize + uiXOffset*uiDstPixSize;
  780. // //LOGE("convertPixelsSubTexture");
  781. //LOGE("=====DstFmt = %d, SrcFmt = %d ====", dstFmt, srcFmt);
  782. //LOGE("=====DstHeight = %d, SrcHeight = %d ====", DstHeight, SrcHeight);
  783. //LOGE("=====DstWidth = %d, SrcWidth = %d ====", DstWidth, SrcWidth);
  784. //LOGE("=====pDst = 0x%x, pSrc = 0x%x===", pDst, pSrc);
  785. //LOGE("=====uiDstStride = 0x%x, uiSrcStride = 0x%x===", uiDstStride, uiSrcStride);
  786. if( dstFmt==srcFmt )
  787. {
  788. for(i = 0; i < SrcHeight; i++)
  789. {
  790. Plat::memcpy(pDst, pSrc, uiSrcStride); // Park Jae Sung 20090202
  791. pDst += uiDstStride;
  792. pSrc += uiSrcStride;
  793. }
  794. }
  795. else if( dstFmt==E_ARGB8 && (srcFmt==E_BGR8 || srcFmt==E_ABGR8 ) )
  796. {
  797. if( srcFmt==E_BGR8 )
  798. convertPixelsSubTexture_BGR2ARGB(dstPixels,srcPixels,uiXOffset,uiYOffset,SrcWidth,SrcHeight, DstWidth, DstHeight);
  799. else
  800. convertPixelsSubTexture_ABGR2ARGB(dstPixels,srcPixels,uiXOffset,uiYOffset,SrcWidth,SrcHeight, DstWidth, DstHeight);
  801. }
  802. else
  803. {
  804. convertPixels(dstFmt, dstPixels, DstWidth, DstHeight, 0,uiXOffset,uiYOffset,0, srcFmt, srcPixels, SrcWidth, SrcHeight, 0,0,0,0, SrcWidth, SrcHeight, 0,0,0,0);
  805. }
  806. }
  807. unsigned int convertFromDepthStencil(PxFmt dFmt, float depth, int stencil)
  808. {
  809. switch(dFmt)
  810. {
  811. case E_Stencil8:
  812. return (stencil&((1<<8)-1))<<24;
  813. case E_Depth24:
  814. return (unsigned int)(depth*(0xFFFFFF));
  815. case E_Stencil8Depth24:
  816. return ((stencil&((1<<8)-1))<<24)|(unsigned int)(depth*(0xFFFFFF));
  817. // default:
  818. LOGMSG("ERROR: unknown destination pixel format: %d\n",dFmt);
  819. }
  820. return 0;
  821. }
  822. unsigned int getDepthStencilMask(PxFmt dFmt, bool depthMask, unsigned char stencilMask)
  823. {
  824. //New mask computation causes unused components to be written to (faster for cpu clear)
  825. unsigned int mask = depthMask ? 0x00FFFFFF : 0;
  826. //mask |= stencilMask? 0xFF000000 : 0;
  827. mask |= ((unsigned int)(stencilMask) << 24);
  828. switch(dFmt)
  829. {
  830. case E_Stencil8:
  831. return (stencilMask<<24)|0xFFFFFF;
  832. case E_Depth24:
  833. return depthMask? 0xFFFFFFFF : 0x0;
  834. case E_Stencil8Depth24:
  835. return mask & 0xFFFFFFFF;
  836. // default:
  837. LOGMSG("ERROR: unknown destination pixel format: %d\n",dFmt);
  838. }
  839. return 0;
  840. }
  841. unsigned int getColorMask(PxFmt dFmt, bool redMask, bool greenMask, bool blueMask, bool alphaMask)
  842. {
  843. return convertFromRGBA(dFmt, (unsigned char)(redMask ? 0xFF : 0), (unsigned char)(greenMask ? 0xFF : 0), (unsigned char)(blueMask ? 0xFF : 0), (unsigned char)(alphaMask ? 0xFF : 0));
  844. }
  845. unsigned int pixelSize(PxFmt fmt)
  846. {
  847. switch(fmt)
  848. {
  849. case E_ARGB8: return PxARGB8::numBytes;
  850. case E_ARGB0888: return PxARGB8::numBytes;
  851. case E_RGB8: return PxRGB8::numBytes;
  852. case E_ARGB4: return PxARGB4::numBytes;
  853. case E_RGB565: return PxRGB565::numBytes;
  854. case E_RGB5: return PxRGB5::numBytes;
  855. case E_ARGB1555: return PxARGB1555::numBytes;
  856. case E_LUMINANCE8 : return PxLUMINANCE8::numBytes;
  857. case E_LUMINANCE_ALPHA88 : return PxLUMINANCE_ALPHA88::numBytes;
  858. case E_LUMINANCE_ALPHA80 : return PxLUMINANCE_ALPHA80::numBytes;
  859. case E_LUMINANCE_ALPHA08 : return PxLUMINANCE_ALPHA08::numBytes;
  860. case E_Stencil8: return 4;
  861. case E_Depth24: return 4;
  862. case E_Stencil8Depth24: return 4;
  863. //added for new formats
  864. case E_ABGR8: return PxABGR8::numBytes;
  865. case E_BGR8: return PxBGR8::numBytes;
  866. case E_RGBA4: return PxRGBA4::numBytes;
  867. case E_RGBA5551: return PxRGBA5551::numBytes;
  868. case E_ALPHA_LUMINANCE88 : return PxALPHA_LIMUNANCE88::numBytes;
  869. case E_ALPHA8:return PxALPHA8::numBytes;
  870. // default:
  871. LOGMSG("ERROR: unknown destination pixel format: %d\n",fmt);
  872. }
  873. return 0;
  874. }
  875. bool isValidPixelFmt(PxFmt fmt)
  876. {
  877. return (fmt < E_NUM_PIXEL_FMTS);
  878. }
  879. bool isValidFBColorPixelFmt(PxFmt fmt)
  880. {
  881. switch(fmt)
  882. {
  883. case E_ARGB8:
  884. case E_RGB8:
  885. case E_ARGB4:
  886. case E_RGB565:
  887. case E_RGB5:
  888. case E_ARGB1555:
  889. case E_LUMINANCE8 :
  890. case E_LUMINANCE_ALPHA88:
  891. case E_LUMINANCE_ALPHA80:
  892. case E_LUMINANCE_ALPHA08:
  893. //Intentional fall through
  894. return true;
  895. //these are compressed formats and input formats
  896. case E_RGBA4:
  897. case E_RGBA5551:
  898. case E_BGR8:
  899. case E_ABGR8:
  900. case E_ALPHA8:
  901. case E_ALPHA_LUMINANCE88:
  902. case E_PALETTE4_RGB8_OES:
  903. case E_PALETTE4_RGBA8_OES:
  904. case E_PALETTE4_R5_G6_B5_OES:
  905. case E_PALETTE4_RGBA4_OES:
  906. case E_PALETTE4_RGB5_A1_OES:
  907. case E_PALETTE8_RGB8_OES:
  908. case E_PALETTE8_RGBA8_OES:
  909. case E_PALETTE8_R5_G6_B5_OES:
  910. case E_PALETTE8_RGBA4_OES:
  911. case E_PALETTE8_RGB5_A1_OES:
  912. case E_RGB_S3TC_OES:
  913. case E_RGBA_S3TC_OES:
  914. return false;
  915. default:
  916. return false;
  917. }
  918. return false;
  919. }
  920. //TBD
  921. #if 0
  922. bool isValidTexPixelFmt(PxFmt fmt)
  923. {
  924. }
  925. #endif
  926. //for framebuffer data
  927. PxFmt translateGLSizedInternal(GLenum format)
  928. {
  929. switch(format)
  930. {
  931. case GL_RGBA8: return E_ARGB8;
  932. case GL_RGB8: return E_RGB8;
  933. case GL_RGBA4: return E_ARGB4; //added by chanchal::GL_RGBA4 should be color renderable
  934. case GL_RGB565: return E_RGB565;
  935. //case GL_RGB5: return E_RGB5;
  936. case GL_RGB5_A1: return E_ARGB1555;
  937. case GL_DEPTH_COMPONENT16:
  938. case GL_DEPTH_COMPONENT24:
  939. return E_Depth24;
  940. case GL_STENCIL_INDEX: return E_Stencil8;
  941. }
  942. return E_INVALID_PIXEL_FORMAT;
  943. }
  944. // the basic format and type combinations
  945. PxFmt translateGLInternal(GLenum format, GLenum type)
  946. {
  947. GLenum temp = GL_RGBA;
  948. switch(type)
  949. {
  950. case GL_UNSIGNED_BYTE: temp = format; break;
  951. case GL_UNSIGNED_SHORT_4_4_4_4: return E_ARGB4;
  952. case GL_UNSIGNED_SHORT_5_6_5: return E_RGB565;
  953. //case GL_RGB5: return E_RGB5;
  954. case GL_UNSIGNED_SHORT_5_5_5_1: return E_ARGB1555;
  955. default:
  956. LOGMSG("ERROR: unknown destination pixel type: %d\n",type);
  957. return E_INVALID_PIXEL_FORMAT;
  958. }
  959. switch(temp)
  960. {
  961. case GL_RGB: return E_ARGB0888;
  962. case GL_RGBA: return E_ARGB8;
  963. //case GL_LUMINANCE: return E_LUMINANCE8;
  964. case GL_LUMINANCE: return E_LUMINANCE_ALPHA80; //since hardware seems to return luminance for alpha if E_LUMINANCE8 is used
  965. case GL_LUMINANCE_ALPHA: return E_LUMINANCE_ALPHA88; //to check
  966. case GL_ALPHA: return E_LUMINANCE_ALPHA08; // previously E_ALPHA8
  967. default:
  968. LOGMSG("ERROR: unknown destination pixel type: %d\n",type);
  969. return E_INVALID_PIXEL_FORMAT;
  970. }
  971. return E_INVALID_PIXEL_FORMAT;
  972. }
  973. //case is the value returned by translateGLSizedInternal function
  974. //i.e. framebuffer format
  975. FGL_PixelFormat translateToFglPixelFormat(PxFmt fmt)
  976. {
  977. switch(fmt)
  978. {
  979. case E_RGB5: return FGL_PIXEL_RGB555;
  980. case E_RGB565: return FGL_PIXEL_RGB565;
  981. case E_ARGB4: return FGL_PIXEL_ARGB4444;
  982. case E_ARGB1555: return FGL_PIXEL_ARGB1555;
  983. case E_ARGB0888: return FGL_PIXEL_ARGB0888;
  984. case E_ARGB8: return FGL_PIXEL_ARGB8888;
  985. //case E_LUMINANCE8:
  986. //case E_LUMINANCE_ALPHA88:
  987. //case E_Stencil8:
  988. //case E_Depth24:
  989. //case E_Stencil8Depth24:
  990. //compressed format and formats input formats
  991. case E_ALPHA_LUMINANCE88:
  992. case E_RGBA4:
  993. case E_RGBA5551:
  994. case E_BGR8:
  995. case E_ABGR8:
  996. case E_ALPHA8:
  997. case E_PALETTE4_RGB8_OES:
  998. case E_PALETTE4_RGBA8_OES:
  999. case E_PALETTE4_R5_G6_B5_OES:
  1000. case E_PALETTE4_RGBA4_OES:
  1001. case E_PALETTE4_RGB5_A1_OES:
  1002. case E_PALETTE8_RGB8_OES:
  1003. case E_PALETTE8_RGBA8_OES:
  1004. case E_PALETTE8_R5_G6_B5_OES:
  1005. case E_PALETTE8_RGBA4_OES:
  1006. case E_PALETTE8_RGB5_A1_OES:
  1007. case E_RGB_S3TC_OES :
  1008. case E_RGBA_S3TC_OES:
  1009. return FGL_PixelFormat(255);
  1010. default:
  1011. return FGL_PixelFormat(255);
  1012. }
  1013. return FGL_PixelFormat(255); //Invalid!
  1014. }
  1015. GLenum translateToGLenum(PxFmt fmt)
  1016. {
  1017. switch(fmt)
  1018. {
  1019. case E_ARGB8: return GL_RGBA8;
  1020. case E_ARGB0888: return GL_RGB;
  1021. case E_RGB8: return GL_RGB8;
  1022. case E_RGB565: return GL_RGB565;
  1023. case E_ARGB1555 : return GL_RGB5_A1;
  1024. case E_Depth24 : return GL_DEPTH_COMPONENT16;
  1025. case E_Stencil8: return GL_STENCIL_INDEX ;
  1026. case E_ARGB4: return GL_RGBA4;
  1027. //case GL_RGB5: return E_RGB5;
  1028. //case GL_RGB4: return E_ARGB4;
  1029. default:
  1030. return 0;
  1031. }
  1032. return 0;
  1033. }
  1034. //added for determining the format and the type from the GL type of framebuffer
  1035. GLenum determineTypeFormat(int format, int Isformat)
  1036. {
  1037. if(Isformat == GL_TRUE){
  1038. switch(format)
  1039. {
  1040. case GL_RGBA8:
  1041. case GL_RGB5_A1:
  1042. return GL_RGBA;
  1043. case GL_RGB8:
  1044. case GL_RGB565:
  1045. return GL_RGB;
  1046. //case GL_ARGB4:
  1047. //return GL_RGBA;
  1048. default:
  1049. LOGMSG("ERROR: unknown FRAMEBUFFER format: %d\n",format);
  1050. return E_INVALID_PIXEL_FORMAT;
  1051. }
  1052. }else if(Isformat == GL_FALSE){
  1053. switch(format)
  1054. {
  1055. //GL_RGBA is automatically supported by the glReadPixel;
  1056. // so we have to support some other format, supporting GL_ARGB4
  1057. case GL_RGBA8:
  1058. case GL_RGB8:
  1059. return GL_UNSIGNED_BYTE;
  1060. case GL_RGB5_A1:
  1061. return GL_UNSIGNED_SHORT_5_5_5_1;;
  1062. case GL_RGB565:
  1063. return GL_UNSIGNED_SHORT_5_6_5;
  1064. case GL_RGBA4: //added by chanchal
  1065. return GL_UNSIGNED_SHORT_4_4_4_4;
  1066. default:
  1067. LOGMSG("ERROR: unknown FRAMEBUFFER format: %d\n",format);
  1068. return E_INVALID_PIXEL_FORMAT;
  1069. }
  1070. }
  1071. return E_INVALID_PIXEL_FORMAT;
  1072. }
  1073. int determinePixelBitSize(PxFmt format, colorType colortype)
  1074. {
  1075. switch(format)
  1076. {
  1077. //case GL_RGB4: return 4;
  1078. case E_ARGB8:
  1079. if((colortype == BLUE) || (colortype == GREEN) || (colortype == RED) || (colortype == ALPHA))return 8;
  1080. else break;
  1081. case E_ARGB0888:
  1082. if((colortype == BLUE) || (colortype == GREEN) || (colortype == RED) )return 8;
  1083. else if(colortype == ALPHA) return 0;
  1084. else break;
  1085. //case GL_RGB5:
  1086. //if(colortype == ALPHA )return 0;
  1087. //else return 5;
  1088. case E_RGB565:
  1089. if(colortype == ALPHA) return 0;
  1090. else if(colortype == GREEN) return 6;
  1091. else if((colortype == BLUE) || (colortype == RED))return 5;
  1092. else break; case E_ARGB1555:
  1093. if(colortype == ALPHA )return 1;
  1094. else if ((colortype == BLUE) || (colortype == GREEN) || (colortype == RED)) return 5;
  1095. else break;
  1096. case E_RGB8:
  1097. if(colortype == ALPHA )return 0;
  1098. else if ((colortype == BLUE) || (colortype == GREEN) || (colortype == RED)) return 8;
  1099. else break;
  1100. case E_Stencil8:
  1101. if(colortype == STENCIL) return 8;
  1102. else if(colortype == DEPTH) return 0;
  1103. else break;
  1104. case E_Depth24:
  1105. if(colortype == DEPTH) return 24;
  1106. if(colortype == STENCIL)return 0;
  1107. else break;
  1108. case E_Stencil8Depth24:
  1109. if(colortype == STENCIL) return 8;
  1110. else if(colortype == DEPTH) return 24;
  1111. else break;
  1112. default:
  1113. LOGMSG("ERROR: unknown FRAMEBUFFER format: %d\n",format);
  1114. return 255;
  1115. }
  1116. LOGMSG("\n the format passed and the colortype does not matches ");
  1117. return 0; //to check for this value
  1118. }
  1119. /*
  1120. *******************************************************************************
  1121. * TESTS
  1122. *******************************************************************************
  1123. */
  1124. #if 0
  1125. //Moved here since the rest of the code does not use this.
  1126. static const char* fmtString []={
  1127. "E_ARGB8",
  1128. "E_RGB8",
  1129. "E_ARGB4",
  1130. "E_RGB565",
  1131. "E_RGB5",
  1132. "E_ARGB1555",
  1133. "E_LUMINANCE8",
  1134. "E_LUMINANCE_ALPHA88",
  1135. "E_LUMINANCE_ALPHA80",
  1136. "E_LUMINANCE_ALPHA08",
  1137. "E_Stencil8",
  1138. "E_Depth24",
  1139. "E_Stencil8Depth24",
  1140. //added shariq
  1141. "E_ABGR8" ,
  1142. "E_BGR8" ,
  1143. "E_RGBA4",
  1144. "E_RGBA5551 ",
  1145. "E_ALPHA_LUMINANCE88",
  1146. };
  1147. template <typename D>
  1148. void testConversion(PxRGBAData s)
  1149. {
  1150. typename D::PixType d = convertFromRGBAData<D>(s);
  1151. LOGMSG("%s \t",fmtString[D::Fmt]);
  1152. D::print(d);
  1153. }
  1154. bool testPixConvert()
  1155. {
  1156. PxRGBAData s;
  1157. s.val = 0xF0EFDFCF;
  1158. testConversion<PxARGB8>(s);
  1159. LOGMSG("\n\n");
  1160. testConversion<PxRGB8>(s);
  1161. LOGMSG("\n\n");
  1162. testConversion<PxARGB4>(s);
  1163. LOGMSG("\n\n");
  1164. testConversion<PxRGB565>(s);
  1165. LOGMSG("\n\n");
  1166. testConversion<PxRGB5>(s);
  1167. LOGMSG("\n\n");
  1168. testConversion<PxARGB1555>(s);
  1169. LOGMSG("\n\n");
  1170. return 0;
  1171. }
  1172. #endif