Advertisement
Guest User

avi output should support interlace

a guest
Feb 4th, 2011
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 7.66 KB | None | 0 0
  1. From e15f643b8fcd897edd56a52aa4429d995b79879a Mon Sep 17 00:00:00 2001
  2. From: gocha <gochaism@gmail.com>
  3. Date: Sat, 5 Feb 2011 00:00:51 +0900
  4. Subject: [PATCH] avi output support interlace
  5.  
  6. ---
  7. win32/win32.cpp |   79 ++++++++++++++++++++++++++++++++++++-------------------
  8.  1 files changed, 52 insertions(+), 27 deletions(-)
  9.  
  10. diff --git a/win32/win32.cpp b/win32/win32.cpp
  11. index 1f1dad1..fc0e919 100644
  12. --- a/win32/win32.cpp
  13. +++ b/win32/win32.cpp
  14. @@ -202,12 +202,8 @@
  15.  //#define DEBUGGER
  16.  
  17.  #include <math.h>
  18. -#ifndef max
  19. -#define max(a, b) (((a) > (b)) ? (a) : (b))
  20. -#endif
  21. -#ifndef min
  22. -#define min(a, b) (((a) < (b)) ? (a) : (b))
  23. -#endif
  24. +
  25. +#include <algorithm>
  26.  
  27.  BYTE *ScreenBuf1 = NULL;
  28.  BYTE *ScreenBuffer = NULL;
  29. @@ -1129,20 +1125,24 @@ void BuildAVIVideoFrame1X (void)
  30.  {
  31.     const int snesWidth = IPPU.RenderedScreenWidth;
  32.     const int snesHeight = IPPU.RenderedScreenHeight;
  33. -   const int width = min(snesWidth, avi_width);
  34. -   const int height = min(snesHeight, avi_height);
  35. +   const bool snesInterlaced = (snesHeight > SNES_HEIGHT_EXTENDED);
  36. +   const int snesVerticalScale = snesInterlaced ? 2 : 1;
  37. +   const int width = std::min(snesWidth, avi_width);
  38. +   const int height = std::min(snesHeight / snesVerticalScale, avi_height);
  39.     const int pitch = GFX.Pitch;
  40.  #ifdef LSB_FIRST
  41.     const bool order_is_rgb = (GUI.RedShift < GUI.BlueShift);
  42.  #else
  43.     const bool order_is_rgb = (GUI.RedShift > GUI.BlueShift);
  44.  #endif
  45. -   const int src_step = pitch - width * 2;
  46. +   const int src_step = (pitch - width * 2) + (snesInterlaced ? pitch : 0);
  47.     const int dst_step = -(avi_pitch + width * 3);
  48.     const int image_offset = (avi_height - height) * avi_pitch;
  49.     uint16 *s = GFX.Screen;
  50.     uint8  *d = &avi_buffer[(avi_height - 1) * avi_pitch];
  51.  
  52. +   // TODO: vertical blend for interlace
  53. +
  54.     for(int y = 0; y < height; y++)
  55.     {
  56.         for(int x = 0; x < width; x++)
  57. @@ -1150,7 +1150,10 @@ void BuildAVIVideoFrame1X (void)
  58.             if(order_is_rgb)
  59.             {
  60.                 // Order is RGB
  61. -               uint32 pixel = *s++;
  62. +               uint32 pixel = s[0];
  63. +               if (snesInterlaced)
  64. +                   pixel = Interp(pixel,s[pitch]);
  65. +               s++;
  66.                 *(d + 0) = (pixel >> (11 - 3)) & 0xf8;
  67.                 *(d + 1) = (pixel >> (6 - 3)) & 0xf8;
  68.                 *(d + 2) = (pixel & 0x1f) << 3;
  69. @@ -1159,7 +1162,10 @@ void BuildAVIVideoFrame1X (void)
  70.             else
  71.             {
  72.                 // Order is BGR
  73. -               uint32 pixel = *s++;
  74. +               uint32 pixel = s[0];
  75. +               if (snesInterlaced)
  76. +                   pixel = Interp(pixel,s[pitch]);
  77. +               s++;
  78.                 *(d + 0) = (pixel & 0x1f) << 3;
  79.                 *(d + 1) = (pixel >> (6 - 3)) & 0xf8;
  80.                 *(d + 2) = (pixel >> (11 - 3)) & 0xf8;
  81. @@ -1181,21 +1187,23 @@ void BuildAVIVideoFrame2X (void)
  82.  {
  83.     const int snesWidth = IPPU.RenderedScreenWidth;
  84.     const int snesHeight = IPPU.RenderedScreenHeight;
  85. -   const int width = min(snesWidth, avi_width / 2);
  86. -   const int height = min(snesHeight, avi_height / 2);
  87. +   const bool snesInterlaced = (snesHeight > SNES_HEIGHT_EXTENDED);
  88. +   const int snesVerticalScale = snesInterlaced ? 2 : 1;
  89. +   const int width = std::min(snesWidth, avi_width / 2);
  90. +   const int height = std::min(snesHeight * 2 / snesVerticalScale, avi_height);
  91.     const int pitch = GFX.Pitch;
  92.  #ifdef LSB_FIRST
  93.     const bool order_is_rgb = (GUI.RedShift < GUI.BlueShift);
  94.  #else
  95.     const bool order_is_rgb = (GUI.RedShift > GUI.BlueShift);
  96.  #endif
  97. -   const int src_step[2] = { -width * 2, pitch - width * 2 };
  98. +   const int src_step[2] = { -width * 2 + (snesInterlaced ? pitch : 0), -width * 2 + pitch };
  99.     const int dst_step = -(avi_pitch + width * 3 * 2);
  100. -   const int image_offset = (avi_height - height * 2) * avi_pitch;
  101. +   const int image_offset = (avi_height - height) * avi_pitch;
  102.     uint16 *s = GFX.Screen;
  103.     uint8  *d = &avi_buffer[(avi_height - 1) * avi_pitch];
  104.  
  105. -   for(int y = 0; y < height * 2; y++)
  106. +   for(int y = 0; y < height; y++)
  107.     {
  108.         for(int x = 0; x < width; x++)
  109.         {
  110. @@ -1233,15 +1241,17 @@ void BuildAVIVideoFrame1XHiRes (void)
  111.  {
  112.     const int snesWidth = IPPU.RenderedScreenWidth;
  113.     const int snesHeight = IPPU.RenderedScreenHeight;
  114. -   const int width = min(snesWidth / 2, avi_width);
  115. -   const int height = min(snesHeight, avi_height);
  116. +   const bool snesInterlaced = (snesHeight > SNES_HEIGHT_EXTENDED);
  117. +   const int snesVerticalScale = snesInterlaced ? 2 : 1;
  118. +   const int width = std::min(snesWidth / 2, avi_width);
  119. +   const int height = std::min(snesHeight / snesVerticalScale, avi_height);
  120.     const int pitch = GFX.Pitch;
  121.  #ifdef LSB_FIRST
  122.     const bool order_is_rgb = (GUI.RedShift < GUI.BlueShift);
  123.  #else
  124.     const bool order_is_rgb = (GUI.RedShift > GUI.BlueShift);
  125.  #endif
  126. -   const int src_step = pitch - width * 2 * 2;
  127. +   const int src_step = (pitch - width * 2 * 2) + (snesInterlaced ? pitch : 0);
  128.     const int dst_step = -(avi_pitch + width * 3);
  129.     const int image_offset = (avi_height - height) * avi_pitch;
  130.     uint16 *s = GFX.Screen;
  131. @@ -1260,6 +1270,11 @@ void BuildAVIVideoFrame1XHiRes (void)
  132.             {
  133.                 // Order is RGB
  134.                 uint32 pixel = Interp(s[0],s[1]);
  135. +               if (snesInterlaced)
  136. +               {
  137. +                   uint32 pixel2 = Interp(s[pitch],s[pitch + 1]);
  138. +                   pixel = Interp(pixel,pixel2);
  139. +               }
  140.                 s += 2;
  141.                 *(d + 0) = (pixel >> (11 - 3)) & 0xf8;
  142.                 *(d + 1) = (pixel >> (6 - 3)) & 0xf8;
  143. @@ -1270,6 +1285,11 @@ void BuildAVIVideoFrame1XHiRes (void)
  144.             {
  145.                 // Order is BGR
  146.                 uint32 pixel = Interp(s[0],s[1]);
  147. +               if (snesInterlaced)
  148. +               {
  149. +                   uint32 pixel2 = Interp(s[pitch],s[pitch + 1]);
  150. +                   pixel = Interp(pixel,pixel2);
  151. +               }
  152.                 s += 2;
  153.                 *(d + 0) = (pixel & 0x1f) << 3;
  154.                 *(d + 1) = (pixel >> (6 - 3)) & 0xf8;
  155. @@ -1292,21 +1312,23 @@ void BuildAVIVideoFrame2XHiRes (void)
  156.  {
  157.     const int snesWidth = IPPU.RenderedScreenWidth;
  158.     const int snesHeight = IPPU.RenderedScreenHeight;
  159. -   const int width = min(snesWidth, avi_width);
  160. -   const int height = min(snesHeight, avi_height / 2);
  161. +   const bool snesInterlaced = (snesHeight > SNES_HEIGHT_EXTENDED);
  162. +   const int snesVerticalScale = snesInterlaced ? 2 : 1;
  163. +   const int width = std::min(snesWidth, avi_width);
  164. +   const int height = std::min(snesHeight * 2 / snesVerticalScale, avi_height);
  165.     const int pitch = GFX.Pitch;
  166.  #ifdef LSB_FIRST
  167.     const bool order_is_rgb = (GUI.RedShift < GUI.BlueShift);
  168.  #else
  169.     const bool order_is_rgb = (GUI.RedShift > GUI.BlueShift);
  170.  #endif
  171. -   const int src_step[2] = { -width * 2, pitch - width * 2 };
  172. +   const int src_step[2] = { -width * 2 + (snesInterlaced ? pitch : 0), -width * 2 + pitch };
  173.     const int dst_step = -(avi_pitch + width * 3);
  174. -   const int image_offset = (avi_height - height * 2) * avi_pitch;
  175. +   const int image_offset = (avi_height - height) * avi_pitch;
  176.     uint16 *s = GFX.Screen;
  177.     uint8  *d = &avi_buffer[(avi_height - 1) * avi_pitch];
  178.  
  179. -   for(int y = 0; y < height * 2; y++)
  180. +   for(int y = 0; y < height; y++)
  181.     {
  182.         for(int x = 0; x < width; x++)
  183.         {
  184. @@ -1371,11 +1393,15 @@ void DoAVIOpen(const TCHAR* filename)
  185.     avi_skip_frames = Settings.SkipFrames;
  186.  
  187.     if(GUI.AVIHiRes && avi_width <= SNES_WIDTH)
  188. -       avi_width = SNES_WIDTH*2;
  189. +       avi_width = SNES_WIDTH * 2;
  190.     else if(!GUI.AVIHiRes && avi_width > SNES_WIDTH)
  191.         avi_width = SNES_WIDTH;
  192. -   if(GUI.HeightExtend && avi_height < SNES_HEIGHT_EXTENDED)
  193. +   if (avi_height > SNES_HEIGHT_EXTENDED)
  194. +       avi_height /= 2;
  195. +   if(GUI.HeightExtend)
  196.         avi_height = SNES_HEIGHT_EXTENDED;
  197. +   else
  198. +       avi_height = std::max(SNES_HEIGHT, avi_height);
  199.     if(GUI.AVIHiRes)
  200.         avi_height *= 2;
  201.     if(avi_height % 2 != 0) // most codecs can't handle odd-height images
  202. @@ -1492,7 +1518,6 @@ void DoAVIVideoFrame(SSurface* source_surface)
  203.  
  204.     // convert to bitdepth 24
  205.     const int snesWidth = IPPU.RenderedScreenWidth;
  206. -   const int snesHeight = IPPU.RenderedScreenHeight;
  207.     if(snesWidth < SNES_WIDTH*2) // normal
  208.     {
  209.         if(avi_width < snesWidth*2) // 1x
  210. --
  211. 1.7.3.1.msysgit.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement