int main( int argc, char **argv ) { int i; progname = argv[0]; for (i = 1; i < argc && argv[i][0] == '-'; i++) switch (argv[i][1]) { case 'd': /* debug output */ i++; if (badarg(argc-i, argv+i, "s")) goto userr; if ((debugfp = fopen(argv[i], "w")) == NULL) { perror(argv[i]); exit(1); } SET_FILE_BINARY(debugfp); newheader("RADIANCE", debugfp); /* start */ printargs(argc, argv, debugfp); /* header */ break; case 'p': /* picture position */ if (badarg(argc-i-1, argv+i+1, "iiiiiiii")) goto userr; bounds[0][0] = atoi(argv[++i]); bounds[0][1] = atoi(argv[++i]); bounds[1][0] = atoi(argv[++i]); bounds[1][1] = atoi(argv[++i]); bounds[2][0] = atoi(argv[++i]); bounds[2][1] = atoi(argv[++i]); bounds[3][0] = atoi(argv[++i]); bounds[3][1] = atoi(argv[++i]); scanning = 2; break; case 'P': /* pick position */ scanning = 3; break; case 'i': /* irradiance factor */ i++; if (badarg(argc-i, argv+i, "f")) goto userr; irrad = atof(argv[i]); break; case 'm': /* raw map output */ rawmap = 1; break; case 'c': /* color input */ scanning = 0; break; default: goto userr; } /* open files */ if (i < argc && freopen(argv[i], "r", stdin) == NULL) { perror(argv[i]); exit(1); } if (i+1 < argc && freopen(argv[i+1], "w", stdout) == NULL) { perror(argv[i+1]); exit(1); } if (scanning) { /* load input picture header */ SET_FILE_BINARY(stdin); if (checkheader(stdin, COLRFMT, NULL) < 0 || fgetresolu(&xmax, &ymax, stdin) < 0) { fprintf(stderr, "%s: bad input picture\n", progname); exit(1); } if (scanning == 3) { if (i >= argc) goto userr; pickchartpos(argv[i]); scanning = 2; } } else { /* else set default xmax and ymax */ xmax = 512; ymax = 2*512/3; } if (scanning != 2) { /* use default boundaries */ bounds[0][0] = bounds[2][0] = .029*xmax + .5; bounds[0][1] = bounds[1][1] = .956*ymax + .5; bounds[1][0] = bounds[3][0] = .971*xmax + .5; bounds[2][1] = bounds[3][1] = .056*ymax + .5; } init(); /* initialize */ if (scanning) /* get picture colors */ getpicture(); else getcolors(); compute(); /* compute color mapping */ if (rawmap) { /* print out raw correspondence */ register int j; printf("# Color correspondence produced by:\n#\t\t"); printargs(argc, argv, stdout); printf("#\tUsage: pcwarp %s uncorrected.hdr > corrected.hdr\n", i+1 < argc ? argv[i+1] : "{this_file}"); printf("#\t Or: pcond [options] -m %s orig.hdr > output.hdr\n", i+1 < argc ? argv[i+1] : "{this_file}"); for (j = 0; j < 24; j++) printf("%f %f %f %f %f %f\n", colval(inpRGB[j],RED), colval(inpRGB[j],GRN), colval(inpRGB[j],BLU), colval(mbRGB[j],RED), colval(mbRGB[j],GRN), colval(mbRGB[j],BLU)); if (scanning && debugfp != NULL) cwarp(); /* color warp for debugging */ } else { /* print color mapping */ /* print header */ printf("{\n\tColor correction file computed by:\n\t\t"); printargs(argc, argv, stdout); printf("\n\tUsage: pcomb -f %s uncorrected.hdr > corrected.hdr\n", i+1 < argc ? argv[i+1] : "{this_file}"); if (!scanning) printf("\t Or: pcond [options] -f %s orig.hdr > output.hdr\n", i+1 < argc ? argv[i+1] : "{this_file}"); printf("}\n"); putmapping(); /* put out color mapping */ } if (debugfp != NULL) { /* put out debug picture */ if (scanning) picdebug(); else clrdebug(); } exit(0); userr: fprintf(stderr, "Usage: %s [-d dbg.hdr][-P | -p xul yul xur yur xll yll xlr ylr][-i irrad][-m] input.hdr [output.{cal|cwp}]\n", progname); fprintf(stderr, " or: %s [-d dbg.hdr][-i irrad][-m] -c [xyY.dat [output.{cal|cwp}]]\n", progname); exit(1); return 1; /* pro forma return */ }
int DecompressFrame(unsigned char *cdata,int size,unsigned char **outdata,int outsize) { static int first=1,framenum=0; //Initialize output pointers... yp=NULL; up=NULL; vp=NULL; // Copy to other buffer can be done... // So that source buffer will be free cindex=0; // index into the cframe.... csize=size; // size of compressed frame cframe=cdata; // pointer to compressed frme //memcpy(cframe,cdata,size); // Reset the pointers... initbits(); // Get the frame header getheader(); // If first time...then call initdecoder.... // This has to be done after calling getheader() // because getheader() setup some variables using the information // from header... if (first) { initdecoder(); first = 0; } // Decompress the frame and get the picture frame in YUV format getpicture(&framenum); framenum++; if(yp==NULL || up==NULL || vp==NULL) { myLog.WriteLog((char*)"DecompressFrame",(char*)"decompression failed..."); return 0; } *outdata = yp; /* if(yp!=NULL && up!=NULL && vp!=NULL){ FILE *fpyuv; if (framenum==1) fpyuv=fopen("/sdcard/video2.yuv","wb"); else fpyuv=fopen("/sdcard/video2.yuv","ab"); if (fpyuv!=NULL){ char sMsgLog[128]; int iUVSize = (horizontal_size/2) * (vertical_size/2); fwrite(yp,1,horizontal_size * vertical_size+(iUVSize*2), fpyuv); fclose(fpyuv); } }*/ return 1; // convert YUV to RGB // ******* TODO ********* // check if outdata is enough to store rgb data // int totalsize=horizontal_size * vertical_size *4; if(outsize< totalsize || outdata==NULL) { myLog.WriteLog((char*)"DecompressFrame",(char*)"Output buffer is not sufficient"); return 0; } // ConvertYUVtoRGB32(yp,up,vp,outdata,horizontal_size,vertical_size); /*FILE *fpyuv; char sFileName[128]; sprintf(sFileName, "/sdcard/video_%d.rgba", framenum); fpyuv=fopen(sFileName,"wb"); if (fpyuv!=NULL){ fwrite(outdata,1,horizontal_size * vertical_size*4, fpyuv); fclose(fpyuv); }*/ //myLog.WriteLog((char*)"DecompressFrame()",(char*)"Decode SUCCESSFUL :-)"); return 1;
int DecompressFrame(unsigned char *cdata,int size,unsigned char *outdata,int outsize) { static int first=1,framenum=0; //Initialize output pointers... yp=NULL; up=NULL; vp=NULL; // Copy to other buffer can be done... // So that source buffer will be free cindex=0; // index into the cframe.... csize=size; // size of compressed frame cframe=cdata; // pointer to compressed frme //memcpy(cframe,cdata,size); // Reset the pointers... initbits(); // Get the frame header getheader(); // If first time...then call initdecoder.... // This has to be done after calling getheader() // because getheader() setup some variables using the information // from header... if (first) { initdecoder(); first = 0; } // Decompress the frame and get the picture frame in YUV format getpicture(&framenum); framenum++; if(yp==NULL || up==NULL || vp==NULL) { if(trace) fputs("decompression failed...",dlog); return 0; } // convert YUV to RGB // ******* TODO ********* // check if outdata is enough to store rgb data // int totalsize=horizontal_size * vertical_size *3; if(outsize< totalsize || outdata==NULL) { if(dlog) fputs("Output buffer is not sufficient",dlog); return 0; } ConvertYUV2RGB(yp,up,vp,outdata,horizontal_size,vertical_size); return 1; }