How does android implement the frontend camera selfie image function?
The default front-end camera, text "XI" is displayed as "IX" during preview (the front-end camera preview has the mirror effect by default), and the photo taken is "XI ", how can we ensure that the photo we take is "IX", that is, consistent with the preview?
For a normal single shot (non-ZSD or other photo mode), the code to be modified is the on1__capture () method in the normalShot. cpp file,
Change the original
Bool
NormalShot ::
On1__capture ()
{
AutoCPTLog cptlog (Event_Shot_capture );
MBOOL ret = MTRUE;
NSCamShot: ISingleShot * pSingleShot = NSCamShot: ISingleShot: createInstance (static_cast (Mu4ShotMode), "NormalShot ");
......
// Shot param
NSCamShot: ShotParam rShotParam (eImgFmt_YUY2, // yuv format
MShotParam. mi4PictureWidth, // picutre width
MShotParam. mi4PictureHeight, // picture height
MShotParam. mi4Rotation, // picture rotation
0, // picture flip
EPostViewFmt, // postview format
MShotParam. mi4PostviewWidth, // postview width
MShotParam. mi4PostviewHeight, // postview height
0, // postview rotation
0, // postview flip
MShotParam. mu4ZoomRatio // zoom
);
......
}
To:
Bool
NormalShot ::
On1__capture ()
{
AutoCPTLog cptlog (Event_Shot_capture );
MBOOL ret = MTRUE;
NSCamShot: ISingleShot * pSingleShot = NSCamShot: ISingleShot: createInstance (static_cast (Mu4ShotMode), "NormalShot ");
......
// Shot param
NSCamShot: ShotParam rShotParam (eImgFmt_YUY2, // yuv format
MShotParam. mi4PictureWidth, // picutre width
MShotParam. mi4PictureHeight, // picture height
MShotParam. mi4Rotation, // picture rotation
(GetOpenId () = 1? 1-0), // picture flip // here is the modified Code. Change the value here to 1, and the bottom layer will perform horizontal flip for the image, which is equivalent to mirror.
EPostViewFmt, // postview format
MShotParam. mi4PostviewWidth, // postview width
MShotParam. mi4PostviewHeight, // postview height
0, // postview rotation
0, // postview flip
MShotParam. mu4ZoomRatio // zoom
);
......
}
Change the flip value in the rShotParam parameter to 1. If the value is 1, the underlying layer performs the image as a horizontal flip. If the value is 0, the image is not made.
(GetOpenId () = 1? 1-0 is used only for testing. It indicates to determine whether the current camera is a front-end camera. If it is a front-end camera, the value is 1)
Note:
In actual application, add a new Flip parameter in Parameters, and pass the Flip value to the HAL layer through Parameters in the app to notify the underlying layer of flip. (to avoid affecting CTS testing and third-party applications, do not write the flip value mentioned above as 1 .)
The files involved in the modification are mainly as follows:
NormalShot. cpp (mediatek \ platform \ mt6589 \ hardware \ camera \ hal \ adapter \ scenario \ shot \ normalshot)
IShot. h (mediatek \ platform \ mt6589 \ hardware \ camera \ hal \ adapter \ inc \ scenario \ shot)
CameraParameters. cpp (frameworks \ av \ camera)
CameraParameters. h (frameworks \ av \ include \ camera)
ParamsManager. update. cpp (mediatek \ hardware \ camera \ common \ paramsmgr \ params)
MtkPhotoCamAdapter. Capture. cpp (mediatek \ platform \ mt6589 \ hardware \ camera \ hal \ adapter \ mtkphoto)
Camera. java (\ frameworks \ base \ core \ java \ android \ hardware \)