/* * ======== main ======== */ int main(int argc, char *argv[]) { char *inFileName, *outFileName; if (argc <= 1) { inFileName = "in.dat"; outFileName = "out.dat"; createInFileIfMissing(inFileName); } else if (argc != 3 && argc != 4) { printf("Usage: %s input-file output-file\n", argv[0]); exit(1); } else { inFileName = argv[1]; outFileName = argv[2]; } printf("App-> Application started.\n"); if (encodeDecodeFile(inFileName, outFileName) == 0) { printf("App-> Application finished successfully.\n"); } else { printf("App-> Application FAILED.\n"); } return 0; }
/* * ======== smain ======== */ Int smain(Int argc, String argv[]) { Engine_Handle ce = NULL; AUDDEC1_Handle dec = NULL; AUDENC1_Handle enc = NULL; FILE *in = NULL; FILE *out = NULL; String inFile, outFile; Memory_AllocParams allocParams; if (argc <= 1) { inFile = "./in.dat"; outFile = "./out.dat"; createInFileIfMissing(inFile); } else if (argc == 3) { progName = argv[0]; inFile = argv[1]; outFile = argv[2]; } else { fprintf(stderr, usage, argv[0]); exit(1); } GT_0trace(curMask, GT_1CLASS, "App-> Application started.\n"); /* allocate buffers */ allocParams.type = Memory_CONTIGPOOL; allocParams.flags = Memory_NONCACHED; allocParams.align = BUFALIGN; allocParams.seg = 0; inBuf = (XDAS_Int8 *)Memory_alloc(IFRAMESIZE, &allocParams); encodedBuf = (XDAS_Int8 *)Memory_alloc(EFRAMESIZE, &allocParams); outBuf = (XDAS_Int8 *)Memory_alloc(OFRAMESIZE, &allocParams); versionBuf = (XDAS_Int8 *)Memory_alloc(MAXVERSIONSIZE, &allocParams); #if USE_ANCDATA ancBuf = (XDAS_Int8 *)Memory_alloc(ENCANCBUFSIZE, &allocParams); if (ancBuf == NULL) { goto end; } #endif if ((inBuf == NULL) || (encodedBuf == NULL) || (outBuf == NULL) || (versionBuf == NULL)) { goto end; } /* open file streams for input and output */ if ((in = fopen(inFile, "rb")) == NULL) { printf("App-> ERROR: can't read file %s\n", inFile); goto end; } if ((out = fopen(outFile, "wb")) == NULL) { printf("App-> ERROR: can't write to file %s\n", outFile); goto end; } /* reset, load, and start DSP Engine */ if ((ce = Engine_open(engineName, NULL, NULL)) == NULL) { fprintf(stderr, "%s: error: can't open engine %s\n", progName, engineName); goto end; } /* allocate and initialize video decoder on the engine */ dec = AUDDEC1_create(ce, decoderName, NULL); if (dec == NULL) { printf( "App-> ERROR: can't open codec %s\n", decoderName); goto end; } /* allocate and initialize video encoder on the engine */ enc = AUDENC1_create(ce, encoderName, NULL); if (enc == NULL) { fprintf(stderr, "%s: error: can't open codec %s\n", progName, encoderName); goto end; } /* use engine to encode, then decode the data */ encode_decode(enc, dec, in, out); end: /* teardown the codecs */ if (enc) { AUDENC1_delete(enc); } if (dec) { AUDDEC1_delete(dec); } /* close the engine */ if (ce) { Engine_close(ce); } /* close the files */ if (in) { fclose(in); } if (out) { fclose(out); } /* free buffers */ if (inBuf) { Memory_free(inBuf, IFRAMESIZE, &allocParams); } if (encodedBuf) { Memory_free(encodedBuf, EFRAMESIZE, &allocParams); } if (outBuf) { Memory_free(outBuf, OFRAMESIZE, &allocParams); } if (versionBuf) { Memory_free(versionBuf, MAXVERSIONSIZE, &allocParams); } #if USE_ANCDATA if (ancBuf) { Memory_free(ancBuf, ENCANCBUFSIZE, &allocParams); } #endif GT_0trace(curMask, GT_1CLASS, "app done.\n"); return (0); }
/* * ======== smain ======== */ Int smain(String progName, String procId, String engineName, String inFile, String outFile) { Engine_Handle ce = NULL; Engine_Attrs attrs; VIDDEC2_Handle dec = NULL; VIDENC1_Handle enc = NULL; FILE *in = NULL; FILE *out = NULL; Memory_AllocParams allocParams; createInFileIfMissing(inFile); Log_print4(Diags_USER1, "[+1] App-> Application started, procId %s " "engineName %s input-file %s output-file %s.", (IArg)procId, (IArg)engineName, (IArg)inFile, (IArg)outFile); /* allocate input, encoded, and output buffers */ allocParams.type = Memory_CONTIGPOOL; allocParams.flags = Memory_NONCACHED; allocParams.align = BUFALIGN; allocParams.seg = 0; inBuf = (XDAS_Int8 *)Memory_alloc(IFRAMESIZE, &allocParams); encodedBuf = (XDAS_Int8 *)Memory_alloc(EFRAMESIZE, &allocParams); outBuf = (XDAS_Int8 *)Memory_alloc(OFRAMESIZE, &allocParams); versionBuf = (XDAS_Int8 *)Memory_alloc(MAXVERSIONSIZE, &allocParams); if ((inBuf == NULL) || (encodedBuf == NULL) || (outBuf == NULL) || (versionBuf == NULL)) { goto end; } /* open file streams for input and output */ if ((in = fopen(inFile, "rb")) == NULL) { printf("App-> ERROR: can't read file %s\n", inFile); goto end; } if ((out = fopen(outFile, "wb")) == NULL) { printf("App-> ERROR: can't write to file %s\n", outFile); goto end; } /* Initialize attrs fields to default values, and set the procId */ Engine_initAttrs(&attrs); attrs.procId = procId; /* reset, load, and start DSP Engine */ if ((ce = Engine_open(engineName, &attrs, NULL)) == NULL) { fprintf(stderr, "%s: error: can't open engine %s\n", progName, engineName); goto end; } /* allocate and initialize video decoder on the engine */ dec = VIDDEC2_create(ce, decoderName, NULL); if (dec == NULL) { printf( "App-> ERROR: can't open codec %s\n", decoderName); goto end; } /* allocate and initialize video encoder on the engine */ enc = VIDENC1_create(ce, encoderName, NULL); if (enc == NULL) { fprintf(stderr, "%s: error: can't open codec %s\n", progName, encoderName); goto end; } /* use engine to encode, then decode the data */ encode_decode(enc, dec, in, out); end: /* teardown the codecs */ if (enc) { VIDENC1_delete(enc); } if (dec) { VIDDEC2_delete(dec); } /* close the engine */ if (ce) { Engine_close(ce); } /* close the files */ if (in) { fclose(in); } if (out) { fclose(out); } /* free buffers */ if (inBuf) { Memory_free(inBuf, IFRAMESIZE, &allocParams); } if (encodedBuf) { Memory_free(encodedBuf, EFRAMESIZE, &allocParams); } if (outBuf) { Memory_free(outBuf, OFRAMESIZE, &allocParams); } if (versionBuf) { Memory_free(versionBuf, MAXVERSIONSIZE, &allocParams); } Log_print0(Diags_USER1, "[+1] app done."); return (0); }
/* * ======== smain ======== */ Int smain(Int argc, String argv[]) { Engine_Handle ce = NULL; IMGDEC1_Handle dec = NULL; IMGENC1_Handle enc = NULL; FILE *in = NULL; FILE *out = NULL; String inFile, outFile; Memory_AllocParams allocParams; if (argc <= 1) { inFile = "./in.dat"; outFile = "./out.dat"; createInFileIfMissing(inFile); } else if (argc >= 3) { progName = argv[0]; inFile = argv[1]; outFile = argv[2]; } else { fprintf(stderr, usage, argv[0]); exit(1); } if ((argc == 4) && (argv[3][0] == '1')) { appPause = 1; } GT_0trace(curMask, GT_1CLASS, "App-> Application started.\n"); /* allocate buffers */ allocParams.type = Memory_CONTIGPOOL; allocParams.flags = Memory_NONCACHED; allocParams.align = BUFALIGN; allocParams.seg = 0; inBuf = (XDAS_Int8 *)Memory_alloc(IFRAMESIZE, &allocParams); encodedBuf = (XDAS_Int8 *)Memory_alloc(EFRAMESIZE, &allocParams); outBuf = (XDAS_Int8 *)Memory_alloc(OFRAMESIZE, &allocParams); versionBuf = (XDAS_Int8 *)Memory_alloc(MAXVERSIONSIZE, &allocParams); if ((inBuf == NULL) || (encodedBuf == NULL) || (outBuf == NULL) || (versionBuf == NULL)) { goto end; } /* open file streams for input and output */ if ((in = fopen(inFile, "rb")) == NULL) { printf("App-> ERROR: can't read file %s\n", inFile); goto end; } if ((out = fopen(outFile, "wb")) == NULL) { printf("App-> ERROR: can't write to file %s\n", outFile); goto end; } /* reset, load, and start DSP Engine */ if ((ce = Engine_open(engineName, NULL, NULL)) == NULL) { fprintf(stderr, "%s: error: can't open engine %s\n", progName, engineName); goto end; } /* allocate and initialize video decoder on the engine */ dec = IMGDEC1_create(ce, decoderName, NULL); if (dec == NULL) { printf( "App-> ERROR: can't open codec %s\n", decoderName); goto end; } /* allocate and initialize video encoder on the engine */ enc = IMGENC1_create(ce, encoderName, NULL); if (enc == NULL) { fprintf(stderr, "%s: error: can't open codec %s\n", progName, encoderName); goto end; } #ifdef USE_POWER_MANAGEMENT /* open local power manager */ if (Global_usePowerManagement) { LPM_Status lpmStat = LPM_SOK; lpmStat = LPM_open("/dev/lpm0", &lpmHandle); if (lpmStat != LPM_SOK) { fprintf(stderr, "%s: error: LPM_open() failed\n", progName); goto end; } } #endif /* use engine to encode, then decode the data */ encode_decode(enc, dec, in, out); end: #ifdef USE_POWER_MANAGEMENT /* close local power manager */ if (lpmHandle != NULL) { LPM_close(lpmHandle); } #endif /* teardown the codecs */ if (enc) { IMGENC1_delete(enc); } if (dec) { IMGDEC1_delete(dec); } /* close the engine */ if (ce) { Engine_close(ce); } /* close the files */ if (in) { fclose(in); } if (out) { fclose(out); } /* free buffers */ if (inBuf) { Memory_free(inBuf, IFRAMESIZE, &allocParams); } if (encodedBuf) { Memory_free(encodedBuf, EFRAMESIZE, &allocParams); } if (outBuf) { Memory_free(outBuf, OFRAMESIZE, &allocParams); } if (versionBuf) { Memory_free(versionBuf, MAXVERSIONSIZE, &allocParams); } GT_0trace(curMask, GT_1CLASS, "app done.\n"); return (0); }
/* * ======== smain ======== */ Int smain(String progName, String procId, String engineName, String inFile, String outFile) { Engine_Handle ce = NULL; Engine_Attrs attrs; UNIVERSAL_Handle hUniversal = NULL; FILE *in = NULL; FILE *out = NULL; Memory_AllocParams allocParams; XDAS_Int8 *inBuf; XDAS_Int8 *outBuf; XDAS_Int8 *versionBuf; /* acquire optional version from codecs */ /* create the input file if it doesn't already exist */ createInFileIfMissing(inFile); Log_print4(Diags_USER1, "[+1] App-> Application started, procId %s " "engineName %s input-file %s output-file %s.", (IArg)procId, (IArg)engineName, (IArg)inFile, (IArg)outFile); /* * Allocate buffers. * Note that the .flags field (cache) is ignored on BIOS-based systems. */ allocParams.type = Memory_CONTIGPOOL; allocParams.flags = Memory_NONCACHED; allocParams.align = BUFALIGN; allocParams.seg = 0; inBuf = (XDAS_Int8 *)Memory_alloc(IFRAMESIZE, &allocParams); outBuf = (XDAS_Int8 *)Memory_alloc(OFRAMESIZE, &allocParams); versionBuf = (XDAS_Int8 *)Memory_alloc(MAXVERSIONSIZE, &allocParams); if ((inBuf == NULL) || (outBuf == NULL) || (versionBuf == NULL)) { goto end; } /* open file streams for input and output */ if ((in = fopen(inFile, "rb")) == NULL) { printf("App-> ERROR: can't read file %s\n", inFile); goto end; } if ((out = fopen(outFile, "wb")) == NULL) { printf("App-> ERROR: can't write to file %s\n", outFile); goto end; } /* Initialize attrs fields to default values, and set the procId */ Engine_initAttrs(&attrs); attrs.procId = procId; /* Open the Engine */ if ((ce = Engine_open(engineName, &attrs, NULL)) == NULL) { printf("App-> ERROR: can't open engine %s\n", engineName); goto end; } /* allocate and initialize universal alg on the engine */ hUniversal = UNIVERSAL_create(ce, universalName, NULL); if (hUniversal == NULL) { printf( "App-> ERROR: can't open codec %s\n", universalName); goto end; } /* use engine to encode, then decode the data */ processLoop(hUniversal, in, out, inBuf, outBuf, versionBuf); end: /* teardown the codec */ if (hUniversal) { UNIVERSAL_delete(hUniversal); } /* close the engine */ if (ce) { Engine_close(ce); } /* close the files */ if (in) { fclose(in); } if (out) { fclose(out); } /* free buffers */ if (inBuf) { Memory_free(inBuf, IFRAMESIZE, &allocParams); } if (outBuf) { Memory_free(outBuf, OFRAMESIZE, &allocParams); } if (versionBuf) { Memory_free(versionBuf, MAXVERSIONSIZE, &allocParams); } Log_print0(Diags_USER1, "[+1] app done."); return (0); }
/* * ======== smain ======== */ Int smain(Int argc, String argv[]) { Engine_Handle ce = NULL; SCALE_Handle codec = NULL; SCALE_Params params; FILE *in = NULL; FILE *out = NULL; String inFile, outFile; Memory_AllocParams allocParams; unsigned char color_table_temp[1024]={0}; //opencv var IplImage * frame; IplImage * gray_frame = NULL; IplImage * BinaryImage =NULL; CvCapture *cap=cvCreateCameraCapture(0); cvSetCaptureProperty(cap,CV_CAP_PROP_FRAME_WIDTH,320); cvSetCaptureProperty(cap,CV_CAP_PROP_FRAME_HEIGHT,240); cvSetCaptureProperty(cap,CV_CAP_PROP_FPS,30); /*YC added the bmp struct*/ #pragma pack(1) //採用1byte為單位對齊(需要讀檔頭) static struct BMP_file_header { //Total 54 bytes unsigned char Identifier[2]; unsigned long File_Size; unsigned long Reserved; unsigned long Bitmap_Data_Offset; unsigned long Bitmap_Header_Size; unsigned long Width; unsigned long Height; unsigned short Planes; unsigned short Bits_Per_Pixel; unsigned long Compression; unsigned long Bitmap_Data_Size; unsigned long H_Resolution; unsigned long V_Resolution; unsigned long Used_Colors; unsigned long Important_Colors; } BMP_header; #pragma pack() static struct BMP_file_header *header_temp; if (argc <= 1) { inFile = "./test2_8bit_gray.bmp"; outFile = "./test2_8bit_sobel.bmp"; createInFileIfMissing(inFile); } else if (argc == 3) { progName = argv[0]; inFile = argv[1]; outFile = argv[2]; } else { fprintf(stderr, usage, argv[0]); exit(1); } printf("App-> Application started.\n"); /* allocate input, encoded, and output buffers */ allocParams.type = Memory_CONTIGPOOL; allocParams.flags = Memory_NONCACHED; allocParams.align = Memory_DEFAULTALIGNMENT; allocParams.seg = 0; inBuf = (XDAS_Int8 *)Memory_alloc(IFRAMESIZE, &allocParams); outBuf = (XDAS_Int8 *)Memory_alloc(OFRAMESIZE, &allocParams); if ((inBuf == NULL) || (outBuf == NULL)) { goto end; } /* open file streams for input and output */ if ((in = fopen(inFile, "rb")) == NULL) { printf("App-> ERROR: can't read file %s\n", inFile); goto end; } if ((out = fopen(outFile, "wb")) == NULL) { printf("App-> ERROR: can't write to file %s\n", outFile); goto end; } /* reset, load, and start DSP Engine */ if ((ce = Engine_open(engineName, NULL, NULL)) == NULL) { fprintf(stderr, "%s: error: can't open engine %s\n", progName, engineName); goto end; } //copy the Bmp_header header_temp=&BMP_header; fread(header_temp,54,sizeof(unsigned char),in); fwrite(header_temp,54,sizeof(unsigned char),out); //copy the color table BGRA total 256*4=1024 bytes fread(color_table_temp,1024,sizeof(unsigned char),in); fwrite(color_table_temp,1024,sizeof(unsigned char),out); //capture video's frame frame = cvQueryFrame(cap); /* initialize scale factor */ params.size = sizeof(SCALE_Params); params.initialScaleFactor = APP_SCALEFACTOR; /* allocate and initialize scale algo on the engine */ codec = SCALE_create(ce, scaleName, ¶ms); if (codec == NULL) { printf( "App-> ERROR: can't open codec %s\n", scaleName); goto end; } /* use engine to encode, then decode the data */ scale(codec, in, out); end: /* teardown the codec */ if (codec) { SCALE_delete(codec); } /* close the engine */ if (ce) { Engine_close(ce); } /* close the files */ if (in) { fclose(in); } if (out) { fclose(out); } /* free buffers */ if (inBuf) { Memory_free(inBuf, IFRAMESIZE, &allocParams); } if (outBuf) { Memory_free(outBuf, OFRAMESIZE, &allocParams); } printf("app done.\n"); return (0); }