[Programming] Calling HQx2 scaler twice to scale by 4 results in crash

Ask for help with ScummVM problems

Moderator: ScummVM Team

Post Reply
Memnarch
Posts: 3
Joined: Thu Sep 16, 2021 10:05 pm

[Programming] Calling HQx2 scaler twice to scale by 4 results in crash

Post by Memnarch »

Hi,
I'm probably doing something wrong but right now I don't know what :/

My goal is to scale a grafic by x4. So I thought I'd call the HQx2 scaler twice. The scaler is initialized with the Pixelformat at this point, BufferA/B are Byte-Vectors.

The first call to scale works as expected, the seconds triggers an AV. My naive expectation was, that BufferA contains a pictures exactly twice as large as the source when the second scale is called, so I'd just multiply all arguments by 2. That's probably wrong, though?

EDIT: Using the "normal" scaler, the code below works as expected in this stepordner. So it seems to be something with the hq scaler I'm not doing right?

Code: Select all

void *RivenVideo::ScaleFrame(const void *Pixels, int Pitch, int Height, int BytesPerPixel) {
        int Size = Height * Pitch * 4* 4;
	int srcPitch = Pitch;
	int srcWidth = Pitch / BytesPerPixel;
	int srcHeight = Height;
	BufferA.reserve(Size);
	BufferB.reserve(Size);
	if (Scaler) {
		Scaler->setFactor(2);
		Scaler->scale((const uint8 *)Pixels, srcPitch, BufferA.data(), srcPitch * 2, srcWidth, srcHeight, 0, 0);
		Scaler->scale((const uint8 *)BufferA.data(), srcPitch*2, BufferB.data(), srcPitch * 4, srcWidth*2, srcHeight*2, 0, 0);
		return BufferB.data();
	} else {
	//fallback 
	}
}
User avatar
sev
ScummVM Lead
Posts: 2273
Joined: Wed Sep 21, 2005 1:06 pm
Contact:

Re: [Programming] Calling HQx2 scaler twice to scale by 4 results in crash

Post by sev »

No, it is not exactly 2x more. Most scalers require extra pixels on the edges in order to avoid generating black borders. Use `Scaler->extraPixels()` call to get the required value. In general, just check how the scalers are used.


Eugene

PS. Hq2x applied sequentially is going to be ugly.
Post Reply