?? zdjpeg.c
字號(hào):
header[32] = 0x03; // IFD1 Entry Count header[33] = 0x00; header[34] = 0x03; // Thumbnail Type tag header[35] = 0x01; header[36] = 0x03; header[37] = 0x00; header[38] = 0x01; header[39] = 0x00; header[40] = 0x00; header[41] = 0x00; header[42] = 0x06; header[43] = 0x00; header[44] = 0x00; header[45] = 0x00; header[46] = 0x01; // Offset to JPEG Thumbnail header[47] = 0x02; header[48] = 0x04; header[49] = 0x00; header[50] = 0x01; header[51] = 0x00; header[52] = 0x00; header[53] = 0x00; header[54] = 0x44; // 68 bytes from start of TIFF to JPEG header[55] = 0x00; header[56] = 0x00; header[57] = 0x00; header[58] = 0x02; // JPEG Thumbnail Length header[59] = 0x02; header[60] = 0x04; header[61] = 0x00; header[62] = 0x01; header[63] = 0x00; header[64] = 0x00; header[65] = 0x00; header[66] = length & 0xFF; header[67] = (length >> 8) & 0xFF; header[68] = 0x00; header[69] = 0x00; header[70] = 0x00; // NULL offset, no more IFDs header[71] = 0x00; header[72] = 0x00; header[73] = 0x00; /* * Write the header */ rewind(input_file); zJpegStdioSrc(&cinfo, input_file); zJpegReadHeader(&cinfo, FALSE, &thumbnailFound); cinfo.dct_method = JDCT_IFAST; cinfo.quantize_colors = FALSE; cinfo.two_pass_quantize = FALSE; cinfo.do_fancy_upsampling = FALSE; cinfo.dither_mode = JDITHER_ORDERED; oWidth = OUTPUT_W; oHeight = OUTPUT_H; zJpegSetOutputSize( &cinfo, &oWidth, &oHeight, SCALE_MAX ); encodeStart( &cinfo, outfilename, oWidth, oHeight, quality ); encodeWriteAPP1( header, length+74); zJpegSetRGBbuffer( &cinfo, rgbBuffer ); /* * Decode the main image to the file */printf("starting main image\n"); (void) zJpegStartDecompress(&cinfo, freeInputBuffer, 0, gpuBuf.vBase, (unsigned long)gpuBuf.pBase); // Buffer assigned internally for now sem_wait(&done); zJpegSetRGBbuffer( &cinfo, NULL ); encodeEnd(); /* * Tidy Up */ free(rgbBuffer); zJpegFinishDecompress(&cinfo); zJpegReleaseDecompress(&cinfo); GPU_Factory_Release(&gpuBuf); fclose(input_file); } else if (slideshow == TRUE) { DIR *dir; struct dirent *ptr; int imageCount = 0, k = loopCounter; char imgFile[128]; // Sometimes long paths! /* * Initialize the JPEG decompression object */ if (zJpegCreateDecompress( &cinfo ) != EXIT_SUCCESS) { fprintf(stderr, "%s: can't create decompression object\n", progname); exit(EXIT_FAILURE); } printf("Slideshow Mode, %d loops requested...\n", k); while (k--) { dir = opendir(argv[file_index]); if (!dir) { printf("[ERROR] Failed to open dir '%s'\n", argv[file_index]); break; } else { while (NULL != (ptr = readdir(dir))) { oWidth = OUTPUT_W; oHeight = OUTPUT_H; if ((!(memcmp(ptr->d_name+strlen(ptr->d_name)-4, ".jpg", 4))) || (!(memcmp(ptr->d_name+strlen(ptr->d_name)-4, ".JPG", 4)))) { /* * Decode and present an image */ sprintf(imgFile, "%s", argv[file_index]); strcat(imgFile, ptr->d_name); imageCount++; if (cinfo.err->trace_level) { printf("\nSlideshow - decoding %s [%d]\n", imgFile, imageCount); } if ((input_file = fopen(imgFile, READ_BINARY)) == NULL) { fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]); exit(EXIT_FAILURE); } if (cinfo.err->trace_level) { timSet.it_interval.tv_sec = INTERVAL_TIME; timSet.it_interval.tv_usec = 0; timSet.it_value.tv_sec = INTERVAL_TIME; timSet.it_value.tv_usec = 0; assert(!setitimer(ITIMER_REAL, &timSet, NULL)); } /* * At this point pZSP which is the ZEVIO specific 'cinfo' extension can be * initialized. The intention is that 'cinfo' remains as standard and all * extensions use the existing 'client_data' pointer to user extensions */// pZSP = (struct zjpeg_command *)cinfo.client_data; zJpegStdioSrc(&cinfo, input_file); /* * Read file header which sets the default decompression parameters. At this * point the ZEVIO decoder can check for an embedded thumbnail, see the logic * below for details... */ zJpegReadHeader(&cinfo, thumbnail, &thumbnailFound); if(thumbnail == TRUE && thumbnailFound == FALSE) { fprintf(stderr, "%s: no thumbnail present\n", progname); zJpegFinishDecompress(&cinfo); rewind(input_file); zJpegStdioSrc(&cinfo, input_file); zJpegReadHeader(&cinfo, FALSE, &thumbnailFound); oWidth = 160; oHeight = 120; } /* * Adjust default decompression parameters by re-parsing the options. In a * real application the decode parameters must be set after reading the * header */ file_index = parse_switches( &cinfo, argc, argv, 0, TRUE ); /* * Scale the image to fit the desired output size. Here we always scale to * match aspect ratio and maximum 800x600 */ zJpegSetOutputSize( &cinfo, &oWidth, &oHeight, SCALE_MAX ); /* * (void*) gpuBuf.pBase = physical address to top left corner of buffer * (unsigned short*) gpuBuf.vBase = virtual address to top left corner of buffer */ GPU_Factory_Request(ZV_GBUF_FULL_SCREEN,&gpuBuf); /* * Start decompressor, the callback and memory pointers for the output * buffer are passed as parameters */ (void) zJpegStartDecompress(&cinfo, freeInputBuffer, 0, gpuBuf.vBase, (unsigned long)gpuBuf.pBase); // Buffer assigned internally for now /* * Pend on callback indicating decode complete */ if (flush == TRUE) { if (imageCount & 1) { sleep(2); zJpegFlushDecoder(); } } sem_wait(&done); /* * Decode time is captured before writing out the file which is subject to * NFS delays. Of course the input and swap file are also plagued by NFS * but at least one source of uncertainty is removed... */ if (cinfo.err->trace_level) { assert(!getitimer(ITIMER_REAL, &timGet1)); } assert(oWidth <= OUTPUT_W); assert(oHeight <= OUTPUT_H); /* * Draw LCD display */ GPU_Factory_BindTexture(&gpuBuf); display_pixels((void *)gpuBuf.vBase,(unsigned short*)gpuVMem,gpuBuf.offset); if (cinfo.err->trace_level) { assert(!getitimer(ITIMER_REAL, &timGet2)); } /* * Tidy up after decode of a single image, this should be used by any * application */ zJpegFinishDecompress(&cinfo); /* * Decode & presentation run time output */ if (cinfo.err->trace_level) { zJpegInstrumentation result; zJpegGetInstrumentation( &cinfo, &result ); printf("\n%d %u.%ums [%d] %u.%ums [%d] %d %dx%d %dx%d %dx%d\n", result.ppPackets, result.zspTimer0ms, result.zspTimer0hus, result.zspTimer0oflow, result.zspTimer1ms, result.zspTimer1hus, result.zspTimer1oflow, result.chromaType, result.imageWidth, result.imageHeight, result.outputWidth, result.outputHeight, result.displayWidth, result.displayHeight); time = INTERVAL_TIME*1000000 - (timGet1.it_value.tv_sec * 1000000 + timGet1.it_value.tv_usec); if (time <= 0) printf("Task Timer Elapsed...\n"); else printf("[D] %ld.%02lds ", time/1000000, (time%1000000)/10000); time = INTERVAL_TIME*1000000 - (timGet2.it_value.tv_sec * 1000000 + timGet2.it_value.tv_usec); if (time <= 0) printf("Task Timer Elapsed...\n"); else printf("[P] %ld.%02lds for %s\n", time/1000000, (time%1000000)/10000, argv[file_index]); } fclose(input_file); GPU_Factory_Release(&gpuBuf); if (presentationDelay) { sleep(presentationDelay); } } } } closedir(dir); } printf("\nSlideshow done, %d images in total\n\n", imageCount); zJpegReleaseDecompress(&cinfo); zevio2d_disable_3dscr(); } else if (play == TRUE) { int imageCount = 1; char imgFile[128]; // Sometimes long paths! /* * Initialize the JPEG decompression object */ if (zJpegCreateDecompress( &cinfo ) != EXIT_SUCCESS) { fprintf(stderr, "%s: can't create decompression object\n", progname); exit(EXIT_FAILURE); } sprintf(imgFile, "%s00001.jpg", playRoot); if ((input_file = fopen(imgFile, READ_BINARY)) == NULL) { sprintf(imgFile, "%s00001.JPG", playRoot); if ((input_file = fopen(imgFile, READ_BINARY)) == NULL) { fprintf(stderr, "%s: can't open first frame - %s00001.[jpg|JPG]\n", progname, playRoot); exit(EXIT_FAILURE); } else { upperCase = TRUE; } } else { upperCase = FALSE; } fclose(input_file); printf("Play - %s\n\n", playRoot); while (1) { oWidth = OUTPUT_W; oHeight = OUTPUT_H; /* * Decode and present an image */ sprintf(imgFile, "%s%05u.%s", playRoot, imageCount++, (upperCase == TRUE) ? "JPG" : "jpg"); if ((input_file = fopen(imgFile, READ_BINARY)) == NULL) { break; } if (cinfo.err->trace_level) { timSet.it_interval.tv_sec = INTERVAL_TIME; timSet.it_interval.tv_usec = 0; timSet.it_value.tv_sec = INTERVAL_TIME; timSet.it_value.tv_usec = 0; assert(!setitimer(ITIMER_REAL, &timSet, NULL)); } /* * At this point pZSP which is the ZEVIO specific 'cinfo' extension can be * initialized. The intention is that 'cinfo' remains as standard and all * extensions use the existing 'client_data' pointer to user extensions */// pZSP = (struct zjpeg_command *)cinfo.client_data; zJpegStdioSrc(&cinfo, input_file); /* * Read file header which sets the default decompression parameters. At this * point the ZEVIO decoder can check for an embedded thumbnail, see the logic * below for details... */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -