--- a/example.c 2024-06-17 10:42:17.345475661 +0200 +++ b/example.c 2024-06-17 10:54:43.345566680 +0200 @@ -9,7 +9,7 @@ * file. * * This file illustrates how to use the IJG code as a subroutine library - * to read or write JPEG image files with 8-bit or 12-bit data precision. You + * to read or write JPEG image files with 8-bit data precision. You * should look at this code in conjunction with the documentation file * libjpeg.txt. * @@ -114,10 +114,6 @@ JSAMPARRAY image_buffer = NULL; /* Points to large array of R,G,B-order data */ JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */ - J12SAMPARRAY image_buffer12 = NULL; - /* Points to large array of R,G,B-order 12-bit - data */ - J12SAMPROW row_pointer12[1]; /* pointer to J12SAMPLE row[s] */ int row_stride; /* physical row width in image buffer */ int row, col; @@ -181,36 +177,18 @@ * sample array and initialize it for each successive scanline written in the * scanline loop below. */ - if (cinfo.data_precision == 12) { - image_buffer12 = (J12SAMPARRAY)(*cinfo.mem->alloc_sarray) - ((j_common_ptr)&cinfo, JPOOL_IMAGE, row_stride, HEIGHT); - - /* Initialize image buffer with a repeating pattern */ - for (row = 0; row < HEIGHT; row++) { - for (col = 0; col < WIDTH; col++) { - image_buffer12[row][col * 3] = - (col * (MAXJ12SAMPLE + 1) / WIDTH) % (MAXJ12SAMPLE + 1); - image_buffer12[row][col * 3 + 1] = - (row * (MAXJ12SAMPLE + 1) / HEIGHT) % (MAXJ12SAMPLE + 1); - image_buffer12[row][col * 3 + 2] = - (row * (MAXJ12SAMPLE + 1) / HEIGHT + - col * (MAXJ12SAMPLE + 1) / WIDTH) % (MAXJ12SAMPLE + 1); - } - } - } else { - image_buffer = (*cinfo.mem->alloc_sarray) - ((j_common_ptr)&cinfo, JPOOL_IMAGE, row_stride, HEIGHT); - - for (row = 0; row < HEIGHT; row++) { - for (col = 0; col < WIDTH; col++) { - image_buffer[row][col * 3] = - (col * (MAXJSAMPLE + 1) / WIDTH) % (MAXJSAMPLE + 1); - image_buffer[row][col * 3 + 1] = - (row * (MAXJSAMPLE + 1) / HEIGHT) % (MAXJSAMPLE + 1); - image_buffer[row][col * 3 + 2] = - (row * (MAXJSAMPLE + 1) / HEIGHT + col * (MAXJSAMPLE + 1) / WIDTH) % - (MAXJSAMPLE + 1); - } + image_buffer = (*cinfo.mem->alloc_sarray) + ((j_common_ptr)&cinfo, JPOOL_IMAGE, row_stride, HEIGHT); + + for (row = 0; row < HEIGHT; row++) { + for (col = 0; col < WIDTH; col++) { + image_buffer[row][col * 3] = + (col * (MAXJSAMPLE + 1) / WIDTH) % (MAXJSAMPLE + 1); + image_buffer[row][col * 3 + 1] = + (row * (MAXJSAMPLE + 1) / HEIGHT) % (MAXJSAMPLE + 1); + image_buffer[row][col * 3 + 2] = + (row * (MAXJSAMPLE + 1) / HEIGHT + col * (MAXJSAMPLE + 1) / WIDTH) % + (MAXJSAMPLE + 1); } } @@ -222,24 +200,13 @@ * To keep things simple, we pass one scanline per call; you can pass * more if you wish, though. */ - if (cinfo.data_precision == 12) { - while (cinfo.next_scanline < cinfo.image_height) { - /* jpeg12_write_scanlines expects an array of pointers to scanlines. - * Here the array is only one element long, but you could pass - * more than one scanline at a time if that's more convenient. - */ - row_pointer12[0] = image_buffer12[cinfo.next_scanline]; - (void)jpeg12_write_scanlines(&cinfo, row_pointer12, 1); - } - } else { - while (cinfo.next_scanline < cinfo.image_height) { - /* jpeg_write_scanlines expects an array of pointers to scanlines. - * Here the array is only one element long, but you could pass - * more than one scanline at a time if that's more convenient. - */ - row_pointer[0] = image_buffer[cinfo.next_scanline]; - (void)jpeg_write_scanlines(&cinfo, row_pointer, 1); - } + while (cinfo.next_scanline < cinfo.image_height) { + /* jpeg_write_scanlines expects an array of pointers to scanlines. + * Here the array is only one element long, but you could pass + * more than one scanline at a time if that's more convenient. + */ + row_pointer[0] = image_buffer[cinfo.next_scanline]; + (void)jpeg_write_scanlines(&cinfo, row_pointer, 1); } /* Step 7: Finish compression */ @@ -388,7 +355,6 @@ FILE *infile; /* source file */ FILE *outfile; /* output file */ JSAMPARRAY buffer = NULL; /* Output row buffer */ - J12SAMPARRAY buffer12 = NULL; /* 12-bit output row buffer */ int col; int row_stride; /* physical row width in output buffer */ int little_endian = 1; @@ -443,8 +409,7 @@ */ /* emit header for raw PPM format */ - fprintf(outfile, "P6\n%d %d\n%d\n", WIDTH, HEIGHT, - cinfo->data_precision == 12 ? MAXJ12SAMPLE : MAXJSAMPLE); + fprintf(outfile, "P6\n%d %d\n%d\n", WIDTH, HEIGHT, MAXJSAMPLE); /* Step 4: set parameters for decompression */ @@ -468,12 +433,8 @@ /* Samples per row in output buffer */ row_stride = cinfo->output_width * cinfo->output_components; /* Make a one-row-high sample array that will go away when done with image */ - if (cinfo->data_precision == 12) - buffer12 = (J12SAMPARRAY)(*cinfo->mem->alloc_sarray) - ((j_common_ptr)cinfo, JPOOL_IMAGE, row_stride, 1); - else - buffer = (*cinfo->mem->alloc_sarray) - ((j_common_ptr)cinfo, JPOOL_IMAGE, row_stride, 1); + buffer = (*cinfo->mem->alloc_sarray) + ((j_common_ptr)cinfo, JPOOL_IMAGE, row_stride, 1); /* Step 6: while (scan lines remain to be read) */ /* jpeg_read_scanlines(...); */ @@ -481,30 +442,13 @@ /* Here we use the library's state variable cinfo->output_scanline as the * loop counter, so that we don't have to keep track ourselves. */ - if (cinfo->data_precision == 12) { - while (cinfo->output_scanline < cinfo->output_height) { - /* jpeg12_read_scanlines expects an array of pointers to scanlines. - * Here the array is only one element long, but you could ask for - * more than one scanline at a time if that's more convenient. - */ - (void)jpeg12_read_scanlines(cinfo, buffer12, 1); - if (*(char *)&little_endian == 1) { - /* Swap MSB and LSB in each sample */ - for (col = 0; col < row_stride; col++) - buffer12[0][col] = ((buffer12[0][col] & 0xFF) << 8) | - ((buffer12[0][col] >> 8) & 0xFF); - } - fwrite(buffer12[0], 1, row_stride * sizeof(J12SAMPLE), outfile); - } - } else { - while (cinfo->output_scanline < cinfo->output_height) { - /* jpeg_read_scanlines expects an array of pointers to scanlines. - * Here the array is only one element long, but you could ask for - * more than one scanline at a time if that's more convenient. - */ - (void)jpeg_read_scanlines(cinfo, buffer, 1); - fwrite(buffer[0], 1, row_stride, outfile); - } + while (cinfo->output_scanline < cinfo->output_height) { + /* jpeg_read_scanlines expects an array of pointers to scanlines. + * Here the array is only one element long, but you could ask for + * more than one scanline at a time if that's more convenient. + */ + (void)jpeg_read_scanlines(cinfo, buffer, 1); + fwrite(buffer[0], 1, row_stride, outfile); } /* Step 7: Finish decompression */ @@ -566,8 +510,6 @@ fprintf(stderr, " %s decompress inputfile[.jpg] outputfile[.ppm]\n", progname); fprintf(stderr, "Switches (names may be abbreviated):\n"); - fprintf(stderr, " -precision N Create JPEG file with N-bit data precision\n"); - fprintf(stderr, " (N is 8 or 12; default is 8)\n"); fprintf(stderr, " -quality N Compression quality (0..100; 5-95 is most useful range,\n"); fprintf(stderr, " default is 75)\n"); @@ -608,14 +550,7 @@ } arg++; /* advance past switch marker character */ - if (!strncasecmp(arg, "p", 1)) { - /* Set data precision. */ - if (++argn >= argc) /* advance to next argument */ - usage(argv[0]); - if (sscanf(argv[argn], "%d", &data_precision) < 1 || - (data_precision != 8 && data_precision != 12)) - usage(argv[0]); - } else if (!strncasecmp(arg, "q", 1)) { + if (!strncasecmp(arg, "q", 1)) { /* Quality rating (quantization table scaling factor). */ if (++argn >= argc) /* advance to next argument */ usage(argv[0]); @@ -631,7 +566,7 @@ usage(argv[0]); if (mode == COMPRESS) - write_JPEG_file(filename, quality, data_precision); + write_JPEG_file(filename, quality, 8); else if (mode == DECOMPRESS) { if (argc - argn < 2) usage(argv[0]);