MWCapture SDK Mac 3.4.62314

- Home
- Development Library
- Release Notes

MWFOURCC.h
1
2// CONFIDENTIAL and PROPRIETARY software of Magewell Electronics Co., Ltd.
3// Copyright (c) 2011-2019 Magewell Electronics Co., Ltd. (Nanjing)
4// All rights reserved.
5// This copyright notice MUST be reproduced on all authorized copies.
7
8#pragma once
9
10#include "LibMWCapture/WinTypes.h"
11
12#ifndef MWFOURCC
13#define MWFOURCC(ch0, ch1, ch2, ch3) \
14 ((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \
15 ((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24))
16#endif
17
23#define MWFOURCC_UNK MWFOURCC('U', 'N', 'K', 'N')
24
34#define MWFOURCC_GREY MWFOURCC('G', 'R', 'E', 'Y')
35
45#define MWFOURCC_Y800 MWFOURCC('Y', '8', '0', '0')
46
56#define MWFOURCC_Y8 MWFOURCC('Y', '8', ' ', ' ')
57
67#define MWFOURCC_Y16 MWFOURCC('Y', '1', '6', ' ')
68
78#define MWFOURCC_RGB15 MWFOURCC('R', 'G', 'B', '5')
79
89#define MWFOURCC_RGB16 MWFOURCC('R', 'G', 'B', '6')
90
100#define MWFOURCC_RGB24 MWFOURCC('R', 'G', 'B', ' ')
101
111#define MWFOURCC_RGBA MWFOURCC('R', 'G', 'B', 'A')
112
122#define MWFOURCC_ARGB MWFOURCC('A', 'R', 'G', 'B')
123
133#define MWFOURCC_BGR15 MWFOURCC('B', 'G', 'R', '5')
134
144#define MWFOURCC_BGR16 MWFOURCC('B', 'G', 'R', '6')
145
155#define MWFOURCC_BGR24 MWFOURCC('B', 'G', 'R', ' ')
156
166#define MWFOURCC_BGRA MWFOURCC('B', 'G', 'R', 'A')
167
177#define MWFOURCC_ABGR MWFOURCC('A', 'B', 'G', 'R')
178
199#define MWFOURCC_NV16 MWFOURCC('N', 'V', '1', '6')
200
221#define MWFOURCC_NV61 MWFOURCC('N', 'V', '6', '1')
222
248#define MWFOURCC_I422 MWFOURCC('I', '4', '2', '2')
249
275#define MWFOURCC_YV16 MWFOURCC('Y', 'V', '1', '6')
276
277
290#define MWFOURCC_YUY2 MWFOURCC('Y', 'U', 'Y', '2')
291
304#define MWFOURCC_YUYV MWFOURCC('Y', 'U', 'Y', 'V')
305
318#define MWFOURCC_UYVY MWFOURCC('U', 'Y', 'V', 'Y')
319
332#define MWFOURCC_YVYU MWFOURCC('Y', 'V', 'Y', 'U')
333
346#define MWFOURCC_VYUY MWFOURCC('V', 'Y', 'U', 'Y')
347
372#define MWFOURCC_I420 MWFOURCC('I', '4', '2', '0')
373
398#define MWFOURCC_IYUV MWFOURCC('I', 'Y', 'U', 'V')
399
422#define MWFOURCC_NV12 MWFOURCC('N', 'V', '1', '2')
423
448#define MWFOURCC_YV12 MWFOURCC('Y', 'V', '1', '2')
449
472#define MWFOURCC_NV21 MWFOURCC('N', 'V', '2', '1')
473
496#define MWFOURCC_P010 MWFOURCC('P', '0', '1', '0')
497
522#define MWFOURCC_P210 MWFOURCC('P', '2', '1', '0')
523
524
537#define MWFOURCC_Y210 MWFOURCC('Y', '2', '1', '0')
538
551#define MWFOURCC_IYU2 MWFOURCC('I', 'Y', 'U', '2')
552
565#define MWFOURCC_V308 MWFOURCC('v', '3', '0', '8')
566
567
580#define MWFOURCC_AYUV MWFOURCC('A', 'Y', 'U', 'V')
581
594#define MWFOURCC_UYVA MWFOURCC('U', 'Y', 'V', 'A')
595
608#define MWFOURCC_V408 MWFOURCC('v', '4', '0', '8')
609
622#define MWFOURCC_VYUA MWFOURCC('V', 'Y', 'U', 'A')
623
637#define MWFOURCC_V210 MWFOURCC('v', '2', '1', '0')
638
651#define MWFOURCC_Y410 MWFOURCC('Y', '4', '1', '0')
652
665#define MWFOURCC_V410 MWFOURCC('v', '4', '1', '0')
666
676#define MWFOURCC_RGB10 MWFOURCC('R', 'G', '1', '0')
677
687#define MWFOURCC_BGR10 MWFOURCC('B', 'G', '1', '0')
688
695 inline BOOLEAN FOURCC_IsRGB(
696 DWORD dwFOURCC
697 )
698{
699 switch (dwFOURCC) {
700 case MWFOURCC_RGB15:
701 case MWFOURCC_BGR15:
702 case MWFOURCC_RGB16:
703 case MWFOURCC_BGR16:
704 case MWFOURCC_RGB24:
705 case MWFOURCC_BGR24:
706 case MWFOURCC_RGBA:
707 case MWFOURCC_BGRA:
708 case MWFOURCC_ARGB:
709 case MWFOURCC_ABGR:
710 case MWFOURCC_RGB10:
711 case MWFOURCC_BGR10:
712 return TRUE;
713 default:
714 return FALSE;
715 }
716}
717
724 inline BOOLEAN FOURCC_IsPacked(
725 DWORD dwFOURCC
726 )
727{
728 switch (dwFOURCC) {
729 case MWFOURCC_NV12:
730 case MWFOURCC_NV21:
731 case MWFOURCC_YV12:
732 case MWFOURCC_IYUV:
733 case MWFOURCC_I420:
734 case MWFOURCC_I422:
735 case MWFOURCC_YV16:
736 case MWFOURCC_NV16:
737 case MWFOURCC_NV61:
738 case MWFOURCC_P010:
739 case MWFOURCC_P210:
740 return FALSE;
741 default:
742 return TRUE;
743 }
744}
745
752 inline int FOURCC_GetBpp(
753 DWORD dwFOURCC
754 )
755{
756 switch (dwFOURCC) {
757 case MWFOURCC_GREY:
758 case MWFOURCC_Y800:
759 case MWFOURCC_Y8:
760 return 8;
761
762 case MWFOURCC_I420:
763 case MWFOURCC_IYUV:
764 case MWFOURCC_YV12:
765 case MWFOURCC_NV12:
766 case MWFOURCC_NV21:
767 return 12;
768
769 case MWFOURCC_Y16:
770 case MWFOURCC_RGB15:
771 case MWFOURCC_BGR15:
772 case MWFOURCC_RGB16:
773 case MWFOURCC_BGR16:
774 case MWFOURCC_YUY2:
775 case MWFOURCC_YUYV:
776 case MWFOURCC_UYVY:
777 case MWFOURCC_YVYU:
778 case MWFOURCC_VYUY:
779 case MWFOURCC_I422:
780 case MWFOURCC_YV16:
781 case MWFOURCC_NV16:
782 case MWFOURCC_NV61:
783 return 16;
784
785 case MWFOURCC_IYU2:
786 case MWFOURCC_V308:
787 case MWFOURCC_RGB24:
788 case MWFOURCC_BGR24:
789 case MWFOURCC_P010:
790 case MWFOURCC_V210:
791 return 24;
792
793 case MWFOURCC_AYUV:
794 case MWFOURCC_UYVA:
795 case MWFOURCC_V408:
796 case MWFOURCC_VYUA:
797 case MWFOURCC_RGBA:
798 case MWFOURCC_BGRA:
799 case MWFOURCC_ARGB:
800 case MWFOURCC_ABGR:
801 case MWFOURCC_Y410:
802 case MWFOURCC_V410:
803 case MWFOURCC_P210:
804 return 32;
805
806 default:
807 return 0;
808 }
809}
810
819 inline DWORD FOURCC_CalcMinStride(
820 DWORD dwFOURCC,
821 int cx,
822 DWORD dwAlign
823 )
824{
825 BOOLEAN bPacked = FOURCC_IsPacked(dwFOURCC);
826
827 DWORD cbLine;
828
829 if (bPacked) {
830 if (dwFOURCC == MWFOURCC_V210) {
831 cx = (cx + 47) / 48 * 48;
832 cbLine = cx * 8 / 3;
833 } else {
834 int nBpp = FOURCC_GetBpp(dwFOURCC);
835 cbLine = (cx * nBpp) / 8;
836 }
837 } else {
838 switch (dwFOURCC) {
839 case MWFOURCC_P010:
840 case MWFOURCC_P210:
841 cbLine = cx * 2;
842 break;
843 default:
844 cbLine = cx;
845 break;
846 }
847 }
848
849 return (cbLine + dwAlign - 1) & ~(dwAlign - 1);
850}
851
861 inline DWORD FOURCC_CalcImageSize(
862 DWORD dwFOURCC,
863 int cx,
864 int cy,
865 DWORD cbStride
866 )
867{
868 BOOLEAN bPacked = FOURCC_IsPacked(dwFOURCC);
869
870 if (bPacked) {
871 DWORD cbLine;
872
873 if (dwFOURCC == MWFOURCC_V210) {
874 cx = (cx + 47) / 48 * 48;
875 cbLine = cx * 8 / 3;
876 } else {
877 int nBpp = FOURCC_GetBpp(dwFOURCC);
878 cbLine = (cx * nBpp) / 8;
879 }
880
881 if (cbStride < cbLine)
882 return 0;
883
884 return cbStride * cy;
885 }
886 else {
887 if (cbStride < (DWORD)cx)
888 return 0;
889
890 switch (dwFOURCC) {
891 case MWFOURCC_NV12:
892 case MWFOURCC_NV21:
893 case MWFOURCC_YV12:
894 case MWFOURCC_IYUV:
895 case MWFOURCC_I420:
896 if ((cbStride & 1) || (cy & 1))
897 return 0;
898 return cbStride * cy * 3 / 2;
899 case MWFOURCC_I422:
900 case MWFOURCC_YV16:
901 case MWFOURCC_NV16:
902 case MWFOURCC_NV61:
903 if (cbStride & 1)
904 return 0;
905 return cbStride * cy * 2;
906 case MWFOURCC_P010:
907 if ((cbStride & 3) || (cy & 1))
908 return 0;
909 return cbStride * cy * 3 / 2;
910 case MWFOURCC_P210:
911 if (cbStride & 3)
912 return 0;
913 return cbStride * cy * 2;
914
915 default:
916 return 0;
917 }
918 }
919}
920
921#pragma pack(push, 1)
922 typedef struct tagKS_BITMAPINFOHEADER {
923 DWORD biSize;
924 int biWidth;
925 int biHeight;
926 WORD biPlanes;
927 WORD biBitCount;
928 DWORD biCompression;
929 DWORD biSizeImage;
930 int biXPelsPerMeter;
931 int biYPelsPerMeter;
932 DWORD biClrUsed;
933 DWORD biClrImportant;
934} KS_BITMAPINFOHEADER, *PKS_BITMAPINFOHEADER;
935#pragma pack(pop)
936#define KS_BI_RGB 0L
937#define KS_BI_RLE8 1L
938#define KS_BI_RLE4 2L
939#define KS_BI_BITFIELDS 3L
940#define MWCAP_BITMAPINFOHEADER KS_BITMAPINFOHEADER
941#define MWCAP_BI_RGB KS_BI_RGB
942#define MWCAP_BI_BITFIELDS KS_BI_BITFIELDS
943
953 inline BOOLEAN FOURCC_IsMask(const DWORD * pdwMasks, DWORD dwRedMask, DWORD dwGreenMask, DWORD dwBlueMask)
954{
955 return ((pdwMasks[0] == dwRedMask) && (pdwMasks[1] == dwGreenMask) && (pdwMasks[2] == dwBlueMask));
956}
957
966 inline DWORD FOURCC_GetFromBitmapHeader(
967 DWORD biCompression,
968 WORD biBitCount,
969 DWORD * pdwMasks
970 )
971{
972 switch (biCompression) {
973 case MWCAP_BI_RGB:
974 switch (biBitCount) {
975 case 16:
976 return MWFOURCC_BGR15;
977 case 24:
978 return MWFOURCC_BGR24;
979 case 32:
980 return MWFOURCC_BGRA;
981 default:
982 return MWFOURCC_UNK;
983 }
984 break;
985
986 case MWCAP_BI_BITFIELDS:
987 {
988 switch (biBitCount) {
989 case 16:
990 if (FOURCC_IsMask(pdwMasks, 0x0000F800, 0x000007E0, 0x0000001F))
991 return MWFOURCC_BGR16;
992 else if (FOURCC_IsMask(pdwMasks, 0x0000001F, 0x000007E0, 0x0000F800))
993 return MWFOURCC_RGB16;
994 else if (FOURCC_IsMask(pdwMasks, 0x00007C00, 0x000003E0, 0x0000001F))
995 return MWFOURCC_BGR15;
996 else if (FOURCC_IsMask(pdwMasks, 0x0000001F, 0x000003E0, 0x00007C00))
997 return MWFOURCC_RGB15;
998 else
999 return MWFOURCC_UNK;
1000
1001 case 24:
1002 if (FOURCC_IsMask(pdwMasks, 0x00FF0000, 0x0000FF00, 0x000000FF))
1003 return MWFOURCC_BGR24;
1004 else if (FOURCC_IsMask(pdwMasks, 0x000000FF, 0x0000FF00, 0x00FF0000))
1005 return MWFOURCC_RGB24;
1006 else
1007 return MWFOURCC_UNK;
1008
1009 case 32:
1010 if (FOURCC_IsMask(pdwMasks, 0x00FF0000, 0x0000FF00, 0x000000FF))
1011 return MWFOURCC_BGRA;
1012 else if (FOURCC_IsMask(pdwMasks, 0x000000FF, 0x0000FF00, 0x00FF0000))
1013 return MWFOURCC_RGBA;
1014 else if (FOURCC_IsMask(pdwMasks, 0xFF000000, 0x00FF0000, 0x0000FF00))
1015 return MWFOURCC_ABGR;
1016 else if (FOURCC_IsMask(pdwMasks, 0x0000FF00, 0x00FF0000, 0xFF000000))
1017 return MWFOURCC_ARGB;
1018 else
1019 return MWFOURCC_UNK;
1020
1021 default:
1022 return MWFOURCC_UNK;
1023 }
1024 }
1025 break;
1026
1027 default:
1028 return biCompression;
1029 }
1030}
1031
1038 inline DWORD FOURCC_GetFromBitmapHeader2(
1039 const MWCAP_BITMAPINFOHEADER * pbmih
1040 )
1041{
1042 DWORD *pdwMasks = (DWORD *)(pbmih + 1);
1043 return FOURCC_GetFromBitmapHeader(pbmih->biCompression, pbmih->biBitCount, pdwMasks);
1044}
1045
FOURCC_GetFromBitmapHeader2
DWORD FOURCC_GetFromBitmapHeader2(const MWCAP_BITMAPINFOHEADER *pbmih)
Gets color format from the bitmap header.
Definition: MWFOURCC.h:1038
MWFOURCC_Y16
#define MWFOURCC_Y16
16bits Grey
Definition: MWFOURCC.h:67
MWFOURCC_Y410
#define MWFOURCC_Y410
Y410.
Definition: MWFOURCC.h:651
FOURCC_IsPacked
BOOLEAN FOURCC_IsPacked(DWORD dwFOURCC)
Determines whether the color format is packed.
Definition: MWFOURCC.h:724
MWFOURCC_RGB15
#define MWFOURCC_RGB15
16bits R5G5B5A1
Definition: MWFOURCC.h:78
MWFOURCC_ARGB
#define MWFOURCC_ARGB
32bits A8R8G8B8
Definition: MWFOURCC.h:122
MWFOURCC_NV21
#define MWFOURCC_NV21
NV21.
Definition: MWFOURCC.h:472
MWFOURCC_V210
#define MWFOURCC_V210
Definition: MWFOURCC.h:637
MWFOURCC_VYUA
#define MWFOURCC_VYUA
VYUA.
Definition: MWFOURCC.h:622
MWFOURCC_ABGR
#define MWFOURCC_ABGR
32bits A8B8G8R8
Definition: MWFOURCC.h:177
FOURCC_IsMask
BOOLEAN FOURCC_IsMask(const DWORD *pdwMasks, DWORD dwRedMask, DWORD dwGreenMask, DWORD dwBlueMask)
Determins whether the mask is the same as specified color format.
Definition: MWFOURCC.h:953
MWFOURCC_I420
#define MWFOURCC_I420
I420.
Definition: MWFOURCC.h:372
FOURCC_IsRGB
BOOLEAN FOURCC_IsRGB(DWORD dwFOURCC)
Determines whether the color format is RGB.
Definition: MWFOURCC.h:695
MWFOURCC_BGR15
#define MWFOURCC_BGR15
16bits B5G5R5A1
Definition: MWFOURCC.h:133
MWFOURCC_BGR24
#define MWFOURCC_BGR24
24bits B8G8R8
Definition: MWFOURCC.h:155
MWFOURCC_V408
#define MWFOURCC_V408
V408.
Definition: MWFOURCC.h:608
FOURCC_CalcImageSize
DWORD FOURCC_CalcImageSize(DWORD dwFOURCC, int cx, int cy, DWORD cbStride)
Counts the number of bytes that a frame takes, depending on the color format, resolution and the line...
Definition: MWFOURCC.h:861
MWFOURCC_YVYU
#define MWFOURCC_YVYU
YVYU.
Definition: MWFOURCC.h:332
MWFOURCC_RGB24
#define MWFOURCC_RGB24
24bits R8G8B8
Definition: MWFOURCC.h:100
MWFOURCC_YUY2
#define MWFOURCC_YUY2
YUY2.
Definition: MWFOURCC.h:290
MWFOURCC_V308
#define MWFOURCC_V308
V308.
Definition: MWFOURCC.h:565
MWFOURCC_RGBA
#define MWFOURCC_RGBA
32bits R8G8B8A8
Definition: MWFOURCC.h:111
MWFOURCC_NV61
#define MWFOURCC_NV61
NV61.
Definition: MWFOURCC.h:221
MWFOURCC_IYUV
#define MWFOURCC_IYUV
IYUV.
Definition: MWFOURCC.h:398
MWFOURCC_Y8
#define MWFOURCC_Y8
8bits Grey
Definition: MWFOURCC.h:56
MWFOURCC_GREY
#define MWFOURCC_GREY
8bits Grey
Definition: MWFOURCC.h:34
MWFOURCC_AYUV
#define MWFOURCC_AYUV
AYUV.
Definition: MWFOURCC.h:580
MWFOURCC_YUYV
#define MWFOURCC_YUYV
YUYV.
Definition: MWFOURCC.h:304
MWFOURCC_YV16
#define MWFOURCC_YV16
YV16.
Definition: MWFOURCC.h:275
MWFOURCC_NV16
#define MWFOURCC_NV16
NV16.
Definition: MWFOURCC.h:199
MWFOURCC_BGR16
#define MWFOURCC_BGR16
16bits B5G6R5
Definition: MWFOURCC.h:144
MWFOURCC_UNK
#define MWFOURCC_UNK
Unknown color formate.
Definition: MWFOURCC.h:23
MWFOURCC_YV12
#define MWFOURCC_YV12
YV12.
Definition: MWFOURCC.h:448
FOURCC_GetBpp
int FOURCC_GetBpp(DWORD dwFOURCC)
Gets the bits that pixel of color format takes.
Definition: MWFOURCC.h:752
MWFOURCC_UYVA
#define MWFOURCC_UYVA
UYVA.
Definition: MWFOURCC.h:594
MWFOURCC_Y800
#define MWFOURCC_Y800
8bits Grey
Definition: MWFOURCC.h:45
MWFOURCC_NV12
#define MWFOURCC_NV12
NV12.
Definition: MWFOURCC.h:422
MWFOURCC_VYUY
#define MWFOURCC_VYUY
VYUY.
Definition: MWFOURCC.h:346
MWFOURCC_IYU2
#define MWFOURCC_IYU2
IYU2.
Definition: MWFOURCC.h:551
MWFOURCC_BGR10
#define MWFOURCC_BGR10
BGR10.
Definition: MWFOURCC.h:687
MWFOURCC_RGB16
#define MWFOURCC_RGB16
16bits R5G6B5
Definition: MWFOURCC.h:89
FOURCC_GetFromBitmapHeader
DWORD FOURCC_GetFromBitmapHeader(DWORD biCompression, WORD biBitCount, DWORD *pdwMasks)
Gets color format from the bitmap header.
Definition: MWFOURCC.h:966
MWFOURCC_V410
#define MWFOURCC_V410
V410.
Definition: MWFOURCC.h:665
MWFOURCC_BGRA
#define MWFOURCC_BGRA
32bits B8G8R8A8
Definition: MWFOURCC.h:166
MWFOURCC_RGB10
#define MWFOURCC_RGB10
RGB10.
Definition: MWFOURCC.h:676
MWFOURCC_P210
#define MWFOURCC_P210
P210.
Definition: MWFOURCC.h:522
MWFOURCC_UYVY
#define MWFOURCC_UYVY
UYVY.
Definition: MWFOURCC.h:318
FOURCC_CalcMinStride
DWORD FOURCC_CalcMinStride(DWORD dwFOURCC, int cx, DWORD dwAlign)
Counts the number of bytes that a line data of image takes, depending on the width of image and the c...
Definition: MWFOURCC.h:819
MWFOURCC_I422
#define MWFOURCC_I422
I422.
Definition: MWFOURCC.h:248
MWFOURCC_P010
#define MWFOURCC_P010
P010.
Definition: MWFOURCC.h:496
tagKS_BITMAPINFOHEADER
Definition: MWFOURCC.h:922