PageRenderTime 54ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/enhanced/archive/classlib/java6/modules/awt/src/main/native/gl/shared/SurfaceDataStructure.cpp

https://bitbucket.org/varialus/dissonance
C++ | 990 lines | 613 code | 106 blank | 271 comment | 104 complexity | ee3e4224551e1096116057e026bdbfaa MD5 | raw file
Possible License(s): Apache-2.0
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /**
  18. * @author Igor V. Stolyarov
  19. * @version $Revision$
  20. */
  21. #include <stdlib.h>
  22. #include <stdlib.h>
  23. #include <memory.h>
  24. #include "SurfaceDataStructure.h"
  25. #include "org_apache_harmony_awt_gl_ImageSurface.h"
  26. #include "LUTTables.h"
  27. #ifdef _WIN32
  28. #include "GDIBlitter.h"
  29. #endif
  30. int parseMask(unsigned int mask, int *shift, int *maxVal){
  31. int bits = 0;
  32. *shift = 0;
  33. *maxVal = 0;
  34. if (mask != 0) {
  35. // Deleting final zeros
  36. while ((mask & 1) == 0) {
  37. mask >>= 1;
  38. (*shift)++;
  39. }
  40. *maxVal = mask;
  41. // Counting component bits
  42. while ((mask & 1) == 1) {
  43. mask >>= 1;
  44. bits++;
  45. }
  46. }
  47. return bits;
  48. }
  49. int getShift(unsigned int mask){
  50. int shift = 0;
  51. if (mask != 0) {
  52. while ((mask & 1) == 0) {
  53. mask >>= 1;
  54. shift++;
  55. }
  56. }
  57. return shift;
  58. }
  59. inline void updateCache
  60. (SURFACE_STRUCTURE *srcSurf, JNIEnv *env, jobject srcData, bool alphaPre){
  61. unsigned int srcstride, dststride, offset;
  62. unsigned int h = srcSurf->height;
  63. unsigned int w = srcSurf->width;
  64. void *bmpDataPtr = srcSurf->bmpData;
  65. void *srcDataPtr = env->GetPrimitiveArrayCritical((jarray)srcData, 0);
  66. switch(srcSurf->ss_type){
  67. case INT_RGB:
  68. {
  69. //if(!srcSurf->invalidated) return false;
  70. srcstride = srcSurf->scanline_stride;
  71. dststride = w;
  72. /*
  73. if(srcstride == dststride){
  74. memcpy(bmpDataPtr, srcDataPtr, (w << 2) * h);
  75. }else{
  76. */
  77. unsigned int *src, *s, *dst, *d;
  78. offset = w - 1;
  79. src = (unsigned int *)srcDataPtr + offset;
  80. dst = (unsigned int *)bmpDataPtr + offset;
  81. for(int y = h; y > 0; y--, src += srcstride, dst += dststride){
  82. s = src;
  83. d = dst;
  84. for(int x = w; x > 0 ; x--){
  85. *d-- = 0xff000000 | *s--;
  86. }
  87. }
  88. //}
  89. }
  90. break;
  91. case INT_ARGB:
  92. {
  93. //if(!srcSurf->invalidated && srcSurf->isAlphaPre && alphaPre) return false;
  94. //if(!srcSurf->invalidated && !srcSurf->isAlphaPre && !alphaPre) return false;
  95. unsigned char *src, *s, *dst, *d, sa;
  96. offset = (w << 2) - 1;
  97. src = (unsigned char *)srcDataPtr + offset;
  98. dst = (unsigned char *)bmpDataPtr + offset;
  99. srcstride = srcSurf->scanline_stride_byte;
  100. dststride = w << 2;
  101. if(alphaPre){
  102. for(int y = h; y > 0 ; y--, src += srcstride, dst += dststride){
  103. s = src;
  104. d = dst;
  105. for(int x = w; x > 0 ; x--){
  106. sa = *s--;
  107. *d-- = sa;
  108. if(sa != 255){
  109. *d-- = MUL(sa, *s--);
  110. *d-- = MUL(sa, *s--);
  111. *d-- = MUL(sa, *s--);
  112. srcSurf->hasRealAlpha = true;
  113. }else{
  114. *d-- = *s--;
  115. *d-- = *s--;
  116. *d-- = *s--;
  117. }
  118. }
  119. }
  120. srcSurf->isAlphaPre = true;
  121. }else{
  122. for(int y = h; y > 0 ; y--, src += srcstride, dst += dststride){
  123. s = src;
  124. d = dst;
  125. for(int x = w; x > 0 ; x--){
  126. sa = *s--;
  127. if(sa == 0){
  128. *d-- = 0;
  129. *d-- = 0;
  130. *d-- = 0;
  131. *d-- = 0;
  132. s -= 3;
  133. }else{
  134. *d-- = sa;
  135. *d-- = MUL(sa, *s--);
  136. *d-- = MUL(sa, *s--);
  137. *d-- = MUL(sa, *s--);
  138. }
  139. }
  140. }
  141. srcSurf->isAlphaPre = false;
  142. }
  143. }
  144. break;
  145. case INT_ARGB_PRE:
  146. {
  147. //if(!srcSurf->invalidated && srcSurf->isAlphaPre && alphaPre) return false;
  148. //if(!srcSurf->invalidated && !srcSurf->isAlphaPre && !alphaPre) return false;
  149. unsigned char *src, *s, *dst, *d, sa;
  150. offset = (w << 2) - 1;
  151. src = (unsigned char *)srcDataPtr + offset;
  152. dst = (unsigned char *)bmpDataPtr + offset;
  153. srcstride = srcSurf->scanline_stride_byte;
  154. dststride = w << 2;
  155. if(alphaPre){
  156. for(int y = h; y > 0; y--, src += srcstride, dst += dststride){
  157. s = src;
  158. d = dst;
  159. for(int x = w; x > 0 ; x--){
  160. sa = *s--;
  161. *d-- = sa;
  162. *d-- = *s--;
  163. *d-- = *s--;
  164. *d-- = *s--;
  165. if(sa != 255){
  166. srcSurf->hasRealAlpha = true;
  167. }
  168. }
  169. }
  170. srcSurf->isAlphaPre = true;
  171. }else{
  172. for(int y = h; y > 0 ; y--, src += srcstride, dst += dststride){
  173. s = src;
  174. d = dst;
  175. for(int x = w; x > 0 ; x--){
  176. sa = *s--;
  177. *d-- = sa;
  178. *d-- = DIV(sa, *s--);
  179. *d-- = DIV(sa, *s--);
  180. *d-- = DIV(sa, *s--);
  181. }
  182. }
  183. srcSurf->isAlphaPre = false;
  184. }
  185. }
  186. break;
  187. case INT_BGR:
  188. {
  189. //if(!srcSurf->invalidated) return false;
  190. unsigned char *src, *s, *dst, *d;
  191. offset = (w << 2) - 1;
  192. src = (unsigned char *)srcDataPtr + offset;
  193. dst = (unsigned char *)bmpDataPtr + offset;
  194. srcstride = srcSurf->scanline_stride_byte;
  195. dststride = w << 2;
  196. for(int y = h; y > 0; y--, src += srcstride, dst += dststride){
  197. s = src;
  198. d = dst;
  199. for(int x = w; x > 0 ; x--){
  200. *d = 255;
  201. *s--;
  202. *(d - 3) = *s--;
  203. *(d - 2) = *s--;
  204. *(d - 1) = *s--;
  205. d -= 4;
  206. }
  207. }
  208. }
  209. break;
  210. case BYTE_BGR:
  211. {
  212. //if(!srcSurf->invalidated) return false;
  213. unsigned char *src, *s, *dst, *d;
  214. offset = (w << 2) - 1;
  215. unsigned int srcOffset = w * 3 - 1;
  216. src = (unsigned char *)srcDataPtr + srcOffset;
  217. dst = (unsigned char *)bmpDataPtr + offset;
  218. srcstride = srcSurf->scanline_stride_byte;
  219. dststride = w << 2;
  220. for(int y = srcSurf->height; y > 0; y--, src += srcstride, dst += dststride){
  221. s = src;
  222. d = dst;
  223. for(int x = w; x > 0 ; x--){
  224. *d-- = 255;
  225. *d-- = *s--;
  226. *d-- = *s--;
  227. *d-- = *s--;
  228. }
  229. }
  230. }
  231. break;
  232. case BYTE_ABGR:
  233. {
  234. //if(!srcSurf->invalidated && srcSurf->isAlphaPre && alphaPre) return false;
  235. //if(!srcSurf->invalidated && !srcSurf->isAlphaPre && !alphaPre) return false;
  236. unsigned char *src, *s, *dst, *d, a, r, g, b;
  237. offset = (w << 2) - 1;
  238. src = (unsigned char *)srcDataPtr + offset;
  239. dst = (unsigned char *)bmpDataPtr + offset;
  240. srcstride = srcSurf->scanline_stride_byte;
  241. dststride = w << 2;
  242. if(alphaPre){
  243. for(int y = h; y > 0 ; y--, src += srcstride, dst += dststride){
  244. s = src;
  245. d = dst;
  246. for(int x = w; x > 0 ; x--){
  247. r = *s--;
  248. g = *s--;
  249. b = *s--;
  250. a = *s--;
  251. *d-- = a;
  252. if(a != 255){
  253. *d-- = MUL(a, r);
  254. *d-- = MUL(a, g);
  255. *d-- = MUL(a, b);
  256. srcSurf->hasRealAlpha = true;
  257. }else{
  258. *d-- = r;
  259. *d-- = g;
  260. *d-- = b;
  261. }
  262. }
  263. }
  264. srcSurf->isAlphaPre = true;
  265. }else{
  266. for(int y = h; y > 0 ; y--, src += srcstride, dst += dststride){
  267. s = src;
  268. d = dst;
  269. for(int x = w; x > 0 ; x--){
  270. r = *s--;
  271. g = *s--;
  272. b = *s--;
  273. a = *s--;
  274. if(a == 0){
  275. *d-- = 0;
  276. *d-- = 0;
  277. *d-- = 0;
  278. *d-- = 0;
  279. }else{
  280. *d-- = a;
  281. *d-- = r;
  282. *d-- = g;
  283. *d-- = b;
  284. }
  285. }
  286. }
  287. srcSurf->isAlphaPre = false;
  288. }
  289. }
  290. break;
  291. case BYTE_ABGR_PRE:
  292. {
  293. //if(!srcSurf->invalidated && srcSurf->isAlphaPre && alphaPre) return false;
  294. //if(!srcSurf->invalidated && !srcSurf->isAlphaPre && !alphaPre) return false;
  295. unsigned char *src, *s, *dst, *d, a, r, g, b;
  296. offset = (w << 2) - 1;
  297. src = (unsigned char *)srcDataPtr + offset;
  298. dst = (unsigned char *)bmpDataPtr + offset;
  299. srcstride = srcSurf->scanline_stride_byte;
  300. dststride = w << 2;
  301. if(alphaPre){
  302. for(int y = h; y > 0 ; y--, src += srcstride, dst += dststride){
  303. s = src;
  304. d = dst;
  305. for(int x = w; x > 0 ; x--){
  306. r = *s--;
  307. g = *s--;
  308. b = *s--;
  309. a = *s--;
  310. if(a != 255){
  311. srcSurf->hasRealAlpha = true;
  312. }
  313. *d-- = a;
  314. *d-- = r;
  315. *d-- = g;
  316. *d-- = b;
  317. }
  318. }
  319. srcSurf->isAlphaPre = true;
  320. }else{
  321. for(int y = h; y > 0 ; y--, src += srcstride, dst += dststride){
  322. s = src;
  323. d = dst;
  324. for(int x = w; x > 0 ; x--){
  325. r = *s--;
  326. g = *s--;
  327. b = *s--;
  328. a = *s--;
  329. *d-- = a;
  330. if(a != 255){
  331. *d-- = DIV(a, r);
  332. *d-- = DIV(a, g);
  333. *d-- = DIV(a, b);
  334. }else{
  335. *d-- = r;
  336. *d-- = g;
  337. *d-- = b;
  338. }
  339. }
  340. }
  341. srcSurf->isAlphaPre = false;
  342. }
  343. }
  344. break;
  345. case USHORT_555:
  346. case USHORT_565:
  347. {
  348. //if(!srcSurf->invalidated) return false;
  349. unsigned char *dst, *d;
  350. unsigned short *src, *s, pixel;
  351. offset = (w << 2) - 1;
  352. unsigned int srcOffset = w - 1;
  353. src = (unsigned short *)srcDataPtr + srcOffset;
  354. dst = (unsigned char *)bmpDataPtr + offset;
  355. srcstride = srcSurf->scanline_stride;
  356. dststride = w << 2;
  357. unsigned int mr = srcSurf->max_red;
  358. unsigned int mg = srcSurf->max_green;
  359. unsigned int mb = srcSurf->max_red;
  360. unsigned int rm = srcSurf->red_mask;
  361. unsigned int gm = srcSurf->green_mask;
  362. unsigned int bm = srcSurf->blue_mask;
  363. unsigned int rs = srcSurf->red_sht;
  364. unsigned int gs = srcSurf->green_sht;
  365. unsigned int bs = srcSurf->blue_sht;
  366. for(int y = h; y > 0; y--, src += srcstride, dst += dststride){
  367. d = dst;
  368. s = src;
  369. for(int x = w; x > 0; x--){
  370. pixel = *s--;
  371. *d-- = 255;
  372. *d-- = DIV(mb, ((pixel & rm) >> rs));
  373. *d-- = DIV(mg, ((pixel & gm) >> gs));
  374. *d-- = DIV(mr, ((pixel & bm) >> bs));
  375. }
  376. }
  377. }
  378. break;
  379. case USHORT_GRAY:
  380. {
  381. //if(!srcSurf->invalidated) return false;
  382. unsigned char *dst, *d, pixel;
  383. unsigned short *src, *s;
  384. src = (unsigned short *)srcDataPtr;
  385. dst = (unsigned char *)bmpDataPtr;
  386. srcstride = srcSurf->scanline_stride;
  387. dststride = w << 2;
  388. for(int y = h; y > 0; y--, src += srcstride, dst += dststride){
  389. s = src;
  390. d = dst;
  391. for(int x = w; x > 0; x--){
  392. pixel = (unsigned char)(*s++ / 257);
  393. *d++ = pixel;
  394. *d++ = pixel;
  395. *d++ = pixel;
  396. *d++ = 255;
  397. }
  398. }
  399. }
  400. break;
  401. case BYTE_BINARY:
  402. {
  403. //if(!srcSurf->invalidated) return false;
  404. unsigned char *src, *s;
  405. unsigned int *dst, *d, pixel, bitnum, elem, shift, bitMask;
  406. src = (unsigned char *)srcDataPtr;
  407. dst = (unsigned int *)bmpDataPtr;
  408. srcstride = srcSurf->scanline_stride;
  409. dststride = w;
  410. unsigned int pixelBits = srcSurf->pixel_stride;
  411. int *cm = srcSurf->colormap;
  412. for(int y = h; y > 0; y--, src += srcstride, dst += dststride){
  413. d = dst;
  414. for(unsigned int x = 0; x < w; x++){
  415. bitnum = x * pixelBits;
  416. s = src + bitnum / 8;
  417. elem = *s;
  418. shift = 8 - (bitnum & 7) - pixelBits;
  419. bitMask = (1 << pixelBits) - 1;
  420. pixel = (elem >> shift) & bitMask;
  421. *d++ = 0xff000000 | *(cm + pixel);
  422. }
  423. }
  424. }
  425. break;
  426. case BYTE_INDEXED:
  427. {
  428. int transparency = srcSurf->transparency;
  429. //if(!srcSurf->invalidated && transparency != GL_TRANSLUCENT) return false;
  430. //if(!srcSurf->invalidated && transparency == GL_TRANSLUCENT &&
  431. // srcSurf->isAlphaPre && alphaPre) return false;
  432. //if(!srcSurf->invalidated && transparency == GL_TRANSLUCENT &&
  433. // !srcSurf->isAlphaPre && !alphaPre) return false;
  434. unsigned char *src, *s;
  435. unsigned int *dst, *d, pixel, r, g, b, a;
  436. unsigned int offset = w - 1;
  437. src = (unsigned char *)srcDataPtr + offset;
  438. dst = (unsigned int *)bmpDataPtr + offset;
  439. srcstride = srcSurf->scanline_stride;
  440. dststride = w;
  441. int *cm = srcSurf->colormap;
  442. int tp = srcSurf->transparent_pixel;
  443. if(transparency == GL_OPAQUE){
  444. for(int y = h; y > 0; y--, src += srcstride, dst += dststride){
  445. s = src;
  446. d = dst;
  447. for(int x = w; x > 0; x--){
  448. *d-- = 0xff000000 | *(cm + *s--);
  449. }
  450. }
  451. }else if(transparency == GL_BITMASK){
  452. for(int y = h; y > 0; y--, src += srcstride, dst += dststride){
  453. s = src;
  454. d = dst;
  455. for(int x = w; x > 0; x--){
  456. pixel = *s--;
  457. if(pixel != tp){
  458. *d-- = 0xff000000 | *(cm + pixel);
  459. }else{
  460. srcSurf->hasRealAlpha = true;
  461. *d-- = 0;
  462. }
  463. }
  464. }
  465. }else{
  466. for(int y = h; y > 0; y--, src += srcstride, dst += dststride){
  467. s = src;
  468. d = dst;
  469. for(int x = w; x > 0; x--){
  470. pixel = *(cm + *s--);
  471. a = (pixel >> 24) & 0xff;
  472. if(alphaPre){
  473. if(a == 255){
  474. *d-- = pixel;
  475. }else{
  476. r = (pixel >> 16) & 0xff;
  477. g = (pixel >> 8) & 0xff;
  478. b = pixel & 0xff;
  479. r = MUL(a, r);
  480. g = MUL(a, g);
  481. b = MUL(a, b);
  482. *d-- = (a << 24) | (r << 16) | (g << 8) | b;
  483. srcSurf->hasRealAlpha = true;
  484. }
  485. srcSurf->isAlphaPre = true;
  486. }else{
  487. if(a == 0) *d-- = 0;
  488. else *d-- = pixel;
  489. srcSurf->isAlphaPre = false;
  490. }
  491. }
  492. }
  493. }
  494. }
  495. break;
  496. case BYTE_GRAY:
  497. {
  498. //if(!srcSurf->invalidated) return false;
  499. unsigned char *src, *s, *dst, *d, pixel;
  500. src = (unsigned char *)srcDataPtr;
  501. dst = (unsigned char *)bmpDataPtr;
  502. srcstride = srcSurf->scanline_stride;
  503. dststride = w << 2;
  504. for(int y = h; y > 0; y--, src += srcstride, dst += dststride){
  505. s = src;
  506. d = dst;
  507. for(int x = srcSurf->width; x > 0; x--){
  508. pixel = *s++;
  509. *d++ = pixel;
  510. *d++ = pixel;
  511. *d++ = pixel;
  512. *d++ = 255;
  513. }
  514. }
  515. }
  516. break;
  517. }
  518. env->ReleasePrimitiveArrayCritical((jarray)srcData, srcDataPtr, 0);
  519. }
  520. /*
  521. * Class: org_apache_harmony_awt_gl_ImageSurface
  522. * Method: createSurfStruct
  523. * Signature: (IIIIIIIIII[I[II[IIZ[I[IIZZI)J
  524. */
  525. JNIEXPORT jlong JNICALL Java_org_apache_harmony_awt_gl_ImageSurface_createSurfStruct
  526. (JNIEnv * env, jobject obj, jint surfType, jint width, jint height, jint cmType,
  527. jint csType, jint smType, jint dataType, jint numComponents, jint pixelStride,
  528. jint scanlineStride, jintArray bits, jintArray masks, jint colorMapSize,
  529. jintArray colorMap, jint transpPixel, jboolean isGrayPalette, jintArray bankIndeces,
  530. jintArray bandOffsets, jint offset, jboolean hasAlpha, jboolean isAlphaPre,
  531. jint transparency){
  532. SURFACE_STRUCTURE *surf = (SURFACE_STRUCTURE *)calloc(sizeof(SURFACE_STRUCTURE), 1);
  533. if(surf != NULL){
  534. surf->ss_type = surfType;
  535. surf->width = width;
  536. surf->height = height;
  537. surf->cm_type = cmType;
  538. surf->cs_type = csType;
  539. surf->data_type = dataType;
  540. surf->num_components = numComponents;
  541. surf->pixel_stride = pixelStride;
  542. surf->scanline_stride = scanlineStride;
  543. surf->offset = offset;
  544. surf->has_alpha = hasAlpha;
  545. surf->isAlphaPre = isAlphaPre != 0;
  546. surf->transparency = transparency;
  547. if(dataType == TYPE_BYTE){
  548. surf->scanline_stride_byte = scanlineStride;
  549. }else if(dataType == TYPE_USHORT){
  550. surf->scanline_stride_byte = scanlineStride << 1;
  551. }else if(dataType == TYPE_INT){
  552. surf->scanline_stride_byte = scanlineStride << 2;
  553. }
  554. void *p;
  555. int *s, *d;
  556. switch(cmType){
  557. case DIRECT_CM:
  558. surf->bits = (int *)malloc(surf->num_components * sizeof(int));
  559. p = env->GetPrimitiveArrayCritical(bits, 0);
  560. d = surf->bits;
  561. s = (int *)p;
  562. for(int i = 0; i < numComponents; i++){
  563. *d++ = *s++;
  564. }
  565. env->ReleasePrimitiveArrayCritical(bits, p, 0);
  566. p = env->GetPrimitiveArrayCritical(masks, 0);
  567. s = (int *)p;
  568. surf->red_mask = *s++;
  569. surf->green_mask = *s++;
  570. surf->blue_mask = *s++;
  571. if(hasAlpha){
  572. surf->alpha_mask = *s;
  573. }
  574. env->ReleasePrimitiveArrayCritical(masks, p, 0);
  575. surf->red_sht = getShift(surf->red_mask);
  576. surf->max_red = (1 << surf->bits[0]) - 1;
  577. surf->green_sht = getShift(surf->green_mask);
  578. surf->max_green = (1 << surf->bits[1]) - 1;
  579. surf->blue_sht = getShift(surf->blue_mask);
  580. surf->max_blue = (1 << surf->bits[2]) - 1;
  581. if(hasAlpha){
  582. surf->alpha_sht = getShift(surf->alpha_mask);
  583. surf->max_alpha = ( 1 << surf->bits[3]) - 1;
  584. }
  585. break;
  586. case INDEX_CM:
  587. surf->colormap_size = colorMapSize;
  588. surf->transparent_pixel = transpPixel;
  589. surf->isGrayPallete = isGrayPalette;
  590. surf->colormap = (int *)malloc(colorMapSize * sizeof(int));
  591. p = env->GetPrimitiveArrayCritical(colorMap, 0);
  592. memcpy(surf->colormap, p, colorMapSize * sizeof(int));
  593. env->ReleasePrimitiveArrayCritical(colorMap, p, 0);
  594. break;
  595. case COMPONENT_CM:
  596. surf->bank_indexes = (int *)malloc(numComponents * sizeof(int));
  597. surf->band_offsets = (int *)malloc(numComponents * sizeof(int));
  598. p = env->GetPrimitiveArrayCritical(bankIndeces, 0);
  599. memcpy((void *)surf->bank_indexes, p, numComponents * sizeof(int));
  600. env->ReleasePrimitiveArrayCritical(bankIndeces, p, 0);
  601. p = env->GetPrimitiveArrayCritical(bandOffsets, 0);
  602. memcpy((void *)surf->band_offsets, p, numComponents * sizeof(int));
  603. env->ReleasePrimitiveArrayCritical(bandOffsets, p, 0);
  604. break;
  605. }
  606. surf->bmp_byte_stride = surf->width << 2;
  607. surf->bmpData = malloc(surf->bmp_byte_stride * surf->height);
  608. surf->invalidated = true;
  609. #ifdef _WIN32
  610. surf->bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  611. surf->bmpInfo.bmiHeader.biWidth = surf->width;
  612. surf->bmpInfo.bmiHeader.biHeight = -surf->height;
  613. surf->bmpInfo.bmiHeader.biPlanes = 1;
  614. surf->bmpInfo.bmiHeader.biBitCount = 32;
  615. surf->bmpInfo.bmiHeader.biSizeImage = surf->bmp_byte_stride * surf->height;
  616. surf->bmpInfo.bmiHeader.biCompression = BI_BITFIELDS;
  617. DWORD *colors = (DWORD *)surf->bmpInfo.bmiColors;
  618. colors[0] = 0xff0000;
  619. colors[1] = 0xff00;
  620. colors[2] = 0xff;
  621. HDC dc = GetDC(NULL);
  622. surf->srcDC = CreateCompatibleDC(dc);
  623. surf->bitmap = CreateCompatibleBitmap(dc, surf->width, surf->height);
  624. ReleaseDC(NULL, dc);
  625. if(surf->srcDC != NULL && surf->bitmap != NULL){
  626. SelectObject(surf->srcDC, surf->bitmap);
  627. }
  628. surf->isAlphaPre = true;
  629. //surf->bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  630. // surf->bmpInfo.bmiHeader.biWidth = surf->width;
  631. // surf->bmpInfo.bmiHeader.biHeight = -surf->height;
  632. // surf->bmpInfo.bmiHeader.biPlanes = 1;
  633. // surf->bmpInfo.bmiHeader.biBitCount = 16;
  634. //surf->bmp_byte_stride = surf->width << 1;
  635. // surf->bmpInfo.bmiHeader.biCompression = BI_BITFIELDS;
  636. // DWORD *colors = (DWORD *)surf->bmpInfo.bmiColors;
  637. //colors[0] = redMask;
  638. //colors[1] = greenMask;
  639. // colors[2] = blueMask;
  640. // surf->bitmap = CreateDIBSection(NULL, (BITMAPINFO *)&surf->bmpInfo, DIB_RGB_COLORS, &surf->bmpData, NULL, 0);
  641. // surf->invalidated = true;
  642. // surf->isAlphaPre = true;
  643. #endif
  644. }
  645. return (jlong)surf;
  646. }
  647. //JNIEXPORT jlong JNICALL Java_org_apache_harmony_awt_gl_ImageSurface_createStructDCM
  648. // (JNIEnv * env, jobject obj, jint surfDataType, jint dataType, jint csType,
  649. // jint redMask, jint greenMask, jint blueMask, jint alphaMask, jint pixelStride,
  650. // jint scanlineStride, jint width, jint height, jint transparancy, jboolean isAlphaPre){
  651. //
  652. // SURFACE_STRUCTURE *surf = (SURFACE_STRUCTURE *)calloc(sizeof(SURFACE_STRUCTURE), 1);
  653. // if(surf != NULL){
  654. // surf->ss_type = surfDataType;
  655. // surf->cm_type = DIRECT_CM;
  656. // surf->cs_type = csType;
  657. // surf->data_type = dataType;
  658. // surf->red_mask = redMask;
  659. // surf->green_mask = greenMask;
  660. // surf->blue_mask = blueMask;
  661. // surf->alpha_mask = alphaMask;
  662. // surf->scanline_stride = scanlineStride;
  663. // switch(surf->ss_type){
  664. // case INT_RGB:
  665. // case INT_ARGB:
  666. // case INT_ARGB_PRE:
  667. // case INT_BGR:
  668. // surf->scanline_stride_byte = scanlineStride << 2;
  669. // break;
  670. // case USHORT_555:
  671. // case USHORT_565:
  672. // surf->scanline_stride_byte = scanlineStride << 1;
  673. // break;
  674. // //default:
  675. // // TODO
  676. // }
  677. // surf->pixel_stride = pixelStride;
  678. // surf->width = width;
  679. // surf->height = height;
  680. // surf->transparency = transparancy;
  681. // surf->alpha_pre = isAlphaPre;
  682. // surf->num_components = (alphaMask == 0 ? 3 : 4);
  683. //
  684. // surf->bits = (int *)malloc(surf->num_components * sizeof(int));
  685. // surf->bits[0] = parseMask(redMask, &surf->red_sht, &surf->max_red);
  686. // surf->bits[1] = parseMask(greenMask, &surf->green_sht, &surf->max_green);
  687. // surf->bits[2] = parseMask(blueMask, &surf->blue_sht, &surf->max_blue);
  688. // if(alphaMask != 0){
  689. // surf->bits[3] = parseMask(alphaMask, &(surf->alpha_sht), &(surf->max_alpha));
  690. // surf->has_alpha = 1;
  691. // }
  692. //
  693. //#ifdef _WIN32
  694. // GLBITMAPINFO glbmpInfo;
  695. // memset(&glbmpInfo, 0, sizeof(GLBITMAPINFO));
  696. // UINT stride;
  697. // glbmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  698. // glbmpInfo.bmiHeader.biWidth = surf->width;
  699. // glbmpInfo.bmiHeader.biHeight = -surf->height;
  700. // glbmpInfo.bmiHeader.biPlanes = 1;
  701. // glbmpInfo.bmiHeader.biBitCount = 32;
  702. // stride = surf->width << 2;
  703. // glbmpInfo.bmiHeader.biSizeImage = stride * surf->height;
  704. // glbmpInfo.bmiHeader.biCompression = BI_BITFIELDS;
  705. // DWORD *colors = (DWORD *)glbmpInfo.bmiColors;
  706. // colors[0] = 0xff0000;
  707. // colors[1] = 0xff00;
  708. // colors[2] = 0xff;
  709. // surf->srcDC = CreateCompatibleDC(NULL);
  710. // surf->bitmap = CreateDIBSection(NULL, (BITMAPINFO *)&glbmpInfo, DIB_RGB_COLORS, &surf->bmpData, NULL, 0);
  711. // if(surf->srcDC != NULL && surf->bitmap != NULL){
  712. // SelectObject(surf->srcDC, surf->bitmap);
  713. // }
  714. // surf->invalidated = true;
  715. // surf->isAlphaPre = true;
  716. //#endif
  717. // }
  718. // return (jlong)surf;
  719. // }
  720. //
  721. //JNIEXPORT jlong JNICALL Java_org_apache_harmony_awt_gl_ImageSurface_createStructICM
  722. // (JNIEnv *env, jobject obj, jint surfDataType, jint dataType, jint pixelStride,
  723. // jint scanlineStride, jint width, jint height, jint mapSize, jintArray colorMap,
  724. // jboolean isGrayPallete, jint transparency, jint trans, jint smType){
  725. //
  726. // SURFACE_STRUCTURE *surf = (SURFACE_STRUCTURE *)calloc(sizeof(SURFACE_STRUCTURE), 1);
  727. // if(surf != NULL){
  728. // surf->ss_type = surfDataType;
  729. // surf->cm_type = INDEX_CM;
  730. // surf->cs_type = sRGB_CS;
  731. // surf->pixel_stride = pixelStride;
  732. // surf->scanline_stride = scanlineStride;
  733. // surf->scanline_stride_byte = scanlineStride;
  734. // surf->width = width;
  735. // surf->height = height;
  736. // surf->colormap_size = mapSize;
  737. // surf->transparency = transparency;
  738. // surf->transparent_pixel = trans;
  739. // surf->sm_type = smType;
  740. // surf->has_alpha = (transparency == GL_OPAQUE ? 0 : 1);
  741. // surf->isGrayPallete = isGrayPallete;
  742. // surf->colormap = (int *)malloc(mapSize * sizeof(int));
  743. // void *p = env->GetPrimitiveArrayCritical(colorMap, 0);
  744. // memcpy((void *)surf->colormap, p, mapSize << 2);
  745. // env->ReleasePrimitiveArrayCritical(colorMap, p, 0);
  746. //#ifdef _WIN32
  747. // GLBITMAPINFO glbmpInfo;
  748. // memset(&glbmpInfo, 0, sizeof(GLBITMAPINFO));
  749. // UINT stride;
  750. // glbmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  751. // glbmpInfo.bmiHeader.biWidth = surf->width;
  752. // glbmpInfo.bmiHeader.biHeight = -surf->height;
  753. // glbmpInfo.bmiHeader.biPlanes = 1;
  754. // glbmpInfo.bmiHeader.biBitCount = 32;
  755. // stride = surf->width << 2;
  756. // glbmpInfo.bmiHeader.biSizeImage = stride * surf->height;
  757. // glbmpInfo.bmiHeader.biCompression = BI_BITFIELDS;
  758. // DWORD *colors = (DWORD *)glbmpInfo.bmiColors;
  759. // colors[0] = 0xff0000;
  760. // colors[1] = 0xff00;
  761. // colors[2] = 0xff;
  762. //
  763. // surf->srcDC = CreateCompatibleDC(NULL);
  764. // surf->bitmap = CreateDIBSection(NULL, (BITMAPINFO *)&glbmpInfo, DIB_RGB_COLORS, &surf->bmpData, NULL, 0);
  765. // if(surf->srcDC != NULL && surf->bitmap != NULL){
  766. // SelectObject(surf->srcDC, surf->bitmap);
  767. // }
  768. // surf->invalidated = true;
  769. // surf->isAlphaPre = true;
  770. //#endif
  771. // }
  772. //
  773. // return (jlong)surf;
  774. // }
  775. //
  776. //JNIEXPORT jlong JNICALL Java_org_apache_harmony_awt_gl_ImageSurface_createStructCCM
  777. // (JNIEnv *env, jobject obj, jint surfDataType, jint dataType, jint csType,
  778. // jint numComponents, jint pixelStride, jint scanlineStride, jint width, jint height, jintArray bits,
  779. // jintArray bankIndeces, jintArray bandOffsets, jint transparency, jboolean isAlphaPre){
  780. //
  781. // SURFACE_STRUCTURE *surf = (SURFACE_STRUCTURE *)calloc(sizeof(SURFACE_STRUCTURE), 1);
  782. // if(surf != NULL){
  783. // surf->ss_type = surfDataType;
  784. // surf->cm_type = COMPONENT_CM;
  785. // surf->cs_type = csType;
  786. // surf->num_components = numComponents;
  787. // surf->pixel_stride = pixelStride;
  788. // surf->scanline_stride = scanlineStride;
  789. // switch(surf->ss_type){
  790. // case BYTE_BGR:
  791. // case BYTE_ABGR:
  792. // case BYTE_ABGR_PRE:
  793. // case BYTE_GRAY:
  794. // surf->scanline_stride_byte = scanlineStride;
  795. // break;
  796. // case USHORT_GRAY:
  797. // surf->scanline_stride_byte = scanlineStride << 1;
  798. // break;
  799. // //default:
  800. // // TODO
  801. // }
  802. // surf->width = width;
  803. // surf->height = height;
  804. // surf->transparency = transparency;
  805. // surf->has_alpha = (transparency == GL_OPAQUE ? 0 : 1);
  806. // surf->alpha_pre = isAlphaPre;
  807. //
  808. // surf->bits = (int *)malloc(numComponents * sizeof(int));
  809. // surf->bank_indexes = (int *)malloc(numComponents * sizeof(int));
  810. // surf->band_offsets = (int *)malloc(numComponents * sizeof(int));
  811. //
  812. // void *p = env->GetPrimitiveArrayCritical(bits, 0);
  813. // memcpy((void *)surf->bits, p, numComponents << 2);
  814. // env->ReleasePrimitiveArrayCritical(bits, p, 0);
  815. //
  816. // p = env->GetPrimitiveArrayCritical(bankIndeces, 0);
  817. // memcpy((void *)surf->bank_indexes, p, numComponents << 2);
  818. // env->ReleasePrimitiveArrayCritical(bankIndeces, p, 0);
  819. //
  820. // p = env->GetPrimitiveArrayCritical(bandOffsets, 0);
  821. // memcpy((void *)surf->band_offsets, p, numComponents << 2);
  822. // env->ReleasePrimitiveArrayCritical(bandOffsets, p, 0);
  823. // }
  824. //#ifdef _WIN32
  825. // GLBITMAPINFO glbmpInfo;
  826. // memset(&glbmpInfo, 0, sizeof(GLBITMAPINFO));
  827. // UINT stride;
  828. // glbmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  829. // glbmpInfo.bmiHeader.biWidth = surf->width;
  830. // glbmpInfo.bmiHeader.biHeight = -surf->height;
  831. // glbmpInfo.bmiHeader.biPlanes = 1;
  832. // glbmpInfo.bmiHeader.biBitCount = 32;
  833. // stride = surf->width << 2;
  834. // glbmpInfo.bmiHeader.biSizeImage = stride * surf->height;
  835. // glbmpInfo.bmiHeader.biCompression = BI_BITFIELDS;
  836. // DWORD *colors = (DWORD *)glbmpInfo.bmiColors;
  837. // colors[0] = 0xff0000;
  838. // colors[1] = 0xff00;
  839. // colors[2] = 0xff;
  840. // surf->srcDC = CreateCompatibleDC(NULL);
  841. // surf->bitmap = CreateDIBSection(NULL, (BITMAPINFO *)&glbmpInfo, DIB_RGB_COLORS, &surf->bmpData, NULL, 0);
  842. // if(surf->srcDC != NULL && surf->bitmap != NULL){
  843. // SelectObject(surf->srcDC, surf->bitmap);
  844. // }
  845. // surf->invalidated = true;
  846. // surf->isAlphaPre = true;
  847. //#endif
  848. //
  849. // return (jlong)surf;
  850. // }
  851. JNIEXPORT jlong JNICALL Java_org_apache_harmony_awt_gl_ImageSurface_updateCache
  852. (JNIEnv *env, jobject obj, jlong ptr, jobject data, jboolean alphaPre){
  853. SURFACE_STRUCTURE *surf = (SURFACE_STRUCTURE *)ptr;
  854. jlong cachePtr = 0;
  855. if(surf != NULL){
  856. updateCache(surf, env, data, alphaPre != 0);
  857. cachePtr = (jlong)surf->bmpData;
  858. }
  859. return cachePtr;
  860. }
  861. JNIEXPORT void JNICALL Java_org_apache_harmony_awt_gl_ImageSurface_dispose
  862. (JNIEnv *env, jobject obj, jlong ptr){
  863. SURFACE_STRUCTURE *surf = (SURFACE_STRUCTURE *)ptr;
  864. if(surf != NULL){
  865. if(surf->bits) free(surf->bits);
  866. if(surf->colormap) free(surf->colormap);
  867. if(surf->bank_indexes) free(surf->bank_indexes);
  868. if(surf->band_offsets) free(surf->band_offsets);
  869. if(surf->bmpData) free(surf->bmpData);
  870. #ifdef _WIN32
  871. if(surf->bitmap) DeleteObject(surf->bitmap);
  872. if(surf->srcDC) DeleteDC(surf->srcDC);
  873. #endif
  874. free(surf);
  875. }
  876. }
  877. JNIEXPORT void JNICALL Java_org_apache_harmony_awt_gl_ImageSurface_setImageSize
  878. (JNIEnv *env, jobject obj, jlong ptr, jint width, jint height) {
  879. SURFACE_STRUCTURE *surf = (SURFACE_STRUCTURE *)ptr;
  880. surf->scanline_stride = surf->scanline_stride / surf->width * width;
  881. surf->scanline_stride_byte = surf->scanline_stride_byte / surf->width * width;
  882. surf->width = width;
  883. surf->height = height;
  884. }