tstcodec.c

来自「君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图」· C语言 代码 · 共 523 行 · 第 1/2 页

C
523
字号
  unsigned char jbig_normal[15*4] = {    0x7c, 0xe2, 0x38, 0x04, 0x92, 0x40, 0x04, 0xe2, 0x5c, 0x44,    0x92, 0x44, 0x38, 0xe2, 0x38,    0x7c, 0xe2, 0x38, 0x04, 0x92, 0x40, 0x04, 0xe2, 0x5c, 0x44,    0x92, 0x44, 0x38, 0xe2, 0x38,    0x7c, 0xe2, 0x38, 0x04, 0x92, 0x40, 0x04, 0xe2, 0x5c, 0x44,    0x92, 0x44, 0x38, 0xe2, 0x38,    0x7c, 0xe2, 0x38, 0x04, 0x92, 0x40, 0x04, 0xe2, 0x5c, 0x44,    0x92, 0x44, 0x38, 0xe2, 0x38  };  unsigned char jbig_upsidedown[15*4] = {    0x38, 0xe2, 0x38, 0x44, 0x92, 0x44, 0x04, 0xe2, 0x5c, 0x04,    0x92, 0x40, 0x7c, 0xe2, 0x38,    0x38, 0xe2, 0x38, 0x44, 0x92, 0x44, 0x04, 0xe2, 0x5c, 0x04,    0x92, 0x40, 0x7c, 0xe2, 0x38,    0x38, 0xe2, 0x38, 0x44, 0x92, 0x44, 0x04, 0xe2, 0x5c, 0x04,    0x92, 0x40, 0x7c, 0xe2, 0x38,    0x38, 0xe2, 0x38, 0x44, 0x92, 0x44, 0x04, 0xe2, 0x5c, 0x04,    0x92, 0x40, 0x7c, 0xe2, 0x38  };  unsigned char jbig_inverse[15*4] = {    0xff^0x7c, 0xff^0xe2, 0xfe^0x38, 0xff^0x04, 0xff^0x92,    0xfe^0x40, 0xff^0x04, 0xff^0xe2, 0xfe^0x5c, 0xff^0x44,    0xff^0x92, 0xfe^0x44, 0xff^0x38, 0xff^0xe2, 0xfe^0x38,    0xff^0x7c, 0xff^0xe2, 0xfe^0x38, 0xff^0x04, 0xff^0x92,    0xfe^0x40, 0xff^0x04, 0xff^0xe2, 0xfe^0x5c, 0xff^0x44,    0xff^0x92, 0xfe^0x44, 0xff^0x38, 0xff^0xe2, 0xfe^0x38,    0xff^0x7c, 0xff^0xe2, 0xfe^0x38, 0xff^0x04, 0xff^0x92,    0xfe^0x40, 0xff^0x04, 0xff^0xe2, 0xfe^0x5c, 0xff^0x44,    0xff^0x92, 0xfe^0x44, 0xff^0x38, 0xff^0xe2, 0xfe^0x38,    0xff^0x7c, 0xff^0xe2, 0xfe^0x38, 0xff^0x04, 0xff^0x92,    0xfe^0x40, 0xff^0x04, 0xff^0xe2, 0xfe^0x5c, 0xff^0x44,    0xff^0x92, 0xfe^0x44, 0xff^0x38, 0xff^0xe2, 0xfe^0x38  };  int orders[] = {    0,    JBG_ILEAVE,    JBG_ILEAVE | JBG_SMID,#if 0    JBG_SEQ,    JBG_SEQ | JBG_SMID,    JBG_SEQ | JBG_ILEAVE,    JBG_HITOLO,    JBG_HITOLO | JBG_ILEAVE,    JBG_HITOLO | JBG_ILEAVE | JBG_SMID,    JBG_HITOLO | JBG_SEQ,    JBG_HITOLO | JBG_SEQ | JBG_SMID,    JBG_HITOLO | JBG_SEQ | JBG_ILEAVE#endif  };  printf("\nAutomatic JBIG Compatibility Test Suite\n"	 "---------------------------------------\n\n"	 "JBIG-KIT Version " JBG_VERSION	 " -- This test will take a few minutes.\n\n\n");  /* allocate test buffer memory */  testbuf = (unsigned char *) checkedmalloc(TESTBUF_SIZE);  testpic = (unsigned char *) checkedmalloc(TESTPIC_SIZE);  se = (struct jbg_arenc_state *) checkedmalloc(sizeof(struct jbg_arenc_state));  sd = (struct jbg_ardec_state *) checkedmalloc(sizeof(struct jbg_ardec_state));  /* test a few properties of the machine architecture */  testbuf[0] = 42;  testbuf[0x10000L] = 0x42;  st = 1 << 16;  testbuf[st]++;  pp = testbuf + 0x4000;  pp += 0x4000;  pp += 0x4000;  pp += 0x4000;  if (testbuf[0] != 42 || *pp != 0x43) {    printf("Porting error detected:\n\n"	   "Pointer arithmetic with this compiler has not at least 32 bits!\n"	   "Are you sure, you have not compiled this program on an 8-bit\n"	   "or 16-bit architecture? This compiler mode can obviously not\n"           "handle arrays with a size of more than 65536 bytes. With this\n"           "memory model, JBIG-KIT can only handle very small images and\n"           "not even this compatibility test suite will run. :-(\n\n");    exit(1);  }  /* only supported command line option:   * output file name for exporting test image */  if (argc > 1) {    FILE *f;    puts("Generating test image ...");    testimage(testpic);    printf("Storing in '%s' ...\n", argv[1]);        /* write out test image as PBM file */    f = fopen(argv[1], "wb");    if (!f) abort();    fprintf(f, "P4\n");#if 0    fprintf(f, "# Test image as defined in ITU-T T.82, clause 7.2.1\n");#endif    fprintf(f, "1960 1951\n");    fwrite(testpic, 1, TESTPIC_SIZE, f);    fclose(f);    exit(0);  }#if 1  puts("1) Arithmetic encoder test sequence from ITU-T T.82, clause 7.1\n"       "---------------------------------------------------------------\n");  arith_encode_init(se, 0);  testbuf_len = 0;  se->byte_out = testbuf_write;  for (i = 0; i < 16 * 16; i++)    arith_encode(se, (t82cx[i >> 4] >> ((15 - i) & 15)) & 1,		 (t82pix[i >> 4] >> ((15 - i) & 15)) & 1);  arith_encode_flush(se);  printf("result of encoder:\n  ");  for (i = 0; i < testbuf_len && i < TESTBUF_SIZE; i++)    printf("%02x", testbuf[i]);  printf("\nexpected result:\n  ");  for (i = 0; i < 30; i++)    printf("%02x", t82sde[i]);  printf("\n\nTest 1: ");  if (testbuf_len != 30 || memcmp(testbuf, t82sde, 30)) {    problems++;    printf(FAILED);  } else    printf(PASSED);  printf("\n\n");  puts("2) Arithmetic decoder test sequence from ITU-T T.82, clause 7.1\n"       "---------------------------------------------------------------\n");  printf("Test 2.1: Decoding whole chunk ...\n");  arith_decode_init(sd, 0);  sd->pscd_ptr = t82sde;  sd->pscd_end = t82sde + 32;  trouble = 0;  for (i = 0; i < 16 * 16 && !trouble; i++) {    pix = arith_decode(sd, (t82cx[i >> 4] >> ((15 - i) & 15)) & 1);    if (pix < 0) {      printf("Problem at Pixel %ld, result code %d.\n\n", i+1, sd->result);      trouble++;      break;    }    if (pix != ((t82pix[i >> 4] >> ((15 - i) & 15)) & 1)) {      printf("Wrong PIX answer at Pixel %ld.\n\n", i+1);      trouble++;      break;    }  }  if (!trouble && sd->result != JBG_READY) {    printf("Result is %d instead of JBG_READY.\n\n", sd->result);    trouble++;  }  printf("Test result: ");  if (trouble) {    problems++;    puts(FAILED);  } else    puts(PASSED);  printf("\n");  printf("Test 2.2: Decoding with single byte feed ...\n");  arith_decode_init(sd, 0);  pp = t82sde;  sd->pscd_ptr = pp;  sd->pscd_end = pp + 1;  trouble = 0;  for (i = 0; i < 16 * 16 && !trouble; i++) {    pix = arith_decode(sd, (t82cx[i >> 4] >> ((15 - i) & 15)) & 1);    while ((sd->result == JBG_MORE || sd->result == JBG_MARKER) &&	   sd->pscd_end < t82sde + 32) {      pp++;      sd->pscd_end = pp + 1;      if (sd->result == JBG_MARKER)	sd->pscd_ptr = pp - 1;      else	sd->pscd_ptr = pp;      pix = arith_decode(sd, (t82cx[i >> 4] >> ((15 - i) & 15)) & 1);    }    if (pix < 0) {      printf("Problem at Pixel %ld, result code %d.\n\n", i+1, sd->result);      trouble++;      break;    }    if (pix != ((t82pix[i >> 4] >> ((15 - i) & 15)) & 1)) {      printf("Wrong PIX answer at Pixel %ld.\n\n", i+1);      trouble++;      break;    }  }  if (!trouble && sd->result != JBG_READY) {    printf("Result is %d instead of JBG_READY.\n\n", sd->result);    trouble++;  }  printf("Test result: ");  if (trouble) {    problems++;    puts(FAILED);  } else    puts(PASSED);  printf("\n");    puts("3) Parametric algorithm test sequence from ITU-T T.82, clause 7.2\n"       "-----------------------------------------------------------------\n");  puts("Generating test image ...");  testimage(testpic);  putchar('\n');  pp = testpic;  puts("Test 3.1: TPBON=0, Mx=0, LRLTWO=0, L0=1951");  problems += test_cycle(&pp, 1960, 1951, JBG_DELAY_AT,			 0, 0, 1, 1951, 0, 317384L, "3.1");  puts("Test 3.2: TPBON=0, Mx=0, LRLTWO=1, L0=1951");  problems += test_cycle(&pp, 1960, 1951, JBG_DELAY_AT | JBG_LRLTWO,			 0, 0, 1, 1951, 0, 317132L, "3.2");  puts("Test 3.3: TPBON=1, DPON=1, TPDON=1, Mx=8, LRLTWO=0, L0=128");  problems += test_cycle(&pp, 1960, 1951, JBG_DELAY_AT | JBG_TPBON,			 0, 0, 1, 128, 8, 253653L, "3.3");  puts("Test 3.4: TPBON=1, DPON=1, TPDON=1, Mx=8, LRLTWO=0, L0=2, 6 layers");  problems += test_cycle(&pp, 1960, 1951,			 JBG_DELAY_AT | JBG_TPBON | JBG_TPDON | JBG_DPON,			 0, 6, 1, 2, 8, 279314L, "3.4");#if 0  puts("Test 3.5: as TEST 4 but with order bit SEQ set");  problems += test_cycle(&pp, 1960, 1951,			 JBG_DELAY_AT | JBG_TPBON | JBG_TPDON | JBG_DPON,			 JBG_SEQ, 6, 1, 2, 8, 279314L, "3.5");#endif#endif  puts("4) Additional regression tests\n"       "------------------------------\n");  ppp[0] = jbig_normal;  ppp[1] = jbig_upsidedown;  ppp[2] = jbig_inverse;  ppp[3] = jbig_inverse;  i = 0;  for (layers = 0; layers <= 3; layers++)    for (order = 0; order < (int) (sizeof(orders)/sizeof(int)); order++) {      sprintf(test, "4.%ld", ++i);      printf("Test %s: order=%d, %d layers, 4 planes", test, orders[order],	     layers);      problems += test_cycle(ppp, 23, 5*4, JBG_TPBON | JBG_TPDON | JBG_DPON,			     orders[order], layers, 4, 2, 8, -1, test);    }  printf("\nTest result summary: the library has %s the test suite.\n\n",	 problems ? FAILED : PASSED);  if (problems)    puts("This is bad. If you cannot identify the problem yourself, please "	 "send\nthis output plus a detailed description of your "	 "compile environment\n(OS, compiler, version, options, etc.) to "	 "Markus Kuhn <http://www.cl.cam.ac.uk/~mgk25/>.");  else    puts("Congratulations, everything is fine.\n");  return problems != 0;}

⌨️ 快捷键说明

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