jint NV_ReadData(JNIEnv *env, jobject object, jlong handler, jbyteArray data, jint size)
{
#ifdef DEBUG
	unsigned long cost = GTimeGet();
#endif
	jint ret = 0;
	jboolean isCopy = false;
	LPVIDEO engine = (LPVIDEO)handler;

	signed char* buffer = env->GetByteArrayElements(data, &isCopy);
	if (buffer == NULL) {
		LOGI("buffer failed!\n");
		return 0;
	}

	//LOGE("%d, %d", engine->mSourceFormat, engine->mTargetFormat);
	ret = Read_Video(engine->mHandle, engine->pSourceBuffer, engine->mSourceSize);
#ifdef DEBUG
	LOGE("Read_Video = %d", ret);
#endif
	if (ret > 0) {
		if (engine->mSourceFormat == CP_MJPEG) { //MJPG PROCESS
			ret = mjpg_raw_insert_huffman(engine->pSourceBuffer, ret, (unsigned char *)engine->pTargetBuffer);
			//mjpg data. decode to raw and convert.
#ifdef DEBUG
			LOGE("mjpeg full size = %d", ret);
#endif
			if (engine->mTargetFormat == CP_MJPEG) {
				memcpy(buffer, engine->pTargetBuffer, ret);
#ifdef DEBUG_DUMP
				if (engine->frame > 0) {
					fwrite(engine->pTargetBuffer, sizeof(char), ret, engine->pfile);
					fclose(engine->pfile);
					engine->frame = 0;
				}
#endif
			} else {
				LOGE("NOT SUPPORT DECODE!");
			}
		} else if (engine->mSourceFormat != engine->mTargetFormat) {
			if (engine->mSourceFormat == CP_PAF_YUYV && engine->mTargetFormat == CP_PAF_NV21) {
				convert_YUYV_NV21(engine->pSourceBuffer, (unsigned char *)buffer, engine->mWidth, engine->mHeight);
				ret = calcImageSize(engine->mWidth, engine->mHeight, engine->mTargetFormat);
			} else if (engine->mSourceFormat == CP_PAF_YUYV && engine->mTargetFormat == CP_PAF_NV12) {
				convert_YUYV_NV12(engine->pSourceBuffer, (unsigned char *)buffer, engine->mWidth, engine->mHeight);
				ret = calcImageSize(engine->mWidth, engine->mHeight, engine->mTargetFormat);
			} else {
				LOGE("convert color format failed!");
				ret = 0;
			}
		} else {
			// copy out
			memcpy(buffer, engine->pSourceBuffer, engine->mSourceSize);
		}
	}

	env->ReleaseByteArrayElements(data, buffer, isCopy);

	return ret;
}
bool DHVideoDecoder::decode( const char* pData, int len, StreamPlug::COLOR_FORMAT cf )
{
	unsigned long dwFrameTypeFlag = *(unsigned long*)pData;
	int nNewWidth = m_nWidth;
	int nNewHeight = m_nHeight;
	if( dwFrameTypeFlag == DH_IFRAME_FLAG )
	{
		m_bSeeIFrame = true;
		calcImageSize( (unsigned char*)pData, len, nNewWidth, nNewHeight );
	}
	if( !m_bSeeIFrame )
		return false;
	
	unsigned long dwNewSize = (nNewWidth*nNewHeight>>1)*3;
	if ( m_nWidth != nNewWidth || m_nHeight != nNewHeight )
	{
		unsigned long dwOldSize = (m_nWidth*m_nHeight>>1)*3;
		m_nWidth = nNewWidth;
		m_nHeight = nNewHeight;
		if( dwNewSize > dwOldSize )
		{
			if ( m_pDecBuff )
				delete []m_pDecBuff;
			m_pDecBuff = new char[ dwNewSize ];
		}
		afkdec_resize( m_decHandler, m_nWidth, m_nHeight );
	}
Exemple #3
0
// 画像ファイルを読み込み、
// type,width,heightを計算
// @param file_name 読み込む画像ファイル名
int open_ImageFile(ImageData *this_,const char *file_name){
  FILE *fp;

  this_->width = -1;
  this_->height = -1;
  this_->type = Type_NONE;

  if((fp = fopen(file_name,"rb")) == NULL){
	fprintf(stderr,
			"error:  %s(%d)::open_ImageFile() - cannot open File '%s'\n",
			__FILE__,__LINE__,file_name);
	return -1;
  }
  // ファイルサイズを求める
  {
	fpos_t fsize;
	// MinGW では __pos が不要
#if __WIN32__
	fsize = 0;
#else
	fsize.__pos = 0;
#endif
	fseek(fp,0,SEEK_END);
	fgetpos(fp,&fsize);
	// MinGW では __pos が不要
#if __WIN32__
	this_->data_size = (unsigned int)fsize;
#else
	this_->data_size = (unsigned int)fsize.__pos;
#endif
	rewind(fp);
  }

  // 領域確保とデータ読み込み
  this_->raw_data = (byte*)new_(this_->data_size);
  {
	int c;
	unsigned int i;
	for(i=0;i<this_->data_size; i++){
	  if(feof(fp) || (c=fgetc(fp))==EOF){
		fprintf(stderr,
				"error:  %s(%d)::open_ImageFile() - can not read File '%s'\n",
				__FILE__,__LINE__,file_name);
		this_->data_size = 0;
		delete_(this_->raw_data);
		fclose(fp);
		this_->raw_data = NULL;
		return -1;
	  }
	  this_->raw_data[i] = (byte)c;
	}
  }
  fclose(fp);

  // 画像のフォーマット特定、サイズの計算
  calcImageSize(this_);
  return 0;
}
Exemple #4
0
int main(int argc, char **argv) {
    printf("\n");
    printf("Welcome to Rasterizer 3000.\n");
    printf("===========================\n\n");

    Config config;

    int rows, //9175,
        cols, //6814,
        i,
        j;

    calcImageSize(&config, &rows, &cols);

    Index index;
    index.nodes = malloc(rows*cols*sizeof(PointNode *));
    index.config = &config;
    index.rows = rows;
    index.cols = cols;

    Image image;
    image.pixels = malloc(rows*cols*sizeof(float));
    image.rows = rows;
    image.cols = cols;
    image.config = &config;

    // Initialize arrays
    for (j=0; j<rows; j++) {
        for (i=0; i<cols; i++) {
            *(index.nodes+(j*cols)+i) = 0;
            *(image.pixels+(j*cols)+i) = EMPTY_VAL;
        }
    }

    // data
    readPointsFromFile("sample.txt", &index);

    printIndexBins(&index);

    rasterize(&index, &image);

    printImage(&image);

    free(image.pixels);
    free(index.nodes);
    return 0;
}
jint NV_Set(JNIEnv *env, jobject object, jlong handler, jint width, jint height, jint format)
{
	LPVIDEO engine = (LPVIDEO)handler;
	int f = 0;

	engine->mWidth = width;
	engine->mHeight = height;
	engine->mTargetFormat = format;

	if (engine->pTargetBuffer != NULL) {
		free(engine->pTargetBuffer);
	}
	engine->mTargetSize = calcImageSize(width, height, engine->mTargetFormat);
	engine->pTargetBuffer = (unsigned char*)malloc(engine->mTargetSize);
	if (engine->pTargetBuffer == NULL) {
		LOGE("malloc fail");
		return -1;
	}

	//set source format and set output format.
	engine->mSourceFormat = CP_MJPEG;
	if (engine->mTargetFormat == CP_PAF_NV12) {
		if (1 == Check_Format(engine->mHandle, V4L2_PIX_FMT_NV12)) {
			f = V4L2_PIX_FMT_NV12;
			engine->mSourceFormat = CP_PAF_NV12;
		} else if (1 == Check_Format(engine->mHandle, V4L2_PIX_FMT_YUYV)) {
			f = V4L2_PIX_FMT_YUYV;
			engine->mSourceFormat = CP_PAF_YUYV;
		}
	} else if (engine->mTargetFormat == CP_PAF_NV21) {
		if (1 == Check_Format(engine->mHandle, V4L2_PIX_FMT_NV21)) {
			f = V4L2_PIX_FMT_NV21;
			engine->mSourceFormat = CP_PAF_NV21;
		} else if (1 == Check_Format(engine->mHandle, V4L2_PIX_FMT_YUYV)) {
			f = V4L2_PIX_FMT_YUYV;
			engine->mSourceFormat = CP_PAF_YUYV;
		}
	} else if (engine->mTargetFormat == CP_PAF_YUYV) {
		if (1 == Check_Format(engine->mHandle, V4L2_PIX_FMT_YUYV)) {
			f = V4L2_PIX_FMT_YUYV;
			engine->mSourceFormat = CP_PAF_YUYV;
		}
	} else if (engine->mTargetFormat == CP_MJPEG) {
		if (1 == Check_Format(engine->mHandle, V4L2_PIX_FMT_MJPEG)) {
			f = V4L2_PIX_FMT_MJPEG;
			engine->mSourceFormat = CP_MJPEG;
		}
	}

	if (f == 0) {
		LOGE("NOT SUPPORT");
		return -1;
	}
#ifdef DEBUG
	LOGE("setting %d, %d", engine->mSourceFormat, engine->mTargetFormat);
#endif
	if (engine->pSourceBuffer != NULL) {
		free(engine->pSourceBuffer);
	}
	engine->mSourceSize = calcImageSize(width, height, engine->mSourceFormat);
	engine->pSourceBuffer = (unsigned char*)malloc(engine->mSourceSize);
	if (engine->pSourceBuffer == NULL) {
		LOGE("malloc fail");
		return -1;
	}

	if (Set_Video(engine->mHandle, width, height, f) == -1) {
		LOGE("Set_Video fail");
		return -1;
	}

	return 0;
}