mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 10:58:58 +00:00
65bd8bc57d
As a rule, we should avoid conditional compilation is it always causes code paths that are sometimes not even seen lexically by the compiler. Also, we want the actual code being fuzzed to be as close as possible to the real code. Conditional compilation is suitable to handle underlying system differences. Instead, favor configuration using callbacks or other methods that can be triggered in the places where they need to be exercised.
64 lines
1.5 KiB
C++
64 lines
1.5 KiB
C++
#include <qpdf/Pl_DCT.hh>
|
|
#include <qpdf/Pl_StdioFile.hh>
|
|
#include <qpdf/QUtil.hh>
|
|
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
#include <iostream>
|
|
|
|
static void
|
|
usage()
|
|
{
|
|
std::cerr << "Usage: dct_compress infile outfile width height {rgb|cmyk|gray}" << std::endl;
|
|
exit(2);
|
|
}
|
|
|
|
int
|
|
main(int argc, char* argv[])
|
|
{
|
|
if (argc != 6) {
|
|
usage();
|
|
}
|
|
|
|
char* infilename = argv[1];
|
|
char* outfilename = argv[2];
|
|
JDIMENSION width = QUtil::string_to_uint(argv[3]);
|
|
JDIMENSION height = QUtil::string_to_uint(argv[4]);
|
|
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];
|
|
Pl_DCT dct("dct", &out, width, height, components, cs);
|
|
while (size_t len = fread(buf, 1, sizeof(buf), infile)) {
|
|
dct.write(buf, len);
|
|
}
|
|
dct.finish();
|
|
|
|
fclose(infile);
|
|
fclose(outfile);
|
|
return 0;
|
|
}
|