Closed natxopedreira closed 9 years ago
VS2012 doesn't like it when you create arrays without literal constants. I haven't fixed this one.
Generally, in these cases, I like to swap in a Poco::Buffer
.
A quick fix would be to create the array dynamically e.g.
//------------------------------------------------------------------------------
ofPixels_<unsigned char> ImageUtils::dither(const ofPixels_<unsigned char>& pixels,
float threshold,
float quantWeight)
{
// Special thanks to @julapy / ofxDither
ofPixels_<unsigned char> pixelsIn = pixels;
// ensure the image is grayscale
if(OF_IMAGE_GRAYSCALE != pixelsIn.getImageType())
{
pixelsIn = toGrayscale(pixels);
}
// make a copy
ofPixels_<unsigned char> pixelsOut = pixelsIn;
// set up the quantization error
int width = pixelsOut.getWidth();
int height = pixelsOut.getHeight();
std::size_t numPixels = width * height; // 1 byte / pixel
float* qErrors = new float[numPixels];
std::fill(qErrors, qErrors + numPixels, 0.0);
//unsigned char* inPix = pixelsIn.getPixels();
unsigned char* outPix = pixelsOut.getPixels();
float limit = ofColor_<unsigned char>::limit();
for(int y = 0; y < height; y++)
{
for(int x = 0; x < width; x++)
{
int p = pixelsIn.getPixelIndex(x, y);
int oldPx = outPix[p] + qErrors[p]; // add error
int newPx = (oldPx < (threshold * limit)) ? 0 : limit; // threshold
outPix[p] = newPx;
int qError = oldPx - newPx;
accumulateDitherError(x+1,y ,pixelsOut,qError,qErrors,quantWeight); // check east
accumulateDitherError(x+2,y ,pixelsOut,qError,qErrors,quantWeight); // check east east
accumulateDitherError(x-1,y+1,pixelsOut,qError,qErrors,quantWeight); // check southwest
accumulateDitherError(x ,y+1,pixelsOut,qError,qErrors,quantWeight); // check south
accumulateDitherError(x+1,y+1,pixelsOut,qError,qErrors,quantWeight); // check southeast
accumulateDitherError(x ,y+2,pixelsOut,qError,qErrors,quantWeight); // check south south
}
}
delete[] qErrors;
return pixelsOut;
}
Give that a try ...
Thanks a lot!!! it works
im using an epson TM-TM20II on windows
Super. I've got about 100 TMT20's if you need more. :)
i will remember that, thanks again
im trying to use the add-on in vs2012 but its trowing an error while compiling on imageUtils.cpp line 84
Error 22 error C2057: expected constant expression
this line has: float qErrors[numPixels];