gdi_image_hwjpg.c
49.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
/*******************************************************************************
* Copyright Statement:
* --------------------
* This software is protected by Copyright and the information contained
* herein is confidential. The software may not be copied and the information
* contained herein may not be used or disclosed except with the written
* permission of MediaTek Inc. (C) 2001
*
*******************************************************************************/
/*******************************************************************************
* Filename:
* ---------
* gdi_image_hwjpeg.c
*
* Project:
* --------
* MAUI
*
* Description:
* ------------
* GDI Image hardware jpeg decoder.
*
* Author:
* -------
* -------
*
*==============================================================================
* HISTORY
* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*------------------------------------------------------------------------------
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*------------------------------------------------------------------------------
* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*==============================================================================
*******************************************************************************/
#include "gdi_internal.h"
#ifdef GDI_USING_JPEG
#include "visual_comm.h"
#if defined(DRV_IDP_OLD_DESIGN)
#include "img_comm.h"
#endif
#include "drm_gprot.h"
#include "med_global.h"
#include "med_utility.h"
#include "med_api.h"
#ifdef __MMI_A2DP_SUPPORT__
#include "mdi_datatype.h"
#include "mdi_audio.h"
#endif
extern kal_bool idp_register_app(MMDI_SCENERIO_ID new_app, MMDI_SCENERIO_ID *old_app);
#include "gdd_include.h"
#include "gd_include.h"
#if defined(GDI_USING_DITHERING) && defined(__MTK_TARGET__) && defined(GDI_HW_JPEG_SUPPORT_COLOR_FORMAT) && !defined(__SW_JPEG_CODEC_SUPPORT__)
#define GDI_HWJPEGV1_USING_SPATIAL_DITHERING
// #include "image_codec_common.h"
extern void iul_sd_bgr888_to_rgb565(kal_uint8 *pSrc, kal_uint16 *pDest,
kal_uint32 uWidth, kal_uint32 uHeight, kal_uint32 uPitch);
struct
{
gdi_handle handle;
U8* buffer;
S32 save_ox;
S32 save_oy;
S32 save_clipx1;
S32 save_clipy1;
S32 save_clipx2;
S32 save_clipy2;
S32 is_push_and_set_active;
} gdi_jpeg_dithering;
#endif
#define GDI_HW_JPEG_CODEC_WAITING_TIME 6000 /* ms */
#define GDI_HW_JPEG_CODEC_NB_WAITING_TIME 8000 /* ms */
#define GDI_IMAGE_JPEG_FILE_BUFFER_LEN_WHEN_A2DP_ENABLE 10*1024 /* 10kb */
#define ROUND16(x) (((x) + 15)&(~0xf))
static jpeg_decode_process_struct jpeg;
static MMI_BOOL gdi_jpeg_intmem_from_ext = MMI_FALSE;
typedef struct
{
U8 cause;
U8 pre_cause;
} gdi_image_hwjpeg_state_struct;
static gdi_image_hwjpeg_state_struct jpeg_result;
/* IMGDEC */
static U32 g_gdi_image_hwjpeg_flag;
static BOOL *g_gdi_imgdec_hwjpeg_is_aborted;
extern void gdi_image_hwjpeg_start_decode(void);
static kal_int32 gdi_imgdec_hwjpeg_progress_callback(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (g_gdi_imgdec_hwjpeg_is_aborted && *g_gdi_imgdec_hwjpeg_is_aborted)
{
return 0;
}
return 1;
}
/*****************************************************************************
* FUNCTION
* gdi_image_hwjpeg_callback
* DESCRIPTION
* handle the jpeg callback
*****************************************************************************/
void gdi_image_hwjpeg_callback(U8 cause)
{
gdi_image_hwjpeg_state_struct data;
data.cause = cause;
gdd_send_img_codec_ind(&data,sizeof(data));
}
/*****************************************************************************
* FUNCTION
* gdi_image_hwjpeg_set_background_mode
* DESCRIPTION
* set background mode.
* Jpeg won't use TCM if in background mode.
*****************************************************************************/
static GDI_RESULT gdi_image_hwjpeg_set_background_mode(void)
{
kal_bool bg_mode = KAL_FALSE;
gdi_image_jpeg_get_background_mode(&bg_mode);
if (bg_mode)
{
jpeg.background_mode = 1;
}
else
{
jpeg.background_mode = 0;
}
return GDI_SUCCEED;
}
/*****************************************************************************
* FUNCTION
* gdi_image_hwjpeg_set_memory
* DESCRIPTION
* try to allocate memory for jpeg decoding from media task.
*****************************************************************************/
static GDI_RESULT gdi_image_hwjpeg_set_memory(void)
{
#if defined(__SW_JPEG_CODEC_USING_CACHEABLE_MEMORY__) /* allocation */
jpeg.intmem_start_address = (U32) gdi_alloc_ext_mem_cacheable(MAX_IMG_DEC_INT_MEM_SIZE);
#elif (defined(__MTK_TARGET__) && defined(DRV_FEATURE__MM_INTMEM_IF))
/* if define DRV_FEATURE__MM_INTMEM_IF, alloc ext mem instead of int mem */
jpeg.intmem_start_address = (U32) gdi_alloc_ext_mem(MAX_IMG_DEC_INT_MEM_SIZE);
if (jpeg.intmem_start_address)
{
gdi_jpeg_intmem_from_ext = MMI_TRUE;
}
#else
jpeg.intmem_start_address = (U32) med_alloc_int_mem(MAX_IMG_DEC_INT_MEM_SIZE);
gdi_jpeg_intmem_from_ext = MMI_FALSE;
if (jpeg.intmem_start_address == 0)
{
jpeg.intmem_start_address = (U32) gdi_alloc_ext_mem(MAX_IMG_DEC_INT_MEM_SIZE);
if (jpeg.intmem_start_address)
{
gdi_jpeg_intmem_from_ext = MMI_TRUE;
}
}
#endif
if(jpeg.intmem_start_address==0)
{
return GDI_IMAGE_ERR_FRAME_BUFFER_NOT_ENOUGH;
}
jpeg.intmem_size = MAX_IMG_DEC_INT_MEM_SIZE;
/* try to allocate large memory to decode jpeg for performance */
{
U32 flag = 0;
int mem_size = MAX_PROG_JPG_DEC_EXT_MEM_SIZE;
int min_size = MAX_IMG_DEC_EXT_MEM_SIZE;
flag = g_gdi_image_hwjpeg_flag;
if (flag & GDI_IMAGE_CODEC_FLAG_USE_LESS_BUF)
{
mem_size = GDI_IMAGE_JPEG_USE_LESS_BUF_SIZE;
}
while(1)
{
#if defined(__SW_JPEG_CODEC_USING_CACHEABLE_MEMORY__) /* allocation */
jpeg.extmem_start_address = (U32)gdi_alloc_ext_mem_cacheable(mem_size);
#else
jpeg.extmem_start_address = (U32)gdi_alloc_ext_mem(mem_size);
#endif
if(jpeg.extmem_start_address >0) break;
if(mem_size == min_size) break;
mem_size/=2;
if( mem_size < min_size)
mem_size = min_size;
}
if(jpeg.extmem_start_address==0)
return GDI_IMAGE_ERR_FRAME_BUFFER_NOT_ENOUGH;
jpeg.extmem_size = mem_size;
GDI_TRACE(GDI_TRC, GDI_TRC_15,//"GDI_HW_JPG set_ext_memory size=%d",
mem_size);
}
return GDI_SUCCEED;
}
/*****************************************************************************
* FUNCTION
* gdi_image_hwjpeg_set_thumbnail_value
* DESCRIPTION
* setting use thumbnail or not, driver will use thumbnail if resize size is match
*****************************************************************************/
static GDI_RESULT gdi_image_hwjpeg_set_thumbnail_value(BOOL is_resized)
{
/* jpeg_thumbnail_mode only work on hw jpeg. */
if (is_resized)
{
jpeg.jpeg_thumbnail_mode = TRUE;
}
else
{
jpeg.jpeg_thumbnail_mode = FALSE;
}
/* jpeg_decode_mode only work on sw jpeg. */
jpeg.jpeg_decode_mode = JPEG_DECODER_DECODE_MODE_AUTO;
return GDI_SUCCEED;
}
/*****************************************************************************
* FUNCTION
* gdi_image_hwjpeg_set_source_image
* DESCRIPTION
* setting image source
*****************************************************************************/
static GDI_RESULT gdi_image_hwjpeg_set_source_image(U8* src,U32 size,BOOL is_file)
{
if (is_file)
{
FS_HANDLE fs = DRM_open_file((U16*) src, FS_READ_ONLY, DRM_PERMISSION_DISPLAY);
if (fs < 0)
return GDI_IMAGE_ERR_OPEN_FILE_FAILED;
jpeg.jpeg_file_handle = (U32) fs;
DRM_file_size(fs, &jpeg.jpeg_file_size);
jpeg.jpeg_file_buffer_address = 0;
// Here will check A2DP is active or not
// Because A2DP need more CPU to process audio,
// JPEG should access file using small file buffer to avoid block A2DP
#ifdef __MMI_A2DP_SUPPORT__
if(mdi_audio_bt_is_a2dp_codec_open())
{
jpeg.jpeg_file_buffer_size = GDI_IMAGE_JPEG_FILE_BUFFER_LEN_WHEN_A2DP_ENABLE;
}
else
#endif
{
U32 flag;
flag = g_gdi_image_hwjpeg_flag;
if (flag & GDI_IMAGE_CODEC_FLAG_USE_LESS_BUF)
{
jpeg.jpeg_file_buffer_size = GDI_IMAGE_JPEG_USE_LESS_BUF_SIZE;
}
else
{
jpeg.jpeg_file_buffer_size = MAX_IMG_DEC_FILE_BUFFER_LEN;
}
}
while(1)
{
#if defined(__SW_JPEG_CODEC_USING_CACHEABLE_MEMORY__) /* allocation */
jpeg.jpeg_file_buffer_address = (kal_uint32) gdi_alloc_ext_mem_cacheable(jpeg.jpeg_file_buffer_size);
#else
jpeg.jpeg_file_buffer_address = (kal_uint32) gdi_alloc_ext_mem(jpeg.jpeg_file_buffer_size);
#endif
if(jpeg.jpeg_file_buffer_address >0) break;
if(jpeg.jpeg_file_buffer_size <= BYTESTREAM_BUFFER_SIZE) break;
jpeg.jpeg_file_buffer_size /= 2;
if( jpeg.jpeg_file_buffer_size < BYTESTREAM_BUFFER_SIZE)
{
jpeg.jpeg_file_buffer_size = BYTESTREAM_BUFFER_SIZE;
}
}
if(jpeg.jpeg_file_buffer_address==0)
{
jpeg.jpeg_file_buffer_address = (kal_uint32)gdi_bytestream_buffer;
jpeg.jpeg_file_buffer_size = BYTESTREAM_BUFFER_SIZE;
//return GDI_IMAGE_ERR_FRAME_BUFFER_NOT_ENOUGH;
}
GDI_TRACE(GDI_TRC, GDI_TRC_16,//"GDI_HW_JPG set_source_image file mem_size=%d",
jpeg.jpeg_file_buffer_size);
}
else
{
jpeg.jpeg_file_buffer_address = (U32) src;
jpeg.jpeg_file_buffer_size = (U32) size;
jpeg.jpeg_file_size = (U32)size;
}
return GDI_SUCCEED;
}
/*****************************************************************************
* FUNCTION
* gdi_image_hwjpeg_enlarge_file_buffer
* DESCRIPTION
* setting image source
*****************************************************************************/
static GDI_RESULT gdi_image_hwjpeg_enlarge_file_buffer(void)
{
GDI_TRACE(GDI_TRC, GDI_TRC_17//"try gdi_image_hwjpeg_enlarge_file_buffer "
);
if(jpeg.jpeg_file_handle)
{
// Here will check A2DP is active or not
// Because A2DP need more CPU to process audio,
// JPEG should access file using small file buffer to avoid block A2DP
#ifdef __MMI_A2DP_SUPPORT__
if(mdi_audio_bt_is_a2dp_codec_open())
return GDI_FAILED;
#endif
/* already reach x3 buffer size */
if(jpeg.jpeg_file_buffer_size >= MAX_IMG_DEC_FILE_BUFFER_LEN*3)
return GDI_FAILED;
if(jpeg.jpeg_file_buffer_address != (kal_uint32)gdi_bytestream_buffer)
gdi_free_ext_mem((void**)&jpeg.jpeg_file_buffer_address);
jpeg.jpeg_file_buffer_size += MAX_IMG_DEC_FILE_BUFFER_LEN;
#if defined(__SW_JPEG_CODEC_USING_CACHEABLE_MEMORY__) /* allocation */
jpeg.jpeg_file_buffer_address = (kal_uint32) gdi_alloc_ext_mem_cacheable(jpeg.jpeg_file_buffer_size);
#else
jpeg.jpeg_file_buffer_address = (kal_uint32) gdi_alloc_ext_mem(jpeg.jpeg_file_buffer_size);
#endif
GDI_TRACE(GDI_TRC, GDI_TRC_18,//"gdi_image_hwjpeg_enlarge_file_buffer size=%d",
jpeg.jpeg_file_buffer_size);
if(jpeg.jpeg_file_buffer_address!=0)
return GDI_SUCCEED;
}
return GDI_FAILED;
}
/*****************************************************************************
* FUNCTION
* gdi_image_hwjpeg_set_real_size
* DESCRIPTION
* parse the jpeg size & real resized size
*****************************************************************************/
static GDI_RESULT gdi_image_hwjpeg_set_real_size(S32 *resized_width,S32* resized_height,S32 *decoded_image_width)
{
U16 resized_width16,resized_height16;
U16 real_resize_width,real_resize_height;
resized_width16 = (U16)*resized_width;
resized_height16 = (U16)*resized_height;
get_jpeg_resize_size(
jpeg.jpeg_file_handle,
jpeg.jpeg_file_buffer_address,
jpeg.jpeg_file_buffer_size,
&(resized_width16),
&(resized_height16),
&(real_resize_width),
&(real_resize_height));
*decoded_image_width = (S32)real_resize_width;
if (*resized_width == 0 && *resized_height == 0)
{
*resized_width = (S32)resized_width16;
*resized_height = (S32)resized_height16;
}
if(resized_width16 == (U16)0xFFFF && resized_height16 == (U16)0xFFFF)
return GDI_IMAGE_ERR_FILE_FORMAT_WRONG;
return GDI_SUCCEED;
}
/*****************************************************************************
* FUNCTION
* gdi_image_hwjpeg_set_clipping
* DESCRIPTION
*
*****************************************************************************/
static GDI_RESULT gdi_image_hwjpeg_set_clipping(
gdi_handle output_layer_handle,
S32 *ox,S32 *oy,
U8 *dest_buf,
S32 resized_width,
S32 resized_height,
S32 *output_clipx1,
S32 *output_clipy1,
S32 *output_clipx2,
S32 *output_clipy2)
{
/**************************************************************************
* revise output clipping & (ox,oy)
**************************************************************************/
gdi_layer_struct *out_layer;
out_layer = (gdi_layer_struct*)output_layer_handle;
/* initialize output_clipping if unset */
if (*output_clipx1 == -1 && *output_clipy1 == -1 && *output_clipx2 == -1 && *output_clipy2 == -1)
{
*output_clipx1 = 0;
*output_clipy1 = 0;
*output_clipx2 = resized_width - 1;
*output_clipy2 = resized_height - 1;
}
/*output clipping should consider the layer clipping area if output target is active layer*/
if (NULL == dest_buf)
{
int tx, ty;
tx = *output_clipx1;
ty = *output_clipy1;
*output_clipx1 += *ox;
*output_clipy1 += *oy;
*output_clipx2 += *ox;
*output_clipy2 += *oy;
GDI_IMGDEC_LAYER_CLIP_RECT_TEST(out_layer, *output_clipx1, *output_clipy1, *output_clipx2, *output_clipy2, return GDI_IMAGE_OUT_OF_CLIP_REGION);
*output_clipx1 -= *ox;
*output_clipy1 -= *oy;
*output_clipx2 -= *ox;
*output_clipy2 -= *oy;
}
/* adjust (ox,oy) to correct position, because output clipping window may change. */
*ox += *output_clipx1;
*oy += *output_clipy1;
/**************************************************************************
* setting output width/height/clipping
**************************************************************************/
jpeg.image_width = (U16)resized_width;
jpeg.image_height = (U16)resized_height;
jpeg.image_clip_x1 = *output_clipx1;
jpeg.image_clip_y1 = *output_clipy1;
jpeg.image_clip_x2 = *output_clipx2;
jpeg.image_clip_y2 = *output_clipy2;
return GDI_SUCCEED;
}
/*****************************************************************************
* FUNCTION
* gdi_image_hwjpeg_set_dest_buffer
* DESCRIPTION
*
*****************************************************************************/
static GDI_RESULT gdi_image_hwjpeg_set_dest_buffer(
gdi_handle output_layer_handle,
S32 ox,S32 oy,
U8* *dest_buf,
S32 *dest_buf_size,
gdi_color_format *dest_buf_cf,
S32 resized_width,S32 resized_height,
S32 output_clipx1,
S32 output_clipy1,
S32 output_clipx2,
S32 output_clipy2)
{
gdi_layer_struct *out_layer;
out_layer = (gdi_layer_struct*)output_layer_handle;
#if !defined(GDI_HW_JPEG_PADDING_PITCH)
/* we can direct output if hardware support pitch & source_key_disable & whole layer size is the same as resized jpeg */
if (NULL == *dest_buf)
{
if ((resized_width == out_layer->width)
&& (resized_height == out_layer->height))
{
if ((jpeg.image_clip_x1 == 0) &&
(jpeg.image_clip_y1 == 0) &&
(jpeg.image_clip_x2 == resized_width - 1) &&
(jpeg.image_clip_y2 == resized_height - 1))
{
*dest_buf = out_layer->buf_ptr;
*dest_buf_size = out_layer->layer_size;
*dest_buf_cf = out_layer->vcf;
}
}
}
#endif /* !defined(GDI_HW_JPEG_PADDING_PITCH) */
if (NULL == *dest_buf)
{
#ifdef GDI_HW_JPEG_SUPPORT_OUTPUT_ANOTHER_BUFFER
jpeg.memory_output = gdi_memory_output;
jpeg.memory_output_width = gdi_memory_output_width;
jpeg.memory_output_height = gdi_memory_output_height;
jpeg.memory_output_buffer_address = gdi_memory_output_buffer_address;
jpeg.memory_output_buffer_size = gdi_memory_output_buffer_size;
#endif /* GDI_HW_JPEG_SUPPORT_OUTPUT_ANOTHER_BUFFER */
#ifdef GDI_HW_JPEG_SUPPORT_DIRECT_OUTPUT_BUFFER
{
jpeg.image_pitch_mode = TRUE;
jpeg.image_pitch_bytes = (out_layer->bits_per_pixel * out_layer->width + 7) >> 3;
jpeg.image_buffer_address = (U32)(out_layer->buf_ptr +
((((out_layer->width * oy + ox) * out_layer->bits_per_pixel) + 7) >> 3));
jpeg.image_buffer_size = ((U32) out_layer->buf_ptr + out_layer->layer_size) - (U32) jpeg.image_buffer_address;
if (g_gdi_image_hwjpeg_flag & GDI_IMAGE_CODEC_FLAG_IS_IMGDEC)
{
/* cannot use draw solid rect because of GDI_LOCK */
// TODO: SHOULD USE A NEW GD API
do
{
S32 y, x1, y1, x2, y2;
U8 *buf_p;
S32 bpp, pitch, line_size;
x1 = ox;
y1 = oy;
x2 = ox + output_clipx2 - output_clipx1;
y2 = oy + output_clipy2 - output_clipy1;
GDI_IMGDEC_LAYER_CLIP_RECT_TEST(out_layer, x1, y1, x2, y2, break);
bpp = gdi_bits_per_pixel(out_layer->vcf) / 8;
pitch = out_layer->width * bpp;
buf_p = out_layer->buf_ptr + y1 * pitch + x1 * bpp;
line_size = (x2 - x1 + 1) * bpp;
for (y = y2 - y1; y >= 0; y--)
{
memset(buf_p, 0xFF, line_size);
buf_p += pitch;
}
} while (0);
}
else
{
gdi_draw_solid_rect(ox,oy, ox+output_clipx2 - output_clipx1,oy+ output_clipy2 - output_clipy1,0xffffffff);
}
}
#else /* GDI_HW_JPEG_SUPPORT_DIRECT_OUTPUT_BUFFER */
{
if (gdi_sizeof_pixels(
out_layer->cf,
output_clipx2 - output_clipx1 + 1,
output_clipy2 - output_clipy1 + 1) > gdi_work_buffer_size)
return GDI_IMAGE_ERR_FRAME_BUFFER_NOT_ENOUGH;
#ifndef GDI_HW_JPEG_SUPPORT_OUTPUT_CLIPPING
if (gdi_sizeof_pixels(out_layer->cf, resized_width, resized_height) > gdi_work_buffer_size)
return GDI_IMAGE_ERR_FRAME_BUFFER_NOT_ENOUGH;
#endif /* GDI_HW_JPEG_SUPPORT_OUTPUT_CLIPPING */
if (((ROUND16(output_clipx2 - output_clipx1 + 1)
* ROUND16(output_clipy2 - output_clipy1 + 1) * GDI_MAINLCD_BIT_PER_PIXEL) >> 3) > gdi_work_buffer_size)
return GDI_IMAGE_ERR_FRAME_BUFFER_NOT_ENOUGH;
/*TODO: Fix Broken JPEG Issue, but it should downgrade performance */
gdi_memset16((U8*)gdi_work_buffer, (U16)gdi_act_get_pixel(ox,oy), gdi_work_buffer_size);
jpeg.image_buffer_address= (U32)gdi_work_buffer;
jpeg.image_buffer_size = (U32) gdi_work_buffer_size;
}
#endif /* GDI_HW_JPEG_SUPPORT_DIRECT_OUTPUT_BUFFER */
}
else
{
/* Check buffer size is enough to decode image or not */
GDI_ASSERT(*dest_buf_size >= gdi_sizeof_pixels(*dest_buf_cf, resized_width, resized_height));
/*TODO: Fix Broken JPEG Issue, but it should downgrade performance */
memset(*dest_buf, 0xff, *dest_buf_size);
jpeg.image_buffer_address = (U32)*dest_buf;
jpeg.image_buffer_size = (U32) *dest_buf_size;
}
return GDI_SUCCEED;
}
/*****************************************************************************
* FUNCTION
* gdi_image_hwjpeg_set_color_format
* DESCRIPTION
* setting color format
*****************************************************************************/
static GDI_RESULT gdi_image_hwjpeg_set_color_format(gdi_handle output_layer_handle, U8* dest_buf,gdi_color_format dest_buf_cf)
{
gdi_layer_struct *out_layer;
out_layer = (gdi_layer_struct*)output_layer_handle;
if (NULL == dest_buf)
{
dest_buf_cf = out_layer->vcf;
}
#if defined( __SW_JPEG_CODEC_SUPPORT__)
switch (dest_buf_cf)
{
case GDI_COLOR_FORMAT_16:
jpeg.image_data_format = IMGDMA_IBW_OUTPUT_RGB565;
break;
case GDI_COLOR_FORMAT_24:
jpeg.image_data_format = IMGDMA_IBW_OUTPUT_RGB888;
break;
case GDI_COLOR_FORMAT_32:
case GDI_COLOR_FORMAT_32_PARGB:
jpeg.image_data_format = IMGDMA_IBW_OUTPUT_ARGB8888;
break;
default:
GDI_ASSERT(0); /* strange color format */
}
#elif defined(GDI_HW_JPEG_SUPPORT_COLOR_FORMAT)
switch (dest_buf_cf)
{
case GDI_COLOR_FORMAT_16:
jpeg.image_data_format = IMGDMA_IBW_OUTPUT_RGB565;
break;
case GDI_COLOR_FORMAT_24:
jpeg.image_data_format = IMGDMA_IBW_OUTPUT_RGB888;
break;
default:
GDI_ASSERT(0); /* strange color format */
}
#endif /* GDI_HW_JPEG_SUPPORT_COLOR_FORMAT */
return GDI_SUCCEED;
}
/*****************************************************************************
* FUNCTION
* gdi_image_hwjpeg_set_callback
* DESCRIPTION
* setting driver jpeg callback
*****************************************************************************/
static GDI_RESULT gdi_image_hwjpeg_set_callback(void)
{
jpeg.jpeg_decode_cb = gdi_image_hwjpeg_callback;
return GDI_SUCCEED;
}
/*****************************************************************************
* FUNCTION
* gdi_image_hwjpeg_init
* DESCRIPTION
* setting driver jpeg parameter
*****************************************************************************/
static GDI_RESULT gdi_image_hwjpeg_init(
gdi_handle output_layer_handle,
S32 *ox,
S32 *oy,
S32 *resized_width,
S32 *resized_height,
S32 *output_clipx1,
S32 *output_clipy1,
S32 *output_clipx2,
S32 *output_clipy2,
U8 *src,
U32 size,
BOOL is_file,
BOOL is_resized,
U8 **dest_buf,
S32 *dest_buf_size,
S32 *decoded_image_width,
gdi_color_format *dest_buf_cf)
{
GDI_RESULT ret;
gdi_layer_struct *out_layer;
out_layer = (gdi_layer_struct*)output_layer_handle;
memset(&jpeg,0,sizeof(jpeg)); /* initialize jpeg decoder struct */
if (g_gdi_image_hwjpeg_flag & GDI_IMAGE_CODEC_FLAG_IS_IMGDEC)
{
jpeg.jpg_timeout_period = GDI_HW_JPEG_CODEC_NB_WAITING_TIME/10;
}
else
{
jpeg.jpg_timeout_period = GDI_HW_JPEG_CODEC_WAITING_TIME/10;
}
jpeg.jpeg_decode_retry_flag = JPEG_DECODER_RETRY_DISABLE;
GDI_TRACE(GDI_TRC, GDI_TRC_19//"---- GDI_HW_JPG INIT BEGIN----"
);
do
{
if((ret = gdi_image_hwjpeg_set_thumbnail_value(is_resized))!=GDI_SUCCEED) break;
if((ret = gdi_image_hwjpeg_set_memory())!=GDI_SUCCEED) break;
if((ret = gdi_image_hwjpeg_set_source_image(src,size,is_file))!=GDI_SUCCEED) break;
if((ret = gdi_image_hwjpeg_set_real_size(resized_width,resized_height,decoded_image_width))!=GDI_SUCCEED) break;
if((ret = gdi_image_hwjpeg_set_clipping(
output_layer_handle,
ox,oy,
*dest_buf,
*resized_width,*resized_height,
output_clipx1,
output_clipy1,
output_clipx2,
output_clipy2
))!=GDI_SUCCEED) break;
if (!(g_gdi_image_hwjpeg_flag & GDI_IMAGE_CODEC_FLAG_IS_IMGDEC))
{
/* WILL get GDI lock */
if ((ret = gdi_image_hwjpeg_set_background_mode())!=GDI_SUCCEED)
{
break;
}
}
#ifdef GDI_HWJPEGV1_USING_SPATIAL_DITHERING
gdi_jpeg_dithering.handle = GDI_NULL_HANDLE;
gdi_jpeg_dithering.is_push_and_set_active = 0;
if(out_layer->bits_per_pixel == 16 // only process 16 bits desintation
&& ((*output_clipx2 - *output_clipx1 + 1)*3 &1)==0 // only process even width because HW didn't support odd pitch_width
&& *dest_buf == NULL // only process direct output to layer
&& is_file // only process file source
&& !(g_gdi_image_hwjpeg_flag & GDI_IMAGE_CODEC_FLAG_IS_IMGDEC)) // no dithering for IMGDEC because of GDI lock...
{
U32 size;
size = gdi_sizeof_pixels(GDI_COLOR_FORMAT_24,
*output_clipx2 - *output_clipx1 + 1,
*output_clipy2 - *output_clipy1 + 1);
size = ROUND16(size);
GDI_TRACE(GDI_TRC, GDI_TRC_48,//"jpeg spatial dithering buffer size = %d",
size);
gdi_jpeg_dithering.buffer = gdi_alloc_ext_mem_framebuffer(size);
if(gdi_jpeg_dithering.buffer)
{
GDI_TRACE(GDI_TRC, GDI_TRC_49//"jpeg spatial dithering enable"
);
gdi_layer_create_cf_using_outside_memory(
GDI_COLOR_FORMAT_24,
0,0,
*output_clipx2 - *output_clipx1 + 1,
*output_clipy2 - *output_clipy1 + 1,
&gdi_jpeg_dithering.handle,
gdi_jpeg_dithering.buffer,
size);
gdi_layer_push_and_set_active(gdi_jpeg_dithering.handle);
gdi_jpeg_dithering.is_push_and_set_active++;
/* change active layer */
output_layer_handle = gdi_jpeg_dithering.handle;
out_layer = (gdi_layer_struct*)output_layer_handle;
gdi_jpeg_dithering.save_ox = *ox; *ox = 0;
gdi_jpeg_dithering.save_oy = *oy; *oy = 0;
gdi_jpeg_dithering.save_clipx1 = *output_clipx1;
gdi_jpeg_dithering.save_clipy1 = *output_clipy1;
gdi_jpeg_dithering.save_clipx2 = *output_clipx2;
gdi_jpeg_dithering.save_clipy2 = *output_clipy2;
*output_clipx1 = 0;
*output_clipy1 = 0;
*output_clipx2 = out_layer->width-1;
*output_clipy2 = out_layer->height-1;
}
}
if(gdi_jpeg_dithering.handle == GDI_NULL_HANDLE)
{
GDI_TRACE(GDI_TRC, GDI_TRC_50//"jpeg spatial dithering disable"
);
}
#endif
#ifdef __SW_JPEG_CODEC_SUPPORT__
{
if (g_gdi_image_hwjpeg_flag & GDI_IMAGE_CODEC_FLAG_IS_IMGDEC)
{
sw_jpeg_hook_decode_progress_callback(gdi_imgdec_hwjpeg_progress_callback);
}
else
{
sw_jpeg_hook_decode_progress_callback(gdi_image_progress_callback);
}
}
#endif
// clear destination as WHITE COLOR for avoid broken JPEG. ( only apply at layer )
//if(*dest_buf==NULL)
// gdi_draw_solid_rect(*ox,*oy,*ox+*resized_width-1, *oy+*resized_height-1, 0xffffffff);
gdi_image_set_update_area(*ox,*oy,*ox+*resized_width-1, *oy+*resized_height-1);
if((ret = gdi_image_hwjpeg_set_dest_buffer(
output_layer_handle,
*ox,*oy,
dest_buf,
dest_buf_size,
dest_buf_cf,
*resized_width,*resized_height,
*output_clipx1,
*output_clipy1,
*output_clipx2,
*output_clipy2
))!=GDI_SUCCEED) break;
if((ret = gdi_image_hwjpeg_set_color_format(output_layer_handle, *dest_buf, *dest_buf_cf))!=GDI_SUCCEED) break;
if((ret = gdi_image_hwjpeg_set_callback())!=GDI_SUCCEED) break;
}while(0);
GDI_TRACE(GDI_TRC, GDI_TRC_20,//"---- GDI_HW_JPG INIT END ret=%d----",
ret);
return ret;
}
/*****************************************************************************
* FUNCTION
* gdi_image_hwjpeg_copy_buf_to_dest
* DESCRIPTION
* copy from intermeidate buffer to destination buffer
*****************************************************************************/
static GDI_RESULT gdi_image_hwjpeg_copy_buf_to_dest(
gdi_handle output_layer_handle,
S32 ox,
S32 oy,
S32 resized_width,
S32 resized_height,
S32 output_clipx1,
S32 output_clipy1,
S32 output_clipx2,
S32 output_clipy2,
S32 decoded_image_width)
{
S32 decoded_width, show_width, show_height;
gdi_rect_struct clip;
gdi_layer_struct *out_layer;
out_layer = (gdi_layer_struct*)output_layer_handle;
clip.x1 = out_layer->clipx1;
clip.y1 = out_layer->clipy1;
clip.x2 = out_layer->clipx2;
clip.y2 = out_layer->clipy2;
/* show_size is MIN( clipping are , resized image size) */
show_width = output_clipx2 - output_clipx1 + 1;
if (show_width > resized_width)
show_width = resized_width;
show_height = output_clipy2 - output_clipy1 + 1;
if (show_height > resized_height)
show_height = resized_height;
/* decoded_width is pass from JPEG codec ( some JPEG codec may have padding bytes ) */
#ifdef GDI_HW_JPEG_SUPPORT_OUTPUT_CLIPPING
decoded_width = show_width;
#else
decoded_width = decoded_image_width;
#endif /* GDI_HW_JPEG_SUPPORT_OUTPUT_CLIPPING */
gdi_2d_memory_blt((U8*) gdi_work_buffer, /* src_ptr */
decoded_width,
#ifdef GDI_HW_JPEG_SUPPORT_OUTPUT_CLIPPING
0, /* src_offset_x */
0, /* src_offset_y */
#else /* GDI_HW_JPEG_SUPPORT_OUTPUT_CLIPPING */
output_clipx1, /* src_offset_x */
output_clipy1, /* src_offset_y */
#endif /* GDI_HW_JPEG_SUPPORT_OUTPUT_CLIPPING */
show_width, /* src_width */
show_height, /* src_height */
out_layer->buf_ptr, /* dest_ptr */
out_layer->width, /* dest_pitch */
ox, oy, clip,
out_layer->bits_per_pixel); /* dest_clip */
return GDI_SUCCEED;
}
/*****************************************************************************
* FUNCTION
* gdi_image_hwjpeg_deinit
* DESCRIPTION
* setting driver jpeg callback
*****************************************************************************/
static GDI_RESULT gdi_image_hwjpeg_deinit(BOOL is_file)
{
if(jpeg.intmem_start_address)
{
#if defined(__SW_JPEG_CODEC_USING_CACHEABLE_MEMORY__) /* free */
gdi_free_ext_mem((void**)&jpeg.intmem_start_address);
#else
if (gdi_jpeg_intmem_from_ext)
{
gdi_free_ext_mem((void**)&jpeg.intmem_start_address);
}
else
{
med_free_int_mem((void**)&jpeg.intmem_start_address);
}
#endif
}
if(jpeg.extmem_start_address)
{
gdi_free_ext_mem((void**)&jpeg.extmem_start_address);
}
if(jpeg.jpeg_file_buffer_address && is_file)
{
if(jpeg.jpeg_file_buffer_address != (kal_uint32)gdi_bytestream_buffer)
gdi_free_ext_mem((void**)&jpeg.jpeg_file_buffer_address);
}
if(jpeg.jpeg_file_handle)
{
DRM_close_file(jpeg.jpeg_file_handle);
jpeg.jpeg_file_handle=NULL;
}
#ifdef GDI_HWJPEGV1_USING_SPATIAL_DITHERING
if(gdi_jpeg_dithering.handle != GDI_NULL_HANDLE)
{
if(gdi_jpeg_dithering.is_push_and_set_active)
gdi_layer_pop_and_restore_active();
gdi_layer_free(gdi_jpeg_dithering.handle);
gdi_free_ext_mem((void**)&gdi_jpeg_dithering.buffer);
gdi_jpeg_dithering.handle = GDI_NULL_HANDLE;
}
#endif
return GDI_SUCCEED;
}
/*****************************************************************************
* FUNCTION
* gdi_image_hwjpeg_timeout_handler
* DESCRIPTION
* This function is to handle image codec timeout.
*****************************************************************************/
void gdi_image_hwjpeg_timeout_handler(void *arg)
{
gdi_image_hwjpeg_callback(JPEG_DECODE_DECODER_TIMEOUT_FAIL);
}
/*****************************************************************************
* FUNCTION
* gdi_image_hwjpeg_msg_handler
* DESCRIPTION
* handle any hwjpeg msg
*****************************************************************************/
void gdi_image_hwjpeg_msg_handler(ilm_struct *ilm)
{
gdi_image_hwjpeg_state_struct *p = (gdi_image_hwjpeg_state_struct*)
&(((gdd_img_codec_event_ind_struct*)ilm->local_para_ptr)->header);
BOOL is_aborted;
if(jpeg_result.cause != JPEG_DECODE_DECODING) // remember error cause only success or problem happen.
jpeg_result.pre_cause = jpeg_result.cause;
jpeg_result.cause = p->cause;
GDI_TRACE(GDI_TRC, GDI_TRC_21,//"gdi_image_hwjpeg_msg_handler cause=%d",
jpeg_result.pre_cause);
GDI_TRACE(GDI_TRC, GDI_TRC_21,//"gdi_image_hwjpeg_msg_handler cause=%d",
jpeg_result.cause);
if (((g_gdi_image_hwjpeg_flag & GDI_IMAGE_CODEC_FLAG_IS_IMGDEC) && g_gdi_imgdec_hwjpeg_is_aborted))
{
is_aborted = *g_gdi_imgdec_hwjpeg_is_aborted;
}
else
{
is_aborted = !gdi_image_progress_callback();
}
if (is_aborted)
{
jpeg_result.cause = JPEG_DECODE_DECODER_TIMEOUT_FAIL;
jpeg.jpeg_decode_retry_flag = JPEG_DECODER_RETRY_THUMBNAIL; // don't retry
}
GDI_TRACE(GDI_TRC, GDI_TRC_21,//"gdi_image_hwjpeg_msg_handler cause=%d",
jpeg_result.cause);
switch(jpeg_result.cause)
{
case JPEG_DECODE_DECODING:
decode_jpeg_next_block();
break;
case JPEG_DECODE_BUFFER_SIZE_FAIL:
case JPEG_DECODE_SUCCESS:
case JPEG_DECODE_DECODER_TIMEOUT_FAIL:
default:
stop_jpeg_decode_process();
gdd_stop_timer(GDD_TIMER_IMAGE_CODEC_TIMEOUT);
gdd_register_msg_handler(MSG_ID_MMI_GDD_IMG_CODEC_EVENT_IND, NULL);
GDD_SET_EVENT(GDD_EVENT_WAIT_DECODING);
break;
}
}
/*****************************************************************************
* FUNCTION
* gdi_image_hwjpeg_start_decode
* DESCRIPTION
* This function is to active jpeg driver to run
*****************************************************************************/
void gdi_image_hwjpeg_start_decode(void) // run by MMI
{
U8 cause;
GDI_TRACE(GDI_TRC, GDI_TRC_22//"---- GDI_HW_JPG decode BEGIN ----"
);
while(1)
{
gdd_register_msg_handler(MSG_ID_MMI_GDD_IMG_CODEC_EVENT_IND, gdi_image_hwjpeg_msg_handler);
cause = jpeg_decode_process(&jpeg);
GDI_TRACE(GDI_TRC, GDI_TRC_23,//"jpeg_decode_process cause=%d",
cause);
if(cause ==JPEG_DECODE_DECODING)
{
if (g_gdi_image_hwjpeg_flag & GDI_IMAGE_CODEC_FLAG_IS_IMGDEC)
{
gdd_start_timer(GDD_TIMER_IMAGE_CODEC_TIMEOUT,
GDI_HW_JPEG_CODEC_NB_WAITING_TIME,
gdi_image_hwjpeg_timeout_handler, 0);
}
else
{
gdd_start_timer(GDD_TIMER_IMAGE_CODEC_TIMEOUT,
GDI_HW_JPEG_CODEC_WAITING_TIME,
gdi_image_hwjpeg_timeout_handler, 0);
}
}
else
{
gdi_image_hwjpeg_callback(cause);
}
GDD_WAIT_EVENT(GDD_EVENT_WAIT_DECODING); // wait GDD finish decode
//try again
if(jpeg_result.cause == JPEG_DECODE_BUFFER_SIZE_FAIL)
if(gdi_image_hwjpeg_enlarge_file_buffer()==GDI_SUCCEED)
continue;
#ifndef __SW_JPEG_CODEC_SUPPORT__
// try use thumbnail to decode
if(jpeg.jpeg_decode_retry_flag == JPEG_DECODER_RETRY_DISABLE )
if(jpeg_result.cause == JPEG_DECODE_DECODER_OVERFLOW_FAIL
|| jpeg_result.cause == JPEG_DECODE_DECODER_BREAK_FAIL
|| jpeg_result.cause == JPEG_DECODE_DECODER_TIMEOUT_FAIL
|| jpeg_result.cause == JPEG_DECODE_SRC_WIDHT_TOO_LARGE_FAIL
|| jpeg_result.cause == JPEG_DECODE_SRC_HEIGHT_TOO_LARGE_FAIL
)
{
jpeg.jpeg_decode_retry_flag = JPEG_DECODER_RETRY_THUMBNAIL;
continue;
}
#endif
break;
}
GDI_TRACE(GDI_TRC, GDI_TRC_24//"---- GDI_HW_JPG decode END ----"
);
}
/*****************************************************************************
* FUNCTION
* gdi_image_hwjpeg_get_result
* DESCRIPTION
* convert jpeg driver return cause into GDI return cause
*****************************************************************************/
static GDI_RESULT gdi_image_hwjpeg_get_result(void)
{
U8 cause = jpeg_result.cause;
if(cause == JPEG_DECODE_NO_THUMBNAIL_FAIL) // re-try fail, caused by no thumbnail. We should use previous error cause
cause = jpeg_result.pre_cause;
switch (cause)
{
case JPEG_DECODE_SUCCESS:
case JPEG_DECODE_DECODER_OVERFLOW_FAIL:
case JPEG_DECODE_DECODER_BREAK_FAIL:
return GDI_SUCCEED;
case JPEG_DECODE_INT_BUFFER_NOT_ENOUGH:
case JPEG_DECODE_EXT_BUFFER_NOT_ENOUGH:
return GDI_IMAGE_ERR_IMAGE_TOO_LARGE;
case JPEG_DECODE_TARGET_BUFFER_NOT_ENOUGH:
case JPEG_DECODE_SRC_WIDHT_TOO_LARGE_FAIL:
case JPEG_DECODE_SRC_HEIGHT_TOO_LARGE_FAIL:
case JPEG_DECODE_TARGET_WIDTH_TOO_LARGE_FAIL:
case JPEG_DECODE_TARGET_HEIGHT_TOO_LARGE_FAIL:
case JPEG_DECODE_BUFFER_SIZE_FAIL:
return GDI_IMAGE_ERR_IMAGE_TOO_LARGE;
case JPEG_DECODE_DECODER_TIMEOUT_FAIL:
return GDI_IMAGE_ERR_DECODE_TIME_OUT;
case JPEG_DECODE_UNSUPPORT_FORMAT:
return GDI_IMAGE_ERR_UNSUPPORTED_FORMAT;
default:
return GDI_FAILED;
}
}
/*****************************************************************************
* FUNCTION
* gdi_image_hwjpeg_draw_internal
* DESCRIPTION
* use jpeg driver to draw
*****************************************************************************/
GDI_RESULT gdi_image_hwjpeg_draw_internal(
gdi_handle output_layer_handle,
S32 ox,
S32 oy,
S32 resized_width,
S32 resized_height,
S32 output_clipx1,
S32 output_clipy1,
S32 output_clipx2,
S32 output_clipy2,
U8 *src,
U32 size,
BOOL is_file,
BOOL is_resized,
U8 *dest_buf,
S32 dest_buf_size,
S32 *ret_decoded_image_width,
gdi_color_format dest_buf_cf,
BOOL *is_aborted,
U32 flag)
{
// GDI_ENTER_CRITICAL_SECTION(gdi_image_hwjpeg_draw_internal)
{
GDI_RESULT ret;
S32 decoded_image_width = 0;
gdi_layer_struct *out_layer;
/* if use want draw dimesion zero image, just return GDI_SUCCEED */
if (is_resized && (resized_width == 0 || resized_height == 0))
return GDI_SUCCEED;
GDI_IMGDEC_HW_LOCK();
out_layer = (gdi_layer_struct*)output_layer_handle;
g_gdi_imgdec_hwjpeg_is_aborted = is_aborted;
g_gdi_image_hwjpeg_flag = flag;
#ifdef GDI_USING_IMAGE_SINGLE_BANK_CACHE
if (!is_file)
{
if (gdi_image_single_bank_cache_load(src, size, NULL) != GDI_SUCCEED)
{
GDI_IMGDEC_HW_UNLOCK();
return GDI_FAILED;
}
src = gdi_image_single_bank_cache_get_buffer();
}
#endif /* __SINGLE_BANK_NOR_FLASH_SUPPORT__ */
#if defined(DRV_IDP_OLD_DESIGN)
{
MMDI_SCENERIO_ID old_app;
if(!idp_register_app(SCENARIO_JPEG_DECODE_ID,&old_app))
{
GDI_IMGDEC_HW_UNLOCK();
return GDI_FAILED;
}
}
#endif /* defined(DRV_IDP_OLD_DESIGN) */
do
{
MMI_BOOL is_output_current_layer;
if(dest_buf==NULL)
is_output_current_layer = MMI_TRUE;
else
is_output_current_layer = MMI_FALSE;
if((ret =gdi_image_hwjpeg_init(
output_layer_handle,
&ox,&oy,
&resized_width,
&resized_height,
&output_clipx1,
&output_clipy1,
&output_clipx2,
&output_clipy2,
src,
size,
is_file,
is_resized,
&dest_buf,
&dest_buf_size,
&decoded_image_width,
&dest_buf_cf))!=GDI_SUCCEED) break;
gdi_image_hwjpeg_start_decode();/* BLOCKING and wait jpeg driver */
if((ret = gdi_image_hwjpeg_get_result())!=GDI_SUCCEED) break;
#ifdef GDI_HWJPEGV1_USING_SPATIAL_DITHERING
if(gdi_jpeg_dithering.handle != GDI_NULL_HANDLE)
{
U8* dest;
S32 show_width,show_height,dest_width;
ox = gdi_jpeg_dithering.save_ox;
oy = gdi_jpeg_dithering.save_oy;
output_clipx1 = gdi_jpeg_dithering.save_clipx1;
output_clipy1 = gdi_jpeg_dithering.save_clipy1;
output_clipx2 = gdi_jpeg_dithering.save_clipx2;
output_clipy2 = gdi_jpeg_dithering.save_clipy2;
show_width = output_clipx2 - output_clipx1+1;
show_height= output_clipy2 - output_clipy1+1;
gdi_jpeg_dithering.is_push_and_set_active--;
gdi_layer_pop_and_restore_active();
if(is_output_current_layer)
{
dest = out_layer->buf_ptr + (((ox + oy * out_layer->width) * out_layer->bits_per_pixel)>>3);
dest_width = out_layer->width;
}
else
{
dest = dest_buf;
dest_width = show_width;
}
GDI_TRACE(GDI_TRC, GDI_TRC_51,//"jpeg spatial_dithering888_565 [%x -> %x] , (%d,%d) (%d x %d)",
gdi_jpeg_dithering.buffer,
dest,
ox,
oy,
show_width,
show_height);
iul_sd_bgr888_to_rgb565(
(U8*) gdi_jpeg_dithering.buffer,
(U16*)dest,
(U32) show_width,
(U32) show_height,
(U32) dest_width);
}
#endif
if(is_output_current_layer
#ifndef GDI_HW_JPEG_SUPPORT_DIRECT_OUTPUT_BUFFER
&& dest_buf != NULL
#endif
&& gdi_layer_info[out_layer->id].source_key_enable)
{
gd_replace_src_key[out_layer->cf](
out_layer->buf_ptr,
out_layer->width,
ox,
oy,
out_layer->clipx1,
out_layer->clipy1,
out_layer->clipx2,
out_layer->clipy2,
gdi_layer_info[out_layer->id].source_key,
resized_width,
resized_height);
break;
}
if(dest_buf != NULL) /* don't need copy to current layer */
break;
#ifdef GDI_HW_JPEG_SUPPORT_DIRECT_OUTPUT_BUFFER
else /* direct output to layer, we need replace src key if need */
break;
#endif
if((ret = gdi_image_hwjpeg_copy_buf_to_dest(
output_layer_handle,
ox,oy,
resized_width,resized_height,
output_clipx1,
output_clipy1,
output_clipx2,
output_clipy2,
decoded_image_width))!=GDI_SUCCEED) break;
}while(0);
gdi_image_hwjpeg_deinit(is_file);
if(ret_decoded_image_width)
*ret_decoded_image_width = decoded_image_width;
/* threat out of clipping as succeed */
if (ret == GDI_IMAGE_OUT_OF_CLIP_REGION)
ret = GDI_SUCCEED;
GDI_IMGDEC_HW_UNLOCK();
return ret;
}
// GDI_EXIT_CRITICAL_SECTION(gdi_image_hwjpeg_draw_internal)
}
#endif /* GDI_USING_JPEG */