Advertisement
Guest User

DDT 3x

a guest
Apr 27th, 2012
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.96 KB | None | 0 0
  1. /*
  2.    Hyllian's Data Dependent Triangulation 3x
  3.    
  4.    Copyright (C) 2011, 2012 Hyllian/Jararaca - sergiogdb@gmail.com
  5.  
  6.    This program is free software; you can redistribute it and/or
  7.    modify it under the terms of the GNU General Public License
  8.    as published by the Free Software Foundation; either version 2
  9.    of the License, or (at your option) any later version.
  10.  
  11.    This program is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with this program; if not, write to the Free Software
  18.    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19.  
  20. */
  21.  
  22. //---------------------------------------------------------------------------------------------------------------------------
  23. // ddt3x plugin for Kega Fusion.
  24. // Programmed by Hyllian
  25. //---------------------------------------------------------------------------------------------------------------------------
  26.  
  27. #include "../../RPI.h"
  28. #include <stdlib.h>
  29.  
  30. //---------------------------------------------------------------------------------------------------------------------------
  31.  
  32. extern "C"
  33. {
  34.     static unsigned char initialized = 0;
  35. //  unsigned int    RGBtoYUV[65536];
  36. //    static unsigned int tbl_5_to_8[32]={0, 8, 16, 25, 33, 41, 49,  58, 66, 74, 82, 90, 99, 107, 115, 123, 132, 140, 148, 156, 165, 173, 181, 189,  197, 206, 214, 222, 230, 239, 247, 255};
  37. //    static unsigned int tbl_6_to_8[64]={0, 4, 8, 12, 16, 20, 24,  28, 32, 36, 40, 45, 49, 53, 57, 61, 65, 69, 73, 77, 81, 85, 89, 93, 97, 101,  105, 109, 113, 117, 121, 125, 130, 134, 138, 142, 146, 150, 154, 158, 162, 166,  170, 174, 178, 182, 186, 190, 194, 198, 202, 206, 210, 215, 219, 223, 227, 231,  235, 239, 243, 247, 251, 255};
  38. }
  39.  
  40. //---------------------------------------------------------------------------------------------------------------------------
  41.  
  42.  
  43. unsigned short int pg_red_blue_mask;
  44. unsigned short int pg_green_mask;
  45. unsigned short int pg_lbmask;
  46.  
  47. #define RED_BLUE_MASK565   0xF81F
  48. #define RED_MASK565   0xF800
  49. #define GREEN_MASK565 0x07E0
  50.  
  51. #define RGB_MASK 0x07E0F81F
  52.  
  53. #define ALPHA_BLEND_X_W(dst, src, alpha) \
  54.     ts = src; td = dst;\
  55.     td = ((td|(td<<16)) & RGB_MASK); ts = ((ts|(ts<<16)) & RGB_MASK);\
  56.     td = ((( ( (ts-td)*alpha ) >> 5 ) + td ) & RGB_MASK); \
  57.     dst= (td|(td>>16));\
  58.  
  59.  
  60. #define BIL3X(PF, PH, PI, N5, N7, N8) \
  61.        ALPHA_BLEND_X_W(E[N5], PF, 5); \
  62.        ALPHA_BLEND_X_W(E[N7], PH, 5); \
  63.        ALPHA_BLEND_X_W(E[N8], PF, 9); \
  64.        ALPHA_BLEND_X_W(E[N8], PH, 7); \
  65.        ALPHA_BLEND_X_W(E[N8], PI, 3); \
  66.  
  67.  
  68. #define DDT3X_BC(PF, PH, PI, N5, N7, N8) \
  69.        ALPHA_BLEND_X_W(E[N5], PF, 6); \
  70.        ALPHA_BLEND_X_W(E[N7], PH, 6); \
  71.        ALPHA_BLEND_X_W(E[N8], PI, 12); \
  72.  
  73. #define DDT3X_D(PF, PH, N5, N7, N8) \
  74.        ALPHA_BLEND_X_W(E[N5], PF, 6); \
  75.        ALPHA_BLEND_X_W(E[N7], PH, 6); \
  76.        ALPHA_BLEND_X_W(E[N8], PF, 12); \
  77.        ALPHA_BLEND_X_W(E[N8], PH, 12); \
  78.  
  79.  
  80. #define FILTRO(PE, PI, PH, PF, PG, PC, PD, PB, PA, N0, N1, N2, N3, N4, N5, N6, N7, N8) \
  81. {\
  82.   if (PE!=PF || PE!=PH || PE!=PI) \
  83.   {\
  84.     ad = abs(PE-PI); bc = abs(PF-PH);\
  85.     if (ad < bc)\
  86.     {\
  87.         DDT3X_BC(PF, PH, PI, N5, N7, N8);\
  88.     }\
  89.     else if (ad > bc)\
  90.     {\
  91.         DDT3X_D(PF, PH, N5, N7, N8);\
  92.     }\
  93.     else\
  94.     {\
  95.         BIL3X(PF, PH, PI, N5, N7, N8) \
  96.     }\
  97.  }\
  98. }\
  99.  
  100.        
  101.  
  102. //---------------------------------------------------------------------------------------------------------------------------
  103.  
  104. extern  "C" __declspec(dllexport) RENDER_PLUGIN_INFO *
  105. RenderPluginGetInfo(void)
  106. {
  107.     rpi_strcpy(&MyRPI.Name[0], "DDT3x - (Hyllian/Jararaca)");
  108.     MyRPI.Flags=RPI_VERSION | RPI_565_SUPP | RPI_OUT_SCL3;
  109.     return(&MyRPI);
  110. }
  111.  
  112. //---------------------------------------------------------------------------------------------------------------------------
  113.  
  114. extern  "C" __declspec(dllexport) void
  115. RenderPluginOutput(RENDER_PLUGIN_OUTP *rpo)
  116. {  
  117.     unsigned short int x, y;
  118.     unsigned char *src, *dest;
  119.     unsigned short int PA, PB, PC, PD, PE, PF, PG, PH, PI;
  120.     register unsigned short int *sa1, *sa2, *sa3; // sa = start_address
  121.     unsigned short int nl, nl_src; // nl = new_line
  122.     unsigned short int nl1;
  123.     unsigned short int *E;  // E = dst_pixel
  124.     unsigned short int src_width, src_height;
  125.     unsigned short int complete_line_src, complete_line_dst;
  126.     unsigned short int src_pitch;
  127.     unsigned char pprev;
  128.     unsigned int ad, bc;
  129.     unsigned int td, ts;
  130.  
  131.     if (!initialized)
  132.     {
  133.        if(rpo->Flags&RPI_565_SUPP)
  134.        {
  135.                  pg_red_blue_mask   = RED_BLUE_MASK565;
  136.                  pg_green_mask = GREEN_MASK565;
  137.                  pg_lbmask     = PG_LBMASK565;
  138.        }
  139.        initialized = 1;
  140.     }
  141.    
  142.     /* Don't blit anything if we don't have enough screen space */
  143.    if(!(((rpo->SrcW * 3)<=rpo->DstW) && ((rpo->SrcH * 3)<=rpo->DstH)))
  144.         return;
  145.  
  146.     src = (unsigned char *)rpo->SrcPtr;
  147.     dest = (unsigned char *)rpo->DstPtr;
  148.     src_pitch = rpo->SrcPitch;
  149.  
  150.     nl_src = src_pitch >> 1;
  151.     nl = rpo->DstPitch >> 1;
  152.     nl1= rpo->DstPitch;
  153.  
  154.     src_width = rpo->SrcW;
  155.     src_height = rpo->SrcH;
  156.  
  157.     // fixed by Steve Snake
  158.     complete_line_src = (src_pitch>>1) - rpo->SrcW;
  159.     complete_line_dst = ((rpo->DstPitch*3)>>1) - rpo->DstW;
  160.    
  161.     sa2 = (unsigned short int *)(src - 4);
  162.     sa1 = sa2;
  163.     sa3 = sa2 + src_pitch;
  164.    
  165.     E = (unsigned short int *)(dest);  
  166.    
  167.     y = src_height;
  168.  
  169.     while(y--)
  170.     {  
  171.         if (!y) sa3 = sa2;
  172.         pprev = 2;
  173.         x = src_width;
  174.        
  175.         while(x--)
  176.         {          
  177.             PB = sa1[2];
  178.             PE = sa2[2];           
  179.             PH = sa3[2];
  180.            
  181.             PA = sa1[pprev];
  182.             PD = sa2[pprev];           
  183.             PG = sa3[pprev];
  184.            
  185.             PC = sa1[3];
  186.             PF = sa2[3];
  187.             PI = sa3[3];
  188.                
  189.             if (!x)            
  190.             {
  191.                 PC = sa1[2];
  192.                 PF = sa2[2];
  193.                 PI = sa3[2];
  194.             }
  195.  
  196.             E[0]   = E[1]     = E[2]     = PE;
  197.             E[nl]  = E[nl+1]  = E[nl+2]  = PE; // 3, 4, 5
  198.             E[nl1] = E[nl1+1] = E[nl1+2] = PE; // 6, 7, 8
  199.            
  200. if (PE!=PH || PE!=PI || PE!=PF || PE!=PC || PE!=PB || PE!=PA || PE!=PD || PE!=PG)
  201. {
  202.            
  203. FILTRO(PE, PI, PH, PF, PG, PC, PD, PB, PA, 0, 1, 2, nl, nl+1, nl+2, nl1, nl1+1, nl1+2);
  204. FILTRO(PE, PC, PF, PB, PI, PA, PH, PD, PG, nl1, nl, 0, nl1+1, nl+1, 1, nl1+2, nl+2, 2);
  205. FILTRO(PE, PA, PB, PD, PC, PG, PF, PH, PI, nl1+2, nl1+1, nl1, nl+2, nl+1, nl, 2, 1, 0);
  206. FILTRO(PE, PG, PD, PH, PA, PI, PB, PF, PC, 2, nl+2, nl1+2, 1, nl+1, nl1+1, 0, nl, nl1);
  207.  
  208. }
  209.             sa1++;
  210.             sa2++;
  211.             sa3++;
  212.            
  213.             E+=3;
  214.            
  215.             pprev = 1;
  216.         }
  217.        
  218.         sa2 += complete_line_src;
  219.         sa1 = sa2 - nl_src;    
  220.         sa3 = sa2 + nl_src;
  221.        
  222.         E += complete_line_dst;            
  223.     }
  224.    
  225.     // Set the output size incase anybody cares.
  226.     rpo->OutW=(rpo->SrcW*3);
  227.     rpo->OutH=(rpo->SrcH*3);
  228. }
  229.  
  230.  
  231. //---------------------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement