Camera 增加1:1拍照

---- vendor/mediatek/proprietary/packages/apps/Camera/res/values/arrays.xml ----
index 80c4b3a..ab8528f 100755
@@ -406,6 +406,9 @@
         <item>@string/pref_camera_picturesize_entry_1280x960</item>
         <item>@string/pref_camera_picturesize_entry_2048x1536</item>
         <item>@string/pref_camera_picturesize_entry_2592x1936</item>
+        <!-- 1:1 -->
+        <item>@string/pref_camera_picturesize_entry_1280x768</item>
+        <item>@string/pref_camera_picturesize_entry_3328x1872</item>
     </string-array>
 
     <!-- When launching the camera app first time, we will set the picture
@@ -461,6 +464,9 @@
         <item>1440x960</item>
         <item>2048x1360</item>
         <item>2560x1712</item>
+        <!-- 1:1 -->
+        <item>960x960</item>
+        <item>2448x2448</item>
     </string-array>
 
     <string-array name="pref_camera_picturesize_ratio_entries" translatable="false">
@@ -468,12 +474,14 @@
         <item>@string/pref_camera_picturesize_ratio_entry_5_3</item>
         <item>@string/pref_camera_picturesize_ratio_entry_3_2</item>
         <item>@string/pref_camera_picturesize_ratio_entry_4_3</item>
+        <item>@string/pref_camera_picturesize_ratio_entry_1_1</item>
     </string-array>
     <string-array name="pref_camera_picturesize_ratio_entryvalues" translatable="false">
         <item>1.7778</item>
         <item>1.6667</item>
         <item>1.5</item>
         <item>1.3333</item>
+        <item>1</item>
     </string-array>
 
     <!-- Default focus mode setting.-->


--- vendor/mediatek/proprietary/packages/apps/Camera/res/values/strings.xml ---
index 59bdb96..0869eba 100755
@@ -201,6 +201,7 @@
     <string name="pref_camera_picturesize_ratio_entry_5_3" translatable="false">@string/pref_camera_picturesize_ratio_entry_16_9</string>
     <string name="pref_camera_picturesize_ratio_entry_3_2" translatable="false">@string/pref_camera_picturesize_ratio_entry_16_9</string>
     <string name="pref_camera_picturesize_ratio_entry_4_3">Standard (4:3)</string>
+    <string name="pref_camera_picturesize_ratio_entry_1_1">Square (1:1)</string>
     <!-- ISO -->
     <string name="pref_camera_iso_title" translatable="false">ISO</string>
     <string name="pref_camera_iso_default" translatable="false">auto</string>


 vendor/mediatek/proprietary/packages/apps/Camera/src/com/mediatek/camera/setting/SettingDataBase.java 
index 7d5336f..e2bec4e 100755
@@ -386,6 +386,7 @@ public class SettingDataBase {
     private static final String PICTURE_RATIO_5_3 = "1.6667";
     private static final String PICTURE_RATIO_3_2 = "1.5";
     private static final String PICTURE_RATIO_4_3 = "1.3333";
+    private static final String PICTURE_RATIO_1_1 = "1";
     
     private static final String[] PICTURE_SIZE_4_3 = new String[] {
         "320x240",
@@ -437,6 +438,10 @@ public class SettingDataBase {
         "2048x1360",
         "2560x1712"
     };
+    private static final String[] PICTURE_SIZE_1_1 = new String[] {
+        "2448x2448",
+        "960x960",
+ };
     
     public static final String[] VIDEO_QUALITY_WHITHOUT_FINE = new String[] {
         Integer.toString(CamcorderProfileEx.QUALITY_HIGH) ,
@@ -605,6 +610,15 @@ public class SettingDataBase {
                     .setEnable(true)
                     .setMappingFinder(new PictureSizeMappingFinder())
                     .setValues(PICTURE_SIZE_3_2)),
+        
+ new Restriction(SettingConstants.ROW_SETTING_PICTURE_RATIO)
+            .setType(Restriction.TYPE_SETTING)
+            .setValues(PICTURE_RATIO_1_1)
+            .setRestrictions(
+                new Restriction(SettingConstants.ROW_SETTING_PICTURE_SIZE)
+                    .setEnable(true)
+                    .setMappingFinder(new PictureSizeMappingFinder())
+                    .setValues(PICTURE_SIZE_1_1)),
                     
         new Restriction(SettingConstants.ROW_SETTING_SMILE_SHOT)
             .setValues("on")


 vendor/mediatek/proprietary/packages/apps/Camera/src/com/mediatek/camera/setting/SettingUtils.java 
index 0fbb09f..d3329d1 100755
@@ -310,6 +310,7 @@ public class SettingUtils {
         if (context != null && parameters != null) {
             // Add standard preview ratio.
             supportedRatios.add(getRatioString(4d / 3));
+            supportedRatios.add(getRatioString(1d / 1));
 
             mCurrentFullScreenRatio = findFullscreenRatio(context);
             List<String> fullScreenPictureSizes = buildSupportedPictureSizeByRatio(parameters,


 vendor/mediatek/proprietary/packages/apps/Camera/src/com/mediatek/camera/v2/util/Utils.java 
index dfe4537..8f51724 100755
@@ -100,7 +100,7 @@ public class Utils {
     public static final String               RESET_STATE_VALUE_DISABLE = "disable-value";
     /** Orientation hysteresis amount used in rounding, in degrees. */
     public static final int                  ORIENTATION_HYSTERESIS = 5;
-    public static final double[]             RATIOS = new double[] { 1.3333, 1.5, 1.6667, 1.7778 };
+    public static final double[]             RATIOS = new double[] { 1, 1.3333, 1.5, 1.6667, 1.7778 };
     public static final double               ASPECT_TOLERANCE = 0.02;
     private static ImageFileNamer            sImageFileNamer;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用 GStreamer 中的多个插件来实现拍照功能,例如 v4l2sink、jpegenc 和 multifilesink。具体流程为:先通过 v4l2src 插件采集视频流,然后将视频流转换为 JPEG 格式并保存到文件中,最后将 JPEG 文件显示在 xvimagesink 上。 以下是一个示例程序,可以启动 MIPI CSI 摄像头的预览,并在按下回车键后拍照并保存 JPEG 文件: ```c #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <fcntl.h> #include <termios.h> #include <sys/select.h> #include <sys/time.h> #define WIDTH 720 #define HEIGHT 576 #define FPS 15 int main(void) { // 设置环境变量 setenv("DISPLAY", ":0.0", 1); setenv("XDG_RUNTIME_DIR", "/run/user/1000", 1); // 检查摄像头设备文件是否存在 char *dev_path = NULL; if (access("/dev/video51", F_OK) == 0) { dev_path = "/dev/video51"; } else if (access("/dev/video31", F_OK) == 0) { dev_path = "/dev/video31"; } else if (access("/dev/video11", F_OK) == 0) { dev_path = "/dev/video11"; } else { fprintf(stderr, "Can not find camera!!!\n"); return 1; } // 启动预览 pipeline char cmd[256]; snprintf(cmd, sizeof(cmd), "gst-launch-1.0 v4l2src device=%s io-mode=4 ! video/x-raw,format=NV12,width=%d,height=%d,framerate=%d/1 ! xvimagesink > /dev/null 2>&1 &", dev_path, WIDTH, HEIGHT, FPS); system(cmd); printf("MIPI CSI Camera Preview started!\n"); // 设置串口 struct termios tty; memset(&tty, 0, sizeof(tty)); tty.c_iflag = IGNBRK; tty.c_oflag = 0; tty.c_cflag = CS8 | CREAD | CLOCAL; tty.c_lflag = 0; tty.c_cc[VTIME] = 0; tty.c_cc[VMIN] = 1; cfsetospeed(&tty, B115200); cfsetispeed(&tty, B115200); int fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY); tcsetattr(fd, TCSANOW, &tty); fcntl(fd, F_SETFL, O_NONBLOCK); printf("Press Enter to take a photo...\n"); while (1) { fd_set fds; FD_ZERO(&fds); FD_SET(fd, &fds); struct timeval tv = {0}; tv.tv_sec = 1; int ret = select(fd + 1, &fds, NULL, NULL, &tv); if (ret > 0) { char buf[256]; read(fd, buf, sizeof(buf)); if (buf[0] == '\n') { // 拍照 char filename[256]; snprintf(filename, sizeof(filename), "photo-%ld.jpg", time(NULL)); snprintf(cmd, sizeof(cmd), "gst-launch-1.0 v4l2src device=%s ! video/x-raw,format=NV12,width=%d,height=%d,framerate=%d/1 ! jpegenc ! multifilesink location=%s > /dev/null 2>&1", dev_path, WIDTH, HEIGHT, FPS, filename); system(cmd); printf("Photo saved to %s\n", filename); } } } close(fd); return 0; } ``` 在程序中,我们使用了 select 函数来监听串口输入,如果读取到回车键,则执行拍照操作。拍照时,我们使用 jpegenc 插件将视频流转换为 JPEG 格式,然后使用 multifilesink 插件将 JPEG 文件保存到指定路径下。同时,预览 pipeline 依然在后台运行,可以在拍照后继续进行预览。 需要注意的是,如果使用该程序,需要在终端上按下 Enter 键才能拍照,而且需要连接串口设备。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值