⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zdjpeg.c

📁 linux环境下jpeg编解码算法的实现
💻 C
📖 第 1 页 / 共 4 页
字号:
      zJpegReadHeader(&cinfo, FALSE, &thumbnailFound);      /*       * Adjust default decompression parameters by re-parsing the options. In a       * real application the decode parameters must be set after reading the       * header       */      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       */      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);      }    }    printf("\nMovie Complete, %d frames in total\n\n", imageCount-2);    zJpegReleaseDecompress(&cinfo);    zevio2d_disable_3dscr();  }  else if (tile == TRUE)  {    /*     * Tiled mode is a derivative of slideshow intended to show (hopefully)     * fast thumbnail drawing without the complexity of queueing images to the     * ZSP. It should give a good indication of the overheads inherent in the     * Linux system without any specific optimization.     */    DIR *dir;    struct dirent *ptr;    int imageCount = 0,        position,        offset,        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);    }    /*     * (void*) gpuBuf.pBase = physical address to top left corner of buffer     * (unsigned short*) gpuBuf.vBase = virtual address to top left corner of     * buffer. The buffer is requested once and overwritten by successive     * thumbnails     */    GPU_Factory_Request(ZV_GBUF_FULL_SCREEN,&gpuBuf);    GPU_Factory_BindTexture(&gpuBuf);    printf("Tile 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("\nTile - 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, TRUE, &thumbnailFound);            if(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 );            cinfo.dct_method          = JDCT_IFAST;            cinfo.quantize_colors     = FALSE;            cinfo.two_pass_quantize   = FALSE;            cinfo.do_fancy_upsampling = FALSE;            cinfo.dither_mode         = JDITHER_ORDERED;            /*             * 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 );            /*             * All thumbnails are presented at incremting positions within the             * single buffer, use imageCount to locate it             */            position = (imageCount-1)%25;            offset = ((position % 5) * 2560) + ((position / 5) * 245760);            /*             * Start decompressor, the callback and memory pointers for the output             * buffer are passed as parameters             */            (void) zJpegStartDecompress(&cinfo, freeInputBuffer, 0, gpuBuf.vBase + offset, (unsigned long)gpuBuf.pBase + offset); // Buffer assigned internally for now            /*             * Pend on callback indicating decode complete             */            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             */            if (!(imageCount%displayCounter))            {              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);            if (presentationDelay)            {              sleep(presentationDelay);            }          }        }      }      closedir(dir);    }    printf("\nTile done, %d images in total\n\n", imageCount);    zJpegReleaseDecompress(&cinfo);    GPU_Factory_Release(&gpuBuf);    zevio2d_disable_3dscr();  }  else // really shouldn't get here  {    assert(0);  }  /*   * Tidy up the JPEG decoder, this should NOT be done unless there is a   * requirement to change ZSP processing to another algorithm.   */  zJpegExit();  /*   * Return the GPU memory, this should be handled accordingly by a real app   */  zevio3d_free( vMem );  return 0;}int main(int argc, char **argv){  zdjpeg(argc, argv);  exit(0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -