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

📄 djpeg.c

📁 jpeg 压缩/解压缩库,是Intel 在ijg基础上改进的libjpeg,encode/decode是ijg的速度的2倍以上。
💻 C
📖 第 1 页 / 共 2 页
字号:
      requested_fmt = FMT_TARGA;    } else if (keymatch(arg, "cpu", 3)) {      int cpu;      if (++argn >= argc) /* advance to next argument */        usage();      if (sscanf(argv[argn], "%d", &cpu) < 1)        usage();      ippStaticInitCpu((IppCpuType)cpu);    } else {      usage();      /* bogus switch */    }  }  return argn;      /* return index of next arg (file name) */}/** Marker processor for COM and interesting APPn markers.* This replaces the library's built-in processor, which just skips the marker.* We want to print out the marker as text, to the extent possible.* Note this code relies on a non-suspending data source.*/LOCAL(unsigned int)jpeg_getc (j_decompress_ptr cinfo)/* Read next byte */{  struct jpeg_source_mgr * datasrc = cinfo->src;  if (datasrc->bytes_in_buffer == 0) {    if (! (*datasrc->fill_input_buffer) (cinfo))      ERREXIT(cinfo, JERR_CANT_SUSPEND);  }  datasrc->bytes_in_buffer--;  return GETJOCTET(*datasrc->next_input_byte++);}METHODDEF(boolean)print_text_marker (j_decompress_ptr cinfo){  boolean traceit = (cinfo->err->trace_level >= 1);  INT32 length;  unsigned int ch;  unsigned int lastch = 0;  length = jpeg_getc(cinfo) << 8;  length += jpeg_getc(cinfo);  length -= 2;      /* discount the length word itself */  if (traceit) {    if (cinfo->unread_marker == JPEG_COM)      fprintf(stderr, "Comment, length %ld:\n", (long) length);    else      /* assume it is an APPn otherwise */      fprintf(stderr, "APP%d, length %ld:\n",      cinfo->unread_marker - JPEG_APP0, (long) length);  }  while (--length >= 0) {    ch = jpeg_getc(cinfo);    if (traceit) {    /* Emit the character in a readable form.    * Nonprintables are converted to \nnn form,    * while \ is converted to \\.    * Newlines in CR, CR/LF, or LF form will be printed as one newline.      */      if (ch == '\r') {        fprintf(stderr, "\n");      } else if (ch == '\n') {        if (lastch != '\r')          fprintf(stderr, "\n");      } else if (ch == '\\') {        fprintf(stderr, "\\\\");      } else if (isprint(ch)) {        putc(ch, stderr);      } else {        fprintf(stderr, "\\%03o", ch);      }      lastch = ch;    }  }  if (traceit)    fprintf(stderr, "\n");  return TRUE;}#ifdef __ENABLE_TIMING__#define get_pentium_counter ippGetCpuClocks#endif/** The main program.*/intmain (int argc, char **argv){  struct jpeg_decompress_struct cinfo;  struct jpeg_error_mgr jerr;#ifdef PROGRESS_REPORT  struct cdjpeg_progress_mgr progress;#endif  int file_index;  djpeg_dest_ptr dest_mgr = NULL;  FILE * input_file;  FILE * output_file;  JDIMENSION num_scanlines;#ifdef __ENABLE_TIMING__  unsigned __int64 clk0;  unsigned __int64 clk1;  int width;  int height;  int nchannels;#endif  if(ippStsNoErr > ippStaticInit())  {    fprintf(stderr,"Can't initialize IPP library\n");    exit(EXIT_FAILURE);  }  /* On Mac, fetch a command line. */#ifdef USE_CCOMMAND  argc = ccommand(&argv);#endif  progname = argv[0];  if (progname == NULL || progname[0] == 0)    progname = "djpeg";   /* in case C library doesn't provide it */  /* Initialize the JPEG decompression object with default error handling. */  cinfo.err = jpeg_std_error(&jerr);  jpeg_create_decompress(&cinfo);  /* Add some application-specific error messages (from cderror.h) */  jerr.addon_message_table = cdjpeg_message_table;  jerr.first_addon_message = JMSG_FIRSTADDONCODE;  jerr.last_addon_message = JMSG_LASTADDONCODE;  /* Insert custom marker processor for COM and APP12.  * APP12 is used by some digital camera makers for textual info,  * so we provide the ability to display it as text.  * If you like, additional APPn marker types can be selected for display,  * but don't try to override APP0 or APP14 this way (see libjpeg.doc).  */  jpeg_set_marker_processor(&cinfo, JPEG_COM, print_text_marker);  jpeg_set_marker_processor(&cinfo, JPEG_APP0+12, print_text_marker);  /* Now safe to enable signal catcher. */#ifdef NEED_SIGNAL_CATCHER  enable_signal_catcher((j_common_ptr) &cinfo);#endif  /* Scan command line to find file names. */  /* It is convenient to use just one switch-parsing routine, but the switch  * values read here are ignored; we will rescan the switches after opening  * the input file.  * (Exception: tracing level set here controls verbosity for COM markers  * found during jpeg_read_header...)  */  file_index = parse_switches(&cinfo, argc, argv, 0, FALSE);#ifdef TWO_FILE_COMMANDLINE  /* Must have either -outfile switch or explicit output file name */  if (outfilename == NULL) {    if (file_index != argc-2) {      fprintf(stderr, "%s: must name one input and one output file\n",        progname);      usage();    }    outfilename = argv[file_index+1];  } else {    if (file_index != argc-1) {      fprintf(stderr, "%s: must name one input and one output file\n",        progname);      usage();    }  }#else  /* Unix style: expect zero or one file name */  if (file_index < argc-1) {    fprintf(stderr, "%s: only one input file\n", progname);    usage();  }#endif /* TWO_FILE_COMMANDLINE */  /* Open the input file. */  if (file_index < argc) {    if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) {      fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]);      exit(EXIT_FAILURE);    }  } else {    /* default input file is stdin */    input_file = read_stdin();  }  /* Open the output file. */  if (outfilename != NULL) {    if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {      fprintf(stderr, "%s: can't open %s\n", progname, outfilename);      exit(EXIT_FAILURE);    }  } else {    /* default output file is stdout */    output_file = write_stdout();  }#ifdef PROGRESS_REPORT  start_progress_monitor((j_common_ptr) &cinfo, &progress);#endif  /* Specify data source for decompression */  jpeg_stdio_src(&cinfo, input_file);  /* Read file header, set default decompression parameters */  (void) jpeg_read_header(&cinfo, TRUE);  /* Adjust default decompression parameters by re-parsing the options */  file_index = parse_switches(&cinfo, argc, argv, 0, TRUE);  /* Initialize the output module now to let it override any crucial  * option settings (for instance, GIF wants to force color quantization).  */  switch (requested_fmt) {#ifdef BMP_SUPPORTED  case FMT_BMP:    dest_mgr = jinit_write_bmp(&cinfo, FALSE);    break;  case FMT_OS2:    dest_mgr = jinit_write_bmp(&cinfo, TRUE);    break;#endif#ifdef GIF_SUPPORTED  case FMT_GIF:    dest_mgr = jinit_write_gif(&cinfo);    break;#endif#ifdef PPM_SUPPORTED  case FMT_PPM:    dest_mgr = jinit_write_ppm(&cinfo);    break;#endif#ifdef RLE_SUPPORTED  case FMT_RLE:    dest_mgr = jinit_write_rle(&cinfo);    break;#endif#ifdef TARGA_SUPPORTED  case FMT_TARGA:    dest_mgr = jinit_write_targa(&cinfo);    break;#endif  default:    ERREXIT(&cinfo, JERR_UNSUPPORTED_FORMAT);    break;  }  dest_mgr->output_file = output_file;#ifdef __ENABLE_TIMING__  SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_TIME_CRITICAL);  Sleep(0);  clk0 = get_pentium_counter();#endif  /* Start decompressor */  (void) jpeg_start_decompress(&cinfo);  /* Write output file header */  (*dest_mgr->start_output) (&cinfo, dest_mgr);  /* Process data */  while (cinfo.output_scanline < cinfo.output_height) {    num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,      dest_mgr->buffer_height);    (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);  }#ifdef PROGRESS_REPORT  /* Hack: count final pass as done in case finish_output does an extra pass.  * The library won't have updated completed_passes.  */  progress.pub.completed_passes = progress.pub.total_passes;#endif  /* Finish decompression and release memory.  * I must do it in this order because output module has allocated memory  * of lifespan JPOOL_IMAGE; it needs to finish before releasing memory.  */  (*dest_mgr->finish_output) (&cinfo, dest_mgr);  (void) jpeg_finish_decompress(&cinfo);#ifdef __ENABLE_TIMING__  clk1 = get_pentium_counter();  SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_NORMAL);  width  = cinfo.image_width;  height = cinfo.image_height;  nchannels = cinfo.num_components;#endif  jpeg_destroy_decompress(&cinfo);  /* Close files, if we opened them */  if (input_file != stdin)    fclose(input_file);  if (output_file != stdout)    fclose(output_file);#ifdef PROGRESS_REPORT  end_progress_monitor((j_common_ptr) &cinfo);#endif#ifdef __ENABLE_TIMING__  {    unsigned int clocks = (unsigned int)(clk1 - clk0);    float cpe = (float)clocks / (width*height);    fprintf(stderr,"image: %s %dx%dx%d clocks - %u\tcpe - %6.2f\n",      argv[file_index],      width,      height,      nchannels,      clocks,      cpe);  }#endif  /* All done. */  exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);  return 0;     /* suppress no-return-value warnings */}

⌨️ 快捷键说明

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