2017-08-18 23:52:53 +00:00
|
|
|
#include <qpdf/Pl_DCT.hh>
|
|
|
|
#include <qpdf/Pl_StdioFile.hh>
|
|
|
|
#include <qpdf/QUtil.hh>
|
|
|
|
|
2023-05-20 11:22:32 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
2017-08-18 23:52:53 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage()
|
|
|
|
{
|
2023-06-01 13:12:39 +00:00
|
|
|
std::cerr << "Usage: dct_compress infile outfile width height {rgb|cmyk|gray}" << std::endl;
|
2017-08-18 23:52:53 +00:00
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
if (argc != 6) {
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
char* infilename = argv[1];
|
|
|
|
char* outfilename = argv[2];
|
2019-06-21 03:35:23 +00:00
|
|
|
JDIMENSION width = QUtil::string_to_uint(argv[3]);
|
|
|
|
JDIMENSION height = QUtil::string_to_uint(argv[4]);
|
2017-08-18 23:52:53 +00:00
|
|
|
char* colorspace = argv[5];
|
|
|
|
J_COLOR_SPACE cs =
|
|
|
|
((strcmp(colorspace, "rgb") == 0) ? JCS_RGB
|
|
|
|
: (strcmp(colorspace, "cmyk") == 0) ? JCS_CMYK
|
|
|
|
: (strcmp(colorspace, "gray") == 0) ? JCS_GRAYSCALE
|
|
|
|
: JCS_UNKNOWN);
|
|
|
|
int components = 0;
|
|
|
|
switch (cs) {
|
|
|
|
case JCS_RGB:
|
|
|
|
components = 3;
|
|
|
|
break;
|
|
|
|
case JCS_CMYK:
|
|
|
|
components = 4;
|
|
|
|
break;
|
|
|
|
case JCS_GRAYSCALE:
|
|
|
|
components = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE* infile = QUtil::safe_fopen(infilename, "rb");
|
|
|
|
FILE* outfile = QUtil::safe_fopen(outfilename, "wb");
|
|
|
|
Pl_StdioFile out("stdout", outfile);
|
|
|
|
unsigned char buf[100];
|
2024-07-02 13:04:53 +00:00
|
|
|
Pl_DCT dct("dct", &out, width, height, components, cs);
|
|
|
|
while (size_t len = fread(buf, 1, sizeof(buf), infile)) {
|
|
|
|
dct.write(buf, len);
|
2017-08-18 23:52:53 +00:00
|
|
|
}
|
|
|
|
dct.finish();
|
2024-07-02 13:04:53 +00:00
|
|
|
|
2017-08-18 23:52:53 +00:00
|
|
|
fclose(infile);
|
|
|
|
fclose(outfile);
|
|
|
|
return 0;
|
|
|
|
}
|