@@ -115,7 +115,7 @@ static struct mmal_fmt formats[] = {
115
115
.name = "RGB24 (LE)" ,
116
116
.fourcc = V4L2_PIX_FMT_RGB24 ,
117
117
.flags = 0 ,
118
- .mmal = MMAL_ENCODING_BGR24 ,
118
+ .mmal = MMAL_ENCODING_RGB24 ,
119
119
.depth = 24 ,
120
120
.mmal_component = MMAL_COMPONENT_CAMERA ,
121
121
.ybbp = 3 ,
@@ -187,7 +187,7 @@ static struct mmal_fmt formats[] = {
187
187
.name = "RGB24 (BE)" ,
188
188
.fourcc = V4L2_PIX_FMT_BGR24 ,
189
189
.flags = 0 ,
190
- .mmal = MMAL_ENCODING_RGB24 ,
190
+ .mmal = MMAL_ENCODING_BGR24 ,
191
191
.depth = 24 ,
192
192
.mmal_component = MMAL_COMPONENT_CAMERA ,
193
193
.ybbp = 3 ,
@@ -1059,6 +1059,13 @@ static int mmal_setup_components(struct bm2835_mmal_dev *dev,
1059
1059
else
1060
1060
camera_port -> format .encoding = mfmt -> mmal ;
1061
1061
1062
+ if (dev -> rgb_bgr_swapped ) {
1063
+ if (camera_port -> format .encoding == MMAL_ENCODING_RGB24 )
1064
+ camera_port -> format .encoding = MMAL_ENCODING_BGR24 ;
1065
+ else if (camera_port -> format .encoding == MMAL_ENCODING_BGR24 )
1066
+ camera_port -> format .encoding = MMAL_ENCODING_RGB24 ;
1067
+ }
1068
+
1062
1069
camera_port -> format .encoding_variant = 0 ;
1063
1070
camera_port -> es .video .width = f -> fmt .pix .width ;
1064
1071
camera_port -> es .video .height = f -> fmt .pix .height ;
@@ -1569,12 +1576,17 @@ static int set_camera_parameters(struct vchiq_mmal_instance *instance,
1569
1576
return ret ;
1570
1577
}
1571
1578
1579
+ #define MAX_SUPPORTED_ENCODINGS 20
1580
+
1572
1581
/* MMAL instance and component init */
1573
1582
static int __init mmal_init (struct bm2835_mmal_dev * dev )
1574
1583
{
1575
1584
int ret ;
1576
1585
struct mmal_es_format * format ;
1577
1586
u32 bool_true = 1 ;
1587
+ u32 supported_encodings [MAX_SUPPORTED_ENCODINGS ];
1588
+ int param_size ;
1589
+ struct vchiq_mmal_component * camera ;
1578
1590
1579
1591
ret = vchiq_mmal_init (& dev -> instance );
1580
1592
if (ret < 0 )
@@ -1586,21 +1598,48 @@ static int __init mmal_init(struct bm2835_mmal_dev *dev)
1586
1598
if (ret < 0 )
1587
1599
goto unreg_mmal ;
1588
1600
1589
- if ( dev -> component [MMAL_COMPONENT_CAMERA ]-> outputs <
1590
- MMAL_CAMERA_PORT_COUNT ) {
1601
+ camera = dev -> component [MMAL_COMPONENT_CAMERA ];
1602
+ if ( camera -> outputs < MMAL_CAMERA_PORT_COUNT ) {
1591
1603
ret = - EINVAL ;
1592
1604
goto unreg_camera ;
1593
1605
}
1594
1606
1595
1607
ret = set_camera_parameters (dev -> instance ,
1596
- dev -> component [ MMAL_COMPONENT_CAMERA ] ,
1608
+ camera ,
1597
1609
dev );
1598
1610
if (ret < 0 )
1599
1611
goto unreg_camera ;
1600
1612
1601
- format =
1602
- & dev -> component [MMAL_COMPONENT_CAMERA ]->
1603
- output [MMAL_CAMERA_PORT_PREVIEW ].format ;
1613
+ /* There was an error in the firmware that meant the camera component
1614
+ * produced BGR instead of RGB.
1615
+ * This is now fixed, but in order to support the old firmwares, we
1616
+ * have to check.
1617
+ */
1618
+ dev -> rgb_bgr_swapped = true;
1619
+ param_size = sizeof (supported_encodings );
1620
+ ret = vchiq_mmal_port_parameter_get (dev -> instance ,
1621
+ & camera -> output [MMAL_CAMERA_PORT_CAPTURE ],
1622
+ MMAL_PARAMETER_SUPPORTED_ENCODINGS ,
1623
+ & supported_encodings ,
1624
+ & param_size );
1625
+ if (ret == 0 ) {
1626
+ int i ;
1627
+
1628
+ for (i = 0 ; i < param_size /sizeof (u32 ); i ++ ) {
1629
+ if (supported_encodings [i ] == MMAL_ENCODING_BGR24 ) {
1630
+ /* Found BGR24 first - old firmware. */
1631
+ break ;
1632
+ }
1633
+ if (supported_encodings [i ] == MMAL_ENCODING_RGB24 ) {
1634
+ /* Found RGB24 first
1635
+ * new firmware, so use RGB24.
1636
+ */
1637
+ dev -> rgb_bgr_swapped = false;
1638
+ break ;
1639
+ }
1640
+ }
1641
+ }
1642
+ format = & camera -> output [MMAL_CAMERA_PORT_PREVIEW ].format ;
1604
1643
1605
1644
format -> encoding = MMAL_ENCODING_OPAQUE ;
1606
1645
format -> encoding_variant = MMAL_ENCODING_I420 ;
@@ -1614,9 +1653,7 @@ static int __init mmal_init(struct bm2835_mmal_dev *dev)
1614
1653
format -> es -> video .frame_rate .num = 0 ; /* Rely on fps_range */
1615
1654
format -> es -> video .frame_rate .den = 1 ;
1616
1655
1617
- format =
1618
- & dev -> component [MMAL_COMPONENT_CAMERA ]->
1619
- output [MMAL_CAMERA_PORT_VIDEO ].format ;
1656
+ format = & camera -> output [MMAL_CAMERA_PORT_VIDEO ].format ;
1620
1657
1621
1658
format -> encoding = MMAL_ENCODING_OPAQUE ;
1622
1659
format -> encoding_variant = MMAL_ENCODING_I420 ;
@@ -1631,14 +1668,11 @@ static int __init mmal_init(struct bm2835_mmal_dev *dev)
1631
1668
format -> es -> video .frame_rate .den = 1 ;
1632
1669
1633
1670
vchiq_mmal_port_parameter_set (dev -> instance ,
1634
- & dev -> component [MMAL_COMPONENT_CAMERA ]->
1635
- output [MMAL_CAMERA_PORT_VIDEO ],
1671
+ & camera -> output [MMAL_CAMERA_PORT_VIDEO ],
1636
1672
MMAL_PARAMETER_NO_IMAGE_PADDING ,
1637
1673
& bool_true , sizeof (bool_true ));
1638
1674
1639
- format =
1640
- & dev -> component [MMAL_COMPONENT_CAMERA ]->
1641
- output [MMAL_CAMERA_PORT_CAPTURE ].format ;
1675
+ format = & camera -> output [MMAL_CAMERA_PORT_CAPTURE ].format ;
1642
1676
1643
1677
format -> encoding = MMAL_ENCODING_OPAQUE ;
1644
1678
@@ -1660,8 +1694,7 @@ static int __init mmal_init(struct bm2835_mmal_dev *dev)
1660
1694
dev -> capture .enc_level = V4L2_MPEG_VIDEO_H264_LEVEL_4_0 ;
1661
1695
1662
1696
vchiq_mmal_port_parameter_set (dev -> instance ,
1663
- & dev -> component [MMAL_COMPONENT_CAMERA ]->
1664
- output [MMAL_CAMERA_PORT_CAPTURE ],
1697
+ & camera -> output [MMAL_CAMERA_PORT_CAPTURE ],
1665
1698
MMAL_PARAMETER_NO_IMAGE_PADDING ,
1666
1699
& bool_true , sizeof (bool_true ));
1667
1700
0 commit comments