1 /*
2 * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <unistd.h>
18 #include <string.h>
19 #include "securec.h"
20 #include "loadbmp.h"
21
22 OSD_COMP_INFO s_OSDCompInfo[OSD_COLOR_FMT_BUTT] = {
23 {0, 4, 4, 4}, /* RGB444 */
24 {4, 4, 4, 4}, /* ARGB4444 */
25 {0, 5, 5, 5}, /* RGB555 */
26 {0, 5, 6, 5}, /* RGB565 */
27 {1, 5, 5, 5}, /* ARGB1555 */
28 {0, 0, 0, 0}, /* RESERVED */
29 {0, 8, 8, 8}, /* RGB888 */
30 {8, 8, 8, 8} /* ARGB8888 */
31 };
32
OSD_MAKECOLOR_U16(HI_U8 r, HI_U8 g, HI_U8 b, OSD_COMP_INFO compinfo)33 static HI_U16 OSD_MAKECOLOR_U16(HI_U8 r, HI_U8 g, HI_U8 b, OSD_COMP_INFO compinfo)
34 {
35 HI_U8 r1, g1, b1;
36 HI_U16 pixel = 0;
37 HI_U32 tmp = 15;
38
39 r1 = r >> (8 - compinfo.rlen); /* 8bit */
40 g1 = g >> (8 - compinfo.glen); /* 8bit */
41 b1 = b >> (8 - compinfo.blen); /* 8bit */
42 while (compinfo.alen) {
43 pixel |= (1 << tmp);
44 tmp--;
45 compinfo.alen--;
46 }
47
48 pixel |= (r1 | (g1 << compinfo.blen) | (b1 << (compinfo.blen + compinfo.glen)));
49 return pixel;
50 }
51
GetBmpInfo(const char *filename, OSD_BITMAPFILEHEADER *pBmpFileHeader, OSD_BITMAPINFO *pBmpInfo)52 HI_S32 GetBmpInfo(const char *filename, OSD_BITMAPFILEHEADER *pBmpFileHeader, OSD_BITMAPINFO *pBmpInfo)
53 {
54 FILE *pFile = HI_NULL;
55 hi_char *path = HI_NULL;
56 HI_U16 bfType;
57
58 if ((filename == NULL) || (pBmpFileHeader == NULL) || (pBmpInfo == NULL)) {
59 printf("null pointer\n");
60 return -1;
61 }
62
63 path = realpath(filename, HI_NULL);
64 if (path == HI_NULL) {
65 return HI_FAILURE;
66 }
67
68 if ((pFile = fopen(path, "rb")) == NULL) {
69 printf("Open file failed:%s!\n", filename);
70 free(path);
71 return -1;
72 }
73
74 (void)fread(&bfType, 1, sizeof(bfType), pFile);
75 if (bfType != 0x4d42) {
76 printf("not bitmap file\n");
77 (HI_VOID)fclose(pFile);
78 free(path);
79 return -1;
80 }
81
82 (void)fread(pBmpFileHeader, 1, sizeof(OSD_BITMAPFILEHEADER), pFile);
83 (void)fread(pBmpInfo, 1, sizeof(OSD_BITMAPINFO), pFile);
84 (HI_VOID)fclose(pFile);
85 free(path);
86
87 return 0;
88 }
89
LoadBMP(const char *filename, OSD_LOGO_T *pVideoLogo)90 static int LoadBMP(const char *filename, OSD_LOGO_T *pVideoLogo)
91 {
92 HI_S32 ret;
93 FILE *pFile = HI_NULL;
94 HI_U16 i, j;
95 hi_char *path = HI_NULL;
96
97 HI_U32 w, h;
98 HI_U16 Bpp;
99 HI_U16 dstBpp;
100
101 OSD_BITMAPFILEHEADER bmpFileHeader;
102 OSD_BITMAPINFO bmpInfo;
103
104 HI_U8 *pOrigBMPBuf = HI_NULL;
105 HI_U8 *pRGBBuf = HI_NULL;
106 HI_U32 stride;
107
108 if ((filename == NULL) || (pVideoLogo == NULL)) {
109 printf("null pointer\n");
110 return -1;
111 }
112
113 path = realpath(filename, HI_NULL);
114 if (path == HI_NULL) {
115 return HI_FAILURE;
116 }
117
118 if (GetBmpInfo(path, &bmpFileHeader, &bmpInfo) < 0) {
119 free(path);
120 return -1;
121 }
122
123 Bpp = bmpInfo.bmiHeader.biBitCount / 8; /* 8bit */
124 if (Bpp < 2) { /* 2byte */
125 /* only support 1555 8888 888 bitmap */
126 printf("bitmap format not supported!\n");
127 free(path);
128 return -1;
129 }
130
131 if (bmpInfo.bmiHeader.biCompression != 0) {
132 printf("not support compressed bitmap file!\n");
133 free(path);
134 return -1;
135 }
136
137 if (bmpInfo.bmiHeader.biHeight < 0) {
138 printf("bmpInfo.bmiHeader.biHeight < 0\n");
139 free(path);
140 return -1;
141 }
142
143 if ((pFile = fopen(path, "rb")) == NULL) {
144 printf("Open file failed:%s!\n", filename);
145 free(path);
146 return -1;
147 }
148
149 pVideoLogo->width = (HI_U16)bmpInfo.bmiHeader.biWidth;
150 pVideoLogo->height =
151 (HI_U16)((bmpInfo.bmiHeader.biHeight > 0) ? bmpInfo.bmiHeader.biHeight : (-bmpInfo.bmiHeader.biHeight));
152 w = pVideoLogo->width;
153 h = pVideoLogo->height;
154
155 stride = w * Bpp;
156 if (stride % 4) { /* 4 align */
157 stride = (stride & 0xfffc) + 4; /* 4 align */
158 }
159
160 /* RGB8888 or RGB1555 */
161 pOrigBMPBuf = (HI_U8 *)malloc(h * stride);
162 if (pOrigBMPBuf == NULL) {
163 printf("not enough memory to malloc!\n");
164 (HI_VOID)fclose(pFile);
165 free(path);
166 return -1;
167 }
168
169 pRGBBuf = pVideoLogo->pRGBBuffer;
170
171 (HI_VOID)fseek(pFile, bmpFileHeader.bfOffBits, 0);
172 if (fread(pOrigBMPBuf, 1, h * stride, pFile) != (h * stride)) {
173 printf("fread error!line:%d\n", __LINE__);
174 perror("fread:");
175 }
176
177 if (Bpp > 2) { /* 2 byte */
178 dstBpp = 4; /* 4 align */
179 } else {
180 dstBpp = 2; /* 2 align */
181 }
182
183 if (pVideoLogo->stride == 0) {
184 pVideoLogo->stride = pVideoLogo->width * dstBpp;
185 }
186
187 for (i = 0; i < h; i++) {
188 for (j = 0; j < w; j++) {
189 ret = memcpy_s(pRGBBuf + i * pVideoLogo->stride + j * dstBpp, Bpp,
190 pOrigBMPBuf + ((h - 1) - i) * stride + j * Bpp, Bpp);
191 if (ret != EOK) {
192 free(pOrigBMPBuf);
193 pOrigBMPBuf = NULL;
194 (HI_VOID)fclose(pFile);
195 free(path);
196 printf("copy bmp failed!line:%d\n", __LINE__);
197 return HI_FAILURE;
198 }
199
200 if (dstBpp == 4) { /* 4 align */
201 *(pRGBBuf + i * pVideoLogo->stride + j * dstBpp + 3) = 0x80; /* alpha + 3 */
202 }
203 }
204 }
205
206 free(pOrigBMPBuf);
207 pOrigBMPBuf = NULL;
208
209 (HI_VOID)fclose(pFile);
210 free(path);
211 return 0;
212 }
213
LoadBMPEx(const char *filename, OSD_LOGO_T *pVideoLogo, OSD_COLOR_FMT_E enFmt)214 static int LoadBMPEx(const char *filename, OSD_LOGO_T *pVideoLogo, OSD_COLOR_FMT_E enFmt)
215 {
216 HI_S32 ret;
217 FILE *pFile = HI_NULL;
218 HI_U16 i, j;
219 hi_char *path = HI_NULL;
220
221 HI_U32 w, h;
222 HI_U16 Bpp;
223
224 OSD_BITMAPFILEHEADER bmpFileHeader;
225 OSD_BITMAPINFO bmpInfo;
226
227 HI_U8 *pOrigBMPBuf = HI_NULL;
228 HI_U8 *pRGBBuf = HI_NULL;
229 HI_U32 stride;
230 HI_U8 r, g, b;
231 HI_U8 *pStart = HI_NULL;
232 HI_U16 *pDst = HI_NULL;
233
234 if ((filename == NULL) || (pVideoLogo== NULL)) {
235 printf("null pointer\n");
236 return -1;
237 }
238
239 path = realpath(filename, HI_NULL);
240 if (path == HI_NULL) {
241 return HI_FAILURE;
242 }
243
244 if (GetBmpInfo(path, &bmpFileHeader, &bmpInfo) < 0) {
245 free(path);
246 return -1;
247 }
248
249 Bpp = bmpInfo.bmiHeader.biBitCount / 8; /* 8bit */
250 if (Bpp < 2) { /* 2 byte */
251 /* only support 1555.8888 888 bitmap */
252 printf("bitmap format not supported!\n");
253 free(path);
254 return -1;
255 }
256
257 if (bmpInfo.bmiHeader.biCompression != 0) {
258 printf("not support compressed bitmap file!\n");
259 free(path);
260 return -1;
261 }
262
263 if (bmpInfo.bmiHeader.biHeight < 0) {
264 printf("bmpInfo.bmiHeader.biHeight < 0\n");
265 free(path);
266 return -1;
267 }
268
269 if ((pFile = fopen(path, "rb")) == NULL) {
270 printf("Open file failed:%s!\n", filename);
271 free(path);
272 return -1;
273 }
274
275 pVideoLogo->width = (HI_U16)bmpInfo.bmiHeader.biWidth;
276 pVideoLogo->height =
277 (HI_U16)((bmpInfo.bmiHeader.biHeight > 0) ? bmpInfo.bmiHeader.biHeight : (-bmpInfo.bmiHeader.biHeight));
278 w = pVideoLogo->width;
279 h = pVideoLogo->height;
280
281 stride = w * Bpp;
282 if (stride % 4) { /* 4 align */
283 stride = (stride & 0xfffc) + 4; /* 4 align */
284 }
285
286 /* RGB8888 or RGB1555 */
287 pOrigBMPBuf = (HI_U8 *)malloc(h * stride);
288 if (pOrigBMPBuf == NULL) {
289 printf("not enough memory to malloc!\n");
290 (HI_VOID)fclose(pFile);
291 free(path);
292 return -1;
293 }
294
295 pRGBBuf = pVideoLogo->pRGBBuffer;
296
297 (HI_VOID)fseek(pFile, bmpFileHeader.bfOffBits, 0);
298 if (fread(pOrigBMPBuf, 1, h * stride, pFile) != (h * stride)) {
299 printf("fread (%d*%d)error!line:%d\n", h, stride, __LINE__);
300 perror("fread:");
301 }
302
303 if (enFmt >= OSD_COLOR_FMT_RGB888) {
304 pVideoLogo->stride = pVideoLogo->width * 4; /* 4 * width */
305 } else {
306 pVideoLogo->stride = pVideoLogo->width * 2; /* 2 * width */
307 }
308
309 for (i = 0; i < h; i++) {
310 for (j = 0; j < w; j++) {
311 if (Bpp == 3) { /* 3 byte */
312 switch (enFmt) {
313 case OSD_COLOR_FMT_RGB444:
314 case OSD_COLOR_FMT_RGB555:
315 case OSD_COLOR_FMT_RGB565:
316 case OSD_COLOR_FMT_RGB1555:
317 case OSD_COLOR_FMT_RGB4444:
318 /* start color convert */
319 pStart = pOrigBMPBuf + ((h - 1) - i) * stride + j * Bpp;
320 pDst = (HI_U16 *)(pRGBBuf + i * pVideoLogo->stride + j * 2); /* one step 2 */
321 r = *(pStart); /* [0] */
322 g = *(pStart + 1); /* [1] */
323 b = *(pStart + 2); /* [2] */
324 *pDst = OSD_MAKECOLOR_U16(r, g, b, s_OSDCompInfo[enFmt]);
325 break;
326
327 case OSD_COLOR_FMT_RGB888:
328 case OSD_COLOR_FMT_RGB8888:
329 ret = memcpy_s(pRGBBuf + i * pVideoLogo->stride + j * 4, Bpp, /* one step 4 */
330 pOrigBMPBuf + ((h - 1) - i) * stride + j * Bpp, Bpp);
331 if (ret != EOK) {
332 free(pOrigBMPBuf);
333 pOrigBMPBuf = NULL;
334 (HI_VOID)fclose(pFile);
335 free(path);
336 printf("copy bmp failed!line:%d\n", __LINE__);
337 return HI_FAILURE;
338 }
339 *(pRGBBuf + i * pVideoLogo->stride + j * 4 + 3) = 0xff; /* one step 4 + 3 */
340 break;
341
342 default:
343 printf("file(%s), line(%d), no such format!\n", __FILE__, __LINE__);
344 break;
345 }
346 } else if ((Bpp == 2) || (Bpp == 4)) { /* 2 or 4 byte */
347 ret = memcpy_s(pRGBBuf + i * pVideoLogo->stride + j * Bpp, Bpp,
348 pOrigBMPBuf + ((h - 1) - i) * stride + j * Bpp, Bpp);
349 if (ret != EOK) {
350 free(pOrigBMPBuf);
351 pOrigBMPBuf = NULL;
352 (HI_VOID)fclose(pFile);
353 free(path);
354 printf("copy bmp failed!line:%d\n", __LINE__);
355 return HI_FAILURE;
356 }
357 }
358 }
359 }
360
361 free(pOrigBMPBuf);
362 pOrigBMPBuf = NULL;
363
364 (HI_VOID)fclose(pFile);
365 free(path);
366 return 0;
367 }
368
369
LoadBMPCanvas(const char *filename, const OSD_LOGO_T *pVideoLogo, OSD_COLOR_FMT_E enFmt)370 static int LoadBMPCanvas(const char *filename, const OSD_LOGO_T *pVideoLogo, OSD_COLOR_FMT_E enFmt)
371 {
372 HI_S32 ret;
373 FILE *pFile = HI_NULL;
374 HI_U16 i, j;
375 hi_char *path = HI_NULL;
376
377 HI_U32 w, h;
378 HI_U16 Bpp;
379
380 OSD_BITMAPFILEHEADER bmpFileHeader;
381 OSD_BITMAPINFO bmpInfo;
382
383 HI_U8 *pOrigBMPBuf = HI_NULL;
384 HI_U8 *pRGBBuf = HI_NULL;
385 HI_U32 stride;
386 HI_U8 r, g, b;
387 HI_U8 *pStart = HI_NULL;
388 HI_U16 *pDst = HI_NULL;
389
390 if (filename == NULL) {
391 printf("OSD_LoadBMP: filename=NULL\n");
392 return -1;
393 }
394
395 path = realpath(filename, HI_NULL);
396 if (path == HI_NULL) {
397 return HI_FAILURE;
398 }
399
400 if (GetBmpInfo(path, &bmpFileHeader, &bmpInfo) < 0) {
401 free(path);
402 return -1;
403 }
404
405 Bpp = bmpInfo.bmiHeader.biBitCount / 8; /* 8bit */
406 if (Bpp < 2) { /* 2 byte */
407 /* only support 1555.8888 888 bitmap */
408 printf("bitmap format not supported!\n");
409 free(path);
410 return -1;
411 }
412
413 if (bmpInfo.bmiHeader.biCompression != 0) {
414 printf("not support compressed bitmap file!\n");
415 free(path);
416 return -1;
417 }
418
419 if (bmpInfo.bmiHeader.biHeight < 0) {
420 printf("bmpInfo.bmiHeader.biHeight < 0\n");
421 free(path);
422 return -1;
423 }
424
425 if ((pFile = fopen(path, "rb")) == NULL) {
426 printf("Open file failed:%s!\n", filename);
427 free(path);
428 return -1;
429 }
430
431 w = (HI_U16)bmpInfo.bmiHeader.biWidth;
432 h = (HI_U16)((bmpInfo.bmiHeader.biHeight > 0) ? bmpInfo.bmiHeader.biHeight : (-bmpInfo.bmiHeader.biHeight));
433
434 stride = w * Bpp;
435
436 if (stride % 4) { /* 4 align */
437 stride = (stride & 0xfffc) + 4; /* 4 align */
438 }
439
440 /* RGB8888 or RGB1555 */
441 pOrigBMPBuf = (HI_U8 *)malloc(h * stride);
442 if (pOrigBMPBuf == NULL) {
443 printf("not enough memory to malloc!\n");
444 (HI_VOID)fclose(pFile);
445 free(path);
446 return -1;
447 }
448
449 pRGBBuf = pVideoLogo->pRGBBuffer;
450
451 if (stride > pVideoLogo->stride) {
452 printf("Bitmap's stride(%d) is bigger than canvas's stide(%d). Load bitmap error!\n", stride,
453 pVideoLogo->stride);
454 free(pOrigBMPBuf);
455 (HI_VOID)fclose(pFile);
456 free(path);
457 return -1;
458 }
459
460 if (h > pVideoLogo->height) {
461 printf("Bitmap's height(%d) is bigger than canvas's height(%d). Load bitmap error!\n", h, pVideoLogo->height);
462 free(pOrigBMPBuf);
463 (HI_VOID)fclose(pFile);
464 free(path);
465 return -1;
466 }
467
468 if (w > pVideoLogo->width) {
469 printf("Bitmap's width(%d) is bigger than canvas's width(%d). Load bitmap error!\n", w, pVideoLogo->width);
470 free(pOrigBMPBuf);
471 (HI_VOID)fclose(pFile);
472 free(path);
473 return -1;
474 }
475
476 (HI_VOID)fseek(pFile, bmpFileHeader.bfOffBits, 0);
477 if (fread(pOrigBMPBuf, 1, h * stride, pFile) != (h * stride)) {
478 printf("fread (%d*%d)error!line:%d\n", h, stride, __LINE__);
479 perror("fread:");
480 }
481
482 for (i = 0; i < h; i++) {
483 for (j = 0; j < w; j++) {
484 if (Bpp == 3) { /* 3 byte */
485 switch (enFmt) {
486 case OSD_COLOR_FMT_RGB444:
487 case OSD_COLOR_FMT_RGB555:
488 case OSD_COLOR_FMT_RGB565:
489 case OSD_COLOR_FMT_RGB1555:
490 case OSD_COLOR_FMT_RGB4444:
491 /* start color convert */
492 pStart = pOrigBMPBuf + ((h - 1) - i) * stride + j * Bpp;
493 pDst = (HI_U16 *)(pRGBBuf + i * pVideoLogo->stride + j * 2); /* one step 2 */
494 r = *(pStart); /* [0] */
495 g = *(pStart + 1); /* [1] */
496 b = *(pStart + 2); /* [2] */
497 *pDst = OSD_MAKECOLOR_U16(r, g, b, s_OSDCompInfo[enFmt]);
498
499 break;
500
501 case OSD_COLOR_FMT_RGB888:
502 case OSD_COLOR_FMT_RGB8888:
503 ret = memcpy_s(pRGBBuf + i * pVideoLogo->stride + j * 4, Bpp, /* one step 4 */
504 pOrigBMPBuf + ((h - 1) - i) * stride + j * Bpp, Bpp);
505 if (ret != EOK) {
506 free(pOrigBMPBuf);
507 pOrigBMPBuf = NULL;
508 (HI_VOID)fclose(pFile);
509 free(path);
510 printf("copy bmp failed!line:%d\n", __LINE__);
511 return HI_FAILURE;
512 }
513 *(pRGBBuf + i * pVideoLogo->stride + j * 4 + 3) = 0xff; /* one step 4 + 3 */
514 break;
515
516 default:
517 printf("file(%s), line(%d), no such format!\n", __FILE__, __LINE__);
518 break;
519 }
520 } else if ((Bpp == 2) || (Bpp == 4)) { /* 2 or 4 byte */
521 ret = memcpy_s(pRGBBuf + i * pVideoLogo->stride + j * Bpp, Bpp,
522 pOrigBMPBuf + ((h - 1) - i) * stride + j * Bpp, Bpp);
523 if (ret != EOK) {
524 free(pOrigBMPBuf);
525 pOrigBMPBuf = NULL;
526 (HI_VOID)fclose(pFile);
527 free(path);
528 printf("copy bmp failed!line:%d\n", __LINE__);
529 return HI_FAILURE;
530 }
531 }
532 }
533 }
534
535 free(pOrigBMPBuf);
536 pOrigBMPBuf = NULL;
537
538 (HI_VOID)fclose(pFile);
539 free(path);
540 return 0;
541 }
542
GetExtName(char *filename)543 static char *GetExtName(char *filename)
544 {
545 char *pret = HI_NULL;
546 HI_U32 fnLen;
547
548 if (filename == NULL) {
549 printf("filename can't be null!");
550 return NULL;
551 }
552
553 fnLen = strlen(filename);
554 while (fnLen) {
555 pret = filename + fnLen;
556 if (*pret == '.') {
557 return (pret + 1);
558 }
559
560 fnLen--;
561 }
562
563 return pret;
564 }
565
LoadImage(const char *filename, OSD_LOGO_T *pVideoLogo)566 int LoadImage(const char *filename, OSD_LOGO_T *pVideoLogo)
567 {
568 char *ext = GetExtName((char *)filename);
569
570 if ((filename == HI_NULL) || (pVideoLogo == HI_NULL) || (ext == NULL)) {
571 printf("null pointer!\n");
572 return -1;
573 }
574 if (strcmp(ext, "bmp") == 0) {
575 if (LoadBMP(filename, pVideoLogo) != 0) {
576 printf("OSD_LoadBMP error!\n");
577 return -1;
578 }
579 } else {
580 printf("not supported image file!\n");
581 return -1;
582 }
583
584 return 0;
585 }
586
LoadImageEx(const char *filename, OSD_LOGO_T *pVideoLogo, OSD_COLOR_FMT_E enFmt)587 static int LoadImageEx(const char *filename, OSD_LOGO_T *pVideoLogo, OSD_COLOR_FMT_E enFmt)
588 {
589 char *ext = GetExtName((char *)filename);
590
591 if (ext == HI_NULL) {
592 printf("LoadImageEx error!\n");
593 return -1;
594 }
595
596 if (strcmp(ext, "bmp") == 0) {
597 if (LoadBMPEx(filename, pVideoLogo, enFmt) != 0) {
598 printf("OSD_LoadBMP error!\n");
599 return -1;
600 }
601 } else {
602 printf("not supported image file!\n");
603 return -1;
604 }
605
606 return 0;
607 }
608
609
LoadCanvasEx(const char *filename, const OSD_LOGO_T *pVideoLogo, OSD_COLOR_FMT_E enFmt)610 static int LoadCanvasEx(const char *filename, const OSD_LOGO_T *pVideoLogo, OSD_COLOR_FMT_E enFmt)
611 {
612 char *ext = GetExtName((char *)filename);
613
614 if (ext == HI_NULL) {
615 printf("LoadCanvasEx error!\n");
616 return -1;
617 }
618
619 if (strcmp(ext, "bmp") == 0) {
620 if (LoadBMPCanvas(filename, pVideoLogo, enFmt) != 0) {
621 printf("OSD_LoadBMP error!\n");
622 return -1;
623 }
624 } else {
625 printf("not supported image file!\n");
626 return -1;
627 }
628
629 return 0;
630 }
631
632
LoadBitMap2Surface(const HI_CHAR *pszFileName, const OSD_SURFACE_S *pstSurface, HI_U8 *pu8Virt)633 HI_S32 LoadBitMap2Surface(const HI_CHAR *pszFileName, const OSD_SURFACE_S *pstSurface, HI_U8 *pu8Virt)
634 {
635 OSD_LOGO_T stLogo;
636
637 if ((pszFileName == NULL) || (pstSurface == NULL) || (pu8Virt == NULL)) {
638 printf("null pointer\n");
639 return HI_FAILURE;
640 }
641 stLogo.stride = pstSurface->u16Stride;
642 stLogo.pRGBBuffer = pu8Virt;
643
644 return LoadImage(pszFileName, &stLogo);
645 }
646
CreateSurfaceByBitMap(const HI_CHAR *pszFileName, OSD_SURFACE_S *pstSurface, HI_U8 *pu8Virt)647 HI_S32 CreateSurfaceByBitMap(const HI_CHAR *pszFileName, OSD_SURFACE_S *pstSurface, HI_U8 *pu8Virt)
648 {
649 OSD_LOGO_T stLogo;
650
651 if ((pszFileName == NULL) || (pstSurface == NULL) || (pu8Virt == NULL)) {
652 printf("null pointer\n");
653 return -1;
654 }
655 stLogo.pRGBBuffer = pu8Virt;
656 if (LoadImageEx(pszFileName, &stLogo, pstSurface->enColorFmt) < 0) {
657 printf("load bmp error!\n");
658 return -1;
659 }
660
661 pstSurface->u16Height = stLogo.height;
662 pstSurface->u16Width = stLogo.width;
663 pstSurface->u16Stride = stLogo.stride;
664
665 return 0;
666 }
667
CreateSurfaceByCanvas(const HI_CHAR *pszFileName, OSD_SURFACE_S *pstSurface, HI_U8 *pu8Virt, HI_U32 u32Width, HI_U32 u32Height, HI_U32 u32Stride)668 HI_S32 CreateSurfaceByCanvas(const HI_CHAR *pszFileName, OSD_SURFACE_S *pstSurface, HI_U8 *pu8Virt, HI_U32 u32Width,
669 HI_U32 u32Height, HI_U32 u32Stride)
670 {
671 OSD_LOGO_T stLogo;
672
673 if ((pstSurface == NULL) || (pu8Virt == NULL) || (pszFileName == NULL)) {
674 printf("null pointer\n");
675 return HI_FAILURE;
676 }
677 stLogo.pRGBBuffer = pu8Virt;
678 stLogo.width = u32Width;
679 stLogo.height = u32Height;
680 stLogo.stride = u32Stride;
681 if (LoadCanvasEx(pszFileName, &stLogo, pstSurface->enColorFmt) < 0) {
682 printf("load bmp error!\n");
683 return -1;
684 }
685
686 pstSurface->u16Height = u32Height;
687 pstSurface->u16Width = u32Width;
688 pstSurface->u16Stride = u32Stride;
689
690 return 0;
691 }
692