2021-12-26 17:47:58 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
2004-08-07 16:04:43 +00:00
|
|
|
*
|
2021-12-26 17:47:58 +00:00
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2004-08-07 16:04:43 +00:00
|
|
|
*
|
2021-12-26 17:47:58 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2004-08-07 16:04:43 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2021-12-26 17:47:58 +00:00
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
2004-08-07 16:04:43 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-12-26 17:47:58 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
2004-08-07 16:04:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file contains a C and MMX implementation of the Scale2x effect.
|
|
|
|
*
|
|
|
|
* You can find an high level description of the effect at :
|
|
|
|
*
|
2022-05-17 23:36:59 +00:00
|
|
|
* https://www.scale2x.it
|
2004-08-07 16:04:43 +00:00
|
|
|
*
|
|
|
|
* Alternatively at the previous license terms, you are allowed to use this
|
|
|
|
* code in your program with these conditions:
|
|
|
|
* - the program is not used in commercial activities.
|
|
|
|
* - the whole source code of the program is released with the binary.
|
|
|
|
* - derivative works of the program are allowed.
|
|
|
|
*/
|
|
|
|
|
2006-04-04 21:45:13 +00:00
|
|
|
#include "common/scummsys.h"
|
2004-08-07 16:04:43 +00:00
|
|
|
|
2006-04-04 21:45:13 +00:00
|
|
|
#include "graphics/scaler/scale3x.h"
|
2004-08-07 16:04:43 +00:00
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
/* Scale3x C implementation */
|
|
|
|
|
2010-11-07 00:37:04 +00:00
|
|
|
static inline void scale3x_8_def_border(scale3x_uint8* __restrict__ dst, const scale3x_uint8* __restrict__ src0, const scale3x_uint8* __restrict__ src1, const scale3x_uint8* __restrict__ src2, unsigned count) {
|
2004-08-07 16:04:43 +00:00
|
|
|
/* central pixels */
|
|
|
|
while (count) {
|
|
|
|
if (src0[0] != src2[0] && src1[-1] != src1[1]) {
|
|
|
|
dst[0] = src1[-1] == src0[0] ? src1[-1] : src1[0];
|
|
|
|
dst[1] = (src1[-1] == src0[0] && src1[0] != src0[1]) || (src1[1] == src0[0] && src1[0] != src0[-1]) ? src0[0] : src1[0];
|
|
|
|
dst[2] = src1[1] == src0[0] ? src1[1] : src1[0];
|
|
|
|
} else {
|
|
|
|
dst[0] = src1[0];
|
|
|
|
dst[1] = src1[0];
|
|
|
|
dst[2] = src1[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
++src0;
|
|
|
|
++src1;
|
|
|
|
++src2;
|
|
|
|
dst += 3;
|
|
|
|
--count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-07 00:37:04 +00:00
|
|
|
static inline void scale3x_8_def_center(scale3x_uint8* __restrict__ dst, const scale3x_uint8* __restrict__ src0, const scale3x_uint8* __restrict__ src1, const scale3x_uint8* __restrict__ src2, unsigned count) {
|
2004-08-07 16:04:43 +00:00
|
|
|
/* central pixels */
|
|
|
|
while (count) {
|
|
|
|
if (src0[0] != src2[0] && src1[-1] != src1[1]) {
|
|
|
|
dst[0] = (src1[-1] == src0[0] && src1[0] != src2[-1]) || (src1[-1] == src2[0] && src1[0] != src0[-1]) ? src1[-1] : src1[0];
|
|
|
|
dst[1] = src1[0];
|
|
|
|
dst[2] = (src1[1] == src0[0] && src1[0] != src2[1]) || (src1[1] == src2[0] && src1[0] != src0[1]) ? src1[1] : src1[0];
|
|
|
|
} else {
|
|
|
|
dst[0] = src1[0];
|
|
|
|
dst[1] = src1[0];
|
|
|
|
dst[2] = src1[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
++src0;
|
|
|
|
++src1;
|
|
|
|
++src2;
|
|
|
|
dst += 3;
|
|
|
|
--count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-07 00:37:04 +00:00
|
|
|
static inline void scale3x_16_def_border(scale3x_uint16* __restrict__ dst, const scale3x_uint16* __restrict__ src0, const scale3x_uint16* __restrict__ src1, const scale3x_uint16* __restrict__ src2, unsigned count) {
|
2004-08-07 16:04:43 +00:00
|
|
|
/* central pixels */
|
|
|
|
while (count) {
|
|
|
|
if (src0[0] != src2[0] && src1[-1] != src1[1]) {
|
|
|
|
dst[0] = src1[-1] == src0[0] ? src1[-1] : src1[0];
|
|
|
|
dst[1] = (src1[-1] == src0[0] && src1[0] != src0[1]) || (src1[1] == src0[0] && src1[0] != src0[-1]) ? src0[0] : src1[0];
|
|
|
|
dst[2] = src1[1] == src0[0] ? src1[1] : src1[0];
|
|
|
|
} else {
|
|
|
|
dst[0] = src1[0];
|
|
|
|
dst[1] = src1[0];
|
|
|
|
dst[2] = src1[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
++src0;
|
|
|
|
++src1;
|
|
|
|
++src2;
|
|
|
|
dst += 3;
|
|
|
|
--count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-07 00:37:04 +00:00
|
|
|
static inline void scale3x_16_def_center(scale3x_uint16* __restrict__ dst, const scale3x_uint16* __restrict__ src0, const scale3x_uint16* __restrict__ src1, const scale3x_uint16* __restrict__ src2, unsigned count) {
|
2004-08-07 16:04:43 +00:00
|
|
|
/* central pixels */
|
|
|
|
while (count) {
|
|
|
|
if (src0[0] != src2[0] && src1[-1] != src1[1]) {
|
|
|
|
dst[0] = (src1[-1] == src0[0] && src1[0] != src2[-1]) || (src1[-1] == src2[0] && src1[0] != src0[-1]) ? src1[-1] : src1[0];
|
|
|
|
dst[1] = src1[0];
|
|
|
|
dst[2] = (src1[1] == src0[0] && src1[0] != src2[1]) || (src1[1] == src2[0] && src1[0] != src0[1]) ? src1[1] : src1[0];
|
|
|
|
} else {
|
|
|
|
dst[0] = src1[0];
|
|
|
|
dst[1] = src1[0];
|
|
|
|
dst[2] = src1[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
++src0;
|
|
|
|
++src1;
|
|
|
|
++src2;
|
|
|
|
dst += 3;
|
|
|
|
--count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-07 00:37:04 +00:00
|
|
|
static inline void scale3x_32_def_border(scale3x_uint32* __restrict__ dst, const scale3x_uint32* __restrict__ src0, const scale3x_uint32* __restrict__ src1, const scale3x_uint32* __restrict__ src2, unsigned count) {
|
2004-08-07 16:04:43 +00:00
|
|
|
/* central pixels */
|
|
|
|
while (count) {
|
|
|
|
if (src0[0] != src2[0] && src1[-1] != src1[1]) {
|
|
|
|
dst[0] = src1[-1] == src0[0] ? src1[-1] : src1[0];
|
|
|
|
dst[1] = (src1[-1] == src0[0] && src1[0] != src0[1]) || (src1[1] == src0[0] && src1[0] != src0[-1]) ? src0[0] : src1[0];
|
|
|
|
dst[2] = src1[1] == src0[0] ? src1[1] : src1[0];
|
|
|
|
} else {
|
|
|
|
dst[0] = src1[0];
|
|
|
|
dst[1] = src1[0];
|
|
|
|
dst[2] = src1[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
++src0;
|
|
|
|
++src1;
|
|
|
|
++src2;
|
|
|
|
dst += 3;
|
|
|
|
--count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-07 00:37:04 +00:00
|
|
|
static inline void scale3x_32_def_center(scale3x_uint32* __restrict__ dst, const scale3x_uint32* __restrict__ src0, const scale3x_uint32* __restrict__ src1, const scale3x_uint32* __restrict__ src2, unsigned count) {
|
2004-08-07 16:04:43 +00:00
|
|
|
/* central pixels */
|
|
|
|
while (count) {
|
|
|
|
if (src0[0] != src2[0] && src1[-1] != src1[1]) {
|
|
|
|
dst[0] = (src1[-1] == src0[0] && src1[0] != src2[-1]) || (src1[-1] == src2[0] && src1[0] != src0[-1]) ? src1[-1] : src1[0];
|
|
|
|
dst[1] = src1[0];
|
|
|
|
dst[2] = (src1[1] == src0[0] && src1[0] != src2[1]) || (src1[1] == src2[0] && src1[0] != src0[1]) ? src1[1] : src1[0];
|
|
|
|
} else {
|
|
|
|
dst[0] = src1[0];
|
|
|
|
dst[1] = src1[0];
|
|
|
|
dst[2] = src1[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
++src0;
|
|
|
|
++src1;
|
|
|
|
++src2;
|
|
|
|
dst += 3;
|
|
|
|
--count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scale by a factor of 3 a row of pixels of 8 bits.
|
|
|
|
* The function is implemented in C.
|
|
|
|
* The pixels over the left and right borders are assumed of the same color of
|
|
|
|
* the pixels on the border.
|
2010-11-07 00:37:04 +00:00
|
|
|
* @param src0 Pointer at the first pixel of the previous row.
|
|
|
|
* @param src1 Pointer at the first pixel of the current row.
|
|
|
|
* @param src2 Pointer at the first pixel of the next row.
|
|
|
|
* @param count Length in pixels of the src0, src1 and src2 rows.
|
2004-08-07 16:04:43 +00:00
|
|
|
* It must be at least 2.
|
2010-11-07 00:37:04 +00:00
|
|
|
* @param dst0 First destination row, triple length in pixels.
|
|
|
|
* @param dst1 Second destination row, triple length in pixels.
|
|
|
|
* @param dst2 Third destination row, triple length in pixels.
|
2004-08-07 16:04:43 +00:00
|
|
|
*/
|
2010-11-07 00:37:04 +00:00
|
|
|
void scale3x_8_def(scale3x_uint8* dst0, scale3x_uint8* dst1, scale3x_uint8* dst2, const scale3x_uint8* src0, const scale3x_uint8* src1, const scale3x_uint8* src2, unsigned count) {
|
2004-08-07 16:04:43 +00:00
|
|
|
scale3x_8_def_border(dst0, src0, src1, src2, count);
|
|
|
|
scale3x_8_def_center(dst1, src0, src1, src2, count);
|
|
|
|
scale3x_8_def_border(dst2, src2, src1, src0, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scale by a factor of 3 a row of pixels of 16 bits.
|
|
|
|
* This function operates like scale3x_8_def() but for 16 bits pixels.
|
2010-11-07 00:37:04 +00:00
|
|
|
* @param src0 Pointer at the first pixel of the previous row.
|
|
|
|
* @param src1 Pointer at the first pixel of the current row.
|
|
|
|
* @param src2 Pointer at the first pixel of the next row.
|
|
|
|
* @param count Length in pixels of the src0, src1 and src2 rows.
|
2004-08-07 16:04:43 +00:00
|
|
|
* It must be at least 2.
|
2010-11-07 00:37:04 +00:00
|
|
|
* @param dst0 First destination row, triple length in pixels.
|
|
|
|
* @param dst1 Second destination row, triple length in pixels.
|
|
|
|
* @param dst2 Third destination row, triple length in pixels.
|
2004-08-07 16:04:43 +00:00
|
|
|
*/
|
2010-11-07 00:37:04 +00:00
|
|
|
void scale3x_16_def(scale3x_uint16* dst0, scale3x_uint16* dst1, scale3x_uint16* dst2, const scale3x_uint16* src0, const scale3x_uint16* src1, const scale3x_uint16* src2, unsigned count) {
|
2004-08-07 16:04:43 +00:00
|
|
|
scale3x_16_def_border(dst0, src0, src1, src2, count);
|
|
|
|
scale3x_16_def_center(dst1, src0, src1, src2, count);
|
|
|
|
scale3x_16_def_border(dst2, src2, src1, src0, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scale by a factor of 3 a row of pixels of 32 bits.
|
|
|
|
* This function operates like scale3x_8_def() but for 32 bits pixels.
|
2010-11-07 00:37:04 +00:00
|
|
|
* @param src0 Pointer at the first pixel of the previous row.
|
|
|
|
* @param src1 Pointer at the first pixel of the current row.
|
|
|
|
* @param src2 Pointer at the first pixel of the next row.
|
|
|
|
* @param count Length in pixels of the src0, src1 and src2 rows.
|
2004-08-07 16:04:43 +00:00
|
|
|
* It must be at least 2.
|
2010-11-07 00:37:04 +00:00
|
|
|
* @param dst0 First destination row, triple length in pixels.
|
|
|
|
* @param dst1 Second destination row, triple length in pixels.
|
|
|
|
* @param dst2 Third destination row, triple length in pixels.
|
2004-08-07 16:04:43 +00:00
|
|
|
*/
|
2010-11-07 00:37:04 +00:00
|
|
|
void scale3x_32_def(scale3x_uint32* dst0, scale3x_uint32* dst1, scale3x_uint32* dst2, const scale3x_uint32* src0, const scale3x_uint32* src1, const scale3x_uint32* src2, unsigned count) {
|
2004-08-07 16:04:43 +00:00
|
|
|
scale3x_32_def_border(dst0, src0, src1, src2, count);
|
|
|
|
scale3x_32_def_center(dst1, src0, src1, src2, count);
|
|
|
|
scale3x_32_def_border(dst2, src2, src1, src0, count);
|
|
|
|
}
|