#include <string.h>
#include <android/log.h>
#include <assert.h>
#include <jni.h>
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <errno.h>
#include "include/libyuv.h"
#define LOG_TAG "kylin_yuv_format"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
void yuv_rotate_90(uint8* des,uint8* src,int width,int height)
{
int n = 0;
int hw = width / 2;
int hh = height / 2;
//copy y
for(int j = 0; j < width;j++)
{
for(int i = height - 1; i >= 0; i--)
{
des[n++] = src[width * i + j];
}
}
//copy u
uint8 *ptemp = src + width * height;
for(int j = 0;j < hw;j++)
{
for(int i = hh - 1;i >= 0;i--)
{
des[n++] = ptemp[ hw*i + j ];
}
}
//copy v
ptemp += width * height / 4;
for(int j = 0; j < hw; j++)
{
for(int i = hh - 1;i >= 0;i--)
{
des[n++] = ptemp[hw*i + j];
}
}
}
void yuv_rotate_180(uint8* des,uint8* src,int width,int height)
{
int n = 0;
int hw = width / 2;
int hh = height / 2;
//copy y
for(int j = height - 1; j >= 0; j--)
{
for(int i = width; i > 0; i--)
{
des[n++] = src[width*j + i];
}
}
//copy u
uint8 *ptemp = src + width * height;
for(int j = hh - 1;j >= 0; j--)
{
for(int i = hw; i > 0; i--)
{
des[n++] = ptemp[hw * j + i];
}
}
//copy v
ptemp += width * height / 4;
for(int j = hh - 1;j >= 0; j--)
{
for(int i = hw; i > 0; i--)
{
des[n++] = ptemp[hw * j + i];
}
}
}
void yuv_rotate_270(uint8* des,uint8* src,int width,int height)
{
int n = 0;
int hw = width / 2;
int hh = height / 2;
//copy y
for(int j = width; j > 0; j--)
{
for(int i = 0; i < height;i++)
{
des[n++] = src[width*i + j];
}
}
//copy u
uint8 *ptemp = src + width * height;
for(int j = hw; j > 0;j--)
{
for(int i = 0; i < hh;i++)
{
des[n++] = ptemp[hw * i + j];
}
}
//copy v
ptemp += width * height / 4;
for(int j = hw; j > 0;j--)
{
for(int i = 0; i < hh;i++)
{
des[n++] = ptemp[hw * i + j];
}
}
}
/*
* Class: package_path/class_name
* Method: native_rotate
* Signature: ([BI[BIIII)I
*/
JNIEXPORT jint JNICALL native_rotate
(JNIEnv *env, jobject obj,
jbyteArray src,jbyteArray dst,jint src_width, jint src_height, jint mode)
{
LOGI("native_rotate %d",mode);
jbyte* src_data = env->GetByteArrayElements( src, JNI_FALSE);
LOGD("rotate src_data[0-7]=%d %d %d %d %d %d %d %d",src_data[0],src_data[1],src_data[2],src_data[3],src_data[4],src_data[5],src_data[6],src_data[7]);
int src_len = env->GetArrayLength(src);
LOGI("src_len:%d",src_len);
jbyte *dst_data = env->GetByteArrayElements(dst, JNI_FALSE);
int dst_len = env->GetArrayLength(dst);
LOGI("dst_len:%d",dst_len);
memset(dst_data,0,dst_len);
if(mode ==90){
yuv_rotate_90((uint8 *)dst_data,(uint8 *)src_data,src_width,src_height);
}else if(mode ==180){
yuv_rotate_180((uint8 *)dst_data,(uint8 *)src_data,src_width,src_height);
}else if(mode ==270){
yuv_rotate_270((uint8 *)dst_data,(uint8 *)src_data,src_width,src_height);
}else{
LOGE("Not support degree!!!");
}
LOGD("rotate dst_data[0-7]=%d %d %d %d %d %d %d %d",dst_data[0],dst_data[1],dst_data[2],dst_data[3],dst_data[4],dst_data[5],dst_data[6],dst_data[7]);
env->ReleaseByteArrayElements(src,src_data,0);
env->ReleaseByteArrayElements(dst,dst_data,0);
LOGI("native_rotate 2");
return 1;
}
jboolean _initialize(JNIEnv* env, jobject thiz, jobject weak_thiz)
{
return JNI_TRUE;
}
static JNINativeMethod gMethods[] = {
{"native_rotate", "([B[BIII)I", (void*)native_rotate},
};
static int registerNativeMethods(JNIEnv* env
, const char* className
, JNINativeMethod* gMethods, int numMethods) {
jclass clazz;
clazz = env->FindClass(className);
if (clazz == NULL) {
return JNI_FALSE;
}
if (env->RegisterNatives(clazz, gMethods, numMethods) < 0) {
return JNI_FALSE;
}
return JNI_TRUE;
}
static int registerNatives(JNIEnv* env) {
const char* kClassName = "com/package_path/class_name";
return registerNativeMethods(env, kClassName, gMethods,
sizeof(gMethods) / sizeof(gMethods[0]));
}
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) {
JNIEnv* env = NULL;
jint result = -1;
if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
return -1;
}
assert(env != NULL);
if (!registerNatives(env)) {
return -1;
}
result = JNI_VERSION_1_4;
return result;
}
该算法为Y、U、V三个分量拷贝方式做旋转,可作为验证或演示两种用途,不能满足性能要求。yuv数据算法可参照安卓源码库中的external\libyuv以及开源库ffmpeg。
分享到:
相关推荐
yuv格式的视频帧旋转处理。算法可以相应的应用到图像处理上面
压缩包内含1张测试用的320x240大小的...RawViewer1.0是一款用于查看播放yuv文件的播放器,支持查看播放及几何变换,可水平镜像、垂直镜像、图像转置、图像缩放与旋转等。 如果打不开图片,请在打开图片时配置图片参数。
Android 使用libyuv对Android yuv数据进行缩放,旋转,镜像,裁剪等操作
对初学视频图像处理,旋转,了解YUV420p图像存储格式有帮助。
史上最强YUV转换RenderScript,支持转换为RGBA、BGRA,同时支持旋转和翻转。 YUV数据格式支持NV21、YV12、YUV420_888,对应Android Camera1API和Camera2 API的YUV处理。 这段时间在做一些Android Camera数据处理相关...
NV21图像旋转、平移、缩放、画矩形的C++实现,作为参考
资源运行环境Android studio, java代码对RGB和YUV图像后台GPU加速flip rotate scale scrop处理, 可直接运行
分别在 CPU 上使用 C 语言和在 GPU 上使用 OpenCL 对一张 YUV420p 的图像顺时针旋转 90 度,比较两者之间的性能差异。
可用,NV21图像,1920*1280,可通过改变变量值换成别的尺寸的图像,缩放应该为2的倍数
Camera预览时需要对yuv帧做水平翻转处理,直接在onPreviewFrame(byte[] data, Camera camera)里调用Mirror函数,处理完后的图片和预览效果成水平翻转关系。 nv21的镜像算法: private void Mirror(byte[] src, int...
本人取一帧数据保存成.yuv数据,同学运行时,自己创建android,将mainAct和res/mian_layout覆盖即可。.yuv数据一定存放在sdcard下(adb shell),自己确定好路径,即可实现效果
yuv图片不同角度旋转并且转成图片
C高级语言程序编写的代码,实现图片的放大,缩小,旋转,增强等功能.
同时在完成实验要求之余,了解了YUV格式和图像负片转化。最后,对图像用matlab导出了matlab内置app和可安装的独立运行的可执行文件。实验为了避免在matlab中出现乱码,GUI界面和代码注释都用采用英文。
支持像框,支持图像旋转180度,支持win7,支持yuv2格式视频流!。使用本软件,您可以拍出的可爱照片制作个人相册,给朋友做贺卡,可以制作动画,记录小宝宝的成长足迹,发给您的亲人网友。提供avi转换为gif功能.
(必做题具体为:以图像中心为原点旋转α+倍率β的变换。设计性选做题为:图像纵方向线性缩小、图像横方向波澜平移、几何校正)(学时:4 ) 实验四 彩色图像处理 (选作:给定ChromeKey,进行图像合成。YUV中UV...
3.练习图像读写命令imread和imwrite并进行图像文件格式间的转换;4.示一幅自定义格式的裸图像Miss America;5.显示JPG,BMP,PCX等格式的图像文件;6.编写程序完成颜色空间的转换RGB -> YUV -> RGB;7.显示...
2.旋转方向后依然无法识别时,可以尝试saveImg( ),保存本地检查图片是否符合要求。 /** * 视频顺时针旋转90 * 该方法仅仅在竖屏时候使用 * */ public static byte[] rotateYUV420Degree90(byte[] data, int ...
这是linux或国产系统上(UOS、麒麟)USB摄像头的测试程序,主要功能有 ...7、预览视频图片的旋转 本程序在ubutn16.4、UOS和麒麟系统测试过,主要代码在ubutn(x86_64)上开发,在麒麟arm上进行过构建
matlab实现图像各种色域转换功能,包含RGB,HSI,YUV,灰度图之间的相互转换。