Path: blob/master/libmupen64plus/mupen64plus-video-glide64mk2/src/Glide64/MiClWr8b.h
2 views
/*1* Glide64 - Glide video plugin for Nintendo 64 emulators.2* Copyright (c) 2002 Dave20013* Copyright (c) 2003-2009 Sergey 'Gonetz' Lipski4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License as published by7* the Free Software Foundation; either version 2 of the License, or8* any later version.9*10* This program is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13* GNU General Public License for more details.14*15* You should have received a copy of the GNU General Public License16* along with this program; if not, write to the Free Software17* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA18*/1920//****************************************************************21//22// Glide64 - Glide Plugin for Nintendo 64 emulators23// Project started on December 29th, 200124//25// Authors:26// Dave2001, original author, founded the project in 2001, left it in 200227// Gugaman, joined the project in 2002, left it in 200228// Sergey 'Gonetz' Lipski, joined the project in 2002, main author since fall of 200229// Hiroshi 'KoolSmoky' Morii, joined the project in 200730//31//****************************************************************32//33// To modify Glide64:34// * Write your name and (optional)email, commented by your work, so I know who did it, and so that you can find which parts you modified when it comes time to send it to me.35// * Do NOT send me the whole project or file that you modified. Take out your modified code sections, and tell me where to put them. If people sent the whole thing, I would have many different versions, but no idea how to combine them all.36//37//****************************************************************3839//****************************************************************40// 8-bit Horizontal Mirror4142static inline void mirror8bS(uint8_t *tex, uint8_t *start, int width, int height, int mask, int line, int full, int count)43{44uint8_t *v8;45int v9;46int v10;4748v8 = start;49v9 = height;50do51{52v10 = 0;53do54{55if ( width & (v10 + width) )56*v8++ = *(&tex[mask] - (mask & v10));57else58*v8++ = tex[mask & v10];59++v10;60}61while ( v10 != count );62v8 += line;63tex += full;64--v9;65}66while ( v9 );67}6869static inline void wrap8bS(uint8_t *tex, uint8_t *start, int height, int mask, int line, int full, int count)70{71uint32_t *v7;72int v8;73int v9;7475v7 = (uint32_t *)start;76v8 = height;77do78{79v9 = 0;80do81{82*v7 = *(uint32_t *)&tex[4 * (mask & v9)];83++v7;84++v9;85}86while ( v9 != count );87v7 = (uint32_t *)((char *)v7 + line);88tex += full;89--v8;90}91while ( v8 );92}9394static inline void clamp8bS(uint8_t *tex, uint8_t *constant, int height, int line, int full, int count)95{96uint8_t *v6;97uint8_t *v7;98int v8;99uint8_t v9;100int v10;101102v6 = constant;103v7 = tex;104v8 = height;105do106{107v9 = *v6;108v10 = count;109do110{111*v7++ = v9;112--v10;113}114while ( v10 );115v6 += full;116v7 += line;117--v8;118}119while ( v8 );120}121122void Mirror8bS (unsigned char * tex, wxUint32 mask, wxUint32 max_width, wxUint32 real_width, wxUint32 height)123{124if (mask == 0) return;125126wxUint32 mask_width = (1 << mask);127wxUint32 mask_mask = (mask_width-1);128if (mask_width >= max_width) return;129int count = max_width - mask_width;130if (count <= 0) return;131int line_full = real_width;132int line = line_full - (count);133if (line < 0) return;134unsigned char * start = tex + (mask_width);135mirror8bS (tex, start, mask_width, height, mask_mask, line, line_full, count);136}137138//****************************************************************139// 8-bit Horizontal Wrap (like mirror) ** UNTESTED **140141142void Wrap8bS (unsigned char * tex, wxUint32 mask, wxUint32 max_width, wxUint32 real_width, wxUint32 height)143{144if (mask == 0) return;145146wxUint32 mask_width = (1 << mask);147wxUint32 mask_mask = (mask_width-1) >> 2;148if (mask_width >= max_width) return;149int count = (max_width - mask_width) >> 2;150if (count <= 0) return;151int line_full = real_width;152int line = line_full - (count << 2);153if (line < 0) return;154unsigned char * start = tex + (mask_width);155wrap8bS (tex, start, height, mask_mask, line, line_full, count);156}157158//****************************************************************159// 8-bit Horizontal Clamp160161162void Clamp8bS (unsigned char * tex, wxUint32 width, wxUint32 clamp_to, wxUint32 real_width, wxUint32 real_height)163{164if (real_width <= width) return;165166unsigned char * dest = tex + (width);167unsigned char * constant = dest-1;168int count = clamp_to - width;169170int line_full = real_width;171int line = width;172clamp8bS (dest, constant, real_height, line, line_full, count);173}174175//****************************************************************176// 8-bit Vertical Mirror177178void Mirror8bT (unsigned char * tex, wxUint32 mask, wxUint32 max_height, wxUint32 real_width)179{180if (mask == 0) return;181182wxUint32 mask_height = (1 << mask);183wxUint32 mask_mask = mask_height-1;184if (max_height <= mask_height) return;185int line_full = real_width;186187unsigned char * dst = tex + mask_height * line_full;188189for (wxUint32 y=mask_height; y<max_height; y++)190{191if (y & mask_height)192{193// mirrored194memcpy ((void*)dst, (void*)(tex + (mask_mask - (y & mask_mask)) * line_full), line_full);195}196else197{198// not mirrored199memcpy ((void*)dst, (void*)(tex + (y & mask_mask) * line_full), line_full);200}201202dst += line_full;203}204}205206//****************************************************************207// 8-bit Vertical Wrap208209void Wrap8bT (unsigned char * tex, wxUint32 mask, wxUint32 max_height, wxUint32 real_width)210{211if (mask == 0) return;212213wxUint32 mask_height = (1 << mask);214wxUint32 mask_mask = mask_height-1;215if (max_height <= mask_height) return;216int line_full = real_width;217218unsigned char * dst = tex + mask_height * line_full;219220for (wxUint32 y=mask_height; y<max_height; y++)221{222// not mirrored223memcpy ((void*)dst, (void*)(tex + (y & mask_mask) * line_full), line_full);224225dst += line_full;226}227}228229//****************************************************************230// 8-bit Vertical Clamp231232void Clamp8bT (unsigned char * tex, wxUint32 height, wxUint32 real_width, wxUint32 clamp_to)233{234int line_full = real_width;235unsigned char * dst = tex + height * line_full;236unsigned char * const_line = dst - line_full;237238for (wxUint32 y=height; y<clamp_to; y++)239{240memcpy ((void*)dst, (void*)const_line, line_full);241dst += line_full;242}243}244245246247