Mndiff-dev
Threads by month
- ----- 2026 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
July 2007
- 1 participants
- 45 discussions
Author: michael
Date: Wed Jul 4 11:48:35 2007
New Revision: 66
Log:
say a few words about what this is
Added:
trunk/2010/README
Added: trunk/2010/README
==============================================================================
--- (empty file)
+++ trunk/2010/README Wed Jul 4 11:48:35 2007
@@ -0,0 +1,19 @@
+2010
+----
+
+About:
+------
+some old code i wrote in 1998-2000 or so, which decodes nagravision,
+videocrypt, sync suppression and teletext
+warning the code is messy, patches to clean it up are welcome!
+
+Requirements:
+-------------
+matrox meteor card or compatible, porting this to some more common hardware
+shouldnt be hard (patch welcome)
+windows/dos something, i dont remember, patches which port it to linux and
+v4l(2) are very welcome
+
+License:
+--------
+GPL v2+
\ No newline at end of file
1
0
[mndiff]: r65 - in trunk/2010: 2010.cpp 2_71x6.cpp 2_crypt.cpp 2_crypt.h 2_grafix.cpp 2_pal.h 2_vpaytv.cpp 2d 2d.txt
by michael 04 Jul '07
by michael 04 Jul '07
04 Jul '07
Author: michael
Date: Wed Jul 4 11:38:46 2007
New Revision: 65
Log:
version from 2000-04-18 13:27
Added:
trunk/2010/2_pal.h
trunk/2010/2d.txt
- copied, changed from r62, /trunk/2010/2d
Removed:
trunk/2010/2d
Modified:
trunk/2010/2010.cpp
trunk/2010/2_71x6.cpp
trunk/2010/2_crypt.cpp
trunk/2010/2_crypt.h
trunk/2010/2_grafix.cpp
trunk/2010/2_vpaytv.cpp
Modified: trunk/2010/2010.cpp
==============================================================================
--- trunk/2010/2010.cpp (original)
+++ trunk/2010/2010.cpp Wed Jul 4 11:38:46 2007
@@ -50,7 +50,7 @@ extern bool drop;
int maxBuf=2;
int some=0;
-
+ int some2=0;
int _crt0_startup_flags = _CRT0_FLAG_NEARPTR | _CRT0_FLAG_NONMOVE_SBRK;
bool fShowRaw=false;
@@ -485,6 +485,10 @@ int main(int argc, char **argv){
break;
case '4' : some--; if(some<0) some=0;
break;
+ case '5' : some2++;
+ break;
+ case '6' : some2--; if(some2<0) some2=0;
+ break;
case 'a' :
case 'A' : if(TVStd!=TXTPAL) break;
tabActive=true;
Modified: trunk/2010/2_71x6.cpp
==============================================================================
--- trunk/2010/2_71x6.cpp (original)
+++ trunk/2010/2_71x6.cpp Wed Jul 4 11:38:46 2007
@@ -761,13 +761,16 @@ void doTxtHack(int txtHackState){
}
void vPayTvShiftHack(int amount)
- {
- write_saa7196(0x0F, 0x50);
+{
+// __dpmi_yield();
- for(int i=0; i<10000*amount; i++);
+ write_saa7196(0x0F, 0x50);
+
+// for(int i=1000*amount; i>0; i--);
+ for(int i=0; i<10000*amount; i++);
write_saa7196(0x0F, 0x10);
- }
+}
void vPayTvBrightHack(bool b, int posInLCC)
@@ -786,10 +789,10 @@ void vPayTvBrightHack(bool b, int posInL
int hSyncBegin= - 96 +posInLCC;
int hSyncStop= - 70 +posInLCC;
int hClampBegin= - 60 +posInLCC;
- int hClampStop= - 59 +posInLCC+some;
+ int hClampStop= - 59 +posInLCC+some/2;
int hSyncStartAfterPH1= 96;//+posInLCC;
- if(some==0) hClampStop= 148 +posInLCC;
+ if(some/2==0) hClampStop= 148 +posInLCC;
//else hClampStop= -59 +posInLCC + 10;
hSyncBegin = minmax(-382, hSyncBegin, 126);
@@ -807,7 +810,7 @@ void vPayTvBrightHack(bool b, int posInL
if(hClampBegin <= hSyncStop) hClampBegin= hSyncStop+1;
if(hClampStop <= hClampBegin) hClampStop= hClampBegin+1;
- if(b)
+ if(b ^ (some&1))
{
write_saa7196(0x01, (-hSyncBegin-3 )&0xFF);/* 7:0 Horizontal Sync Begin for 50hz */
write_saa7196(0x02, (-hSyncBegin )&0xFF);/* 7:0 Horizontal Sync Begin for 50hz */
Modified: trunk/2010/2_crypt.cpp
==============================================================================
--- trunk/2010/2_crypt.cpp (original)
+++ trunk/2010/2_crypt.cpp Wed Jul 4 11:38:46 2007
@@ -46,7 +46,7 @@ void decrypt(void){
}
if( cryptStd == nag && satur!=0 ) Decomb(0);
- if( cryptStd == vc && satur!=0 ) Decomb(1);
+ if( cryptStd == vc && satur!=0 ) Decomb(1);
if(iState){
T2=uclock();
Modified: trunk/2010/2_crypt.h
==============================================================================
--- trunk/2010/2_crypt.h (original)
+++ trunk/2010/2_crypt.h Wed Jul 4 11:38:46 2007
@@ -5,11 +5,6 @@
#define max_x 900
#define max_y 700
-#define BLACK_LEVEL 0.0
-#define BLANK_LEVEL 0.0
-#define WHITE_LEVEL 1.0
-#define SYNC_LEVEL (-43.0 / 100.0)
-
#define FREQ_CHROM 4433618.75
#define FREQ_HS 15625.0
#define FREQ_PIX (FREQ_HS * 1888.0 * 0.5)
Modified: trunk/2010/2_grafix.cpp
==============================================================================
--- trunk/2010/2_grafix.cpp (original)
+++ trunk/2010/2_grafix.cpp Wed Jul 4 11:38:46 2007
@@ -26,7 +26,7 @@
extern int infoPosX;
extern int infoPosY;
extern VID2MEMBUF *vid2MemBuf;
- extern int some;
+ extern int some, some2;
extern bool allowDrop;
bool helpState=true;
@@ -127,6 +127,8 @@ void showStuff(void){
sprintf(textbuf,"%d Some", some);
gprint(infoPosX, infoPosY+=10, c.col, textbuf);
+ sprintf(textbuf,"%d Some2", some2);
+ gprint(infoPosX, infoPosY+=10, c.col, textbuf);
infoPosY+=5;
}
if(iState==2){
Added: trunk/2010/2_pal.h
==============================================================================
--- (empty file)
+++ trunk/2010/2_pal.h Wed Jul 4 11:38:46 2007
@@ -0,0 +1,16 @@
+//2010 0.1 Copyright (C) Michael Niedermayer 2000
+#ifndef n2_pal_h
+#define n2_pal_h
+
+#define PAL_FREQ_CHROM 4433618.75
+#define PAL_FREQ_HS 15625.0
+#define PAL_NUM_LINES 625
+#define PAL_PHASE_DRIFT_PER_LINE (-fmod(PAL_FREQ_CHROM/PAL_FREQ_HS*4.0, 1.0)/4.0*PI*2.0)
+#define PAL_VSYNC_SIZE 26 //?
+
+#define PAL_BLACK_LEVEL 0.0
+#define PAL_BLANK_LEVEL 0.0
+#define PAL_WHITE_LEVEL 1.0
+#define PAL_SYNC_LEVEL (-43.0 / 100.0) //?
+
+#endif
Modified: trunk/2010/2_vpaytv.cpp
==============================================================================
--- trunk/2010/2_vpaytv.cpp (original)
+++ trunk/2010/2_vpaytv.cpp Wed Jul 4 11:38:46 2007
@@ -15,34 +15,41 @@
#include "2_nag_a.h"
#include "2_hw_mem.h"
#include "2_vpaytv.h"
+#include "2_pal.h"
#include "2010.h"
-#define FREQ_CHROM 4433618.75
-#define FREQ_HS 15625.0
-#define PHASE_DRIFT_PER_LINE (-fmod(FREQ_CHROM/FREQ_HS*4.0, 1.0)/4.0*PI*2.0)
-#define Q_2_HSYNC_DISTANCE 6 //HACK (only 400x300)
-#define VSYNC_SIZE 26
-
-#define REAL_QLINE_POS (wndx-10)
+/* SyncSupression Encoding Constants */
+#define Q_2_HSYNC_DISTANCE (QCOL_SIZE + 2) // only 400x300
+#define QCOL_SIZE 14 // only 400x300
-#define QLINE_COEFFICIENT_THRESHOLD 0.20
-//#define QLINE_OVERBRIGHT_THRESHOLD 220
-#define QLINE_OVERBRIGHT_THRESHOLD 240
-#define OVERBRIGHT_TEST_COLUMN 4
-#define HSYNC_THRESHOLD 30
-#define HSYNC_SEARCH_START (Q_2_HSYNC_DISTANCE-3)
-#define HSYNC_SEARCH_END 22
+/* VSync Detection */
#define VSYNC_SEARCH_COLUMN (-2)
-#define VSYNC_OVERBRIGHT_THRESHOLD 230
#define MIN_VSYNC_DISTANCE 20
-#define LEFT_QLINE_BOUNDRY (wndx-20)
-#define RIGHT_QLINE_BOUNDRY (wndx-7)
+/* HSync Detection */
+#define QCOL_CORREL_QCOL_SIZE 5 // only 400x300
+#define QCOL_CORREL_BORDER_SIZE (QCOL_CORREL_QCOL_SIZE) // only right, there is none at the left
+#define QCOL_CORREL_SIZE (QCOL_CORREL_QCOL_SIZE + QCOL_CORREL_BORDER_SIZE)
+#define QCOL_COEFFICIENT_THRESHOLD 0.20
+#define HSYNC_SEARCH_START (Q_2_HSYNC_DISTANCE-5)
+#define HSYNC_SEARCH_END (Q_2_HSYNC_DISTANCE+5)
+
+#define REAL_HSYNC_LOC (wndx-10)
+#define LEFT_HSYNC_BOUNDRY (wndx-10)
+#define RIGHT_HSYNC_BOUNDRY (wndx-5)
#define TOP_VSYNC_BOUNDRY (wndy-50)
#define BOTTOM_VSYNC_BOUNDRY (wndy+50)
-#define RELATIV_LEVEL_SHIFT 2.0
+/* Brightness / Contrast Fix */
+#define RELATIV_LEVEL_SHIFT 2.0
+#define BLANK_REF_LOC (-3)
+#define SYNC_REF_LOC 3
+//#define CLIP_REJECTION_THRESHOLD 1.5
+
+/* Color-Phase Fix */
+#define START_Q_PHASE (some2 /180.0*PI)
+#define Q_PHASE_DELTA (-2*PI /(PAL_NUM_LINES))
extern vgax, vgay, wndx, wndy, outy, y_field, x_field;
@@ -55,9 +62,11 @@ extern int yuvMode;
extern bool mmx;
extern int infoPosX;
extern int infoPosY;
-extern int some;
+extern int some, some2;
extern bool drop;
extern bool isVCPhaseTrick;
+extern int bright;
+extern int contr;
static inline float atan3(const float f1, const float f2){
float out;
@@ -73,7 +82,7 @@ static inline float atan3(const float f1
}
static int qPhase=0;
-int findQLine(void)
+int findHSync(void)
{
long T1=0, T2;
color c;
@@ -82,39 +91,53 @@ int findQLine(void)
if(iState==2)
T1=uclock();
+
+ static float blankCorrelVector[4]= {0.5, 0.5, 0.5, 0.5};
+ static float qColCorrelVector[4]= {1.0, 1.0, 0.0, 0.0};
- const int xSizeOfCorrelVector= 4;
- float correlVector[4][4]= { {1,1,0 ,0 },
- {0,0,0.33,0.33},
- {0,0,0.33,0.33},
- {0,0,0.33,0.33} };
+ static bool isFirst= true;
+ if(isFirst)
+ {
- float meanOfCorrelVector= 0;
- for(int y=0; y<4; y++)
- for(int x=0; x<xSizeOfCorrelVector; x++)
- meanOfCorrelVector+= correlVector[y][x];
+ /* Normalize CorrelVectors */
- meanOfCorrelVector/= xSizeOfCorrelVector*4;
-
- float varianceOfCorrelVector= 0;
- for(int y=0; y<4; y++)
- for(int x=0; x<xSizeOfCorrelVector; x++)
- {
- correlVector[y][x] -= meanOfCorrelVector;
- varianceOfCorrelVector+= correlVector[y][x] * correlVector[y][x];
- }
+ double mean= 0;
+ for(int y=0; y<4; y++)
+ {
+ mean+= blankCorrelVector[y] * QCOL_CORREL_BORDER_SIZE;
+ mean+= qColCorrelVector[y] * QCOL_CORREL_QCOL_SIZE;
+ }
+ mean/= 4.0 * QCOL_CORREL_SIZE;
- varianceOfCorrelVector/= xSizeOfCorrelVector*4;
+ float variance= 0;
+ for(int y=0; y<4; y++)
+ {
+ blankCorrelVector[y] -= mean;
+ qColCorrelVector[y] -= mean;
+
+ variance += blankCorrelVector[y] * blankCorrelVector[y] * QCOL_CORREL_BORDER_SIZE;
+ variance += qColCorrelVector[y] * qColCorrelVector[y] * QCOL_CORREL_QCOL_SIZE;
+ }
+ variance/= 4.0 * QCOL_CORREL_SIZE;
+ double stdDev= sqrt(variance);
+ for(int y=0; y<4; y++)
+ {
+ blankCorrelVector[y] /= stdDev;
+ qColCorrelVector[y] /= stdDev;
+ }
+
+ }
+
byte const * const p= &actVid2MemBufp->b[0];
if(iState==2)
- {
+ {
T2=uclock();
sprintf(textbuf,"%f X", (float)(T2-T1)/UCLOCKS_PER_SEC);
gprint(infoPosX, infoPosY+=10, c.col, textbuf);
T1=T2;
- }
+ }
int aSumsOfEquivalentPoints[4][1000];
for(int i=0; i<4; i++)
@@ -127,15 +150,13 @@ int findQLine(void)
for(int line=0; line<wndy; line+=3)
for(int x=0; x<wndx; x++)
- {
+ {
const int index= (line*vgax + x)*2;
- const int a=
- int(p[index + 1])
- + mabs(int((char)(p[index + 2])))
- + mabs(int((char)(p[index])));
+ const int a= mabs(int((char)(p[index + 2])))
+ + mabs(int((char)(p[index ])));
aSumsOfEquivalentPoints[line & 3][x]+= a;
aSumsOfSqrs[x]+= a*a;
- }
+ }
for(int x=0; x<wndx; x++)
{
@@ -143,117 +164,119 @@ int findQLine(void)
aSumsOfEquivalentPoints[1][x]*= 3;
aSumsOfEquivalentPoints[2][x]*= 3;
aSumsOfEquivalentPoints[3][x]*= 3;
- aSumsOfSqrs[x]*= 3;;
+ aSumsOfSqrs[x]*= 3;
}
if(iState==2)
- {
+ {
T2=uclock();
sprintf(textbuf,"%f EquivSum & SumSqr", (float)(T2-T1)/UCLOCKS_PER_SEC);
gprint(infoPosX, infoPosY+=10, c.col, textbuf);
T1=T2;
- }
+ }
+
int bestQLine=-1;
float bestCoefficient=-1;
- for(int qLine=0; qLine<wndx-xSizeOfCorrelVector+1; qLine++)
+ for(int xStart=0; xStart<wndx-QCOL_CORREL_SIZE; xStart++)
{
int sum=0;
for(int line=0; line<4; line++)
- for(int x=qLine; x<qLine + xSizeOfCorrelVector; x++)
+ for(int x=xStart; x<xStart + QCOL_CORREL_SIZE; x++)
sum+= aSumsOfEquivalentPoints[line][x];
- const double mean= double(sum) / (xSizeOfCorrelVector*wndy);
+ const double mean= double(sum) / (QCOL_CORREL_SIZE*wndy);
int sumOfSqrs=0;
- for(int x=qLine; x<qLine + xSizeOfCorrelVector; x++)
+ for(int x=xStart; x<xStart + QCOL_CORREL_SIZE; x++)
sumOfSqrs+= aSumsOfSqrs[x];
- float variance= (sumOfSqrs - sum*mean) / (xSizeOfCorrelVector*wndy);
+ float variance= (sumOfSqrs - sum*mean) / (QCOL_CORREL_SIZE*wndy);
// printf("%f = %d - %d * %f / ...\n", variance, sumOfSqrs, sum, mean);
if(variance<0.0) variance=0;
float coefficient[4]={0,0,0,0};
for(int line=0; line<4; line++)
- for(int x=qLine; x<qLine + xSizeOfCorrelVector; x++)
- {
- coefficient[0]+= (aSumsOfEquivalentPoints[line][x]-mean*wndy/4)
- * correlVector[(line+0) &3][x-qLine];
- coefficient[1]+= (aSumsOfEquivalentPoints[line][x]-mean*wndy/4)
- * correlVector[(line+1) &3][x-qLine];
- coefficient[2]+= (aSumsOfEquivalentPoints[line][x]-mean*wndy/4)
- * correlVector[(line+2) &3][x-qLine];
- coefficient[3]+= (aSumsOfEquivalentPoints[line][x]-mean*wndy/4)
- * correlVector[(line+3) &3][x-qLine];
- }
+ {
+ for(int x=xStart; x<xStart + QCOL_CORREL_QCOL_SIZE; x++)
+ {
+ coefficient[0]+= (aSumsOfEquivalentPoints[line][x]-mean*wndy/4) * qColCorrelVector[(line+0) &3];
+ coefficient[1]+= (aSumsOfEquivalentPoints[line][x]-mean*wndy/4) * qColCorrelVector[(line+1) &3];
+ coefficient[2]+= (aSumsOfEquivalentPoints[line][x]-mean*wndy/4) * qColCorrelVector[(line+2) &3];
+ coefficient[3]+= (aSumsOfEquivalentPoints[line][x]-mean*wndy/4) * qColCorrelVector[(line+3) &3];
+ }
- for(int i=0; i<4; i++)
+ for(int x=xStart + QCOL_CORREL_QCOL_SIZE; x<xStart + QCOL_CORREL_SIZE; x++)
{
- coefficient[i]/= xSizeOfCorrelVector*wndy* sqrt(variance * varianceOfCorrelVector + 0.000001);
+ coefficient[0]+= (aSumsOfEquivalentPoints[line][x]-mean*wndy/4) * blankCorrelVector[(line+0) &3];
+ coefficient[1]+= (aSumsOfEquivalentPoints[line][x]-mean*wndy/4) * blankCorrelVector[(line+1) &3];
+ coefficient[2]+= (aSumsOfEquivalentPoints[line][x]-mean*wndy/4) * blankCorrelVector[(line+2) &3];
+ coefficient[3]+= (aSumsOfEquivalentPoints[line][x]-mean*wndy/4) * blankCorrelVector[(line+3) &3];
+ }
+ }
- if(coefficient[i]>bestCoefficient)
- {
+ for(int i=0; i<4; i++)
+ {
+ coefficient[i]/= QCOL_CORREL_SIZE * wndy * sqrt(variance + 0.000001);
+
+ if(coefficient[i] > bestCoefficient)
+ {
bestCoefficient= coefficient[i];
- bestQLine= qLine;
+ bestQLine= xStart - QCOL_SIZE + QCOL_CORREL_QCOL_SIZE;
qPhase= (4-i) &3;
// some= int(minmax(-10000, bestCoefficient*100, 10000));
- }
}
}
+ }
if(iState==2)
- {
+ {
T2=uclock();
- sprintf(textbuf,"%f coeff", (float)(T2-T1)/UCLOCKS_PER_SEC);
+ sprintf(textbuf,"%f coeffTime", (float)(T2-T1)/UCLOCKS_PER_SEC);
gprint(infoPosX, infoPosY+=10, c.col, textbuf);
T1=T2;
- }
-
-
- if(bestCoefficient < QLINE_COEFFICIENT_THRESHOLD) return -1;
-
-
- // try to find the Sync pulse
+
+ sprintf(textbuf,"%f coeff", bestCoefficient);
+ gprint(infoPosX, infoPosY+=10, c.col, textbuf);
+ }
- int score[1000];
- for(int i=0; i<1000; i++)
- score[i]=0;
+
+ if(bestCoefficient < QCOL_COEFFICIENT_THRESHOLD) return -1;
- for(int x= min(bestQLine+HSYNC_SEARCH_END, wndx-1); x >= bestQLine + HSYNC_SEARCH_START; x--)
+ int bestHSyncScore= 0;
+ int bestHSync= 0;
+ int hSync;
+ for(hSync= bestQLine + HSYNC_SEARCH_START; hSync < bestQLine + HSYNC_SEARCH_END; hSync++)
+ {
+ if(hSync+1 >= wndx) return -1;
+
+ int hSyncScore= 0;
+ for(int line= 0; line<wndy; line+=3)
{
- for(int line=0; line<wndy; line+=3)
- {
- score[x] += p[(line*vgax + x)*2 + 1];
- }
-
- score[x]*= 3;
-
- if( x+2 <= min(bestQLine+HSYNC_SEARCH_END, wndx-1)
- && (score[x] - score[x+2])/wndy > HSYNC_THRESHOLD)
- {
- bestQLine= x - Q_2_HSYNC_DISTANCE;
- if(bestQLine<0) bestQLine=0;
- return bestQLine;
- }
+ if(line&3 == qPhase) continue;
+ hSyncScore+= (int)( (byte)( p[(line*vgax + hSync-1)*2 + 1] ) )
+ -(int)( (byte)( p[(line*vgax + hSync+1)*2 + 1] ) );
}
-
- if(bestQLine + OVERBRIGHT_TEST_COLUMN >= wndx) return -1;
- int sum=0;
- for(int line=0; line<wndy; line++)
- sum+= p[(line*vgax + bestQLine + OVERBRIGHT_TEST_COLUMN)*2 + 1];
-
- if(sum/wndy > QLINE_OVERBRIGHT_THRESHOLD) return -1; // Sync Pulse not found and Pic to Bright
-
- return bestQLine; //no Sync Pulse Found (Picture perhaps too dark)
- //perhaps -1 better
+
+ if(hSyncScore > bestHSyncScore)
+ {
+ bestHSyncScore= hSyncScore;
+ bestHSync= hSync;
+ }
+ }
+
+ return bestHSync;
+
+
+// return minmax(0, bestQLine + Q_2_HSYNC_DISTANCE, wndx-1);
}
-int findVSync(int qLine)
+int findVSync(int qCol)
{
- if(qLine==-1) return -1;
- if(qLine<2 || qLine+1>=wndx) return -1;
+ if(qCol==-1) return -1;
+ if(qCol<2 || qCol+1>=wndx) return -1;
byte const * const p= &actVid2MemBufp->b[0];
@@ -266,15 +289,15 @@ int findVSync(int qLine)
int runningNotQSum=0;
int nRunningQSum=0;
int nRunningNotQSum=0;
- for(int vSyncStart= -VSYNC_SIZE; vSyncStart<wndy; vSyncStart++)
+ for(int vSyncStart= -PAL_VSYNC_SIZE; vSyncStart<wndy; vSyncStart++)
{
- const vSyncEnd= vSyncStart + VSYNC_SIZE;
+ const vSyncEnd= vSyncStart + PAL_VSYNC_SIZE;
int index= vSyncStart;
- if(index<0) index= vSyncStart + wndy + VSYNC_SIZE;
+ if(index<0) index= vSyncStart + wndy + PAL_VSYNC_SIZE;
if(vSyncStart>=0)
{
- const int xP= (vSyncStart*vgax + qLine + VSYNC_SEARCH_COLUMN) * 2;
+ const int xP= (vSyncStart*vgax + qCol + VSYNC_SEARCH_COLUMN) * 2;
const int scoreStart= int(p[xP + 1])
+ mabs(int((char)(p[xP + 2])))
+ mabs(int((char)(p[xP])));
@@ -292,7 +315,7 @@ int findVSync(int qLine)
}
if(vSyncEnd<wndy)
{
- const int xP= (vSyncEnd*vgax + qLine + VSYNC_SEARCH_COLUMN) * 2;
+ const int xP= (vSyncEnd*vgax + qCol + VSYNC_SEARCH_COLUMN) * 2;
const int scoreEnd= int(p[xP + 1])
+ mabs(int((char)(p[xP + 2])))
+ mabs(int((char)(p[xP])));
@@ -322,7 +345,7 @@ int findVSync(int qLine)
int bestScore= -1000000;
int bestVSync= -1;
- for(int vSync= 0; vSync<wndy+VSYNC_SIZE; vSync++)
+ for(int vSync= 0; vSync<wndy+PAL_VSYNC_SIZE; vSync++)
{
if(vSync < wndy && vSync > wndy-MIN_VSYNC_DISTANCE) continue;
if(vSync >= wndy && vSync-wndy < MIN_VSYNC_DISTANCE) continue;
@@ -342,15 +365,17 @@ int findVSync(int qLine)
// Should be writen as an Object...
//6015X 10960D 994498XX 3224315DD 1789858XD 55n
+
static int hSyncDelaySumX= 6015;
static int hSyncDelaySumD= 10960;
static int hSyncDelaySumXX= 994498;
static int hSyncDelaySumDD= 3224315;
static int hSyncDelaySumDX= 1789858;
static int hSyncDelays=55;
+
static int lastHSyncDelay=0;
-static int lastQLine=0; //from last call to doHSyncDelay
-void doHSyncDelay(int hDistance, int qLine)
+static int lastHSync=0; //from last call to doHSyncDelay
+void doHSyncDelay(int hDistance, int hSync)
{
double sigmaXD= double(hSyncDelaySumDX) * double(hSyncDelays)
- double(hSyncDelaySumX) * double(hSyncDelaySumD);
@@ -363,7 +388,9 @@ void doHSyncDelay(int hDistance, int qLi
double diffFromMeanX= double(hDistance) - double(hSyncDelaySumX) / double(hSyncDelays);
double diffFromMeanD= diffFromMeanX * sigmaXD / sigmaX2;
-/* printf("%d %d\n", hDistance, qLine);
+
+ /*
+ printf("%d %d\n", hDistance, hSync);
printf("%dX %dD %dXX %dDD %dXD %dn\n",
hSyncDelaySumX, hSyncDelaySumD,
hSyncDelaySumXX, hSyncDelaySumDD,
@@ -371,7 +398,10 @@ void doHSyncDelay(int hDistance, int qLi
printf("%fSXD %fSX2\n",sigmaXD, sigmaX2);
printf("%fdfmx %fdfmd\n", diffFromMeanX, diffFromMeanD);
- printf("%f\n", diffFromMeanD + double(hSyncDelaySumD) / double(hSyncDelays) + 0.5);*/
+ printf("%f\n", diffFromMeanD + double(hSyncDelaySumD) / double(hSyncDelays) + 0.5);
+ */
+
+
int delay= int(diffFromMeanD + double(hSyncDelaySumD) / double(hSyncDelays) + 0.5);
if(delay<0) delay=0;
@@ -379,7 +409,7 @@ void doHSyncDelay(int hDistance, int qLi
// printf("%d Delay\n", delay);
lastHSyncDelay= delay;
- lastQLine= qLine;
+ lastHSync= hSync;
vPayTvShiftHack(delay);
}
@@ -387,13 +417,13 @@ void doHSyncDelay(int hDistance, int qLi
static nStat=0;
static int *statX= new int[10000];
static int *statY= new int[10000];
-void analyzeHSyncDelay(int newQLine)
+void analyzeHSyncDelay(int newHSync)
{
- int realHDistance= newQLine - lastQLine;
- if(newQLine!=-1 && realHDistance>0)
+ int realHDistance= newHSync - lastHSync;
+ if(newHSync!=-1 && realHDistance>0)
{
-// statX[nStat]= realHDistance;
-// statY[nStat++]= lastHSyncDelay;
+ statX[nStat]= realHDistance;
+ statY[nStat++]= lastHSyncDelay;
hSyncDelaySumX+= realHDistance;
hSyncDelaySumD+= lastHSyncDelay;
@@ -468,8 +498,8 @@ void analyzeVSyncDelay(int newVSync)
if(newVSync!=-1 && realVDistance>0)
{
- statX[nStat]= lastVSyncDelay;
- statY[nStat++]= realVDistance;
+// statX[nStat]= lastVSyncDelay;
+ // statY[nStat++]= realVDistance;
vSyncDelaySumY+= realVDistance;
vSyncDelaySumD+= lastVSyncDelay;
@@ -502,26 +532,61 @@ void analyzeVSyncDelay(int newVSync)
*/
}
-/*
-void fixColor(int qLine)
+
+void fixColor(int qCol)
{
- qLine&= ~1;
+ /*
+ qCol&= ~2;
byte * const p= &actVid2MemBufp->b[0];
- for(int line=qPhase; line<wndy-3; line+=4)
+ for(int qLine=qPhase+1; qLine<wndy-3; qLine+=4)
+ {
+ const float targetPhase= (START_Q_PHASE - Q_PHASE_DELTA*qLine)*0;
+
+ int nSamples=0;
+ int uSum=0, vSum=0;
+ for(int x=qCol+2; x<qCol + QCOL_SIZE-1; x+=2)
{
- int u=char(p[(line*vgax + qLine-2)*2 ]);
- int v=char(p[(line*vgax + qLine-2)*2 + 2]);
- printf("%d %d %f\n", u, v, atan3(u,v)/PI*180);
- for(int x=0; x<wndx-1; x+=2)
+ if(x>=wndx) break;
+
+ uSum+= char(p[(qLine*vgax + x)*2 ]);
+ vSum+= char(p[(qLine*vgax + x)*2 + 2]);
+
+ nSamples++;
+ }
+
+ const float u= ((float)uSum) / nSamples;
+ const float v= ((float)vSum) / nSamples;
+
+ const float qPhase= atan3(u, v);
+ const float phaseDiff= targetPhase - qPhase;
+
+ const int s= (int)(sin(phaseDiff)*127.0);
+ const int c= (int)(cos(phaseDiff)*127.0);
+
+ printf("%f %f %f %f \n", u, v, atan3(u,v)/PI*180, targetPhase/PI*180);
+ for(int line= qLine; line< qLine+4; line++)
+ {
+ for(int x=0; x<wndx-1; x+=2)
{
+ int ou= (char)p[ (line*vgax + x)*2 ];
+ int ov= (char)p[ (line*vgax + x)*2 + 2 ];
+
+ int nu= (ou*c - ov*s)>>7;
+ int nv= (ou*s + ov*c)>>7;
+
+ p[ (line*vgax + x)*2 ]= (char)nu;
+ p[ (line*vgax + x)*2 + 2 ]= (char)nv;
+
}
-
}
+
+ }
+ */
}
-*/
-void fixBrightness(int qLine)
+
+void fixBrightness(int hSync)
{
static int darkestVal=0;
static int brightestVal=255;
@@ -531,54 +596,84 @@ void fixBrightness(int qLine)
byte * const p= &actVid2MemBufp->b[0];
+ int nClipedPixels= 0;
+
+ infoPosY+=10;
+
for(int line=1; line<wndy; line++)
{
- if(qLine + Q_2_HSYNC_DISTANCE + 3>=wndx) break;
+ if(hSync + 3>=wndx) break;
double encodedBlankLevel = 0;
double encodedSyncLevel = 0;
int nLines= 0;
- for(int refLine= max(line-4, 0); refLine<min(wndy, line+4); refLine++)
+ for(int refLine= max(line-2, 0); refLine<min(wndy, line+2); refLine++)
{
if((refLine&3) == qPhase) continue;
nLines++;
- encodedBlankLevel += p[(refLine*vgax + qLine + Q_2_HSYNC_DISTANCE - 3)*2 + 1];
- encodedSyncLevel += p[(refLine*vgax + qLine + Q_2_HSYNC_DISTANCE + 3)*2 + 1];
+ encodedBlankLevel += p[(refLine*vgax + hSync + BLANK_REF_LOC)*2 + 1];
+ encodedSyncLevel += p[(refLine*vgax + hSync + SYNC_REF_LOC )*2 + 1];
}
encodedBlankLevel/= nLines;
encodedSyncLevel /= nLines;
- const double shift= RELATIV_LEVEL_SHIFT* (encodedBlankLevel - encodedSyncLevel);
+ const double shift= (RELATIV_LEVEL_SHIFT + (bright - 0x80) / 4.0)* (encodedBlankLevel - encodedSyncLevel);
const double blankLevel = encodedBlankLevel - shift;
const double syncLevel = encodedSyncLevel - shift;
- const int blackLevel = int(blankLevel) -20;
+ const int blackLevel = int(blankLevel) ;
- const int scale = int((BLANK_LEVEL - SYNC_LEVEL) / max(blankLevel - syncLevel, 1.0) * (256.0 * 235.0));
+ const int scale =
+ int((PAL_BLANK_LEVEL - PAL_SYNC_LEVEL) / max(blankLevel - syncLevel, 1.0) * (256.0 * 255.0) * (contr-0x40+10)/10.0);
+
+ const int brightestPossible= ((255 - blackLevel) * scale) >> 8;
+ const int darkestPossible= ((0 - blackLevel) * scale) >> 8;
+
+ if(iState>=1)
+ {
+ for(int x=0; x<256; x++)
+ {
+ if(x<darkestPossible || x>brightestPossible)
+ {
+ p[((infoPosY+5)*vgax + x)*2 + 1]= 255;
+ p[((infoPosY+6)*vgax + x)*2 + 1]= 0;
+
+ p[((infoPosY+5)*vgax + x)*2 ]= 0;
+ p[((infoPosY+6)*vgax + x)*2 ]= 0;
+ }
+ }
+ }
- for(int x=0; x<min(qLine, wndx); x++)
- {
+
+
+
+ for(int x=0; x<min(hSync + BLANK_REF_LOC - 1, wndx); x++)
+ {/*
if(p[(line*vgax + x)*2 + 1] >= brightestVal && (some&1))
{
p[(line*vgax + x)*2]= 127;
+ // nClipedPixels++;
+
if(p[(line*vgax + x)*2 + 1] > brightestVal) brightestVal= p[(line*vgax + x)*2 + 1];
}
else if( p[(line*vgax + x)*2 + 1] <= darkestVal && (some&1))
{
p[(line*vgax + x)*2]= 128;
+ // nClipedPixels++;
+
if(p[(line*vgax + x)*2 + 1] < darkestVal) darkestVal= p[(line*vgax + x)*2 + 1];
}
- else
+ else*/
{
int v = p[(line*vgax + x)*2 + 1];
@@ -589,6 +684,11 @@ void fixBrightness(int qLine)
}
}
}
+
+
+// static int nClipedPixelSum=0;
+
+// nClipedPixelSum += nClipedPixels;
}
void showStat(void)
@@ -604,7 +704,7 @@ void showStat(void)
for(int i=0; i<nStat; i++)
{
int x= statX[i] + 100;
- int y= statY[i] + 100;
+ int y= statY[i]/10 + 100;
if(y<0 || x<0) continue;
if(y>=wndy || x>=wndx) continue;
@@ -613,6 +713,38 @@ void showStat(void)
}
}
+void movePic(int hSync)
+{
+ int nPixMove= REAL_HSYNC_LOC - hSync;
+
+ if(nPixMove>wndx) nPixMove=0;
+ if(nPixMove<-wndx) nPixMove=0;
+
+ byte * p= &actVid2MemBufp->b[0];
+ for(int line=1; line<wndy; line++)
+ {
+ if(nPixMove>0)
+ {
+ memmove(&p[nPixMove*2], &p[0], (wndx-nPixMove)*2);
+ }
+ else if(nPixMove<0)
+ {
+ memmove(&p[0], &p[-nPixMove*2], (wndx+nPixMove)*2);
+ }
+ if(nPixMove & 1)
+ for(int x=0; x<wndx-2; x++)
+ {
+ p[x*2]= p[x*2+2];
+ }
+ for(int x=0; x<wndx-2; x++)
+ {
+// p[x*2]=0;
+ }
+ p+= vgax<<1;
+ }
+}
+
+
extern volatile bool isVPayTvBrightHack;
extern volatile int vPayTvQPosInLCC;
@@ -633,118 +765,98 @@ void vPayTvDecrypt(void)
if(dropList[0]&2) return;
}
- int qLine= findQLine();
- int vSync= -1;//findVSync(qLine);
+ int hSync= findHSync();
+ int vSync= -1;//findVSync(qCol);
- if(qLine!= -1)
- {
- vPayTvQPosInLCC= (qLine-wndx-6)*1888 / wndx;
- }
+ if(hSync!= -1)
+ {
+ vPayTvQPosInLCC= (hSync-wndx-12)*1888 / wndx; //FIXME #DEFINE IT
+ }
+ int qCol;
+ if(hSync==-1) qCol= -1;
+ else qCol= hSync - Q_2_HSYNC_DISTANCE;
+
byte * p= &actVid2MemBufp->b[0];
for(int line=0; line<wndy; line++)
- {
+ {
if((line&3) == qPhase)
- {
- p[2*qLine+1]=0;
- p[2*qLine+3]=255;
- }
- p+= vgax<<1;
+ {
+ p[2*qCol+1]=0;
+ p[2*qCol+3]=255;
+ p[2*hSync+1]=0;
+ p[2*hSync+3]=255;
}
+ p+= vgax<<1;
+ }
p= &actVid2MemBufp->b[0];
for(int x=0; x<wndx; x++)
- {
+ {
if((x&3)==0)
- {
+ {
// p[(vSync*vgax + x)*2 + 1]=0;
// p[(vSync*vgax + x)*2 + 3]=255;
- }
}
+ }
if(lastHSyncDelay!=0)
- {
- analyzeHSyncDelay(qLine);
- }
+ {
+ analyzeHSyncDelay(hSync);
+ }
if(lastVSyncDelay!=0)
- {
+ {
analyzeVSyncDelay(vSync);
- }
+ }
static bool isVSyncBad= false;
if(vSync!=-1 && (vSync<TOP_VSYNC_BOUNDRY || vSync>BOTTOM_VSYNC_BOUNDRY) && 0)
- {
+ {
if(isVSyncBad)
- {
+ {
doVSyncDelay(BOTTOM_VSYNC_BOUNDRY - vSync, vSync);
dropList[1]|=2;
isVSyncBad= false;
- }
+ }
else
- {
+ {
isVSyncBad= true;
- }
}
- else if(qLine!=-1 && qLine<LEFT_QLINE_BOUNDRY)
- {
- doHSyncDelay((RIGHT_QLINE_BOUNDRY + LEFT_QLINE_BOUNDRY)/2 - qLine, qLine);
+ }
+ else if(hSync!=-1 && hSync<LEFT_HSYNC_BOUNDRY)
+ {
+ doHSyncDelay((RIGHT_HSYNC_BOUNDRY + LEFT_HSYNC_BOUNDRY)/2 - hSync, hSync);
dropList[1]|=2;
- }
- else if(qLine==-1 && 0)
- {
+ }
+ else if(hSync==-1 && 0)
+ {
doHSyncDelay(wndx/2, 1);
lastHSyncDelay=0;
dropList[1]|=2;
- }
+ }
else if(isVCPhaseTrick)
- {
+ {
isVCPhaseTrick= false;
vPayTvShiftHack(1000);
dropList[1]|=2;
- }
+ }
else
- {
+ {
isVSyncBad= false;
- }
+ }
- if(qLine==-1) dropList[1]|=2;
+ if(hSync==-1) dropList[1]|=2;
- fixBrightness(qLine);
+ fixBrightness(hSync);
+
+ //fixColor(qCol);
// showStat();
- int nPixMove= REAL_QLINE_POS - qLine;
-
- if(nPixMove>wndx) nPixMove=0;
- if(nPixMove<-wndx) nPixMove=0;
-
-
- p= &actVid2MemBufp->b[0];
- for(int line=1; line<wndy; line++)
- {
- if(nPixMove>0)
- {
- memmove(&p[nPixMove*2], &p[0], (wndx-nPixMove)*2);
- }
- else if(nPixMove<0)
- {
- memmove(&p[0], &p[-nPixMove*2], (wndx+nPixMove)*2);
- }
- if(nPixMove & 1)
- for(int x=0; x<wndx-2; x++)
- {
- p[x*2]= p[x*2+2];
- }
- for(int x=0; x<wndx-2; x++)
- {
-// p[x*2]=0;
- }
- p+= vgax<<1;
- }
-
+ movePic(hSync);
- lastQLine= qLine;
+ lastHSync= hSync;
}
Copied: trunk/2010/2d.txt (from r62, /trunk/2010/2d)
==============================================================================
--- /trunk/2010/2d (original)
+++ trunk/2010/2d.txt Wed Jul 4 11:38:46 2007
@@ -1,3 +1,9 @@
+VPAYTV
+timing Info
+optimieren
+fine Tunenen v #defines
+
+sync info verschieben abh�ngig v vLine
txt restart!?
rgb565 / 1555 stuff not realy correct but works
add rgb1555 support
@@ -21,11 +27,11 @@ vc color deco mmx
nag last line ?
-yuv2rgb mmx
-
NAG_LINES ?
teletext:
BETTER decode
SAVE
fix fractional digits
+
+a few PAL-Constants are in 2_crypt.h should be in 2_pal.h
1
0
[mndiff]: r64 - in trunk/2010: 2010.cpp 2_71x6.cpp 2_crypt.h 2_file.cpp 2_hw.cpp 2_vpaytv.cpp countppm.cpp extractppm.cpp makefile
by michael 04 Jul '07
by michael 04 Jul '07
04 Jul '07
Author: michael
Date: Wed Jul 4 11:27:15 2007
New Revision: 64
Log:
version from 2000-02-23 22:30
Added:
trunk/2010/countppm.cpp
trunk/2010/extractppm.cpp
Modified:
trunk/2010/2010.cpp
trunk/2010/2_71x6.cpp
trunk/2010/2_crypt.h
trunk/2010/2_file.cpp
trunk/2010/2_hw.cpp
trunk/2010/2_vpaytv.cpp
trunk/2010/makefile
Modified: trunk/2010/2010.cpp
==============================================================================
--- trunk/2010/2010.cpp (original)
+++ trunk/2010/2010.cpp Wed Jul 4 11:27:15 2007
@@ -23,6 +23,7 @@
#include "2_71x6.h"
#include "2_nag.h"
#include "2_vc.h"
+//#include "2_vpaytv.h" //REMOVE FIXME (Debuging only)
extern volatile bool oneField;
extern int iVSmooth;
@@ -45,6 +46,7 @@
extern char reqChanStr[];
extern char findTxt[];
extern bool isVCPhaseTrick;
+extern bool drop;
int maxBuf=2;
int some=0;
@@ -65,6 +67,7 @@ int _crt0_startup_flags = _CRT0_FLAG_NEA
int infoPosY;
bool strangeRgb16= true; // commandLineOpt FIX
long uclockWaste;
+ int vgaBytesPerScanLine;
static inline void getUclockWaste(void){
long T1=uclock();
@@ -296,6 +299,7 @@ int main(int argc, char **argv){
xresvb=vgax*vb;
if(mib->pages>0 && NoFlip==0) page_flip=1;
else page_flip=0;
+ vgaBytesPerScanLine= mib->BLine;
printf("Allocating Physical Continous Buffers...\n");
@@ -327,7 +331,7 @@ int main(int argc, char **argv){
bool quit=false;
while(!quit){
-
+ //vPayTvBrightHack(false, 0);
infoPosY=0;
infoPosX=10;
@@ -338,10 +342,13 @@ int main(int argc, char **argv){
decrypt();
showStuff();
-
- if(grabf==1 && TVStd!=TXTPAL) GrabBmp(), grabf=0;
+
+ if(!drop)
+ {
+ if(grabf==1 && TVStd!=TXTPAL) GrabBmp(), grabf=0;
- if(grabV==1) RecordVideo();
+ if(grabV==1) RecordVideo();
+ }
for(int k=0; k<delay*10000000; k++);
Modified: trunk/2010/2_71x6.cpp
==============================================================================
--- trunk/2010/2_71x6.cpp (original)
+++ trunk/2010/2_71x6.cpp Wed Jul 4 11:27:15 2007
@@ -184,6 +184,9 @@ static inline void wait(double wt){
while(uclock() <= u+wt);
}
+volatile bool isVPayTvBrightHack= false;
+volatile int vPayTvQPosInLCC= 100;
+
void meteor_int_handler(void){
saa7116 *a_saa7116=(saa7116*)meteors[active_meteor].saa7116;
@@ -191,7 +194,7 @@ void meteor_int_handler(void){
if(a_saa7116->ints_ctl.stat_even == 0 &
a_saa7116->ints_ctl.stat_odd == 0 &
- a_saa7116->ints_ctl.stat_start == 0 ) asm("int $3\n\t"); // VERY BAD (?? WHO called that int)
+ a_saa7116->ints_ctl.stat_start == 0 ) return; //asm("int $3\n\t"); // VERY BAD (?? WHO called that int)
if((cap & 0x300) != 0){
corr_errors++;
@@ -230,6 +233,7 @@ void meteor_int_handler(void){
res1: 0, corr_dis: 0, range_en: 1, res2: 0};
grab_next( vid2MemBuf[ grabVid2MemBuf ] );
}
+
}
else if( a_saa7116->ints_ctl.stat_start==1 && fields>=11111
&& vid2MemBuf[ grabVid2MemBuf ].state == Empty ){
@@ -241,7 +245,18 @@ void meteor_int_handler(void){
res1: 0, corr_dis: 0, range_en: 1, res2: 0};
vid2MemBuf[ grabVid2MemBuf ].state= Grabbing;
}
+
+
+ if(cryptStd == vpaytv
+ && ( a_saa7116->ints_ctl.stat_odd == 1
+ || a_saa7116->ints_ctl.stat_even == 1) )
+ {
+ isVPayTvBrightHack= !isVPayTvBrightHack;
+ vPayTvBrightHack( isVPayTvBrightHack, vPayTvQPosInLCC );
+ }
+
+
a_saa7116->ints_ctl_a|=0x7;
}
@@ -301,9 +316,6 @@ void grab_next(VID2MEMBUF v2mb){
}
-void meteor_int_handler_end(void){
-}
-
void setCont(void){
@@ -319,6 +331,10 @@ void setStdScale(void){
mc=1;
+ if(cryptStd == vpaytv) satur=0x18;
+ else satur=0x40;
+ setCont();
+
if(TVStd==TXTPAL){
scales_y=0x0 + 100, scalee_y=0x0 -288 + 20 + 100;
xresc=vgax<<(mc+2);
@@ -406,10 +422,7 @@ void setStdScale(void){
/* 2 Select HREF Position
1:0 Vertical noise reduction */
- if(cryptStd==vpaytv)
- write_saa7196(0x0C, 0xE0); //0xE0
- else
- write_saa7196(0x0C, 0xC0); //0xC0
+ write_saa7196(0x0C, 0xC0); //0xC0
/* 7 Colour-on bit
6:5 AGC filter */
@@ -585,6 +598,7 @@ void init_meteor(void){
write_saa7196(0x09, 0x7F);/* 7:3 Colour-killer threshold SECAM */
write_saa7196(0x0A, 0x7F);/* 7:0 PAL switch sensitivity */
write_saa7196(0x0B, 0x7F);/* 7:0 SECAM switch sensitivity */
+
write_saa7196(0x11, 0x2C);/* 7:0 Chrominance gain conrtol for QAM */
write_saa7196(0x14, 0x34);/* 7:0 Horizontal sync begin for 60hz */
//#ifdef notdef
@@ -758,18 +772,26 @@ void vPayTvShiftHack(int amount)
void vPayTvBrightHack(bool b, int posInLCC)
{
+
-/* int hSyncBegin= - 96 +posInLCC;
+/*
+ int hSyncBegin= - 96 +posInLCC;
int hSyncStop= 0 +posInLCC;
int hClampBegin= 48 +posInLCC;
- int hClampStop= 148 +posInLCC;*/
+ int hClampStop= 148 +posInLCC;
+ int hSyncStartAfterPH1= 96;//+posInLCC;
+*/
- int hSyncBegin= - 96 +posInLCC;
+
+ int hSyncBegin= - 96 +posInLCC;
int hSyncStop= - 70 +posInLCC;
int hClampBegin= - 60 +posInLCC;
- int hClampStop= 148 +posInLCC-some;
+ int hClampStop= - 59 +posInLCC+some;
int hSyncStartAfterPH1= 96;//+posInLCC;
+ if(some==0) hClampStop= 148 +posInLCC;
+ //else hClampStop= -59 +posInLCC + 10;
+
hSyncBegin = minmax(-382, hSyncBegin, 126);
hSyncStop = minmax(-380, hSyncStop, 128);
hClampBegin= minmax(-254, hClampBegin, 254);
@@ -785,21 +807,16 @@ void vPayTvBrightHack(bool b, int posInL
if(hClampBegin <= hSyncStop) hClampBegin= hSyncStop+1;
if(hClampStop <= hClampBegin) hClampStop= hClampBegin+1;
-
- // write_saa7196(0x01, 0x30);/* 7:0 Horizontal Sync Begin for 50hz */
- // write_saa7196(0x02, 0x00);/* 7:0 Horizontal Sync Stop for 50hz */
- // write_saa7196(0x03, 0xE8);/* 7:0 Horizontal Sync Clamp Start for 50hz */
- // write_saa7196(0x04, 0xB6);/* 7:0 Horizontal Sync Clamp Stop for 50hz */
- // write_saa7196(0x05, 0xF4);/* 7:0 Horizontal Sync Start after PH1 for 50hz */
-
if(b)
{
- write_saa7196(0x01, (-hSyncBegin )&0xFF);/* 7:0 Horizontal Sync Begin for 50hz */
- write_saa7196(0x02, (-hSyncBegin+10 )&0xFF);/* 7:0 Horizontal Sync Stop for 50hz */
- write_saa7196(0x03, (-hClampBegin )&0xFF);/* 7:0 Horizontal Sync Clamp Start for 50hz */
- write_saa7196(0x04, (-hClampStop )&0xFF);/* 7:0 Horizontal Sync Clamp Stop for 50hz */
+ write_saa7196(0x01, (-hSyncBegin-3 )&0xFF);/* 7:0 Horizontal Sync Begin for 50hz */
+ write_saa7196(0x02, (-hSyncBegin )&0xFF);/* 7:0 Horizontal Sync Begin for 50hz */
+ // write_saa7196(0x02, (-hSyncStop )&0xFF);/* 7:0 Horizontal Sync Stop for 50hz */
+ write_saa7196(0x03, (-hClampBegin-3 )&0xFF);/* 7:0 Horizontal Sync Clamp Start for 50hz */
+ write_saa7196(0x04, (-hClampBegin )&0xFF);/* 7:0 Horizontal Sync Clamp Start for 50hz */
+ // write_saa7196(0x04, (-hClampStop )&0xFF);/* 7:0 Horizontal Sync Clamp Stop for 50hz */
write_saa7196(0x05, (-hSyncStartAfterPH1)&0xFF);/* 7:0 Horizontal Sync Start after PH1 for 50hz */
- }
+ }
else
{
write_saa7196(0x01, (-hSyncBegin )&0xFF);/* 7:0 Horizontal Sync Begin for 50hz */
@@ -808,12 +825,18 @@ void vPayTvBrightHack(bool b, int posInL
write_saa7196(0x04, (-hClampStop )&0xFF);/* 7:0 Horizontal Sync Clamp Stop for 50hz */
write_saa7196(0x05, (-hSyncStartAfterPH1)&0xFF);/* 7:0 Horizontal Sync Start after PH1 for 50hz */
}
- printf("T %d %d %d %d %d\n"
+ /*
+ printf("T %d %d %d %d %d\n"
,(-hSyncBegin )&0xFF
,(-hSyncStop )&0xFF
,(-hClampBegin )&0xFF
,(-hClampStop )&0xFF
,(-hSyncStartAfterPH1)&0xFF);
-
+*/
+
}
+
+void meteor_int_handler_end(void){
+}
+
Modified: trunk/2010/2_crypt.h
==============================================================================
--- trunk/2010/2_crypt.h (original)
+++ trunk/2010/2_crypt.h Wed Jul 4 11:27:15 2007
@@ -5,6 +5,11 @@
#define max_x 900
#define max_y 700
+#define BLACK_LEVEL 0.0
+#define BLANK_LEVEL 0.0
+#define WHITE_LEVEL 1.0
+#define SYNC_LEVEL (-43.0 / 100.0)
+
#define FREQ_CHROM 4433618.75
#define FREQ_HS 15625.0
#define FREQ_PIX (FREQ_HS * 1888.0 * 0.5)
Modified: trunk/2010/2_file.cpp
==============================================================================
--- trunk/2010/2_file.cpp (original)
+++ trunk/2010/2_file.cpp Wed Jul 4 11:27:15 2007
@@ -169,7 +169,7 @@ void RecordVideo(void)
int image_width= wndx/2;
int image_height= wndy/2;
- int quality= 70;
+ int quality= 90;
static byte * image_buffer= new byte[wndx*wndy*3];
byte * pYUV= &actVid2MemBufp->b[ 0 ];
@@ -179,9 +179,9 @@ void RecordVideo(void)
{
for(int x=0; x<(wndx>>1); x++)
{
- pYCbCr[0] = (pYUV[1] + pYUV[3]) >> 1;
- pYCbCr[1] = pYUV[0]+127;
- pYCbCr[2] = pYUV[2]+127;
+ pYCbCr[0] = (pYUV[1] + pYUV[3] + pYUV[(vgax<<1) + 1] + pYUV[(vgax<<1)+3] ) >> 2;
+ pYCbCr[1] = ((char)(pYUV[0] + pYUV[(vgax<<1) ] ) >> 1) + 127;
+ pYCbCr[2] = ((char)(pYUV[2] + pYUV[(vgax<<1) + 2] ) >> 1) + 127;
pYCbCr+=3;
pYUV+=4;
}
@@ -227,8 +227,6 @@ void RecordVideo(void)
jpeg_finish_compress(&cinfo);
-
- fflush(outFile);
// jpeg_destroy_compress(&cinfo);
Modified: trunk/2010/2_hw.cpp
==============================================================================
--- trunk/2010/2_hw.cpp (original)
+++ trunk/2010/2_hw.cpp Wed Jul 4 11:27:15 2007
@@ -42,6 +42,7 @@
extern int infoPosX, infoPosY;
extern TVSTD TVStd;
extern int iVSmooth;
+ extern int vgaBytesPerScanLine;
bool drop=false;
bool allowDrop=true;
@@ -196,24 +197,30 @@ void copy_vidbuffer(void){
const int goody= TVStd!=TXTPAL ? wndy : vgay;
if(page_flip==0){
- int p=0;
+ int pVga=0;
+ int pBuf=0;
for(int y=0; y<goody; y++){
- mem2vid(vidbuf+p, actVid2MemBufp->b+p, goodx, bpp, y);
- p+=vgax<<1;
+ mem2vid(vidbuf+pVga, actVid2MemBufp->b+pBuf, goodx, bpp, y);
+ pVga+= vgaBytesPerScanLine;
+ pBuf+= vgax<<1;
}
}else if(page_flip==2){
- int p=0;
+ int pVga=0;
+ int pBuf=0;
for(int y=0; y<goody; y++){
- mem2vid(vidbuf+xresvb*vgay+p, actVid2MemBufp->b+p, goodx, bpp, y);
- p+=vgax<<1;
+ mem2vid(vidbuf+vgay*vgaBytesPerScanLine+pVga, actVid2MemBufp->b+pBuf, goodx, bpp, y);
+ pVga+= vgaBytesPerScanLine;
+ pBuf+= vgax<<1;
}
page_flip=1;
set_start_disp(0, vgay);
}else{
- int p=0;
+ int pVga=0;
+ int pBuf=0;
for(int y=0; y<goody; y++){
- mem2vid(vidbuf+p, actVid2MemBufp->b+p, goodx, bpp, y);
- p+=vgax<<1;
+ mem2vid(vidbuf+pVga, actVid2MemBufp->b+pBuf, goodx, bpp, y);
+ pVga+= vgaBytesPerScanLine;
+ pBuf+= vgax<<1;
}
page_flip=2;
set_start_disp(0, 0);
Modified: trunk/2010/2_vpaytv.cpp
==============================================================================
--- trunk/2010/2_vpaytv.cpp (original)
+++ trunk/2010/2_vpaytv.cpp Wed Jul 4 11:27:15 2007
@@ -42,8 +42,7 @@
#define TOP_VSYNC_BOUNDRY (wndy-50)
#define BOTTOM_VSYNC_BOUNDRY (wndy+50)
-#define BRIGHTNESS_REF_POS 3
-#define BRIGHTNESS_DELTA 180
+#define RELATIV_LEVEL_SHIFT 2.0
extern vgax, vgay, wndx, wndy, outy, y_field, x_field;
@@ -126,7 +125,7 @@ int findQLine(void)
for(int x=0; x<wndx; x++)
aSumsOfSqrs[x]=0;
- for(int line=0; line<wndy; line++)
+ for(int line=0; line<wndy; line+=3)
for(int x=0; x<wndx; x++)
{
const int index= (line*vgax + x)*2;
@@ -137,6 +136,17 @@ int findQLine(void)
aSumsOfEquivalentPoints[line & 3][x]+= a;
aSumsOfSqrs[x]+= a*a;
}
+
+ for(int x=0; x<wndx; x++)
+ {
+ aSumsOfEquivalentPoints[0][x]*= 3;
+ aSumsOfEquivalentPoints[1][x]*= 3;
+ aSumsOfEquivalentPoints[2][x]*= 3;
+ aSumsOfEquivalentPoints[3][x]*= 3;
+ aSumsOfSqrs[x]*= 3;;
+ }
+
+
if(iState==2)
{
@@ -213,10 +223,12 @@ int findQLine(void)
for(int x= min(bestQLine+HSYNC_SEARCH_END, wndx-1); x >= bestQLine + HSYNC_SEARCH_START; x--)
{
- for(int line=0; line<wndy; line++)
+ for(int line=0; line<wndy; line+=3)
{
score[x] += p[(line*vgax + x)*2 + 1];
}
+
+ score[x]*= 3;
if( x+2 <= min(bestQLine+HSYNC_SEARCH_END, wndx-1)
&& (score[x] - score[x+2])/wndy > HSYNC_THRESHOLD)
@@ -403,6 +415,7 @@ void analyzeHSyncDelay(int newQLine)
}
lastHSyncDelay=0;
+ /*
printf("%dX %dD %dXX %dDD %dXD %dn\n",
hSyncDelaySumX,
hSyncDelaySumD,
@@ -410,6 +423,7 @@ void analyzeHSyncDelay(int newQLine)
hSyncDelaySumDD,
hSyncDelaySumDX,
hSyncDelays);
+ */
}
@@ -477,6 +491,7 @@ void analyzeVSyncDelay(int newVSync)
}
lastVSyncDelay=0;
+ /*
printf("%dY %dD %dYY %dDD %dYD %dn\n",
vSyncDelaySumY,
vSyncDelaySumD,
@@ -484,6 +499,7 @@ void analyzeVSyncDelay(int newVSync)
vSyncDelaySumDD,
vSyncDelaySumDY,
vSyncDelays);
+ */
}
/*
@@ -507,28 +523,72 @@ void fixColor(int qLine)
void fixBrightness(int qLine)
{
- byte * const p= &actVid2MemBufp->b[0];
+ static int darkestVal=0;
+ static int brightestVal=255;
+
+ darkestVal++;
+ brightestVal--;
+
+ byte * const p= &actVid2MemBufp->b[0];
- for(int line=0; line<wndy; line++)
- {
+ for(int line=1; line<wndy; line++)
+ {
- if(qLine + BRIGHTNESS_REF_POS>=wndx) break;
+ if(qLine + Q_2_HSYNC_DISTANCE + 3>=wndx) break;
+
+ double encodedBlankLevel = 0;
+ double encodedSyncLevel = 0;
+
+ int nLines= 0;
+
+ for(int refLine= max(line-4, 0); refLine<min(wndy, line+4); refLine++)
+ {
+ if((refLine&3) == qPhase) continue;
+
+ nLines++;
+ encodedBlankLevel += p[(refLine*vgax + qLine + Q_2_HSYNC_DISTANCE - 3)*2 + 1];
+ encodedSyncLevel += p[(refLine*vgax + qLine + Q_2_HSYNC_DISTANCE + 3)*2 + 1];
+ }
+
+ encodedBlankLevel/= nLines;
+ encodedSyncLevel /= nLines;
+
+ const double shift= RELATIV_LEVEL_SHIFT* (encodedBlankLevel - encodedSyncLevel);
+
+ const double blankLevel = encodedBlankLevel - shift;
+ const double syncLevel = encodedSyncLevel - shift;
+
+ const int blackLevel = int(blankLevel) -20;
+
+ const int scale = int((BLANK_LEVEL - SYNC_LEVEL) / max(blankLevel - syncLevel, 1.0) * (256.0 * 235.0));
- int brightnessRef=0;
- int nBrightnessRef=0;
- for(int refLine=max(line-2, 0); refLine<min(line+2, vgay); refLine++)
- {
- brightnessRef+= p[(refLine*vgax + qLine + BRIGHTNESS_REF_POS)*2 + 1];
- nBrightnessRef++;
- }
- brightnessRef/= nBrightnessRef;
+
for(int x=0; x<min(qLine, wndx); x++)
- {
- p[(line*vgax + x)*2 + 1]=
- minmax(0, p[(line*vgax + x)*2 + 1] - brightnessRef + BRIGHTNESS_DELTA, 255);
- }
+ {
+ if(p[(line*vgax + x)*2 + 1] >= brightestVal && (some&1))
+ {
+ p[(line*vgax + x)*2]= 127;
+
+ if(p[(line*vgax + x)*2 + 1] > brightestVal) brightestVal= p[(line*vgax + x)*2 + 1];
+ }
+ else if( p[(line*vgax + x)*2 + 1] <= darkestVal && (some&1))
+ {
+ p[(line*vgax + x)*2]= 128;
+
+ if(p[(line*vgax + x)*2 + 1] < darkestVal) darkestVal= p[(line*vgax + x)*2 + 1];
+ }
+ else
+ {
+ int v = p[(line*vgax + x)*2 + 1];
+
+ v = ((v - blackLevel) * scale) >> 8;
+
+ p[(line*vgax + x)*2 + 1]= minmax(0, v, 255);
+
+ }
}
+ }
}
void showStat(void)
@@ -553,6 +613,9 @@ void showStat(void)
}
}
+extern volatile bool isVPayTvBrightHack;
+extern volatile int vPayTvQPosInLCC;
+
void vPayTvDecrypt(void)
{
static int dropList[10]; //0 -> nothing, 1 -> Drop, 2 -> Drop & Return
@@ -560,24 +623,22 @@ void vPayTvDecrypt(void)
dropList[i]= dropList[i+1];
dropList[9]= 0;
- static int lastQLineInLCC=0;
- static bool isBrightHack=true;
- vPayTvBrightHack(isBrightHack, lastQLineInLCC);
- isBrightHack = !isBrightHack;
- if(!isBrightHack) dropList[1]|=2;
-
+ // if(isVPayTvBrightHack) dropList[1]|=2;
+
+ //isVPayTvBrightHack= true;
+ isVPayTvBrightHack= false;
if(dropList[0])
- {
+ {
drop=true;
if(dropList[0]&2) return;
- }
+ }
int qLine= findQLine();
int vSync= -1;//findVSync(qLine);
- if(vSync!= -1)
+ if(qLine!= -1)
{
- lastQLineInLCC= (qLine-wndx-6)*1888 / wndx;
+ vPayTvQPosInLCC= (qLine-wndx-6)*1888 / wndx;
}
byte * p= &actVid2MemBufp->b[0];
Added: trunk/2010/countppm.cpp
==============================================================================
--- (empty file)
+++ trunk/2010/countppm.cpp Wed Jul 4 11:27:15 2007
@@ -0,0 +1,53 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <string.h>
+
+int main(int argc, char **argv)
+{
+ if(argc<2)
+ {
+ printf("Command line Error!\n");
+ exit(1);
+ }
+
+ FILE * inFile= fopen(argv[1], "rb");
+ if(inFile==NULL)
+ {
+ printf("Cant open inFile!\n");
+ exit(1);
+ }
+
+ const int bufferSize= 1024*1024;
+ unsigned char *buffer= new unsigned char[bufferSize];
+
+ int xBuffer= bufferSize;
+
+ for(int i=0; ; i++)
+ {
+ memmove(buffer, &buffer[xBuffer], bufferSize - xBuffer);
+ memset(&buffer[bufferSize - xBuffer], 0, xBuffer);
+
+ fread(&buffer[bufferSize - xBuffer], xBuffer, 1, inFile);
+
+ for(xBuffer=1; ; xBuffer++)
+ {
+ if(xBuffer+20>bufferSize) exit(1); // can happen if jpeg too large or at end (HACK)
+
+ if( buffer[xBuffer ] == 0xFF
+ && buffer[xBuffer + 2] == 0xFF
+ && buffer[xBuffer + 6] == 'J'
+ && buffer[xBuffer + 7] == 'F'
+ && buffer[xBuffer + 8] == 'I'
+ && buffer[xBuffer + 9] == 'F'
+ && buffer[xBuffer + 10] == 0)
+ {
+ break;
+ }
+ }
+
+ printf("%d\r", i);
+ fflush(stdout);
+ }
+}
+
Added: trunk/2010/extractppm.cpp
==============================================================================
--- (empty file)
+++ trunk/2010/extractppm.cpp Wed Jul 4 11:27:15 2007
@@ -0,0 +1,124 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <string.h>
+
+int main(int argc, char **argv)
+{
+ if(argc<3)
+ {
+ printf("Command line Error!\n");
+ exit(1);
+ }
+
+ FILE * inFile= fopen(argv[1], "rb");
+ if(inFile==NULL)
+ {
+ printf("Cant open inFile!\n");
+ exit(1);
+ }
+
+ /* load the Pos at witch the Jpeg beginns */
+
+ long filePos=0;
+
+ FILE * datFile= fopen("extractppm.dat", "rb");
+ if(datFile==NULL)
+ {
+ filePos=0;
+ }
+ else
+ {
+ fscanf(datFile, "%D", &filePos);
+
+ fclose(datFile);
+ }
+
+ if( stricmp("X000000.ppm", argv[2])==0 ) filePos=0;
+
+ fseek(inFile, filePos, SEEK_SET);
+
+ const int bufferSize= 1024*100;
+ unsigned char *buffer= new unsigned char[bufferSize];
+
+ memset(buffer, 0, bufferSize);
+ fread(buffer, bufferSize, 1, inFile);
+
+ fclose(inFile);
+
+ int xNextJpeg;
+ for(xNextJpeg=1; xNextJpeg+20<bufferSize; xNextJpeg++)
+ {
+ if( buffer[xNextJpeg ] == 0xFF
+ && buffer[xNextJpeg + 2] == 0xFF
+ && buffer[xNextJpeg + 6] == 'J'
+ && buffer[xNextJpeg + 7] == 'F'
+ && buffer[xNextJpeg + 8] == 'I'
+ && buffer[xNextJpeg + 9] == 'F'
+ && buffer[xNextJpeg + 10] == 0)
+ {
+ filePos+= xNextJpeg;
+ break;
+ }
+ }
+
+ if(xNextJpeg+20 >= bufferSize) // End
+ {
+ filePos=0;
+ }
+
+ /* save Pos at witch the next Jpeg beginns */
+
+ datFile= fopen("extractppm.dat", "wb");
+ if(datFile==NULL)
+ {
+ printf("Cant open datFile!\n");
+ exit(1);
+ }
+
+ fprintf(datFile, "%D\n", filePos);
+
+ fclose(datFile);
+
+
+ /* extract the Jpeg */
+
+ FILE * outFile= fopen("temp.jpg", "wb");
+ if(outFile==NULL)
+ {
+ printf("Cant open outFile!\n");
+ exit(1);
+ }
+
+ fwrite(buffer, xNextJpeg, 1, outFile); // FIXME the last one will be too Large
+
+ fclose(outFile);
+
+ /* convert it to a PPM (Binary) */
+
+ //char textBuffer[50];
+ //sprintf(textBuffer, "djpeg -outfile %s temp.jpg", argv[2]);
+ //system( textBuffer );
+ system( "djpeg -outfile temp.ppm temp.jpg" );
+
+
+ /* convert the Binary PPM to a Ascii (Bug in Dos or Mpeg_enc ?)*/
+
+ FILE * ppmFile= fopen("temp.ppm", "rb");
+ if(outFile==NULL)
+ {
+ printf("Cant open ppmFile!\n");
+ exit(1);
+ }
+
+ fread(buffer, 99999, 1, ppmFile);
+
+ fprintf(stdout, "P3\n192 144\n255\n");
+
+ for(int i=0; i<192*144*3; i++)
+ {
+ fprintf(stdout, "%d ", buffer[i]);
+ }
+
+}
+
Modified: trunk/2010/makefile
==============================================================================
--- trunk/2010/makefile (original)
+++ trunk/2010/makefile Wed Jul 4 11:27:15 2007
@@ -31,6 +31,9 @@ crypt: ;$(MAKE) 2010C CFLAGS="$(OPTS)
2010 : $(O) ; gcc $(CFLAGS) -o 2010 $(O) -ljpeg
2010C : $(OC) ; gcc $(CFLAGS) -o 2010C $(OC) -ljpeg
+jpeg2Ppms : jpeg2Ppms.o ; gcc $(CFLAGS) -o jpeg2Ppms jpeg2Ppms.o -ljpeg
+countppm : countppm.o ; gcc $(CFLAGS) -o countppm countppm.o
+extractppm : extractppm.o ; gcc $(CFLAGS) -o extractppm extractppm.o
clean: ; del $(O) 2010
2010.o : 2010.cpp 2_all.h 2010.h 2_file.h 2_hw.h 2_grafix.h\
@@ -57,3 +60,6 @@ clean: ; del $(O) 2010
2_cryp_a.o : 2_cryp_a.asm 2_all_a.asm
2_hw_a.o : 2_hw_a.asm 2_all_a.asm
+extractppm.o: extractppm.cpp
+jpeg2Ppms.o : jpeg2Ppms.cpp
+countppm.o : countppm.cpp
1
0
[mndiff]: r63 - in trunk/2010: 2010.cpp 2_71x6.cpp 2_71x6.h 2_crypt.cpp 2_file.cpp 2_file.h 2_grafix.cpp 2_hw_mem.cpp 2_hw_mem.h 2_nag.cpp 2_txt.cpp 2_vc.cpp 2_vpaytv.cpp 2_vpaytv.h makefile
by michael 04 Jul '07
by michael 04 Jul '07
04 Jul '07
Author: michael
Date: Wed Jul 4 10:58:24 2007
New Revision: 63
Log:
version from 2000-02-03 17:54
Added:
trunk/2010/2_vpaytv.cpp
trunk/2010/2_vpaytv.h
Modified:
trunk/2010/2010.cpp
trunk/2010/2_71x6.cpp
trunk/2010/2_71x6.h
trunk/2010/2_crypt.cpp
trunk/2010/2_file.cpp
trunk/2010/2_file.h
trunk/2010/2_grafix.cpp
trunk/2010/2_hw_mem.cpp
trunk/2010/2_hw_mem.h
trunk/2010/2_nag.cpp
trunk/2010/2_txt.cpp
trunk/2010/2_vc.cpp
trunk/2010/makefile
Modified: trunk/2010/2010.cpp
==============================================================================
--- trunk/2010/2010.cpp (original)
+++ trunk/2010/2010.cpp Wed Jul 4 10:58:24 2007
@@ -1,4 +1,3 @@
-
//2010 0.1 Copyright (c) 1998 Michael Niedermayer
#include <stdlib.h>
@@ -45,6 +44,7 @@
extern int reqPage, reqSubPage, reqChanNum;
extern char reqChanStr[];
extern char findTxt[];
+ extern bool isVCPhaseTrick;
int maxBuf=2;
int some=0;
@@ -53,6 +53,7 @@
int _crt0_startup_flags = _CRT0_FLAG_NEARPTR | _CRT0_FLAG_NONMOVE_SBRK;
bool fShowRaw=false;
int grabf;
+ int grabV=0;
int fysize;
byte font[4096];
int vid=0;
@@ -137,6 +138,7 @@ int error(error_code e){
break;
}
+// asm("int $3\n\t");
exit(e);
}
@@ -330,6 +332,7 @@ int main(int argc, char **argv){
infoPosX=10;
if(grabf==2 && TVStd!=TXTPAL) GrabRaw(), grabf=0;
+// if(grabf==2) GrabRaw(), grabf=0; //REMOVE
if(fShowRaw) ShowRaw();
@@ -337,6 +340,8 @@ int main(int argc, char **argv){
showStuff();
if(grabf==1 && TVStd!=TXTPAL) GrabBmp(), grabf=0;
+
+ if(grabV==1) RecordVideo();
for(int k=0; k<delay*10000000; k++);
@@ -375,11 +380,17 @@ int main(int argc, char **argv){
}
switch(menuLevel){
- case mLNorm : switch(key){
- case 'p' :
- case 'P' : getkey();
- break;
- case 'g' : key=0, grabf=1;
+ case mLNorm : switch(key){
+ case 'p' :
+ case 'P' : getkey();
+ break;
+
+ case 'r' : key=0,
+ grabV&=1;
+ grabV^=1;
+ break;
+
+ case 'g' : key=0, grabf=1;
break;
case 'G' : key=0, grabf=2;
break;
@@ -420,6 +431,9 @@ int main(int argc, char **argv){
break;
case 's' : menuLevel=mLTVStd, helpState=false;
break;
+ case 't' :
+ case 'T' : isVCPhaseTrick=true;
+ break;
case 'i' :
case 'I' : iState++; iState%=ISTATES;
break;
@@ -531,6 +545,14 @@ int main(int argc, char **argv){
setStdScale();
contGrab();
break;
+ case '7' : TVStd= PAL;
+ cryptStd= vpaytv;
+ if(yuvMode==0) yuvMode=1;
+ grabYuvMode=yuvMode;
+// iVSmooth=2;
+ setStdScale();
+ contGrab();
+ break;
#endif
}
menuLevel=mLNorm;
Modified: trunk/2010/2_71x6.cpp
==============================================================================
--- trunk/2010/2_71x6.cpp (original)
+++ trunk/2010/2_71x6.cpp Wed Jul 4 10:58:24 2007
@@ -307,7 +307,7 @@ void meteor_int_handler_end(void){
void setCont(void){
- write_saa7196(0x12, satur);/*7:0 Chrominance saturation control for VRAM port */
+ write_saa7196(0x12, satur);/*7:0 Chrominance saturation control for VRAM port (Signed (: Negativ Saturation) */
write_saa7196(0x13, contr);/*7:0 Luminance contract control for VRAM port */
write_saa7196(0x19,bright);/*7:0 Luminance brightness control for VRAM port */
@@ -385,24 +385,60 @@ void setStdScale(void){
1:0 Aperture bandpass filter weights */
if(TVStd==SECAM) write_saa7196(0x0D, 0x85);
- else write_saa7196(0x0D, 0x84);
+ else write_saa7196(0x0D, 0x84); //0x84
/* 7 VTR/TV mode bit = 1->VTR mode
3 Realtime output mode select bit
2 HREF position select
1 Status byte select
0 SECAM mode bit */
+
if(TVStd==SECAM) write_saa7196(0x0F, 0xB0);
- else write_saa7196(0x0F, 0x90);
+ else write_saa7196(0x0F, 0x90); //90
/* 7 Automatic Field detection
6 Field Select 0 = 50hz, 1=60hz
5 SECAM cross-colour reduction
4 Enable sync and clamping pulse
3:1 Luminance delay compensation */
-// write_saa7196(0x10, 0x04);
- write_saa7196(0x10, 0x00);
+ if(cryptStd==vpaytv)
+ write_saa7196(0x10, 0x02);
+ else
+ write_saa7196(0x10, 0x00); //0
/* 2 Select HREF Position
1:0 Vertical noise reduction */
+ if(cryptStd==vpaytv)
+ write_saa7196(0x0C, 0xE0); //0xE0
+ else
+ write_saa7196(0x0C, 0xC0); //0xC0
+ /* 7 Colour-on bit
+ 6:5 AGC filter */
+
+ if(cryptStd==vpaytv)
+ write_saa7196(0x0E, 0xB8); //B8
+ else
+ write_saa7196(0x0E, 0x38); //38
+
+
+ /* 7 Horizontal clock PLL //38 / B8
+ 5 Select interal/external clock source
+ 4 Output enable of Horizontal/Vertical sync
+ 3 Data output YUV enable
+ 2 S-VHS bit
+ 1 GPSW2
+ 0 GPSW1 */
+
+
+// if(some-0x60>=124 ) some=123+0x60;
+ write_saa7196(0x01, 0x30);/* 7:0 Horizontal Sync Begin for 50hz */
+ write_saa7196(0x02, 0x00);/* 7:0 Horizontal Sync Stop for 50hz */
+ write_saa7196(0x03, 0xE8);/* 7:0 Horizontal Sync Clamp Start for 50hz */
+ write_saa7196(0x04, 0xB6);/* 7:0 Horizontal Sync Clamp Stop for 50hz */
+ write_saa7196(0x05, 0xF4);/* 7:0 Horizontal Sync Start after PH1 for 50hz */
+
+ //TEST
+// write_saa7196(0x11, some);/* 7:0 Chrominance gain conrtol for QAM */
+
+
if(grabYuvMode==0){
/* if(oneField) write_saa7196(0x20, 0xF2);
else write_saa7196(0x20, 0x92);
@@ -549,15 +585,6 @@ void init_meteor(void){
write_saa7196(0x09, 0x7F);/* 7:3 Colour-killer threshold SECAM */
write_saa7196(0x0A, 0x7F);/* 7:0 PAL switch sensitivity */
write_saa7196(0x0B, 0x7F);/* 7:0 SECAM switch sensitivity */
- write_saa7196(0x0C, 0xC0);/* 7 Colour-on bit
- 6:5 AGC filter */
- write_saa7196(0x0E, 0x38);/* 7 Horizontal clock PLL
- 5 Select interal/external clock source
- 4 Output enable of Horizontal/Vertical sync
- 3 Data output YUV enable
- 2 S-VHS bit
- 1 GPSW2
- 0 GPSW1 */
write_saa7196(0x11, 0x2C);/* 7:0 Chrominance gain conrtol for QAM */
write_saa7196(0x14, 0x34);/* 7:0 Horizontal sync begin for 60hz */
//#ifdef notdef
@@ -680,6 +707,7 @@ void contGrab(void){
}
void doTxtHack(int txtHackState){
+// return; //REMOVE
switch(txtHackState){
case 8 ... 100:
write_saa7196(0x10, 0x00);
@@ -717,3 +745,75 @@ void doTxtHack(int txtHackState){
break;
}
}
+
+void vPayTvShiftHack(int amount)
+ {
+ write_saa7196(0x0F, 0x50);
+
+ for(int i=0; i<10000*amount; i++);
+
+ write_saa7196(0x0F, 0x10);
+ }
+
+
+void vPayTvBrightHack(bool b, int posInLCC)
+ {
+
+/* int hSyncBegin= - 96 +posInLCC;
+ int hSyncStop= 0 +posInLCC;
+ int hClampBegin= 48 +posInLCC;
+ int hClampStop= 148 +posInLCC;*/
+
+ int hSyncBegin= - 96 +posInLCC;
+ int hSyncStop= - 70 +posInLCC;
+ int hClampBegin= - 60 +posInLCC;
+ int hClampStop= 148 +posInLCC-some;
+ int hSyncStartAfterPH1= 96;//+posInLCC;
+
+ hSyncBegin = minmax(-382, hSyncBegin, 126);
+ hSyncStop = minmax(-380, hSyncStop, 128);
+ hClampBegin= minmax(-254, hClampBegin, 254);
+ hClampStop = minmax(-252, hClampStop, 256);
+
+ hSyncBegin/=2;
+ hSyncStop/=2;
+ hClampBegin/=2;
+ hClampStop/=2;
+ hSyncStartAfterPH1/=8;
+
+ if(hSyncStop <= hSyncBegin) hSyncStop= hSyncBegin+1;
+ if(hClampBegin <= hSyncStop) hClampBegin= hSyncStop+1;
+ if(hClampStop <= hClampBegin) hClampStop= hClampBegin+1;
+
+
+ // write_saa7196(0x01, 0x30);/* 7:0 Horizontal Sync Begin for 50hz */
+ // write_saa7196(0x02, 0x00);/* 7:0 Horizontal Sync Stop for 50hz */
+ // write_saa7196(0x03, 0xE8);/* 7:0 Horizontal Sync Clamp Start for 50hz */
+ // write_saa7196(0x04, 0xB6);/* 7:0 Horizontal Sync Clamp Stop for 50hz */
+ // write_saa7196(0x05, 0xF4);/* 7:0 Horizontal Sync Start after PH1 for 50hz */
+
+ if(b)
+ {
+ write_saa7196(0x01, (-hSyncBegin )&0xFF);/* 7:0 Horizontal Sync Begin for 50hz */
+ write_saa7196(0x02, (-hSyncBegin+10 )&0xFF);/* 7:0 Horizontal Sync Stop for 50hz */
+ write_saa7196(0x03, (-hClampBegin )&0xFF);/* 7:0 Horizontal Sync Clamp Start for 50hz */
+ write_saa7196(0x04, (-hClampStop )&0xFF);/* 7:0 Horizontal Sync Clamp Stop for 50hz */
+ write_saa7196(0x05, (-hSyncStartAfterPH1)&0xFF);/* 7:0 Horizontal Sync Start after PH1 for 50hz */
+ }
+ else
+ {
+ write_saa7196(0x01, (-hSyncBegin )&0xFF);/* 7:0 Horizontal Sync Begin for 50hz */
+ write_saa7196(0x02, (-hSyncStop )&0xFF);/* 7:0 Horizontal Sync Stop for 50hz */
+ write_saa7196(0x03, (-hClampBegin )&0xFF);/* 7:0 Horizontal Sync Clamp Start for 50hz */
+ write_saa7196(0x04, (-hClampStop )&0xFF);/* 7:0 Horizontal Sync Clamp Stop for 50hz */
+ write_saa7196(0x05, (-hSyncStartAfterPH1)&0xFF);/* 7:0 Horizontal Sync Start after PH1 for 50hz */
+ }
+ printf("T %d %d %d %d %d\n"
+ ,(-hSyncBegin )&0xFF
+ ,(-hSyncStop )&0xFF
+ ,(-hClampBegin )&0xFF
+ ,(-hClampStop )&0xFF
+ ,(-hSyncStartAfterPH1)&0xFF);
+
+ }
+
Modified: trunk/2010/2_71x6.h
==============================================================================
--- trunk/2010/2_71x6.h (original)
+++ trunk/2010/2_71x6.h Wed Jul 4 10:58:24 2007
@@ -20,6 +20,7 @@ enum CRYPTSTD{
nix,
vc,
nag,
+ vpaytv
};
/*
@@ -219,5 +220,7 @@ void setStdScale(void);
void grab_next(VID2MEMBUF v2mb);
void grab_nix();
void doTxtHack(int);
+void vPayTvShiftHack(int);
+void vPayTvBrightHack(bool, int);
#endif
Modified: trunk/2010/2_crypt.cpp
==============================================================================
--- trunk/2010/2_crypt.cpp (original)
+++ trunk/2010/2_crypt.cpp Wed Jul 4 10:58:24 2007
@@ -12,6 +12,7 @@
#include "2_txt.h"
#include "2_71x6.h"
#include "2_gfunc.h"
+#include "2_vpaytv.h"
#define COMB_FIX 256
@@ -45,7 +46,7 @@ void decrypt(void){
}
if( cryptStd == nag && satur!=0 ) Decomb(0);
- if( cryptStd == vc && satur!=0 ) Decomb(1);
+ if( cryptStd == vc && satur!=0 ) Decomb(1);
if(iState){
T2=uclock();
@@ -56,6 +57,7 @@ void decrypt(void){
#ifdef CRYPT
if(cryptStd==vc) vc_decrypt();
else if(cryptStd==nag) nag_decrypt();
+ else if(cryptStd==vpaytv) vPayTvDecrypt();
#endif
if(TVStd==TXTPAL) txt_decrypt();
Modified: trunk/2010/2_file.cpp
==============================================================================
--- trunk/2010/2_file.cpp (original)
+++ trunk/2010/2_file.cpp Wed Jul 4 10:58:24 2007
@@ -2,10 +2,14 @@
#include <stdio.h>
#include <dos.h>
+#include <time.h>
#include "2_all.h"
#include "2010.h"
#include "2_file.h"
#include "2_hw.h"
+#include "2_hw_mem.h"
+#include "2_gfunc.h"
+#include <jpeglib.h>
extern int vgax, vgay, wndx, wndy, outy;
extern int fysize;
@@ -14,6 +18,7 @@
extern int g_mode;
extern int yuvMode;
extern char *yuv2rgb_lut;
+extern int infoPosX, infoPosY;
static byte *ppbRawDat[64];
static int nRawDats=0;
@@ -132,6 +137,113 @@ void ShowRaw(void){
i%=nRawDats;
memcpy(actVid2MemBufp->b, ppbRawDat[i], vgax*outy*2);
}
+/*
+static byte *jpegStorage= null;
+static int nJpegs=0;
+static byte **apJpeg= null;
+static int *aJpegSizes= null;
+static int jpegStorageSize=0;
+*/
+void RecordVideo(void)
+{
+ if(yuvMode==0) return;
+ long T0= uclock();
+
+ static FILE * outFile= NULL;
+ if(outFile == NULL)
+ {
+ char fileName[16];
+ struct time ti;
+
+ gettime(&ti);
+ sprintf(fileName, "V%02d%02d%02d.jpg", ti.ti_hour, ti.ti_min, ti.ti_sec);
+
+ outFile = fopen(fileName, "wb");
+ if (outFile == NULL)
+ {
+ fprintf(stderr, "can't open %s\n", fileName);
+ exit(1);
+ }
+
+ }
+
+ int image_width= wndx/2;
+ int image_height= wndy/2;
+ int quality= 70;
+
+ static byte * image_buffer= new byte[wndx*wndy*3];
+ byte * pYUV= &actVid2MemBufp->b[ 0 ];
+ byte * pYCbCr= &image_buffer[0];
+
+ for(int y=0; y<(wndy>>1); y++)
+ {
+ for(int x=0; x<(wndx>>1); x++)
+ {
+ pYCbCr[0] = (pYUV[1] + pYUV[3]) >> 1;
+ pYCbCr[1] = pYUV[0]+127;
+ pYCbCr[2] = pYUV[2]+127;
+ pYCbCr+=3;
+ pYUV+=4;
+ }
+ pYUV+=(vgax*2 - wndx)*2;
+ }
+
+ static struct jpeg_compress_struct cinfo;
+
+ static struct jpeg_error_mgr jerr;
+
+ JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */
+ const int row_stride= image_width * 3;; /* physical row width in image buffer */
+
+ static bool isInit=true;
+ if(isInit)
+ {
+ isInit=false;
+ cinfo.err = jpeg_std_error(&jerr);
+
+ /* Now we can initialize the JPEG compression object. */
+ jpeg_create_compress(&cinfo);
+
+ jpeg_stdio_dest(&cinfo, outFile);
+ }
+
+ cinfo.image_width = image_width; /* image width and height, in pixels */
+ cinfo.image_height = image_height;
+ cinfo.input_components = 3; /* # of color components per pixel */
+ cinfo.in_color_space = JCS_YCbCr; /* colorspace of input image */
+ jpeg_set_defaults(&cinfo);
+
+ cinfo.dct_method= JDCT_ISLOW; // JDCT_IFAST is 30% faster
+ cinfo.optimize_coding= TRUE; // almost no differenc in speed
+
+ jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */);
+
+ jpeg_start_compress(&cinfo, TRUE);
+
+ while (cinfo.next_scanline < cinfo.image_height) {
+ row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride];
+ (void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
+ }
+
+
+ jpeg_finish_compress(&cinfo);
+
+ fflush(outFile);
+
+// jpeg_destroy_compress(&cinfo);
+
+ long T1= uclock();
+ char textBuffer[20];
+ sprintf(textBuffer, "Recording %f", float(T1-T0)/float(UCLOCKS_PER_SEC));
+
+ color c;
+ c.init(255, 0, 0, false);
+
+ gprint(infoPosX, infoPosY+=10, c.col, textBuffer);
+
+}
+
+
long fsize(FILE *f){
long i,j;
Modified: trunk/2010/2_file.h
==============================================================================
--- trunk/2010/2_file.h (original)
+++ trunk/2010/2_file.h Wed Jul 4 10:58:24 2007
@@ -25,5 +25,6 @@ long fsize(FILE *f);
void LoadRaws(int, char **);
void GrabRaw(void);
void ShowRaw(void);
+void RecordVideo(void);
#endif
Modified: trunk/2010/2_grafix.cpp
==============================================================================
--- trunk/2010/2_grafix.cpp (original)
+++ trunk/2010/2_grafix.cpp Wed Jul 4 10:58:24 2007
@@ -8,9 +8,12 @@
#include "2010.h"
#include "2_gfunc.h"
#include "2_hw.h"
+#include "2_hw_mem.h"
#include "2_file.h"
#include "2_crypt.h"
+#include <dpmi.h> // remove
+
extern int xres, yres, xresc;
extern int fysize;
extern byte font[4096];
@@ -27,7 +30,7 @@
extern bool allowDrop;
bool helpState=true;
- bool iState=false;
+ int iState=0;
int showCont=0;
void showStuff(void){
@@ -41,7 +44,7 @@ void showStuff(void){
"g ScreenShot G SaveRaw",
"v smoothIterlace p Pause",
"d allowDrop q Quit",
- "S ShowRaw",
+ "S ShowRaw r Record",
" TELETXT:",
"+ Page+ - Page-",
"right subPage+ left subPage-",
@@ -73,28 +76,35 @@ void showStuff(void){
if(menuLevel==mLTVStd){
#ifndef CRYPT
- char text[3][256]={ "1. PAL 4. PAL-TeleText",
+ char text[4][256]={ "1. PAL 4. PAL-TeleText",
"2. NTSC",
- "3. SECAM"};
+ "3. SECAM",
+ ""};
#else
- char text[3][256]={ "1. PAL 4. PAL-TeleText",
+ char text[4][256]={ "1. PAL 4. PAL-TeleText",
"2. NTSC 5. VideoCrypt (PAL)",
- "3. SECAM 6. NagraVision (PAL/secam)"};
+ "3. SECAM 6. NagraVision (PAL/secam)",
+ "7. "};
#endif
- for(int i=0; i<3; i++){
+ for(int i=0; i<4; i++){
c.init(255, 0, 0, false);
gprint(infoPosX, infoPosY+=10, c.col, text[i]);
}
infoPosY+=5;
}
- static long T2=uclock();
- long T1=uclock();
-
if(iState){
c.init(255, 0, 0, false);
- sprintf(textbuf,"%2.2f Fps",1/((float)(T1-T2)/UCLOCKS_PER_SEC));
+
+ static long T[10];
+ for(int i=8; i>=0; i--)
+ {
+ T[i+1] = T[i];
+ }
+ T[0] = uclock();
+
+ sprintf(textbuf,"%2.2f Fps",1/((float)(T[0]-T[9])/(UCLOCKS_PER_SEC*9)));
gprint(infoPosX, infoPosY+=10, c.col, textbuf);
sprintf(textbuf,"%d Buf", vid2MemBuf[0].num);
@@ -119,8 +129,15 @@ void showStuff(void){
gprint(infoPosX, infoPosY+=10, c.col, textbuf);
infoPosY+=5;
}
+ if(iState==2){
+ c.init(255, 0, 0, false);
+
+ int nMbLeft= getFreeMemory() / (1024 * 1024);
- T2=T1;
+ sprintf(textbuf,"%dMb left", nMbLeft);
+ gprint(infoPosX, infoPosY+=10, c.col, textbuf);
+ infoPosY+=5;
+ }
}
Modified: trunk/2010/2_hw_mem.cpp
==============================================================================
--- trunk/2010/2_hw_mem.cpp (original)
+++ trunk/2010/2_hw_mem.cpp Wed Jul 4 10:58:24 2007
@@ -7,6 +7,7 @@
#include <string.h>
#include <sys/nearptr.h>
#include <sys/farptr.h>
+#include <math.h>
#include "2_all.h"
#include "2_hw_mem.h"
#include "2010.h"
@@ -23,7 +24,7 @@ bool checkAlign(void *p, int align){
else return true;
}
-void *newAlign(int size, int align){
+void *newAlign(int size, int align){
int v= int(new char[size + align + 3]);
#ifdef debug
printf("anew %d\n", v);
@@ -455,3 +456,26 @@ void unmapall(void){
delete llp2;
}
}
+
+int getFreeMemory(void)
+{
+ int h[3000];
+ int x;
+ __dpmi_meminfo dmi;
+
+ for(x=0; ; x++)
+ {
+ dmi.size= 1024*1024;
+ int e=__dpmi_allocate_memory(&dmi);
+ if(e==-1) break;
+ h[x]=dmi.handle;
+ }
+
+
+ for(int i = x-1; i>=0; i--)
+ {
+ __dpmi_free_memory(h[i]);
+ }
+
+ return x * 1024 * 1024 ;
+}
Modified: trunk/2010/2_hw_mem.h
==============================================================================
--- trunk/2010/2_hw_mem.h (original)
+++ trunk/2010/2_hw_mem.h Wed Jul 4 10:58:24 2007
@@ -56,5 +56,6 @@ void vds_freeall(void);
void *map(u_long start, u_long end);
void unmap(void *start);
void unmapall(void);
+int getFreeMemory(void);
#endif
Modified: trunk/2010/2_nag.cpp
==============================================================================
--- trunk/2010/2_nag.cpp (original)
+++ trunk/2010/2_nag.cpp Wed Jul 4 10:58:24 2007
@@ -20,6 +20,8 @@
#define dwnSmp 3
+#define SAVE_SEEDS
+
#define FREQ_CHROM 4433618.75
#define FREQ_HS 15625.0
#define PHASE_DRIFT_PER_LINE (-fmod(FREQ_CHROM/FREQ_HS*4.0, 1.0)/4.0*PI*2.0)
@@ -255,7 +257,15 @@ void nag_decrypt(void){
static long long *sinPerLine=new long long[NAG_LINES+32];
static long long *cosPerLine=new long long[NAG_LINES+32];
+ static FILE *seedsFile=NULL;
+
if(first){
+
+#ifdef SAVE_SEEDS
+ seedsFile= fopen("nagSeeds.dat", "w");
+ if(seedsFile==NULL) error(error_code(-987));
+#endif
+
decoLines=32;
decoLine=new int[decoLines];
decoLine[ 0]= 14;
@@ -738,6 +748,11 @@ void nag_decrypt(void){
printf("%X\n", bestKey);
#endif
+#ifdef SAVE_SEEDS
+ if(drop) fprintf(seedsFile, "FFFF\n");
+ else fprintf(seedsFile, "%04X\n", bestKey);
+#endif
+
delete [] bestCoeffs; // kill this
Modified: trunk/2010/2_txt.cpp
==============================================================================
--- trunk/2010/2_txt.cpp (original)
+++ trunk/2010/2_txt.cpp Wed Jul 4 10:58:24 2007
@@ -12,7 +12,7 @@
#include "2_txt.h"
#include "2_71x6.h"
-#define FORCE_ORDER true
+#define FORCE_ORDER false
extern int vgax, vgay, wndx, wndy, mc, x_field;
extern bool iState, helpState;
@@ -118,13 +118,15 @@ static inline int sample(byte *b, int fi
return (a1+a2) >> FIXP_SH;
}
-
void txt_decrypt(void){
char textbuf[9][128];
+ int cross= (some-20)*1000;
+
static int hammErr=0;
static int pages=0;
- static int parities=0;
+ static double parities= 0;
+ static double magics= 0;
const double freqPix2= double(wndx) / double(x_field) * FREQ_PIX;
const int delta= int(freqPix2/FREQ_TXT*ONE_FIXP);
@@ -250,6 +252,7 @@ void txt_decrypt(void){
}
if(x>=70) continue;
+ magics++;
/*
actVid2MemBufp->b[linep + (x<<1) ]= 128;
@@ -465,10 +468,11 @@ void txt_decrypt(void){
}
memset(actVid2MemBufp->b, 0, vgax*vgay<<mc);
-
-// if(yuvMode<2) memset(actVid2MemBufp->b, 0, vgax*vgay<<mc);
-// yuvMode++;
-// if(yuvMode>2) yuvMode=2;
+/*
+ if(yuvMode<2) memset(actVid2MemBufp->b, 0, vgax*vgay<<mc);
+ yuvMode++;
+ if(yuvMode>2) yuvMode=2;
+ */
if(txtHack>0 && txtHackState==0) txtHackState=14;
@@ -635,7 +639,7 @@ void txt_decrypt(void){
}
if(line==0){
- sprintf(textbuf[0], " %d %d", pages, parities);
+ sprintf(textbuf[0], " %d %f", pages, parities);
gprint(10+32*9, yPos, txtColor[7].col, textbuf[0]);
}
@@ -698,8 +702,8 @@ void txt_decrypt(void){
infoPosY+=5;
- if(parities>9999) parities-=9000;
-
+ parities*= 0.9;
+ magics*=0.9;
}
Modified: trunk/2010/2_vc.cpp
==============================================================================
--- trunk/2010/2_vc.cpp (original)
+++ trunk/2010/2_vc.cpp Wed Jul 4 10:58:24 2007
@@ -39,12 +39,12 @@
#define MIN_LINES_FOR_EDGE_AREA 50
-#define EDGE_CHANGE_THRESHOLD 0.3
-#define PHASE_CORRECT_THRESHOLD (1.0/128*PI)
+#define EDGE_CHANGE_THRESHOLD 0.2
+#define PHASE_CORRECT_THRESHOLD (0.5/128*PI)
#define MAX_PHASE_CORRECT ( 22.0/180.0*PI)
#define MIN_PHASE_CORRECT (-22.0/180.0*PI)
-#define FIELDS_PER_PHASE_CHECK 30
-#define EDGE_AREA_TRUNC_DIV 6
+#define FIELDS_PER_PHASE_CHECK 50
+//#define EDGE_AREA_TRUNC_DIV 6
#define EDGE_AREA_START -4
#define EDGE_AREA_END 4
#define DEFINAL_WAIT 30
@@ -56,8 +56,8 @@
#define SCORE_THRESHOLD 3
#define MAX_EQ_SETS 14
#define nTEST_LINES 10
-#define MAX_BAD_CACHES 30000
-#define MAX_GOOD_CACHES 70000
+#define MAX_BAD_CACHES 50000
+#define MAX_GOOD_CACHES 25000
#define MAGIC_ID "VCC0"
#define STEP_START 16
@@ -74,7 +74,8 @@
#define PHASE_EXP 4
#define PHASE_LIMIT 40
#define MAX_PHASE_PENALTY 1000
-#define AMP_THRESHOLD 200
+#define AMP_THRESHOLD1 250
+#define AMP_THRESHOLD2 600
#define PHASE_COEFF (MAX_PHASE_PENALTY/pow(PHASE_LIMIT, PHASE_EXP))
#define EDGE_COEFF (MAX_EDGE/log(EDGE_LIMIT))
@@ -95,6 +96,8 @@ extern int infoPosY;
extern long uclockWaste;
extern bool drop;
+bool isVCPhaseTrick=false;
+
static void loadVCCache(void);
@@ -501,7 +504,7 @@ static CutPCache *findInLutX(int *piCutP
else
{
if( pCutPCache->score>=SCORE_THRESHOLD
- && pCutPCache!=pMergeCutPCache && 0)
+ && pCutPCache!=pMergeCutPCache && 0) //FIX ?!
{
addCutPsToCache(
@@ -724,16 +727,18 @@ static void loadVCCache(void){
tpCutPCache= new CutPCache;
fread(tpCutPCache, sizeof(CutPCache), 1, pFCache);
+ if( feof(pFCache) ) break; // FIX LOOKS UGLY
// printf("test %d %d\n", tpCutPCache->iScore, tpCutPCache->nUsed);
tpCutPCache->pbCCutP= new byte[tpCutPCache->nbCCutP];
+ if(tpCutPCache->nbCCutP > 600) printf("%d\n", tpCutPCache->nbCCutP);
fread(tpCutPCache->pbCCutP, sizeof(byte),
tpCutPCache->nbCCutP, pFCache);
if(tpCutPCache->isDeFinal==0) badFinalsLeft++;
- addToCache(tpCutPCache);
+ addToCache(tpCutPCache);
// printf("B\n");
addToLut(tpCutPCache);
// printf("A\n");
@@ -751,15 +756,10 @@ void vc_decrypt(void){
long T1=0, T2;
color c;
+ int pChromAmp[max_x];
+
static int edgePos=1;
static int edgeAlgo=0;
-/* static int *pEdgeArea=NULL;
- if(pEdgeArea==NULL)
- {
- pEdgeArea= new int[ (EDGE_AREA_END - EDGE_AREA_START) ];
- memset( pEdgeArea, 0, (EDGE_AREA_END - EDGE_AREA_START)*sizeof(int));
- }
-*/
// const int lowResSize= mmx ? DWN_SMP : (DWN_SMP-1);
@@ -843,7 +843,13 @@ void vc_decrypt(void){
static bool findPhases=true;
static double phaseCorrect=0;
static double lastPhaseCorrect=0;
- if(mabs(phaseCorrect-lastPhaseCorrect) > PHASE_CORRECT_THRESHOLD)
+ if(isVCPhaseTrick)
+ {
+ phaseCorrect+=12.0/180.0*PI;
+ if(phaseCorrect > MAX_PHASE_CORRECT) phaseCorrect= MIN_PHASE_CORRECT;
+ isVCPhaseTrick=false;
+ }
+ if(mabs(phaseCorrect-lastPhaseCorrect) > PHASE_CORRECT_THRESHOLD && some==0)
{
lastPhaseCorrect= phaseCorrect;
findPhases=true;
@@ -861,6 +867,7 @@ void vc_decrypt(void){
sin2PerCutP[cutP]= char( round( sin( -phase )*127 ) );
cos2PerCutP[cutP]= char( round( cos( -phase )*127 ) );
}
+ findPhases=false;
}
if(first){
@@ -1177,6 +1184,7 @@ void vc_decrypt(void){
chromAmp+= mabs(un) + mabs(vn);
}
if(line<2) chromAmp=1;
+ pChromAmp[line]= chromAmp;
// linep[ ((vcStartX + 0)<<1) + 1]=255;
// linep[ ((vcStartX + relCutPX)<<1) + 1]=200;
@@ -1290,7 +1298,7 @@ void vc_decrypt(void){
const int phase1= (a + phasePerCutP[ lastCutP ]) & 0xFF;
const int lastPhaseErrLastCutP= pPhaseErr[(line-1)*256 + lastCutP] + 128;
// FIX (ASM_OPTIMIZE)
- if(chromAmp>AMP_THRESHOLD){
+ if(chromAmp>AMP_THRESHOLD1){
for(int newCutP= newCutPStart; newCutP <= newCutPEnd; newCutP++){
const int phaseErr= (phase1 + phasePerCutP[ newCutP ]) & 0xFF;
const int val= lastVal[lastCutP] - *(++piDrift)
@@ -1458,7 +1466,7 @@ void vc_decrypt(void){
int phaseErrSum=0;
for(int line=10; line<wndy-10; line++)
{
- if(black[line] || black[line-1]) continue;
+ if(black[line] || black[line-1] || pChromAmp[line]<AMP_THRESHOLD2) continue;
int phaseErr= pPhaseErr[ line*256 + piBestCutP[line] ];
if(phaseErr>128) phaseErr-=256;
phaseErrSum+= phaseErr;
Added: trunk/2010/2_vpaytv.cpp
==============================================================================
--- (empty file)
+++ trunk/2010/2_vpaytv.cpp Wed Jul 4 10:58:24 2007
@@ -0,0 +1,689 @@
+//2010 0.1 Copyright (C) Michael Niedermayer 2000
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <time.h>
+#include <math.h>
+#include "2_all.h"
+#include "2_crypt.h"
+#include "2_vc.h"
+#include "2_nag.h"
+#include "2_71x6.h"
+#include "2_gfunc.h"
+#include "2_mmx.h"
+#include "2_nag_a.h"
+#include "2_hw_mem.h"
+#include "2_vpaytv.h"
+#include "2010.h"
+
+#define FREQ_CHROM 4433618.75
+#define FREQ_HS 15625.0
+#define PHASE_DRIFT_PER_LINE (-fmod(FREQ_CHROM/FREQ_HS*4.0, 1.0)/4.0*PI*2.0)
+#define Q_2_HSYNC_DISTANCE 6 //HACK (only 400x300)
+#define VSYNC_SIZE 26
+
+#define REAL_QLINE_POS (wndx-10)
+
+#define QLINE_COEFFICIENT_THRESHOLD 0.20
+//#define QLINE_OVERBRIGHT_THRESHOLD 220
+#define QLINE_OVERBRIGHT_THRESHOLD 240
+#define OVERBRIGHT_TEST_COLUMN 4
+#define HSYNC_THRESHOLD 30
+#define HSYNC_SEARCH_START (Q_2_HSYNC_DISTANCE-3)
+#define HSYNC_SEARCH_END 22
+#define VSYNC_SEARCH_COLUMN (-2)
+#define VSYNC_OVERBRIGHT_THRESHOLD 230
+#define MIN_VSYNC_DISTANCE 20
+
+#define LEFT_QLINE_BOUNDRY (wndx-20)
+#define RIGHT_QLINE_BOUNDRY (wndx-7)
+
+#define TOP_VSYNC_BOUNDRY (wndy-50)
+#define BOTTOM_VSYNC_BOUNDRY (wndy+50)
+
+#define BRIGHTNESS_REF_POS 3
+#define BRIGHTNESS_DELTA 180
+
+
+extern vgax, vgay, wndx, wndy, outy, y_field, x_field;
+extern VID2MEMBUF *actVid2MemBufp;
+extern volatile int scales_x, scalee_x;
+extern volatile int scales_y, scalee_y;
+extern u_long asm_temp, asm_temp4;
+extern bool iState;
+extern int yuvMode;
+extern bool mmx;
+extern int infoPosX;
+extern int infoPosY;
+extern int some;
+extern bool drop;
+extern bool isVCPhaseTrick;
+
+static inline float atan3(const float f1, const float f2){
+ float out;
+ // ?! atan2 crashes
+ asm(//"int $3\n\t"
+ "fpatan \n\t"
+ : "=t"(out)
+ : "0"(f2), "u"(f1)
+ : "st(1)"
+ );
+
+ return out;
+}
+
+static int qPhase=0;
+int findQLine(void)
+{
+ long T1=0, T2;
+ color c;
+ c.init(255, 0, 0, false);
+ char textbuf[100];
+
+ if(iState==2)
+ T1=uclock();
+
+ const int xSizeOfCorrelVector= 4;
+ float correlVector[4][4]= { {1,1,0 ,0 },
+ {0,0,0.33,0.33},
+ {0,0,0.33,0.33},
+ {0,0,0.33,0.33} };
+
+ float meanOfCorrelVector= 0;
+ for(int y=0; y<4; y++)
+ for(int x=0; x<xSizeOfCorrelVector; x++)
+ meanOfCorrelVector+= correlVector[y][x];
+
+ meanOfCorrelVector/= xSizeOfCorrelVector*4;
+
+ float varianceOfCorrelVector= 0;
+ for(int y=0; y<4; y++)
+ for(int x=0; x<xSizeOfCorrelVector; x++)
+ {
+ correlVector[y][x] -= meanOfCorrelVector;
+ varianceOfCorrelVector+= correlVector[y][x] * correlVector[y][x];
+ }
+
+ varianceOfCorrelVector/= xSizeOfCorrelVector*4;
+
+ byte const * const p= &actVid2MemBufp->b[0];
+
+ if(iState==2)
+ {
+ T2=uclock();
+ sprintf(textbuf,"%f X", (float)(T2-T1)/UCLOCKS_PER_SEC);
+ gprint(infoPosX, infoPosY+=10, c.col, textbuf);
+ T1=T2;
+ }
+
+ int aSumsOfEquivalentPoints[4][1000];
+ for(int i=0; i<4; i++)
+ for(int x=0; x<wndx; x++)
+ aSumsOfEquivalentPoints[i][x]= 0;
+
+ int aSumsOfSqrs[1000];
+ for(int x=0; x<wndx; x++)
+ aSumsOfSqrs[x]=0;
+
+ for(int line=0; line<wndy; line++)
+ for(int x=0; x<wndx; x++)
+ {
+ const int index= (line*vgax + x)*2;
+ const int a=
+ int(p[index + 1])
+ + mabs(int((char)(p[index + 2])))
+ + mabs(int((char)(p[index])));
+ aSumsOfEquivalentPoints[line & 3][x]+= a;
+ aSumsOfSqrs[x]+= a*a;
+ }
+
+ if(iState==2)
+ {
+ T2=uclock();
+ sprintf(textbuf,"%f EquivSum & SumSqr", (float)(T2-T1)/UCLOCKS_PER_SEC);
+ gprint(infoPosX, infoPosY+=10, c.col, textbuf);
+ T1=T2;
+ }
+
+ int bestQLine=-1;
+ float bestCoefficient=-1;
+ for(int qLine=0; qLine<wndx-xSizeOfCorrelVector+1; qLine++)
+ {
+ int sum=0;
+ for(int line=0; line<4; line++)
+ for(int x=qLine; x<qLine + xSizeOfCorrelVector; x++)
+ sum+= aSumsOfEquivalentPoints[line][x];
+
+ const double mean= double(sum) / (xSizeOfCorrelVector*wndy);
+
+ int sumOfSqrs=0;
+ for(int x=qLine; x<qLine + xSizeOfCorrelVector; x++)
+ sumOfSqrs+= aSumsOfSqrs[x];
+
+ float variance= (sumOfSqrs - sum*mean) / (xSizeOfCorrelVector*wndy);
+// printf("%f = %d - %d * %f / ...\n", variance, sumOfSqrs, sum, mean);
+ if(variance<0.0) variance=0;
+
+ float coefficient[4]={0,0,0,0};
+ for(int line=0; line<4; line++)
+ for(int x=qLine; x<qLine + xSizeOfCorrelVector; x++)
+ {
+ coefficient[0]+= (aSumsOfEquivalentPoints[line][x]-mean*wndy/4)
+ * correlVector[(line+0) &3][x-qLine];
+ coefficient[1]+= (aSumsOfEquivalentPoints[line][x]-mean*wndy/4)
+ * correlVector[(line+1) &3][x-qLine];
+ coefficient[2]+= (aSumsOfEquivalentPoints[line][x]-mean*wndy/4)
+ * correlVector[(line+2) &3][x-qLine];
+ coefficient[3]+= (aSumsOfEquivalentPoints[line][x]-mean*wndy/4)
+ * correlVector[(line+3) &3][x-qLine];
+ }
+
+ for(int i=0; i<4; i++)
+ {
+ coefficient[i]/= xSizeOfCorrelVector*wndy* sqrt(variance * varianceOfCorrelVector + 0.000001);
+
+ if(coefficient[i]>bestCoefficient)
+ {
+ bestCoefficient= coefficient[i];
+ bestQLine= qLine;
+ qPhase= (4-i) &3;
+// some= int(minmax(-10000, bestCoefficient*100, 10000));
+ }
+ }
+ }
+
+ if(iState==2)
+ {
+ T2=uclock();
+ sprintf(textbuf,"%f coeff", (float)(T2-T1)/UCLOCKS_PER_SEC);
+ gprint(infoPosX, infoPosY+=10, c.col, textbuf);
+ T1=T2;
+ }
+
+
+ if(bestCoefficient < QLINE_COEFFICIENT_THRESHOLD) return -1;
+
+
+ // try to find the Sync pulse
+
+ int score[1000];
+ for(int i=0; i<1000; i++)
+ score[i]=0;
+
+ for(int x= min(bestQLine+HSYNC_SEARCH_END, wndx-1); x >= bestQLine + HSYNC_SEARCH_START; x--)
+ {
+ for(int line=0; line<wndy; line++)
+ {
+ score[x] += p[(line*vgax + x)*2 + 1];
+ }
+
+ if( x+2 <= min(bestQLine+HSYNC_SEARCH_END, wndx-1)
+ && (score[x] - score[x+2])/wndy > HSYNC_THRESHOLD)
+ {
+ bestQLine= x - Q_2_HSYNC_DISTANCE;
+ if(bestQLine<0) bestQLine=0;
+ return bestQLine;
+ }
+ }
+
+ if(bestQLine + OVERBRIGHT_TEST_COLUMN >= wndx) return -1;
+ int sum=0;
+ for(int line=0; line<wndy; line++)
+ sum+= p[(line*vgax + bestQLine + OVERBRIGHT_TEST_COLUMN)*2 + 1];
+
+ if(sum/wndy > QLINE_OVERBRIGHT_THRESHOLD) return -1; // Sync Pulse not found and Pic to Bright
+
+ return bestQLine; //no Sync Pulse Found (Picture perhaps too dark)
+ //perhaps -1 better
+}
+
+int findVSync(int qLine)
+{
+ if(qLine==-1) return -1;
+ if(qLine<2 || qLine+1>=wndx) return -1;
+
+ byte const * const p= &actVid2MemBufp->b[0];
+
+ int aRunningMeanQ[600];
+ int aRunningMeanNotQ[600];
+
+ int qSum=0;
+ int notQSum=0;
+ int runningQSum=0;
+ int runningNotQSum=0;
+ int nRunningQSum=0;
+ int nRunningNotQSum=0;
+ for(int vSyncStart= -VSYNC_SIZE; vSyncStart<wndy; vSyncStart++)
+ {
+ const vSyncEnd= vSyncStart + VSYNC_SIZE;
+ int index= vSyncStart;
+ if(index<0) index= vSyncStart + wndy + VSYNC_SIZE;
+
+ if(vSyncStart>=0)
+ {
+ const int xP= (vSyncStart*vgax + qLine + VSYNC_SEARCH_COLUMN) * 2;
+ const int scoreStart= int(p[xP + 1])
+ + mabs(int((char)(p[xP + 2])))
+ + mabs(int((char)(p[xP])));
+
+ if((vSyncStart&3) == qPhase)
+ {
+ runningQSum-= scoreStart;
+ nRunningQSum--;
+ }
+ else
+ {
+ runningNotQSum-= scoreStart;
+ nRunningNotQSum--;
+ }
+ }
+ if(vSyncEnd<wndy)
+ {
+ const int xP= (vSyncEnd*vgax + qLine + VSYNC_SEARCH_COLUMN) * 2;
+ const int scoreEnd= int(p[xP + 1])
+ + mabs(int((char)(p[xP + 2])))
+ + mabs(int((char)(p[xP])));
+
+ if((vSyncEnd&3) == qPhase)
+ {
+ qSum+=scoreEnd;
+ runningQSum+= scoreEnd;
+ nRunningQSum++;
+ }
+ else
+ {
+ notQSum+= scoreEnd;
+ runningNotQSum+= scoreEnd;
+ nRunningNotQSum++;
+ }
+ }
+
+ if(nRunningQSum) aRunningMeanQ[index]= runningQSum / nRunningQSum;
+ if(nRunningNotQSum) aRunningMeanNotQ[index]= runningNotQSum / nRunningNotQSum;
+ }
+
+
+ const int qMean= qSum * 4 / (wndy*3);
+ const int notQMean= notQSum * 4 / wndy;
+
+ int bestScore= -1000000;
+ int bestVSync= -1;
+
+ for(int vSync= 0; vSync<wndy+VSYNC_SIZE; vSync++)
+ {
+ if(vSync < wndy && vSync > wndy-MIN_VSYNC_DISTANCE) continue;
+ if(vSync >= wndy && vSync-wndy < MIN_VSYNC_DISTANCE) continue;
+
+ int score= aRunningMeanNotQ[vSync] - aRunningMeanQ[vSync];
+
+// if(aRunningMeanNotQ[vSync] > VSYNC_OVERBRIGHT_THRESHOLD) score=-1000000;
+
+ if(score>bestScore)
+ {
+ bestScore= score;
+ bestVSync= vSync;
+ }
+ }
+ return bestVSync;
+}
+
+// Should be writen as an Object...
+//6015X 10960D 994498XX 3224315DD 1789858XD 55n
+static int hSyncDelaySumX= 6015;
+static int hSyncDelaySumD= 10960;
+static int hSyncDelaySumXX= 994498;
+static int hSyncDelaySumDD= 3224315;
+static int hSyncDelaySumDX= 1789858;
+static int hSyncDelays=55;
+static int lastHSyncDelay=0;
+static int lastQLine=0; //from last call to doHSyncDelay
+void doHSyncDelay(int hDistance, int qLine)
+{
+ double sigmaXD= double(hSyncDelaySumDX) * double(hSyncDelays)
+ - double(hSyncDelaySumX) * double(hSyncDelaySumD);
+ sigmaXD/= double(hSyncDelays) * double(hSyncDelays);
+
+ double sigmaX2= double(hSyncDelaySumXX) * double(hSyncDelays)
+ - double(hSyncDelaySumX) * double(hSyncDelaySumX);
+ sigmaX2/= double(hSyncDelays) * double(hSyncDelays);
+ if(sigmaX2 <= 0.0) sigmaX2 = 1e-50;
+
+ double diffFromMeanX= double(hDistance) - double(hSyncDelaySumX) / double(hSyncDelays);
+ double diffFromMeanD= diffFromMeanX * sigmaXD / sigmaX2;
+/* printf("%d %d\n", hDistance, qLine);
+ printf("%dX %dD %dXX %dDD %dXD %dn\n",
+ hSyncDelaySumX, hSyncDelaySumD,
+ hSyncDelaySumXX, hSyncDelaySumDD,
+ hSyncDelaySumDX, hSyncDelays);
+ printf("%fSXD %fSX2\n",sigmaXD, sigmaX2);
+ printf("%fdfmx %fdfmd\n", diffFromMeanX, diffFromMeanD);
+
+ printf("%f\n", diffFromMeanD + double(hSyncDelaySumD) / double(hSyncDelays) + 0.5);*/
+ int delay= int(diffFromMeanD + double(hSyncDelaySumD) / double(hSyncDelays) + 0.5);
+ if(delay<0) delay=0;
+
+// delay= random() % 511;
+// printf("%d Delay\n", delay);
+
+ lastHSyncDelay= delay;
+ lastQLine= qLine;
+
+ vPayTvShiftHack(delay);
+}
+
+static nStat=0;
+static int *statX= new int[10000];
+static int *statY= new int[10000];
+void analyzeHSyncDelay(int newQLine)
+{
+ int realHDistance= newQLine - lastQLine;
+ if(newQLine!=-1 && realHDistance>0)
+ {
+// statX[nStat]= realHDistance;
+// statY[nStat++]= lastHSyncDelay;
+
+ hSyncDelaySumX+= realHDistance;
+ hSyncDelaySumD+= lastHSyncDelay;
+ hSyncDelaySumXX+= realHDistance * realHDistance;
+ hSyncDelaySumDD+= lastHSyncDelay * lastHSyncDelay;
+ hSyncDelaySumDX+= lastHSyncDelay * realHDistance;
+ hSyncDelays++;
+
+ if( mabs(hSyncDelaySumDX) + mabs(hSyncDelaySumDD) + mabs(hSyncDelaySumXX) > 100000000
+ && hSyncDelays%2==0)
+ {
+ hSyncDelaySumX/=2;
+ hSyncDelaySumD/=2;
+ hSyncDelaySumXX/=2;
+ hSyncDelaySumDD/=2;
+ hSyncDelaySumDX/=2;
+ hSyncDelays/=2;
+ }
+ }
+
+ lastHSyncDelay=0;
+ printf("%dX %dD %dXX %dDD %dXD %dn\n",
+ hSyncDelaySumX,
+ hSyncDelaySumD,
+ hSyncDelaySumXX,
+ hSyncDelaySumDD,
+ hSyncDelaySumDX,
+ hSyncDelays);
+
+}
+
+// Should be writen as an Object...
+static int vSyncDelaySumY= 3;
+static int vSyncDelaySumD= 3;
+static int vSyncDelaySumYY= 10;
+static int vSyncDelaySumDD= 10;
+static int vSyncDelaySumDY= 10;
+static int vSyncDelays=2;
+static int lastVSyncDelay=0;
+static int lastVSync=0; //from last call to doVSyncDelay
+void doVSyncDelay(int vDistance, int vSync)
+{
+ double sigmaYD= double(vSyncDelaySumDY) * double(vSyncDelays)
+ - double(vSyncDelaySumY) * double(vSyncDelaySumD);
+ sigmaYD/= double(vSyncDelays) * double(vSyncDelays);
+
+ double sigmaY2= double(vSyncDelaySumYY) * double(vSyncDelays)
+ - double(vSyncDelaySumY) * double(vSyncDelaySumY);
+ sigmaY2/= double(vSyncDelays) * double(vSyncDelays);
+ if(sigmaY2 <= 0.0) sigmaY2 = 1e-50;
+
+ double diffFromMeanY= double(vDistance) - double(vSyncDelaySumY) / double(vSyncDelays);
+ double diffFromMeanD= diffFromMeanY * sigmaYD / sigmaY2;
+
+ int delay= int(diffFromMeanD + double(vSyncDelaySumD) / double(vSyncDelays) + 0.5);
+ if(delay<0) delay=0;
+
+ delay/=2;
+ if(delay>500) delay=500;
+ delay= random() % 151;
+ lastVSyncDelay= delay;
+ lastVSync= vSync;
+
+ vPayTvShiftHack(delay*10);
+}
+
+void analyzeVSyncDelay(int newVSync)
+{
+ int realVDistance= newVSync - lastVSync;
+ if(newVSync!=-1 && realVDistance>0)
+ {
+
+ statX[nStat]= lastVSyncDelay;
+ statY[nStat++]= realVDistance;
+
+ vSyncDelaySumY+= realVDistance;
+ vSyncDelaySumD+= lastVSyncDelay;
+ vSyncDelaySumYY+= realVDistance * realVDistance;
+ vSyncDelaySumDD+= lastVSyncDelay * lastVSyncDelay;
+ vSyncDelaySumDY+= lastVSyncDelay * realVDistance;
+ vSyncDelays++;
+
+ if( mabs(vSyncDelaySumDY) + mabs(vSyncDelaySumDD) + mabs(vSyncDelaySumYY) > 100000000
+ && vSyncDelays%2==0)
+ {
+ vSyncDelaySumY/=2;
+ vSyncDelaySumD/=2;
+ vSyncDelaySumYY/=2;
+ vSyncDelaySumDD/=2;
+ vSyncDelaySumDY/=2;
+ vSyncDelays/=2;
+ }
+ }
+
+ lastVSyncDelay=0;
+ printf("%dY %dD %dYY %dDD %dYD %dn\n",
+ vSyncDelaySumY,
+ vSyncDelaySumD,
+ vSyncDelaySumYY,
+ vSyncDelaySumDD,
+ vSyncDelaySumDY,
+ vSyncDelays);
+
+}
+/*
+void fixColor(int qLine)
+{
+ qLine&= ~1;
+ byte * const p= &actVid2MemBufp->b[0];
+
+ for(int line=qPhase; line<wndy-3; line+=4)
+ {
+ int u=char(p[(line*vgax + qLine-2)*2 ]);
+ int v=char(p[(line*vgax + qLine-2)*2 + 2]);
+ printf("%d %d %f\n", u, v, atan3(u,v)/PI*180);
+ for(int x=0; x<wndx-1; x+=2)
+ {
+ }
+
+ }
+}
+*/
+
+void fixBrightness(int qLine)
+{
+ byte * const p= &actVid2MemBufp->b[0];
+
+ for(int line=0; line<wndy; line++)
+ {
+
+ if(qLine + BRIGHTNESS_REF_POS>=wndx) break;
+
+ int brightnessRef=0;
+ int nBrightnessRef=0;
+ for(int refLine=max(line-2, 0); refLine<min(line+2, vgay); refLine++)
+ {
+ brightnessRef+= p[(refLine*vgax + qLine + BRIGHTNESS_REF_POS)*2 + 1];
+ nBrightnessRef++;
+ }
+ brightnessRef/= nBrightnessRef;
+
+ for(int x=0; x<min(qLine, wndx); x++)
+ {
+ p[(line*vgax + x)*2 + 1]=
+ minmax(0, p[(line*vgax + x)*2 + 1] - brightnessRef + BRIGHTNESS_DELTA, 255);
+ }
+ }
+}
+
+void showStat(void)
+{
+ byte * const p= &actVid2MemBufp->b[0];
+
+ for(int i=0; i<200; i+=2)
+ {
+ p[(100*vgax + i)*2 + 1]=128;
+ p[(i*vgax + 100)*2 + 1]=128;
+ }
+
+ for(int i=0; i<nStat; i++)
+ {
+ int x= statX[i] + 100;
+ int y= statY[i] + 100;
+ if(y<0 || x<0) continue;
+ if(y>=wndy || x>=wndx) continue;
+
+ int xP= (y*vgax + x)*2;
+ p[xP + 1]=255;
+ }
+}
+
+void vPayTvDecrypt(void)
+{
+ static int dropList[10]; //0 -> nothing, 1 -> Drop, 2 -> Drop & Return
+ for(int i=0; i<9; i++)
+ dropList[i]= dropList[i+1];
+ dropList[9]= 0;
+
+ static int lastQLineInLCC=0;
+ static bool isBrightHack=true;
+ vPayTvBrightHack(isBrightHack, lastQLineInLCC);
+ isBrightHack = !isBrightHack;
+ if(!isBrightHack) dropList[1]|=2;
+
+ if(dropList[0])
+ {
+ drop=true;
+ if(dropList[0]&2) return;
+ }
+
+ int qLine= findQLine();
+ int vSync= -1;//findVSync(qLine);
+
+ if(vSync!= -1)
+ {
+ lastQLineInLCC= (qLine-wndx-6)*1888 / wndx;
+ }
+
+ byte * p= &actVid2MemBufp->b[0];
+ for(int line=0; line<wndy; line++)
+ {
+ if((line&3) == qPhase)
+ {
+ p[2*qLine+1]=0;
+ p[2*qLine+3]=255;
+ }
+ p+= vgax<<1;
+ }
+
+ p= &actVid2MemBufp->b[0];
+ for(int x=0; x<wndx; x++)
+ {
+ if((x&3)==0)
+ {
+// p[(vSync*vgax + x)*2 + 1]=0;
+ // p[(vSync*vgax + x)*2 + 3]=255;
+ }
+ }
+
+
+ if(lastHSyncDelay!=0)
+ {
+ analyzeHSyncDelay(qLine);
+ }
+
+ if(lastVSyncDelay!=0)
+ {
+ analyzeVSyncDelay(vSync);
+ }
+
+ static bool isVSyncBad= false;
+ if(vSync!=-1 && (vSync<TOP_VSYNC_BOUNDRY || vSync>BOTTOM_VSYNC_BOUNDRY) && 0)
+ {
+ if(isVSyncBad)
+ {
+ doVSyncDelay(BOTTOM_VSYNC_BOUNDRY - vSync, vSync);
+ dropList[1]|=2;
+ isVSyncBad= false;
+ }
+ else
+ {
+ isVSyncBad= true;
+ }
+ }
+ else if(qLine!=-1 && qLine<LEFT_QLINE_BOUNDRY)
+ {
+ doHSyncDelay((RIGHT_QLINE_BOUNDRY + LEFT_QLINE_BOUNDRY)/2 - qLine, qLine);
+ dropList[1]|=2;
+ }
+ else if(qLine==-1 && 0)
+ {
+ doHSyncDelay(wndx/2, 1);
+ lastHSyncDelay=0;
+ dropList[1]|=2;
+ }
+ else if(isVCPhaseTrick)
+ {
+ isVCPhaseTrick= false;
+ vPayTvShiftHack(1000);
+ dropList[1]|=2;
+ }
+ else
+ {
+ isVSyncBad= false;
+ }
+
+ if(qLine==-1) dropList[1]|=2;
+
+
+ fixBrightness(qLine);
+
+// showStat();
+
+ int nPixMove= REAL_QLINE_POS - qLine;
+
+ if(nPixMove>wndx) nPixMove=0;
+ if(nPixMove<-wndx) nPixMove=0;
+
+
+ p= &actVid2MemBufp->b[0];
+ for(int line=1; line<wndy; line++)
+ {
+ if(nPixMove>0)
+ {
+ memmove(&p[nPixMove*2], &p[0], (wndx-nPixMove)*2);
+ }
+ else if(nPixMove<0)
+ {
+ memmove(&p[0], &p[-nPixMove*2], (wndx+nPixMove)*2);
+ }
+ if(nPixMove & 1)
+ for(int x=0; x<wndx-2; x++)
+ {
+ p[x*2]= p[x*2+2];
+ }
+ for(int x=0; x<wndx-2; x++)
+ {
+// p[x*2]=0;
+ }
+ p+= vgax<<1;
+ }
+
+
+ lastQLine= qLine;
+}
Added: trunk/2010/2_vpaytv.h
==============================================================================
--- (empty file)
+++ trunk/2010/2_vpaytv.h Wed Jul 4 10:58:24 2007
@@ -0,0 +1,7 @@
+//2010 0.1 Copyright (C) Michael Niedermayer 1999
+#ifndef n2_vpaytv_h
+#define n2_vpaytv_h
+
+void vPayTvDecrypt(void);
+
+#endif
Modified: trunk/2010/makefile
==============================================================================
--- trunk/2010/makefile (original)
+++ trunk/2010/makefile Wed Jul 4 10:58:24 2007
@@ -22,15 +22,15 @@ O = 2_glob_a.o 2_cryp_a.o 2_hw_a.o\
OC = 2_nag_a.o 2_vc_a.o 2_glob_a.o 2_cryp_a.o 2_hw_a.o\
2010.o 2_file.o 2_grafix.o 2_hw.o 2_gfunc.o \
- 2_hw_asm.o 2_71x6.o 2_hw_mem.o 2_crypt.o 2_vc.o 2_nag.o 2_txt.o
+ 2_hw_asm.o 2_71x6.o 2_hw_mem.o 2_crypt.o 2_vc.o 2_nag.o 2_txt.o 2_vpaytv.o
default: ;$(MAKE) 2010 CFLAGS="$(OPTS)"
crypt: ;$(MAKE) 2010C CFLAGS="$(OPTS) -DCRYPT"
-2010 : $(O) ; gcc $(CFLAGS) -o 2010 $(O)
-2010C : $(OC) ; gcc $(CFLAGS) -o 2010C $(OC)
+2010 : $(O) ; gcc $(CFLAGS) -o 2010 $(O) -ljpeg
+2010C : $(OC) ; gcc $(CFLAGS) -o 2010C $(OC) -ljpeg
clean: ; del $(O) 2010
2010.o : 2010.cpp 2_all.h 2010.h 2_file.h 2_hw.h 2_grafix.h\
@@ -42,11 +42,12 @@ clean: ; del $(O) 2010
2_71x6.h 2_mmx.h 2_hw_a.h
2_hw_mem.o : 2_hw_mem.cpp 2_all.h 2_hw_mem.h 2010.h
2_71x6.o : 2_71x6.cpp 2_all.h 2_71x6.h 2_hw.h 2_hw_mem.h 2010.h 2_hw_asm.h
-2_crypt.o : 2_crypt.cpp 2_all.h 2_crypt.h 2_71x6.h 2_vc.h 2_nag.h 2_txt.h
+2_crypt.o : 2_crypt.cpp 2_all.h 2_crypt.h 2_71x6.h 2_vc.h 2_nag.h 2_txt.h 2_vpaytv.h
2_vc.o : 2_vc.cpp 2_all.h 2_vc.h 2_crypt.h 2_gfunc.h 2_vc_a.h
2_nag.o : 2_nag.cpp 2_all.h 2_nag.h 2_crypt.h 2_gfunc.h 2_mmx.h 2_nag_a.h\
2010.h 2_hw_mem.h
2_txt.o : 2_txt.cpp 2_all.h 2_txt.h 2_crypt.h 2_gfunc.h 2010.h 2_71x6.h
+2_vpaytv.o : 2_vpaytv.cpp 2_all.h 2_crypt.h 2_vpaytv.h 2_mmx.h
2_hw_asm.o : 2_hw_asm.s
1
0
[mndiff]: r62 - in trunk/2010: 2010.cpp 2_all.h 2_cryp_a.asm 2_crypt.cpp 2_hw_a.asm 2_nag.cpp 2_vc.cpp 2_vc.h 2d makefile
by michael 04 Jul '07
by michael 04 Jul '07
04 Jul '07
Author: michael
Date: Wed Jul 4 10:47:18 2007
New Revision: 62
Log:
version from 1999-06-18 22:00
Modified:
trunk/2010/2010.cpp
trunk/2010/2_all.h
trunk/2010/2_cryp_a.asm
trunk/2010/2_crypt.cpp
trunk/2010/2_hw_a.asm
trunk/2010/2_nag.cpp
trunk/2010/2_vc.cpp
trunk/2010/2_vc.h
trunk/2010/2d
trunk/2010/makefile
Modified: trunk/2010/2010.cpp
==============================================================================
--- trunk/2010/2010.cpp (original)
+++ trunk/2010/2010.cpp Wed Jul 4 10:47:18 2007
@@ -240,9 +240,9 @@ int main(int argc, char **argv){
{
for(int y=0; y<=31; y++)
{
- int r= minmax(0, int( y + double(v) * 1.375 ), 31);
- int g= minmax(0, int((y - double(v) * 0.703 - double(u) * 0.343)*2), 63);
- int b= minmax(0, int( y + double(u) * 1.734 ), 31);
+ int r= minmax(0, int( y + double(v) * 1.375 +.5), 31);
+ int g= minmax(0, int((y - double(v) * 0.703 - double(u) * 0.343)*2+.5), 63);
+ int b= minmax(0, int( y + double(u) * 1.734 +.5), 31);
const int xLut= y + ((u&0x1F)<<5) + ((v&0x1F)<<10);
yuv2RgbLut[ xLut ]= b + (g<<5) + (r<<11);
Modified: trunk/2010/2_all.h
==============================================================================
--- trunk/2010/2_all.h (original)
+++ trunk/2010/2_all.h Wed Jul 4 10:47:18 2007
@@ -6,6 +6,7 @@
#define sign(a) ((a)<0 ? -1 : 1)
#define is_neg(a) ((a)<0 ? 0 : -1)
#define is_pos(a) ((a)<0 ? -1 : 0)
+#define round(a) ( (a)<0.0 ? (a)-.5 : (a)+.5 )
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
Modified: trunk/2010/2_cryp_a.asm
==============================================================================
--- trunk/2010/2_cryp_a.asm (original)
+++ trunk/2010/2_cryp_a.asm Wed Jul 4 10:47:18 2007
@@ -93,6 +93,7 @@ _Decomb2__Fiii:
xor ecx, byte -1
inc ecx
+; int3
movq mm6, [decombYMask]
movq mm7, [decombInc]
align16
Modified: trunk/2010/2_crypt.cpp
==============================================================================
--- trunk/2010/2_crypt.cpp (original)
+++ trunk/2010/2_crypt.cpp Wed Jul 4 10:47:18 2007
@@ -94,7 +94,7 @@ static void Decomb(int q){
for(int i=0; i<wndx; i++) temp[i]=0;
// SetDecombInc((some<<4) + (some<<20));
- SetDecombInc( 128 + (128<<16) );
+ SetDecombInc( 256 + (256<<16) );
if(q==1){
int linep= stride*256;
@@ -105,6 +105,8 @@ static void Decomb(int q){
}
}
+ SetDecombInc( 128 + (128<<16) );
+
int linep= 0;
if(o) linep+=vgax<<1;
for(int line=0; line<end; line++){
Modified: trunk/2010/2_hw_a.asm
==============================================================================
--- trunk/2010/2_hw_a.asm (original)
+++ trunk/2010/2_hw_a.asm Wed Jul 4 10:47:18 2007
@@ -40,8 +40,10 @@ _CopyYuv2Rgb1__Fiiii:
align16
CopyLoop1:
movq mm0, [esi+ecx] ;4p2 wMM0rESIECX 1 0 3
- movq mm1, [esi+ecx] ;4p2 wMM1rESIECX 10 1 4
- movq mm2, [esi+ecx] ;4p2 wMM2rESIECX 10 2 5
+; movq mm1, [esi+ecx] ;4p2 wMM1rESIECX 10 1 4 // Hotspot ?2%
+; movq mm2, [esi+ecx] ;4p2 wMM2rESIECX 10 2 5
+movq mm1, mm0
+movq mm2, mm0
psrlw mm0, 11 ;4p1 wMM0rMM0 0 1
;iFetch
Modified: trunk/2010/2_nag.cpp
==============================================================================
--- trunk/2010/2_nag.cpp (original)
+++ trunk/2010/2_nag.cpp Wed Jul 4 10:47:18 2007
@@ -310,7 +310,7 @@ void nag_decrypt(void){
}
- f=fopen("2010.dat", "rb");
+ f=fopen("nagra.dat", "rb");
if(f!=NULL){
int s=0;
int decoLines2;
@@ -533,7 +533,7 @@ void nag_decrypt(void){
*/
- f=fopen("2010.dat", "wb");
+ f=fopen("nagra.dat", "wb");
if(f==NULL) error(DatWrite);
fwrite(&decoLines, sizeof(int), 1, f);
Modified: trunk/2010/2_vc.cpp
==============================================================================
--- trunk/2010/2_vc.cpp (original)
+++ trunk/2010/2_vc.cpp Wed Jul 4 10:47:18 2007
@@ -15,41 +15,57 @@
#include "2010.h"
//#define DEBUG_CUTP
-
+#define SHOW_EDGE_AREA
//#define DEBUG
+#define SHOW_FINALS
+//#define NO_CACHE
#define FREQ_SMP 2.1e7
#define POINT_LAND 765.0
-#define NO_POINT_LAND1 150.0 // GUESSED and ok
-#define NO_POINT_LAND2 150.0 // GUESSED and ok
-#define PHASE_PATCH (-28) // GUESSED ? -9, ...
+#define NO_POINT_LAND1 (148) // GUESSED 148/153
+#define NO_POINT_LAND2 (152) // GUESSED 152/147
// ? POINT_LAND + NO_POINT_LAND(1|2) = 910 (FIFO SIZE)
- // ? NO_POINT_LAND + POINT_LAND = 1065 (PHASE ~+-60deg)
+ // ? NO_POINT_LAND + POINT_LAND = 1065, (1060)
+ // ? NO_POINT_LAND1 not 150 ?
+ // PHASE_SEG 268-306 Grad
#define NO_POINT_LAND (NO_POINT_LAND1 + NO_POINT_LAND2)
#define PHASE_POINT (fmod(FREQ_CHROM / (FREQ_SMP/3.0), 1.0) * PI * 2.0)
#define PHASE_SMP (fmod(FREQ_CHROM / (FREQ_SMP ), 1.0) * PI * 2.0)
+#define PHASE_LINE (fmod(FREQ_CHROM / FREQ_HS , 1.0) * PI * 2.0) // + some/180.0*PI)
#define PHASE_SEG (fmod(FREQ_CHROM / FREQ_SMP \
- * (POINT_LAND + NO_POINT_LAND), 1.0) * PI * 2.0)
+ * (POINT_LAND + NO_POINT_LAND), 1.0) * PI * 2.0)// + some/180.0*PI)
+
+#define MIN_LINES_FOR_EDGE_AREA 50
+#define EDGE_CHANGE_THRESHOLD 0.3
+#define PHASE_CORRECT_THRESHOLD (1.0/128*PI)
+#define MAX_PHASE_CORRECT ( 22.0/180.0*PI)
+#define MIN_PHASE_CORRECT (-22.0/180.0*PI)
+#define FIELDS_PER_PHASE_CHECK 30
+#define EDGE_AREA_TRUNC_DIV 6
+#define EDGE_AREA_START -4
+#define EDGE_AREA_END 4
+#define DEFINAL_WAIT 30
#define NOT_VC_THRESHOLD 20 // below 10 and above 90 bad
#define HEADER_EMPTY 0
#define HEADER_FINAL 15
-#define GOOD_CACHE_THRESHOLD 5
-#define FINAL_CACHE_THRESHOLD 4
+#define GOOD_CACHE_THRESHOLD 3
+#define FINAL_CACHE_DIFF_THRESHOLD 4
#define SCORE_THRESHOLD 3
#define MAX_EQ_SETS 14
#define nTEST_LINES 10
#define MAX_BAD_CACHES 30000
#define MAX_GOOD_CACHES 70000
+#define MAGIC_ID "VCC0"
#define STEP_START 16
#define STEP_END 2
#define DWN_SMP 1
#define MAX_DRIFT 2
#define DRIFT_TAB {1200, 400, 0, 400, 1200}
-#define PHASE_CMP_STEP 3
+#define PHASE_CMP_STEP 3
#define BAD_MEAN_THRESHOLD 17
#define BAD_THRESHOLD1 0.8
#define BAD_THRESHOLD2 200
@@ -81,6 +97,7 @@ extern bool drop;
static void loadVCCache(void);
+
static inline float atan3(const float f1, const float f2){
float out;
// ?! atan2 crashes
@@ -105,6 +122,7 @@ static int iCurrentLUTScore=0;
static int iCurrentUsed=0;
static CutPCache *pGoodCutPCache=NULL;
static CutPCache *pBadCutPCache=NULL;
+static int badFinalsLeft=0;
static void delFromCache(CutPCache *pOld){
@@ -148,37 +166,58 @@ static void addCutPsToCache(CutPCache *p
xIn++;
}
- bool bOldGood=true;
- bool bGood=true;
+ bool isOldFinal=true;
+ bool isFinal=true;
+ int bestCutP= piCutP[line];
+ int bestCutPs=1;
+ if(bestCutP==-1) bestCutPs=0;
+
+ int nextBestCutP=-1;
+ int nextBestCutPs=0;
if(nInBytes!=HEADER_FINAL)
{
- bOldGood=false;
- bGood=false;
- int nCurrentCutPs=1;
+ isOldFinal=false;
+ isFinal=false;
+ int currentCutP=-1;
+ int currentCutPs=0;
for(int i=0; i<nInBytes; i++)
{
- if(int(pCutPCache->pbCCutP[xIn+i]) == piCutP[line])
- {
- nCurrentCutPs++;
- if(nCurrentCutPs>=FINAL_CACHE_THRESHOLD)
- {
- bGood=true;
- }
- }
- }
+ if(int(pCutPCache->pbCCutP[xIn+i]) != currentCutP)
+ {
+ currentCutP= pCutPCache->pbCCutP[xIn+i];
+ currentCutPs=0;
+ if(currentCutP == piCutP[line]) currentCutPs++;
+ }
+ currentCutPs++;
+
+ if(currentCutPs >= bestCutPs)
+ {
+ if(bestCutP != currentCutP)
+ {
+ nextBestCutP= bestCutP;
+ nextBestCutPs= bestCutPs;
+ }
+ bestCutP= currentCutP;
+ bestCutPs= currentCutPs;
+ }
+ }
+
+ if(bestCutPs-nextBestCutPs >= FINAL_CACHE_DIFF_THRESHOLD) isFinal=true;
}
- int nOutBytes=nInBytes;
- if(!bGood && piCutP[line]!=-1) nOutBytes++;
+
+ int nOutBytes=nInBytes;
+ if(!isFinal && piCutP[line]!=-1) nOutBytes++;
int xKill=-1;
- if(!bGood && nOutBytes>MAX_EQ_SETS)
+ if(!isFinal && nOutBytes>MAX_EQ_SETS)
{
nOutBytes=MAX_EQ_SETS;
xKill=random() % MAX_EQ_SETS;
}
- if(bGood) nOutBytes=1;
+ if(isFinal) nOutBytes=1;
- int iOutHeader=nOutBytes;
- if(bGood) iOutHeader=HEADER_FINAL;
+ int iOutHeader;
+ if(isFinal) iOutHeader= HEADER_FINAL;
+ else iOutHeader= nOutBytes;
if(iLastOutHeader == iOutHeader && nOutHeaders<16)
nOutHeaders++;
@@ -194,20 +233,22 @@ static void addCutPsToCache(CutPCache *p
}
- if(bOldGood)
+ if(isOldFinal)
{
pbCScratchPad[xOut]= pCutPCache->pbCCutP[xIn];
xOut++;
}
- else if(bGood)
+ else if(isFinal)
{
- pbCScratchPad[xOut]= piCutP[line];
+ pbCScratchPad[xOut]= bestCutP;
xOut++;
}
else
{
- bool bOut=false;
+ bool bOut;
if(piCutP[line]==-1) bOut=true;
+ else bOut=false;
+
for(int i=0; i<nInBytes; i++)
{
if(i==xKill) continue;
@@ -247,15 +288,30 @@ static int *getBestCutPs(CutPCache *pCut
int x=0;
int nBytes=-1;
int nHeaders=0;
+ bool isFinal=false;
for(int line=0; line<wndy; line++)
{
if(nHeaders==0)
{
+ isFinal=false;
nHeaders= (pCutPCache->pbCCutP[x]>>4) + 1;
nBytes= pCutPCache->pbCCutP[x] & 15;
- if(nBytes==HEADER_FINAL) nBytes=1;
+ if(nBytes==HEADER_FINAL)
+ {
+ nBytes=1;
+ isFinal= true;
+ }
x++;
}
+
+#ifdef SHOW_FINALS
+ if(isFinal)
+ {
+ actVid2MemBufp->b[((line) * vgax<<1) +1]=255;
+ actVid2MemBufp->b[((line) * vgax<<1) +3]=0;
+ }
+#endif
+
// printf("x %d %d %d\n", nHeaders, nBytes, pCutPCache->nbCCutP);
@@ -292,6 +348,60 @@ static int *getBestCutPs(CutPCache *pCut
return piCutP;
}
+static void deFinalize(CutPCache *pCutPCache){
+ static byte *pbCScratchPad= new byte[ (MAX_EQ_SETS+1)*wndy+10 ];
+
+ badFinalsLeft--;
+
+ int xIn=0;
+ int xOut=0;
+ int nInBytes=-1;
+ int nInHeaders=0;
+ bool isFinal=false;
+ do
+ {
+ if(nInHeaders==0)
+ {
+ isFinal=false;
+ nInHeaders= (pCutPCache->pbCCutP[xIn]>>4) + 1;
+ nInBytes= pCutPCache->pbCCutP[xIn] & 15;
+ if(nInBytes==HEADER_FINAL)
+ {
+ nInBytes=1;
+ isFinal= true;
+ pbCScratchPad[xOut]= ((nInHeaders-1)<<4) | 2;
+ }
+ else
+ {
+ pbCScratchPad[xOut]= pCutPCache->pbCCutP[xIn];
+ }
+ xOut++;
+ xIn++;
+ }
+
+ for(int i=0; i<nInBytes; i++)
+ {
+ if(isFinal)
+ {
+ pbCScratchPad[xOut]= pCutPCache->pbCCutP[xIn];
+ xOut++;
+ }
+ pbCScratchPad[xOut]= pCutPCache->pbCCutP[xIn];
+ xOut++;
+ xIn++;
+ }
+
+ nInHeaders--;
+ }while(xIn < pCutPCache->nbCCutP);
+
+ delete [] pCutPCache->pbCCutP;
+ pCutPCache->pbCCutP= new byte[xOut];
+ pCutPCache->nbCCutP= xOut;
+ memcpy(pCutPCache->pbCCutP, pbCScratchPad, xOut);
+
+ pCutPCache->isDeFinal= 1;
+}
+
static int addToLut(CutPCache *pNewCutPCache){
int *piCutP= getBestCutPs(pNewCutPCache);
int nTimesAdded=0;
@@ -381,16 +491,16 @@ static CutPCache *findInLutX(int *piCutP
if(bInc)
{
- pCutPCache->iScore++;
- if(pCutPCache->iScore > iBestScore)
+ pCutPCache->score++;
+ if(pCutPCache->score > iBestScore)
{
- iBestScore=pCutPCache->iScore;
+ iBestScore=pCutPCache->score;
pBestCutPCache=pCutPCache;
}
}
else
{
- if( pCutPCache->iScore>=SCORE_THRESHOLD
+ if( pCutPCache->score>=SCORE_THRESHOLD
&& pCutPCache!=pMergeCutPCache && 0)
{
@@ -405,7 +515,7 @@ static CutPCache *findInLutX(int *piCutP
}
else
{
- pCutPCache->iScore=0;
+ pCutPCache->score=0;
}
}
pCutPLut= pNextCutPLut;
@@ -487,10 +597,18 @@ static void cache(int *piCurrentCutP){
int iBestScore;
- if(pBestCutPCache!=NULL) iBestScore=pBestCutPCache->iScore;
+ if(pBestCutPCache!=NULL) iBestScore=pBestCutPCache->score;
else iBestScore=0;
- mergeAndClean(piCurrentCutP, pBestCutPCache);
+ static int deFinalWait= DEFINAL_WAIT;
+ if(iBestScore>=SCORE_THRESHOLD && deFinalWait<=0 && pBestCutPCache->isDeFinal==0 )
+ {
+ deFinalWait+= DEFINAL_WAIT;
+ deFinalize(pBestCutPCache);
+ }
+ if(iBestScore>=SCORE_THRESHOLD) deFinalWait--;
+
+ mergeAndClean(piCurrentCutP, pBestCutPCache);
if(pBestCutPCache!=NULL && iBestScore>=SCORE_THRESHOLD)
{
@@ -513,7 +631,8 @@ static void cache(int *piCurrentCutP){
CutPCache *pNewCutPCache= new CutPCache;
pNewCutPCache->nUsed=0;
- pNewCutPCache->iScore=0;
+ pNewCutPCache->score=0;
+ pNewCutPCache->isDeFinal=1;
pNewCutPCache->pbCCutP=NULL;
addCutPsToCache(pNewCutPCache, piCurrentCutP);
@@ -532,9 +651,14 @@ static void cache(int *piCurrentCutP){
drop=true;
nFieldsUnCached++;
iCurrentLUTScore=iBestScore;
- iCurrentUsed=pBestCutPCache->nUsed;
+ iCurrentUsed=0;
- if(iBestScore<SCORE_THRESHOLD || some==0) return;
+#ifdef NO_CACHE
+ return;
+#endif
+ if(iBestScore<SCORE_THRESHOLD) return;
+
+ iCurrentUsed=pBestCutPCache->nUsed;
nFieldsUnCached--;
nFieldsCached++;
@@ -556,8 +680,11 @@ void saveVCCache(void){
static FILE *pFCache=fopen("vc_cache.dat", "wb");
if(pFCache==NULL) error(error_code(-91));
- fwrite(&nGoodCaches, sizeof(int), 1, pFCache);
- fwrite(&nBadCaches, sizeof(int), 1, pFCache);
+
+ char magicId[5]=MAGIC_ID;
+ fwrite(&magicId, 4*sizeof(char), 1, pFCache);
+ int reserved=0;
+ fwrite(&reserved, sizeof(int), 1, pFCache);
CutPCache *tpCutPCache= pGoodCutPCache->pPrev;
for(int i=0; i<nGoodCaches; i++)
@@ -587,12 +714,12 @@ static void loadVCCache(void){
bWasLoaded=true;
static FILE *pFCache=fopen("vc_cache.dat", "rb");
if(pFCache==NULL) return;
- int nEntGood, nEntBad;
- fread(&nEntGood, sizeof(int), 1, pFCache);
- fread(&nEntBad, sizeof(int), 1, pFCache);
+ int reserved;
+ fread(&reserved, sizeof(int), 1, pFCache);
+ fread(&reserved, sizeof(int), 1, pFCache);
CutPCache *tpCutPCache;
- for(int i=0; i<nEntGood+nEntBad; i++)
+ while( !feof(pFCache) )
{
tpCutPCache= new CutPCache;
@@ -605,7 +732,8 @@ static void loadVCCache(void){
fread(tpCutPCache->pbCCutP, sizeof(byte),
tpCutPCache->nbCCutP, pFCache);
- addToCache(tpCutPCache);
+ if(tpCutPCache->isDeFinal==0) badFinalsLeft++;
+ addToCache(tpCutPCache);
// printf("B\n");
addToLut(tpCutPCache);
// printf("A\n");
@@ -616,10 +744,22 @@ static void loadVCCache(void){
void vc_decrypt(void){
int cutPointX[max_y];
+ cutPointX[0]=
+ cutPointX[1]=0;
int addapBuff[max_x];
char textbuf[9][128];
long T1=0, T2;
color c;
+
+ static int edgePos=1;
+ static int edgeAlgo=0;
+/* static int *pEdgeArea=NULL;
+ if(pEdgeArea==NULL)
+ {
+ pEdgeArea= new int[ (EDGE_AREA_END - EDGE_AREA_START) ];
+ memset( pEdgeArea, 0, (EDGE_AREA_END - EDGE_AREA_START)*sizeof(int));
+ }
+*/
// const int lowResSize= mmx ? DWN_SMP : (DWN_SMP-1);
@@ -632,13 +772,13 @@ void vc_decrypt(void){
// showPoints=true;
- const double freqPix2= double(wndx) / double(x_field) * FREQ_PIX;
+ const double freqPix2= double(wndx) / double(x_field) * FREQ_PIX; //FIX CHECK (xfield...)
#ifdef DEBUG2
printf("xy%d %d\n", wndx, x_field);
#endif
// 18
// const int vcStartX=int(double(16 -scales_x+3)/x_field*wndx + .5) + some - 10;
- const int vcStartX=int(double(16 -scales_x+3)/x_field*wndx + .5);
+ const int vcStartX=int(double(16 -scales_x+3)/x_field*wndx + .5); //FIX CHECK
static FILE *pF= fopen("out.dat", "wb");
@@ -649,13 +789,13 @@ void vc_decrypt(void){
if(wndx != wndxBak){
for(int x=0; x<max_x; x++){
- const int cutP=int( double(x) / ( 3.0 * freqPix2) * FREQ_SMP
- - (NO_POINT_LAND1)/3.0 + .5);
+ const int cutP=int( round(
+ double(x) / ( 3.0 * freqPix2) * FREQ_SMP - (NO_POINT_LAND1)/3.0 ) );
x2CutP[x]= cutP;
}
for(int cutP=0; cutP<256; cutP++){
- const int x=int( double(cutP*3 + NO_POINT_LAND1)
- * freqPix2 / FREQ_SMP + .5);
+ const int x=int( round(
+ double(cutP*3 + NO_POINT_LAND1) * freqPix2 / FREQ_SMP ) );
cutP2X[cutP]= x;
}
wndxBak=wndx;
@@ -671,23 +811,22 @@ void vc_decrypt(void){
// const int minDist= cutP2X[0];
- cutPointX[0]=0;
-
char *lowRes[2];
lowRes[0]= (char*)newAlign(vcDiff, 8);
lowRes[1]= (char*)newAlign(vcDiff, 8);
- int *convVec= new int[vcDiff>>(PHASE_CMP_STEP-1)];
+ int *convVec= new int[ (vcDiff>>(PHASE_CMP_STEP-1)) + 1 ];
+ memset(convVec, 0, ( (vcDiff>>(PHASE_CMP_STEP-1)) + 1 )*sizeof(int) );
- long TCorr=0, TReSmp=0, TUVDetect=0, TPhaseDiff1=0,
- TPhaseDiff2_Drift=0, TEdgeDetect=0 ,TCache=0;
+ long TCorr=0, TReSmp=0, TUVDetect=0, TPhaseDiff1=0, TPhaseCorrect=0,
+ TPhaseDiff2_Drift=0, TEdgeDetect=0 ,TEdgeArea=0, TCache=0;
if(iState==2){
T1=uclock();
}
- static int edgeLut[512];
+ static int edgeLut[2048];
static int phaseLut[256];
static bool first= true;
@@ -701,26 +840,40 @@ void vc_decrypt(void){
static int fields=0;
fields++;
+ static bool findPhases=true;
+ static double phaseCorrect=0;
+ static double lastPhaseCorrect=0;
+ if(mabs(phaseCorrect-lastPhaseCorrect) > PHASE_CORRECT_THRESHOLD)
+ {
+ lastPhaseCorrect= phaseCorrect;
+ findPhases=true;
+ }
+
+ if(findPhases)
+ {
+ for(int cutP=0; cutP<256; cutP++)
+ {
+ const double phase= PHASE_SMP*NO_POINT_LAND1 - PHASE_LINE
+ + PHASE_POINT*cutP - phaseCorrect;
+ phasePerCutP[cutP]= (byte)( round( phase * 128 / PI) );
+ sin1PerCutP[cutP]= char( round( sin( -phase + PHASE_SEG )*127 ) );
+ cos1PerCutP[cutP]= char( round( cos( -phase + PHASE_SEG )*127 ) );
+ sin2PerCutP[cutP]= char( round( sin( -phase )*127 ) );
+ cos2PerCutP[cutP]= char( round( cos( -phase )*127 ) );
+ }
+ }
+
if(first){
- if(first) some=10;
+// if(first) some=10;
- for(int i=0; i<512; i++){
+ for(int i=0; i<2048; i++){
const int j= min(i+1, EDGE_LIMIT);
- edgeLut[i]=int( log(j)*EDGE_COEFF );
+ edgeLut[i]=int( log(j)*EDGE_COEFF +.5 );
}
for(int i=0; i<256; i++){
const int j= max(min(mabs(i-128), PHASE_LIMIT), 1);
- phaseLut[i]=int( pow(j, PHASE_EXP)*PHASE_COEFF );
- }
-
- for(int cutP=0; cutP<256; cutP++){
- const double phase= PHASE_SMP*(NO_POINT_LAND1 + PHASE_PATCH) + PHASE_POINT*cutP; // - some/360.0*2.0*PI;
- phasePerCutP[cutP]= (byte)( phase * 128 / PI );
- sin1PerCutP[cutP]= char(sin( -phase + PHASE_SEG )*127);
- cos1PerCutP[cutP]= char(cos( -phase + PHASE_SEG )*127);
- sin2PerCutP[cutP]= char(sin( -phase )*127);
- cos2PerCutP[cutP]= char(cos( -phase )*127);
+ phaseLut[i]=int( pow(j, PHASE_EXP)*PHASE_COEFF +.5);
}
first=false;
@@ -734,10 +887,11 @@ void vc_decrypt(void){
const float cosSegPhase2= cos(PHASE_SEG*2);
bool *black= new bool[wndy];
+ black[0]= true;
- byte * llinep=&actVid2MemBufp->b[ -(vgax<<2) ];
- byte * linep= &actVid2MemBufp->b[ -(vgax<<1) ];
- for(int line=0; line<wndy; line++){
+ byte * llinep=&actVid2MemBufp->b[ -(vgax<<1) ];
+ byte * linep= &actVid2MemBufp->b[ 0 ];
+ for(int line=1; line<wndy-1; line++){
llinep+=vgax<<1;
linep+=vgax<<1;
@@ -751,10 +905,10 @@ void vc_decrypt(void){
{
int iMean;
asm(//"int $3 \n\t"
-
"xorl %%ecx, %%ecx \n\t"
+ ".align 3 \n\t"
"1: \n\t"
- "movzbl 2(%%esi, %%edx, 4), %%eax \n\t"
+ "movzbl 0(%%esi, %%edx, 4), %%eax \n\t"
"movzbl 2(%%esi, %%edx, 4), %%ebx \n\t"
"addl %%eax, %%ebx \n\t"
"shrl $1, %%ebx \n\t"
@@ -770,7 +924,9 @@ void vc_decrypt(void){
: "%eax", "%ebx", "%edx", "%esi", "%edi");
if(double(iMean) / double(vcDiff>>1) < BAD_MEAN_THRESHOLD)
- black[line]=true;
+ {
+ black[ line ]=true;
+ }
}
else if(mmx){
asm(//"int $3 \n\t"
@@ -842,7 +998,7 @@ void vc_decrypt(void){
T1=T2;
}
- if(line==0) continue;
+ if(line<2) continue;
int bestDiff=0x1FFFFFFF;
int avgDiff=0; // for detecting bad lines
@@ -900,10 +1056,17 @@ void vc_decrypt(void){
}
asm("emms\n\t");
-
- if( int( avgDiff*BAD_THRESHOLD1/float(avgDiffNum) ) - BAD_THRESHOLD2
- < bestDiff )
- black[line]=true;
+/*
+ bestCutPX= bestCutPX+some-10;
+ if(bestCutPX<0) bestCutPX+=vcDiff;
+ if(bestCutPX>=vcDiff) bestCutPX-=vcDiff;
+ */
+ if( int( avgDiff*BAD_THRESHOLD1/float(avgDiffNum) ) - BAD_THRESHOLD2 < bestDiff
+ && !black[line-1] && !black[line])
+ {
+ black[line-1]=true;
+ black[line ]=true;
+ }
if(iState==2){
T2=uclock();
@@ -911,10 +1074,9 @@ void vc_decrypt(void){
T1=T2;
}
- if(line>2){
-
- int sumI=0;
- for(int x=-2; x<2; x+=2){
+// bestCutPX+=some-10;
+ int sumI=0;
+ for(int x=-2; x<2; x+=2){
const int nx= x + (vcDiff & ~1);
const int ul= char(linep[ (((vcStartX & ~1) + x)<<1) + 0]);
const int vl= char(linep[ (((vcStartX & ~1) + x)<<1) + 2]);
@@ -923,17 +1085,16 @@ void vc_decrypt(void){
sumI+= ul*vn - vl*un;
// linep[ (((vcStartX & ~1) - x)<<1) + 1]=255;
// linep[ (((vcStartX & ~1) - nx)<<1) + 1]=255;
- }
+ }
- if(line>10 && line<250){
- if(line & 1){
+ if(line>10 && line<250){
+ if(line & 1){
vScore+= sumI;
}else{
vScore-= sumI;
}
- }
-
}
+
bestCutPX+= cutPointX[line-1];
if(bestCutPX>=vcDiff) bestCutPX-=vcDiff;
@@ -951,7 +1112,7 @@ void vc_decrypt(void){
int iSumOfAbsDiff=0;
int iCount=1;
- for(int xLine=1; xLine<wndy; xLine++)
+ for(int xLine=2; xLine<wndy-1; xLine++)
{
if( black[xLine] || black[xLine-1]) continue;
@@ -972,53 +1133,53 @@ void vc_decrypt(void){
const int driftPenalty[MAX_DRIFT*2+1]= DRIFT_TAB;
+ byte *pPhaseErr= new byte[256*wndy];
+
llinep=&actVid2MemBufp->b[ -(vgax<<2) ];
linep= &actVid2MemBufp->b[ -(vgax<<1) ];
if(bVC){
- int *newVal=new int[256], *lastVal=new int[256];
+ int *newVal=new int[257], *lastVal=new int[257];
memset(lastVal, 0, 256<<2);
+ lastVal[256]=1; //for edge detect (faster at skiping zeros)
- byte *newPhaseErr=new byte[256], *lastPhaseErr=new byte[256];
- memset(lastPhaseErr, 0, 256);
+// byte *newPhaseErr=new byte[256], *lastPhaseErr=new byte[256];
+// memset(lastPhaseErr, 0, 256);
- for(int line=0; line<wndy; line++){
+ for(int line=0; line<wndy-1; line++){
llinep+=vgax<<1;
linep+=vgax<<1;
memset(newVal, 0, 256<<2);
- memset(newPhaseErr, 0, 256);
+ newVal[256]=1; //for edge detect (faster at skiping zeros)
+// memset(newPhaseErr, 0, 256);
+// memset(pPhaseErr+line*256, 0, 256);
bool noLeft=true;
bestDir[line]=-1;
- if(line==0) continue;
+ if(line<1) continue;
int relCutPX= cutPointX[line] - cutPointX[line-1];
if(relCutPX<0) relCutPX+=vcDiff;
int chromAmp=1;
- for(int x=0; x<vcDiff; x+= 1<<PHASE_CMP_STEP){
- int nx= x + (relCutPX & ~1);
- if(nx>=vcDiff) nx-= (vcDiff & ~1);
+ for(int x=8; x<vcDiff-8; x+= 1<<PHASE_CMP_STEP){
+ int nx= x + relCutPX;
+ if(nx>=vcDiff) nx-= vcDiff;
+ nx&= ~1; //Changed
const int ul= char(llinep[ (((vcStartX & ~1) + x)<<1) + 0]);
const int vl= char(llinep[ (((vcStartX & ~1) + x)<<1) + 2]);
- const int un= char( linep[ (((vcStartX & ~1) + nx)<<1) + 0]);
+ const int un= char( linep[ (((vcStartX & ~1) + nx)<<1) + 0]); //HOTSPOT 2.7%
const int vn= char( linep[ (((vcStartX & ~1) + nx)<<1) + 2]);
const int p= x>>(PHASE_CMP_STEP-1);
convVec[p ]= ul*un + vl*vn;
convVec[p+1]= ul*vn - vl*un;
-/*
- const float fsScale= sqrt(convVec[p ]*convVec[p ] +
- convVec[p+1]*convVec[p+1] );
- convVec[p ]= int(convVec[p ]/pow(fsScale + .001, .9));
- convVec[p+1]= int(convVec[p+1]/pow(fsScale + .001, .9));
-*/
chromAmp+= mabs(un) + mabs(vn);
}
- if(line<4) chromAmp=1;
+ if(line<2) chromAmp=1;
// linep[ ((vcStartX + 0)<<1) + 1]=255;
-// linep[ ((vcStartX + relCutPX)<<1) + 1]=200;
+ // linep[ ((vcStartX + relCutPX)<<1) + 1]=200;
if(iState==2){
T2=uclock();
@@ -1026,91 +1187,90 @@ void vc_decrypt(void){
T1=T2;
}
- int sumR0=0, sumI0=0;
- int sumR1=0, sumI1=0;
+ int rrR=0, rrI=0;
+ int rlR=0, rlI=0;
{
int x=0;
for(; x<vcDiff-relCutPX; x+= 1<<PHASE_CMP_STEP){
const int p= x>>(PHASE_CMP_STEP-1);
- sumR0+= convVec[p ];
- sumI0+= convVec[p+1];
+ rrR+= convVec[p ];
+ rrI+= convVec[p+1];
}
for(; x<vcDiff; x+= 1<<PHASE_CMP_STEP){
const int p= x>>(PHASE_CMP_STEP-1);
- sumR1+= convVec[p ];
- sumI1+= convVec[p+1];
+ rlR+= convVec[p ];
+ rlI+= convVec[p+1];
}
}
const float s= ( (line & 1) ^ ( vScore>0 ) ) ? -1 : 1;
- int sumR0C= int( sumR0*cosSegPhase + sumI0*sinSegPhase*s);
- int sumI0C= int(-sumR0*sinSegPhase*s + sumI0*cosSegPhase);
- int sumR1C= int( sumR1*cosSegPhase + sumI1*sinSegPhase*s);
- int sumI1C= int(-sumR1*sinSegPhase*s + sumI1*cosSegPhase);
-
-
- int ffR0=0 , ffI0=0;
- int ssR0=sumR0, ssI0=sumI0;
- int ffR1=0 , ffI1=0;
- int ssR1=sumR1, ssI1=sumI1;
+ int llR=0, llI=0;
+ int lrR=0, lrI=0;
+ int rlRC= int( round( rlR*cosSegPhase + rlI*sinSegPhase*s) );
+ int rlIC= int( round(-rlR*sinSegPhase*s + rlI*cosSegPhase ) );
+ int lrRC=0;
+ int lrIC=0;
int lastPhasePos=0;
byte ang=0;
- if(!black[line]){
+ if(!black[line] && !black[line-1]){
for(int lastCutP = 0; lastCutP < 256; lastCutP++){
- if(lastVal[lastCutP]==0) continue;
+ while(lastVal[lastCutP]==0) lastCutP++;
+ if(lastCutP>=256) break;
- const int newPhasePos= cutP2X[ lastCutP ] & ((-1) << PHASE_CMP_STEP);
+ const int newPhasePos=
+ min(
+ (cutP2X[ lastCutP ]+(1 << (PHASE_CMP_STEP-1)) )
+ & ((-1) << PHASE_CMP_STEP),
+ (vcDiff-1) & ((-1) << PHASE_CMP_STEP)
+ );
- if( newPhasePos >= lastPhasePos ){
+ if( newPhasePos >= lastPhasePos )
+ {
- for(; lastPhasePos <= newPhasePos; lastPhasePos += (1<<PHASE_CMP_STEP)){
+ for(; lastPhasePos <= newPhasePos; lastPhasePos += (1<<PHASE_CMP_STEP))
+ {
const bool isLast= lastPhasePos == newPhasePos;
- const int p= lastPhasePos>>(PHASE_CMP_STEP-1);
+ const int p= (lastPhasePos>>(PHASE_CMP_STEP-1)) ;
- if(lastPhasePos+relCutPX<vcDiff){
- ssR0-=convVec[p ];
- ssI0-=convVec[p+1];
-
- if(isLast){
- const int r= ssR0 + sumR1C
- + int( ffR0*cosSegPhase2
- + ffI0*sinSegPhase2*s);
- const int i= ssI0 + sumI1C
- + int( -ffR0*sinSegPhase2*s
- + ffI0*cosSegPhase2);
-
- ang= (byte)( atan3(i, r)/PI*128 );
- }
+ if( lastPhasePos+relCutPX >= vcDiff
+ && lastPhasePos+relCutPX < vcDiff+(1<<PHASE_CMP_STEP) )
+ {
+ rrR=rlR, rrI=rlI;
+ lrR=llR, lrI=llI;
+ llR=0 , llI=0;
+ rlR=0 , rlI=0;
+ lrRC= int( round( lrR*cosSegPhase + lrI*sinSegPhase*s) );
+ lrIC= int( round(-lrR*sinSegPhase*s + lrI*cosSegPhase ) );
+ rlRC=0;
+ rlIC=0;
+ }
- ffR0+=convVec[p ];
- ffI0+=convVec[p+1];
- }
- else{
- ssR1-=convVec[p ];
- ssI1-=convVec[p+1];
-
- if(isLast){
- const int r= ssR1 + sumR0C
- + int( ffR0*cosSegPhase2
- + ffI0*sinSegPhase2*s);
- const int i= ssI1 + sumI0C
- + int( -ffR0*sinSegPhase2*s
- + ffI0*cosSegPhase2);
+ rrR-=convVec[p ];
+ rrI-=convVec[p+1];
+
+ if(isLast)
+ {
- ang= (byte)( atan3(i, r)/PI*128 );
+ const float r= rrR + rlRC + lrRC
+ + llR*cosSegPhase2
+ + llI*sinSegPhase2*s;
+ const float i= rrI + rlIC + lrIC
+ - llR*sinSegPhase2*s
+ + llI*cosSegPhase2;
+
+ ang= (byte)round( atan3(i, r)/PI*128 );
}
- ffR1+=convVec[p ];
- ffI1+=convVec[p+1];
- }
-
+ llR+=convVec[p ];
+ llI+=convVec[p+1];
+ }
+
}
- }
int newXTemp= cutPointX[line] - cutPointX[line-1] + cutP2X[lastCutP];
if(newXTemp < 0 ) newXTemp+= vcDiff;
@@ -1124,10 +1284,11 @@ void vc_decrypt(void){
const int *piDrift=
&driftPenalty[newCutPStart - (x2CutP[ newXTemp ] - MAX_DRIFT)-1];
- const byte a= (line & 1) ^ ( vScore>0 ) ? -ang: ang;
+ byte a= (line & 1) ^ ( vScore>0 ) ? -ang: ang;
+ a+=256/2;
const int phase1= (a + phasePerCutP[ lastCutP ]) & 0xFF;
- const int lastPhaseErrLastCutP= lastPhaseErr[lastCutP] + 128;
+ const int lastPhaseErrLastCutP= pPhaseErr[(line-1)*256 + lastCutP] + 128;
// FIX (ASM_OPTIMIZE)
if(chromAmp>AMP_THRESHOLD){
for(int newCutP= newCutPStart; newCutP <= newCutPEnd; newCutP++){
@@ -1139,7 +1300,7 @@ void vc_decrypt(void){
if(newVal[newCutP] < val){
newVal[newCutP]= val;
dir[(line<<8) + newCutP]= lastCutP;
- newPhaseErr[newCutP]= phaseErr;
+ pPhaseErr[line*256 + newCutP]= phaseErr;
noLeft=false;
}
@@ -1148,13 +1309,13 @@ void vc_decrypt(void){
else{
linep[ ((vcStartX - 1)<<1) + 1]=255;
for(int newCutP= newCutPStart; newCutP <= newCutPEnd; newCutP++){
- const int phaseErr= (phase1 + phasePerCutP[ newCutP ]) & 0xFF;
+// const int phaseErr= (phase1 + phasePerCutP[ newCutP ]) & 0xFF;
const int val= lastVal[lastCutP] - *(++piDrift);
if(newVal[newCutP] < val){
newVal[newCutP]= val;
dir[(line<<8) + newCutP]= lastCutP;
- newPhaseErr[newCutP]= phaseErr;
+ pPhaseErr[line*256 + newCutP]= 0; //phaseErr;
noLeft=false;
}
@@ -1169,27 +1330,67 @@ void vc_decrypt(void){
T1=T2;
}
- if(!black[line]){
+ if(!black[line])
+ {
int iBestVal=0;
- for(int newCutP = 0; newCutP < 256; newCutP++){
- if(!noLeft && newVal[newCutP]==0) continue;
- const byte * const p=
- &linep[ ((cutP2X[ newCutP ] + vcStartX)<<1) + 1 - 4];
+ if(edgeAlgo==0)
+ {
+ for(int newCutP = 0; newCutP < 256; newCutP++)
+ {
+ if(!noLeft)
+ {
+ while(newVal[newCutP]==0) newCutP++;
+ }
+ if(newCutP>=256) break;
- const int diff=edgeLut[ mabs( + int(* p ) + int(*(p+2))
- - int(*(p+4)) - int(*(p+6)) ) ];
+
+ const byte * const p=
+ &linep[ ((cutP2X[ newCutP ] + vcStartX + edgePos)<<1) + 1]; // (-0) - (-4)
+
+ const int diff=edgeLut[ mabs( + int(* p ) + int(*(p+2))
+ - int(*(p+4)) - int(*(p+6)) ) ];
- if(newVal[newCutP]==0) newVal[newCutP] = diff + 1000000000;
- else newVal[newCutP] += diff;
+ if(newVal[newCutP]==0) newVal[newCutP] = diff + 1000000000;
+ else newVal[newCutP] += diff;
+
+ if(iBestVal < newVal[newCutP])
+ {
+ iBestVal= newVal[newCutP];
+ bestDir[line]= newCutP;
+ }
+
+ }
+ }
+ else
+ {
+ for(int newCutP = 0; newCutP < 256; newCutP++)
+ {
+ if(!noLeft)
+ {
+ while(newVal[newCutP]==0) newCutP++;
+ }
+ if(newCutP>=256) break;
- if(iBestVal < newVal[newCutP]){
- iBestVal= newVal[newCutP];
- bestDir[line]= newCutP;
- }
+
+ const byte * const p=
+ &linep[ ((cutP2X[ newCutP ] + vcStartX + edgePos)<<1) + 1];
- }
- }
+ const int diff=edgeLut[ mabs( + int(* p ) + int(*(p+2))
+ - int(*(p+6)) - int(*(p+8)) ) ]; //no converting factor!
+
+ if(newVal[newCutP]==0) newVal[newCutP] = diff + 1000000000;
+ else newVal[newCutP] += diff;
+
+ if(iBestVal < newVal[newCutP])
+ {
+ iBestVal= newVal[newCutP];
+ bestDir[line]= newCutP;
+ }
+
+ }
+ }
+ }
if(iState==2){
T2=uclock();
@@ -1201,22 +1402,19 @@ void vc_decrypt(void){
lastVal=newVal;
newVal=tempVal;
- byte *tempErr=lastPhaseErr;
- lastPhaseErr=newPhaseErr;
- newPhaseErr=tempErr;
}
delete [] newVal;
delete [] lastVal;
-
- delete [] newPhaseErr;
- delete [] lastPhaseErr;
}
delete [] convVec;
int piBestCutP[600];
+ piBestCutP[0 ]=
+ piBestCutP[wndy-1]=-1;
+
int iBestCutP=-1;
for(int line=wndy-2; line>0; line--)
{
@@ -1248,14 +1446,166 @@ void vc_decrypt(void){
#endif
if(bVC) cache(piBestCutP);
+
if(iState==2)
{
T2=uclock();
TCache+=T2-T1-uclockWaste;
T1=T2;
- }
+ }
+
+ int phaseErrSum=0;
+ for(int line=10; line<wndy-10; line++)
+ {
+ if(black[line] || black[line-1]) continue;
+ int phaseErr= pPhaseErr[ line*256 + piBestCutP[line] ];
+ if(phaseErr>128) phaseErr-=256;
+ phaseErrSum+= phaseErr;
+ }
+
+ if(bVC) phaseCorrect-= double(phaseErrSum) / FIELDS_PER_PHASE_CHECK / wndy / 2 /128.0*PI;
+
+ if(phaseCorrect>MAX_PHASE_CORRECT) phaseCorrect= MAX_PHASE_CORRECT;
+ if(phaseCorrect<MIN_PHASE_CORRECT) phaseCorrect= MIN_PHASE_CORRECT;
+
+
+ delete [] pPhaseErr;
+
+ if(iState==2)
+ {
+ T2=uclock();
+ TPhaseCorrect+=T2-T1-uclockWaste;
+ T1=T2;
+ }
+
+
+ int ppEdgeAreaScore[2][ (EDGE_AREA_END - EDGE_AREA_START) ];
+ memset( ppEdgeAreaScore[0], 0, (EDGE_AREA_END - EDGE_AREA_START)*sizeof(int));
+ memset( ppEdgeAreaScore[1], 0, (EDGE_AREA_END - EDGE_AREA_START)*sizeof(int));
+ for(int line=10; line<wndy-10; line+=3)
+ {
+ if(!black[line] && piBestCutP[line]!=-1)
+ {
+ for(int x = EDGE_AREA_START; x<EDGE_AREA_END; x++)
+ {
+ const byte * const p=
+ &actVid2MemBufp->b
+ [
+ +(line * (vgax<<1))
+ +((cutP2X[ piBestCutP[line] ] + vcStartX + x)<<1) + 1
+ ];
+
+ int pDiff[2];
+ pDiff[0]= edgeLut[ mabs( + int(* p ) + int(*(p+2))
+ - int(*(p+4)) - int(*(p+6)) ) ];
+ pDiff[1]= edgeLut[ mabs( + int(* p ) + int(*(p+2))
+ - int(*(p+6)) - int(*(p+8)) )*7/8 ];
+
+ ppEdgeAreaScore[0][x-EDGE_AREA_START]+= pDiff[0];
+ ppEdgeAreaScore[1][x-EDGE_AREA_START]+= pDiff[1];
+ }
+ }
+ }
+
+ int pBestEdgeScore[2]={0,0};
+ int pBestEdgePos[2]={0,0};
+ for(int a=0; a<2; a++)
+ {
+ for(int x = EDGE_AREA_START; x<EDGE_AREA_END; x++)
+ {
+ if(ppEdgeAreaScore[a][x-EDGE_AREA_START] > pBestEdgeScore[a])
+ {
+ pBestEdgeScore[a]= ppEdgeAreaScore[a][x-EDGE_AREA_START];
+ pBestEdgePos[a]= x-EDGE_AREA_START;
+ }
+ }
+ }
+
+ double bestFit=0;
+ int bestEdgeAlgo=0;
+ int bestEdgePos=0;
+ for(int a=0; a<2; a++)
+ {
+ int larger= max(
+ ppEdgeAreaScore[a][ (pBestEdgePos[a]-1<0) ? (pBestEdgePos[a]+1) : (pBestEdgePos[a]-1) ],
+ ppEdgeAreaScore[a][ (pBestEdgePos[a]+1>=(EDGE_AREA_END - EDGE_AREA_START)) ?
+ (pBestEdgePos[a]-1) : (pBestEdgePos[a]+1) ]
+ );
+
+ double fit= double(pBestEdgeScore[a]) / double(larger+.0001);
+ if(fit>bestFit)
+ {
+ bestFit=fit;
+ bestEdgeAlgo=a;
+ bestEdgePos= pBestEdgePos[a] + EDGE_AREA_START;
+ }
+ }
+ int linesOkEdge=0;
+ int lines=0;
+ for(int line=10; line<wndy-10; line+=3)
+ {
+ if(!black[line] && piBestCutP[line]!=-1)
+ {
+ int goodPos= 0;
+ int goodScore= 0;
+ lines++;
+
+ for(int x = EDGE_AREA_START; x<EDGE_AREA_END; x++)
+ {
+ const byte * const p=
+ &actVid2MemBufp->b
+ [
+ +(line * (vgax<<1))
+ +((cutP2X[ piBestCutP[line] ] + vcStartX + x)<<1) + 1
+ ];
+
+ int pDiff[2];
+ pDiff[0]= edgeLut[ mabs( + int(* p ) + int(*(p+2))
+ - int(*(p+4)) - int(*(p+6)) ) ];
+ pDiff[1]= edgeLut[ mabs( + int(* p ) + int(*(p+2))
+ - int(*(p+6)) - int(*(p+8)) )*7/8 ];
+
+ if(pDiff[bestEdgeAlgo] > goodScore)
+ {
+ goodScore= pDiff[bestEdgeAlgo];
+ goodPos= x;
+ }
+ }
+ if(goodPos == bestEdgePos)
+ linesOkEdge++;
+ }
+ }
+
+if(lines>MIN_LINES_FOR_EDGE_AREA && lines*EDGE_CHANGE_THRESHOLD<linesOkEdge)
+ {
+ edgePos= bestEdgePos;
+ edgeAlgo= bestEdgeAlgo;
+ }
+
+
+#ifdef SHOW_EDGE_AREA
+ for(int line=10; line<wndy-10; line+=3)
+ {
+ actVid2MemBufp->b
+ [
+ +(line * (vgax<<1))
+ +((cutP2X[ piBestCutP[line] ] + vcStartX + edgePos)<<1) + 1
+ ]= 255;
+ actVid2MemBufp->b
+ [
+ +(line * (vgax<<1))
+ +((cutP2X[ piBestCutP[line] ] + vcStartX + edgePos)<<1) + 7
+ ]= 255;
+ }
+#endif
+ if(iState==2)
+ {
+ T2=uclock();
+ TEdgeArea+=T2-T1-uclockWaste;
+ T1=T2;
+ }
if(showPoints)
{
@@ -1313,14 +1663,19 @@ void vc_decrypt(void){
const char u= * p;
const char v= *(p+2);
- const char u1=(char)(( - v*c1 - u*s1)>>7);
- const char v1=(char)(( + v*s1 - u*c1)>>7);
+// const char u1=(char)(( + v*c1 + u*s1)>>7);
+// const char v1=(char)(( - v*s1 + u*c1)>>7);
+
+ const char u1=(char)(( + u*c1 - v*s1)>>7);
+ const char v1=(char)(( - u*s1 - v*c1)>>7);
+
if( (vcDiff - cutX) & 1 ){
* p = v1;
*(p+2)= u1;
*(p+4)= v1;
*(p+6)= u1;
+
}
else{
* p = u1;
@@ -1335,8 +1690,12 @@ void vc_decrypt(void){
const char u= * p;
const char v= *(p+2);
- const char u1=(char)(( - v*c2 - u*s2)>>7);
- const char v1=(char)(( + v*s2 - u*c2)>>7);
+// const char u1=(char)(( + v*c2 + u*s2)>>7);
+// const char v1=(char)(( - v*s2 + u*c2)>>7);
+
+ const char u1=(char)(( + u*c2 - v*s2)>>7);
+ const char v1=(char)(( - u*s2 - v*c2)>>7);
+
if( cutX & 1 ){
* p = v1;
@@ -1417,7 +1776,9 @@ void vc_decrypt(void){
sprintf(textbuf[4],"%f FindPhaseDiff2 / Drift", (float)(TPhaseDiff2_Drift)/UCLOCKS_PER_SEC);
sprintf(textbuf[5],"%f EdgeDetect", (float)(TEdgeDetect)/UCLOCKS_PER_SEC);
sprintf(textbuf[6],"%f Cache", (float)(TCache)/UCLOCKS_PER_SEC);
- sprintf(textbuf[7],"%f Rotate / ColorFix", (float)(T2-T1-uclockWaste)/UCLOCKS_PER_SEC);
+ sprintf(textbuf[7],"%f FindPhaseCorrect", (float)(TPhaseCorrect)/UCLOCKS_PER_SEC);
+ sprintf(textbuf[7],"%f EdgeArea", (float)(TEdgeArea)/UCLOCKS_PER_SEC);
+ sprintf(textbuf[8],"%f Rotate / ColorFix", (float)(T2-T1-uclockWaste)/UCLOCKS_PER_SEC);
c.init(255, 0, 0, false);
gprint(infoPosX, infoPosY+=10, c.col, textbuf[0]);
gprint(infoPosX, infoPosY+=10, c.col, textbuf[1]);
@@ -1427,6 +1788,7 @@ void vc_decrypt(void){
gprint(infoPosX, infoPosY+=10, c.col, textbuf[5]);
gprint(infoPosX, infoPosY+=10, c.col, textbuf[6]);
gprint(infoPosX, infoPosY+=10, c.col, textbuf[7]);
+ gprint(infoPosX, infoPosY+=10, c.col, textbuf[8]);
infoPosY+=5;
T1=T2;
}
@@ -1467,6 +1829,14 @@ void vc_decrypt(void){
gprint(infoPosX, infoPosY+=10, c.col, textbuf[1]);
+
+ sprintf(textbuf[1],"Bad Final Left %d", badFinalsLeft);
+ gprint(infoPosX, infoPosY+=10, c.col, textbuf[1]);
+
+
+ sprintf(textbuf[1],"phaseCorrect %3.1f", phaseCorrect/PI*180);
+ gprint(infoPosX, infoPosY+=10, c.col, textbuf[1]);
+
}
delete [] bestDir;
Modified: trunk/2010/2_vc.h
==============================================================================
--- trunk/2010/2_vc.h (original)
+++ trunk/2010/2_vc.h Wed Jul 4 10:47:18 2007
@@ -9,7 +9,10 @@ struct CutPCache{
byte *pbCCutP;
CutPCache *pNext;
CutPCache *pPrev;
- int iScore;
+ byte score;
+ byte isDeFinal;
+ byte reserved1;
+ byte reserved2;
int nUsed;
int nbCCutP;
};
Modified: trunk/2010/2d
==============================================================================
--- trunk/2010/2d (original)
+++ trunk/2010/2d Wed Jul 4 10:47:18 2007
@@ -1,10 +1,31 @@
-load ?
-vsmooth
-vc color
-vc rightdrift ?
+txt restart!?
+rgb565 / 1555 stuff not realy correct but works
+add rgb1555 support
+add better support for hi-res (800x600) or so
+
+decomb 2 pass in nagra ?
+
+double buffer code sucks (field droping is wrong)
+
+vtune detected hotspot at decomb(1,2)+4 and CopyLoop1+4 ?
vc (black like)
vc exact start/end lines (last one not in 300x400)
-vc use amp to reject phase
-crypt decomb (math proofs and fixPoint Arith)
-double2float
+vc use amp to reject phase (?)
+vc integral phase test
+vc use MulTab in color deco
+vc !oneField
+vc optimize 2algo
+
+vc color deco mmx
+
+nag last line ?
+
+yuv2rgb mmx
+
+NAG_LINES ?
+
+teletext:
+ BETTER decode
+ SAVE
+ fix fractional digits
Modified: trunk/2010/makefile
==============================================================================
--- trunk/2010/makefile (original)
+++ trunk/2010/makefile Wed Jul 4 10:47:18 2007
@@ -1,7 +1,8 @@
.SUFFIXES: .c .cc .cpp .h .o .asm .S .s
OPTS = -g
-OPTS = -O5 -mpentiumpro -fomit-frame-pointer -g -Wall -Wstrict-prototypes -malign-double -ffast-math -funroll-loops -fno-default-inline
+OPTS = -O5 -mpentiumpro -fomit-frame-pointer -g -Wall -Wstrict-prototypes -malign-double -ffast-math -funroll-all-loops -fno-default-inline
+OPTS = -O5 -mpentiumpro -fomit-frame-pointer -g -Wall -Wstrict-prototypes -malign-double -ffast-math -funroll-all-loops -fno-default-inline
AFLAGS = -f coff
.c.o: ; gcc $(CFLAGS) -c $<
1
0
[mndiff]: r61 - in trunk/2010: 2010.cpp 2_crypt.cpp 2_file.cpp 2_nag.cpp 2_vc.cpp
by michael 04 Jul '07
by michael 04 Jul '07
04 Jul '07
Author: michael
Date: Wed Jul 4 10:44:08 2007
New Revision: 61
Log:
version from 1999
Modified:
trunk/2010/2010.cpp
trunk/2010/2_crypt.cpp
trunk/2010/2_file.cpp
trunk/2010/2_nag.cpp
trunk/2010/2_vc.cpp
Modified: trunk/2010/2010.cpp
==============================================================================
--- trunk/2010/2010.cpp (original)
+++ trunk/2010/2010.cpp Wed Jul 4 10:44:08 2007
@@ -23,6 +23,7 @@
#include "2_crypt.h"
#include "2_71x6.h"
#include "2_nag.h"
+#include "2_vc.h"
extern volatile bool oneField;
extern int iVSmooth;
@@ -38,7 +39,7 @@
extern int showCont;
extern CRYPTSTD cryptStd;
extern TVSTD TVStd;
- extern bool iState;
+ extern int iState;
extern bool helpState;
extern bool allowDrop;
extern int reqPage, reqSubPage, reqChanNum;
@@ -132,6 +133,7 @@ int error(error_code e){
" -? / -h (This stuff)\n");
break;
default : printg_t("\nUnknown error!");
+ printf("error %d\n", int(e));
break;
}
@@ -140,6 +142,7 @@ int error(error_code e){
void exitt(void){
close_hw();
+ saveVCCache();
}
int main(int argc, char **argv){
@@ -335,7 +338,7 @@ int main(int argc, char **argv){
if(grabf==1 && TVStd!=TXTPAL) GrabBmp(), grabf=0;
- for(int k=0; k<delay*1000000; k++);
+ for(int k=0; k<delay*10000000; k++);
copy_vidbuffer();
@@ -418,7 +421,7 @@ int main(int argc, char **argv){
case 's' : menuLevel=mLTVStd, helpState=false;
break;
case 'i' :
- case 'I' : iState= !iState;
+ case 'I' : iState++; iState%=ISTATES;
break;
case 'v' :
case 'V' : iVSmooth++; iVSmooth%=3;
@@ -536,6 +539,6 @@ int main(int argc, char **argv){
}
}
}
-
+
exit(0);
}
Modified: trunk/2010/2_crypt.cpp
==============================================================================
--- trunk/2010/2_crypt.cpp (original)
+++ trunk/2010/2_crypt.cpp Wed Jul 4 10:44:08 2007
@@ -93,6 +93,9 @@ static void Decomb(int q){
// for(int i=0; i<wndx; i++) temp[i]=128<<8;
for(int i=0; i<wndx; i++) temp[i]=0;
+// SetDecombInc((some<<4) + (some<<20));
+ SetDecombInc( 128 + (128<<16) );
+
if(q==1){
int linep= stride*256;
if(o) linep+=vgax<<1;
Modified: trunk/2010/2_file.cpp
==============================================================================
--- trunk/2010/2_file.cpp (original)
+++ trunk/2010/2_file.cpp Wed Jul 4 10:44:08 2007
@@ -7,7 +7,7 @@
#include "2_file.h"
#include "2_hw.h"
- extern int vgax, vgay, wndx, wndy;
+ extern int vgax, vgay, wndx, wndy, outy;
extern int fysize;
extern byte font[4096];
extern VID2MEMBUF *actVid2MemBufp;
@@ -73,11 +73,10 @@ void GrabBmp(void){
const int v = char(actVid2MemBufp->b[ ((j + i*vgax)<<1) + 2 ]);
const int y2= actVid2MemBufp->b[ ((j + i*vgax)<<1) + 3 ];
color c[2];
- c[0].init(y1, u, v, 1);
- c[1].init(y2, u, v, 1);
+ c[0].init(y1, u, v, 0);
+ c[1].init(y2, u, v, 0);
byte bgr2[6]={ c[0].col.b, c[0].col.g, c[0].col.r,
c[1].col.b, c[1].col.g, c[1].col.r };
-
fwrite(bgr2, 1, 6, fg);
}
}
@@ -92,12 +91,15 @@ void GrabRaw(void){
char grab_name[16];
struct time ti;
+ static int iCounter= ti.ti_hour;
+
gettime(&ti);
- sprintf(grab_name, "G%02d%02d%02d.RAW", ti.ti_hour, ti.ti_min, ti.ti_sec);
+ sprintf(grab_name, "G%02d%02d%02d.RAW", iCounter%100, ti.ti_min, ti.ti_sec);
+ iCounter++;
if((fg=fopen(grab_name, "ab"))==NULL && g_mode==0) error(FileWrite);
- fwrite(actVid2MemBufp->b, 1, vgax*wndy*2, fg);
+ fwrite(actVid2MemBufp->b, 1, vgax*outy*2, fg);
fclose(fg);
}
@@ -128,7 +130,7 @@ void ShowRaw(void){
i++;
i%=nRawDats;
- memcpy(actVid2MemBufp->b, ppbRawDat[i], vgax*vgay*2);
+ memcpy(actVid2MemBufp->b, ppbRawDat[i], vgax*outy*2);
}
long fsize(FILE *f){
Modified: trunk/2010/2_nag.cpp
==============================================================================
--- trunk/2010/2_nag.cpp (original)
+++ trunk/2010/2_nag.cpp Wed Jul 4 10:44:08 2007
@@ -1,4 +1,4 @@
-//2010 0.1 Copyright (C) Michael Niedermayer 1998
+//2010 0.1 Copyright (C) Michael Niedermayer 1999
//FIX search multiply (use deltas)
Modified: trunk/2010/2_vc.cpp
==============================================================================
--- trunk/2010/2_vc.cpp (original)
+++ trunk/2010/2_vc.cpp Wed Jul 4 10:44:08 2007
@@ -1,9 +1,10 @@
-//2010 0.1 Copyright (C) Michael Niedermayer 1998
+//2010 0.1 Copyright (C) Michael Niedermayer 1999
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <math.h>
+#include <stdlib.h>
#include "2_all.h"
#include "2_crypt.h"
#include "2_vc.h"
@@ -12,7 +13,11 @@
#include "2_vc_a.h"
#include "2_hw_mem.h"
#include "2010.h"
-
+
+//#define DEBUG_CUTP
+
+//#define DEBUG
+
#define FREQ_SMP 2.1e7
#define POINT_LAND 765.0
#define NO_POINT_LAND1 150.0 // GUESSED and ok
@@ -28,12 +33,24 @@
* (POINT_LAND + NO_POINT_LAND), 1.0) * PI * 2.0)
+#define NOT_VC_THRESHOLD 20 // below 10 and above 90 bad
+#define HEADER_EMPTY 0
+#define HEADER_FINAL 15
+#define GOOD_CACHE_THRESHOLD 5
+#define FINAL_CACHE_THRESHOLD 4
+#define SCORE_THRESHOLD 3
+#define MAX_EQ_SETS 14
+#define nTEST_LINES 10
+#define MAX_BAD_CACHES 30000
+#define MAX_GOOD_CACHES 70000
+
#define STEP_START 16
#define STEP_END 2
#define DWN_SMP 1
#define MAX_DRIFT 2
#define DRIFT_TAB {1200, 400, 0, 400, 1200}
#define PHASE_CMP_STEP 3
+#define BAD_MEAN_THRESHOLD 17
#define BAD_THRESHOLD1 0.8
#define BAD_THRESHOLD2 200
#define EDGE_LIMIT 70
@@ -53,14 +70,16 @@ extern VID2MEMBUF *actVid2MemBufp;
extern volatile int scales_x, scalee_x;
extern volatile int scales_y, scalee_y;
extern bool showPoints;
-extern bool iState;
+extern int iState;
extern int yuvMode;
extern int some;
extern bool mmx;
extern int infoPosX;
extern int infoPosY;
extern long uclockWaste;
+extern bool drop;
+static void loadVCCache(void);
static inline float atan3(const float f1, const float f2){
float out;
@@ -75,6 +94,526 @@ static inline float atan3(const float f1
return out;
}
+static pTestLine[nTEST_LINES]= {43, 62, 84, 109, 122, 147, 160, 181, 205, 238};
+static CutPLut *ppCutPLut[nTEST_LINES];
+static int nGoodCaches=0;
+static int nBadCaches=0;
+static int nFieldsCached=0;
+static int nFieldsUnCached=0;
+static int nFields=0;
+static int iCurrentLUTScore=0;
+static int iCurrentUsed=0;
+static CutPCache *pGoodCutPCache=NULL;
+static CutPCache *pBadCutPCache=NULL;
+
+static void delFromCache(CutPCache *pOld){
+
+ if(pOld->nUsed<GOOD_CACHE_THRESHOLD) nBadCaches--;
+ else nGoodCaches--;
+
+ if(pOld==pBadCutPCache)
+ pBadCutPCache=pOld->pNext;
+ if(pOld==pGoodCutPCache)
+ pGoodCutPCache=pOld->pNext;
+
+ pOld->pNext->pPrev= pOld->pPrev;
+ pOld->pPrev->pNext= pOld->pNext;
+
+ if(pOld->pNext == pOld)
+ {
+ if( pBadCutPCache == pOld )
+ pBadCutPCache= NULL;
+ else if( pGoodCutPCache == pOld )
+ pGoodCutPCache= NULL;
+ else error(error_code(-76));
+ }
+}
+
+static void addCutPsToCache(CutPCache *pCutPCache, int *piCutP){
+
+ static byte *pbCScratchPad= new byte[ (MAX_EQ_SETS+1)*wndy+10 ];
+
+ int xIn=0, xOut=0;
+ int nInBytes=0;
+ int nInHeaders=0;
+ int xLastOutHeader=-1;
+ int nOutHeaders=-1;
+ int iLastOutHeader=-1;
+ for(int line=0; line<wndy; line++)
+ {
+ if(nInHeaders==0 && pCutPCache->pbCCutP!=NULL)
+ {
+ nInHeaders= (pCutPCache->pbCCutP[xIn]>>4) + 1;
+ nInBytes= pCutPCache->pbCCutP[xIn] & 15;
+ xIn++;
+ }
+
+ bool bOldGood=true;
+ bool bGood=true;
+ if(nInBytes!=HEADER_FINAL)
+ {
+ bOldGood=false;
+ bGood=false;
+ int nCurrentCutPs=1;
+ for(int i=0; i<nInBytes; i++)
+ {
+ if(int(pCutPCache->pbCCutP[xIn+i]) == piCutP[line])
+ {
+ nCurrentCutPs++;
+ if(nCurrentCutPs>=FINAL_CACHE_THRESHOLD)
+ {
+ bGood=true;
+ }
+ }
+ }
+ }
+ int nOutBytes=nInBytes;
+ if(!bGood && piCutP[line]!=-1) nOutBytes++;
+ int xKill=-1;
+ if(!bGood && nOutBytes>MAX_EQ_SETS)
+ {
+ nOutBytes=MAX_EQ_SETS;
+ xKill=random() % MAX_EQ_SETS;
+ }
+ if(bGood) nOutBytes=1;
+
+ int iOutHeader=nOutBytes;
+ if(bGood) iOutHeader=HEADER_FINAL;
+
+ if(iLastOutHeader == iOutHeader && nOutHeaders<16)
+ nOutHeaders++;
+ else
+ {
+ if(xLastOutHeader>=0)
+ pbCScratchPad[xLastOutHeader]=
+ ((nOutHeaders-1)<<4) + iLastOutHeader;
+ iLastOutHeader= iOutHeader;
+ nOutHeaders=1;
+ xLastOutHeader=xOut;
+ xOut++;
+ }
+
+
+ if(bOldGood)
+ {
+ pbCScratchPad[xOut]= pCutPCache->pbCCutP[xIn];
+ xOut++;
+ }
+ else if(bGood)
+ {
+ pbCScratchPad[xOut]= piCutP[line];
+ xOut++;
+ }
+ else
+ {
+ bool bOut=false;
+ if(piCutP[line]==-1) bOut=true;
+ for(int i=0; i<nInBytes; i++)
+ {
+ if(i==xKill) continue;
+ if(piCutP[line] < pCutPCache->pbCCutP[xIn+i] && !bOut)
+ {
+ pbCScratchPad[xOut]= piCutP[line];
+ xOut++;
+ bOut=true;
+ }
+ pbCScratchPad[xOut]= pCutPCache->pbCCutP[xIn+i];
+ xOut++;
+ }
+ if(!bOut)
+ {
+ pbCScratchPad[xOut]= piCutP[line];
+ xOut++;
+ }
+ }
+
+
+ if(nInBytes!=HEADER_FINAL) xIn+=nInBytes;
+ else xIn++;
+
+ nInHeaders--;
+ }
+ pbCScratchPad[xLastOutHeader]= ((nOutHeaders-1)<<4) + iLastOutHeader;
+
+ delete [] pCutPCache->pbCCutP;
+ pCutPCache->pbCCutP= new byte[xOut];
+ pCutPCache->nbCCutP= xOut;
+ memcpy(pCutPCache->pbCCutP, pbCScratchPad, xOut);
+
+}
+
+static int *getBestCutPs(CutPCache *pCutPCache){
+ static int piCutP[600];
+ int x=0;
+ int nBytes=-1;
+ int nHeaders=0;
+ for(int line=0; line<wndy; line++)
+ {
+ if(nHeaders==0)
+ {
+ nHeaders= (pCutPCache->pbCCutP[x]>>4) + 1;
+ nBytes= pCutPCache->pbCCutP[x] & 15;
+ if(nBytes==HEADER_FINAL) nBytes=1;
+ x++;
+ }
+// printf("x %d %d %d\n", nHeaders, nBytes, pCutPCache->nbCCutP);
+
+
+ int iCurrentCutP=0;
+ int nCurrentCutPs=0;
+ int iBestCutP=0;
+ int nBestCutPs=0;
+ for(int i=0; i<nBytes; i++)
+ {
+// printf("y %d %d\n", x, pCutPCache->pbCCutP[x]);
+ if(pCutPCache->pbCCutP[x] == iCurrentCutP)
+ {
+ nCurrentCutPs++;
+ }
+ else
+ {
+ nCurrentCutPs=1;
+ iCurrentCutP=pCutPCache->pbCCutP[x];
+ }
+
+ if(nCurrentCutPs>nBestCutPs)
+ {
+ nBestCutPs= nCurrentCutPs;
+ iBestCutP= iCurrentCutP;
+ }
+ x++;
+ }
+// printf("z %d %d\n", x, bBestCutP);
+ piCutP[line] =iBestCutP;
+
+ nHeaders--;
+ }
+
+ return piCutP;
+}
+
+static int addToLut(CutPCache *pNewCutPCache){
+ int *piCutP= getBestCutPs(pNewCutPCache);
+ int nTimesAdded=0;
+
+ for(int xTestLine=0; xTestLine<nTEST_LINES; xTestLine++)
+ {
+ int iTestLine= pTestLine[ xTestLine ];
+ int iDiff1= (byte)(piCutP[ iTestLine ] - piCutP[ iTestLine-1 ]);
+ int iDiff2= (byte)(piCutP[ iTestLine+1 ] - piCutP[ iTestLine ]);
+ if(iDiff1==0 && iDiff2==0) continue;
+
+ nTimesAdded++;
+
+ int xDiff= (iDiff1<<8) + iDiff2;
+ CutPLut *pCutPLut= &ppCutPLut[ xTestLine ][ xDiff ];
+ while( pCutPLut->pNext!=NULL ) pCutPLut= pCutPLut->pNext;
+
+ if(pCutPLut->pCutPCache!=NULL)
+ {
+ pCutPLut->pNext= new CutPLut;
+ pCutPLut= pCutPLut->pNext;
+ }
+ pCutPLut->pNext=NULL;
+ pCutPLut->pCutPCache= pNewCutPCache;
+ }
+ return nTimesAdded;
+}
+
+static void delFromLut(CutPCache *pOldCutPCache){
+ int *piCutP= getBestCutPs(pOldCutPCache);
+ for(int xTestLine=0; xTestLine<nTEST_LINES; xTestLine++)
+ {
+ int iTestLine= pTestLine[ xTestLine ];
+ int iDiff1= (byte)(piCutP[ iTestLine ] - piCutP[ iTestLine-1 ]);
+ int iDiff2= (byte)(piCutP[ iTestLine+1 ] - piCutP[ iTestLine ]);
+// if(iDiff1==0 && iDiff2==0) continue;
+
+ int xDiff= (iDiff1<<8) + iDiff2;
+ CutPLut *pCutPLut= &ppCutPLut[ xTestLine ][ xDiff ];
+ CutPLut *pPrev=NULL;
+ while( pCutPLut!=NULL )
+ {
+ if(pCutPLut->pCutPCache==pOldCutPCache)
+ {
+ if(pPrev!=NULL)
+ {
+ pPrev->pNext=pCutPLut->pNext;
+ delete pCutPLut;
+ }
+ else
+ {
+ pCutPLut->pCutPCache=NULL;
+ }
+ break;
+ }
+ pPrev=pCutPLut;
+ pCutPLut= pCutPLut->pNext;
+ }
+ }
+}
+
+static CutPCache *findInLutX(int *piCutP, CutPCache *pMergeCutPCache, bool bInc){
+ int iBestScore=0;
+ CutPCache *pBestCutPCache=NULL;
+ for(int xTestLine=0; xTestLine<nTEST_LINES; xTestLine++)
+ {
+ int iTestLine= pTestLine[ xTestLine ];
+
+ if( piCutP[ iTestLine-1 ]==-1 || piCutP[ iTestLine ]==-1
+ ||piCutP[ iTestLine+1 ]==-1 ) continue;
+
+ int iDiff1= (byte)(piCutP[ iTestLine ] - piCutP[ iTestLine-1 ]);
+ int iDiff2= (byte)(piCutP[ iTestLine+1 ] - piCutP[ iTestLine ]);
+ for(int iDrift1=-1; iDrift1<2; iDrift1++)
+ {
+ int iTDiff1= (byte)(iDiff1 + iDrift1);
+ for(int iDrift2=-1; iDrift2<2; iDrift2++)
+ {
+ int iTDiff2= (byte)(iDiff2 + iDrift2);
+
+ int xDiff= (int(iTDiff1)<<8) + int(iTDiff2);
+ CutPLut *pCutPLut= &ppCutPLut[ xTestLine ][ xDiff ];
+ while( pCutPLut!=NULL && pCutPLut->pCutPCache!=NULL)
+ {
+ CutPLut *pNextCutPLut= pCutPLut->pNext;
+ CutPCache *pCutPCache= pCutPLut->pCutPCache;
+
+ if(bInc)
+ {
+ pCutPCache->iScore++;
+ if(pCutPCache->iScore > iBestScore)
+ {
+ iBestScore=pCutPCache->iScore;
+ pBestCutPCache=pCutPCache;
+ }
+ }
+ else
+ {
+ if( pCutPCache->iScore>=SCORE_THRESHOLD
+ && pCutPCache!=pMergeCutPCache && 0)
+ {
+
+ addCutPsToCache(
+ pMergeCutPCache,
+ getBestCutPs(pCutPCache));
+
+ delFromLut(pCutPCache);
+ delFromCache(pCutPCache);
+ delete [] pCutPCache->pbCCutP;
+ delete pCutPCache;
+ }
+ else
+ {
+ pCutPCache->iScore=0;
+ }
+ }
+ pCutPLut= pNextCutPLut;
+ }
+ }
+ }
+ }
+ return pBestCutPCache;
+}
+
+static void mergeAndClean(int *piCutP, CutPCache *pBestCutPCache){
+ findInLutX(piCutP, pBestCutPCache, false);
+}
+
+static CutPCache *findInLut(int *piCutP){
+ return findInLutX(piCutP, NULL, true);
+}
+
+static void addToCache(CutPCache *pNew){
+ // ? FIX too many pointers
+ CutPCache **ppPlace;
+ if(pNew->nUsed < GOOD_CACHE_THRESHOLD)
+ {
+ if(nBadCaches>MAX_BAD_CACHES)
+ {
+ CutPCache *pDel= pBadCutPCache->pPrev;
+ delFromLut(pDel);
+ delFromCache(pDel);
+ delete [] pDel->pbCCutP;
+ delete pDel;
+ }
+ ppPlace= &pBadCutPCache;
+ nBadCaches++;
+ }
+ else
+ {
+ if(nGoodCaches>MAX_GOOD_CACHES)
+ {
+ CutPCache *pDel= pGoodCutPCache->pPrev;
+ delFromLut(pDel);
+ delFromCache(pDel);
+ delete [] pDel->pbCCutP;
+ delete pDel;
+ }
+ ppPlace= &pGoodCutPCache;
+ nGoodCaches++;
+ }
+
+ if(*ppPlace==NULL)
+ {
+ *ppPlace= pNew;
+ (*ppPlace)->pNext= pNew;
+ (*ppPlace)->pPrev= pNew;
+ }
+
+ pNew->pNext= *ppPlace;
+ pNew->pPrev= (*ppPlace)->pPrev;
+
+ pNew->pNext->pPrev=pNew;
+ pNew->pPrev->pNext=pNew;
+ *ppPlace= pNew;
+}
+
+static void cache(int *piCurrentCutP){
+
+ static bool bInit=true;
+ if(bInit)
+ {
+ for(int i=0; i<nTEST_LINES; i++)
+ {
+ ppCutPLut[i]=new CutPLut[1<<16];
+ memset( ppCutPLut[i], 0, sizeof(CutPLut)*(1<<16) );
+ }
+ bInit=false;
+ loadVCCache();
+ }
+
+ CutPCache *pBestCutPCache= findInLut(piCurrentCutP);
+
+
+ int iBestScore;
+ if(pBestCutPCache!=NULL) iBestScore=pBestCutPCache->iScore;
+ else iBestScore=0;
+
+ mergeAndClean(piCurrentCutP, pBestCutPCache);
+
+ if(pBestCutPCache!=NULL && iBestScore>=SCORE_THRESHOLD)
+ {
+
+ /* LRU Stuff */
+ delFromCache(pBestCutPCache);
+ pBestCutPCache->nUsed++;
+ addToCache(pBestCutPCache);
+
+
+ delFromLut(pBestCutPCache);
+
+ addCutPsToCache(pBestCutPCache, piCurrentCutP);
+
+ addToLut(pBestCutPCache);
+
+ }
+ else if(iBestScore<SCORE_THRESHOLD)
+ {
+ CutPCache *pNewCutPCache= new CutPCache;
+
+ pNewCutPCache->nUsed=0;
+ pNewCutPCache->iScore=0;
+ pNewCutPCache->pbCCutP=NULL;
+ addCutPsToCache(pNewCutPCache, piCurrentCutP);
+
+ addToCache(pNewCutPCache);
+
+ // add and check if we could ever use it, if not thrash it
+ if( addToLut(pNewCutPCache)<SCORE_THRESHOLD )
+ {
+ delFromLut(pNewCutPCache);
+ delFromCache(pNewCutPCache);
+ delete [] pNewCutPCache->pbCCutP;
+ delete pNewCutPCache;
+ }
+ }
+
+ drop=true;
+ nFieldsUnCached++;
+ iCurrentLUTScore=iBestScore;
+ iCurrentUsed=pBestCutPCache->nUsed;
+
+ if(iBestScore<SCORE_THRESHOLD || some==0) return;
+ nFieldsUnCached--;
+ nFieldsCached++;
+
+#ifdef DEBUG
+ printf("Field Cached %d\n", nFields);
+#endif
+
+ if(pBestCutPCache->nUsed<2) return;
+
+ drop=false;
+
+ int *piCutP= getBestCutPs(pBestCutPCache);
+ memcpy(piCurrentCutP, piCutP, sizeof(int)*wndy);
+}
+
+static bool bWasLoaded=false;
+void saveVCCache(void){
+ if(!bWasLoaded) return;
+
+ static FILE *pFCache=fopen("vc_cache.dat", "wb");
+ if(pFCache==NULL) error(error_code(-91));
+ fwrite(&nGoodCaches, sizeof(int), 1, pFCache);
+ fwrite(&nBadCaches, sizeof(int), 1, pFCache);
+ CutPCache *tpCutPCache= pGoodCutPCache->pPrev;
+
+ for(int i=0; i<nGoodCaches; i++)
+ {
+ fwrite(tpCutPCache, sizeof(CutPCache), 1, pFCache);
+ fwrite(tpCutPCache->pbCCutP, sizeof(byte),
+ tpCutPCache->nbCCutP, pFCache);
+
+ tpCutPCache= tpCutPCache->pPrev;
+ }
+
+ tpCutPCache=pBadCutPCache->pPrev;
+ for(int i=0; i<nBadCaches; i++)
+ {
+ fwrite(tpCutPCache, sizeof(CutPCache), 1, pFCache);
+ fwrite(tpCutPCache->pbCCutP, sizeof(byte),
+ tpCutPCache->nbCCutP, pFCache);
+
+ tpCutPCache= tpCutPCache->pPrev;
+ }
+
+ fclose(pFCache);
+}
+
+static void loadVCCache(void){
+
+ bWasLoaded=true;
+ static FILE *pFCache=fopen("vc_cache.dat", "rb");
+ if(pFCache==NULL) return;
+ int nEntGood, nEntBad;
+ fread(&nEntGood, sizeof(int), 1, pFCache);
+ fread(&nEntBad, sizeof(int), 1, pFCache);
+ CutPCache *tpCutPCache;
+
+ for(int i=0; i<nEntGood+nEntBad; i++)
+ {
+ tpCutPCache= new CutPCache;
+
+ fread(tpCutPCache, sizeof(CutPCache), 1, pFCache);
+
+// printf("test %d %d\n", tpCutPCache->iScore, tpCutPCache->nUsed);
+
+
+ tpCutPCache->pbCCutP= new byte[tpCutPCache->nbCCutP];
+ fread(tpCutPCache->pbCCutP, sizeof(byte),
+ tpCutPCache->nbCCutP, pFCache);
+
+ addToCache(tpCutPCache);
+// printf("B\n");
+ addToLut(tpCutPCache);
+// printf("A\n");
+ }
+
+ fclose(pFCache);
+}
+
void vc_decrypt(void){
int cutPointX[max_y];
int addapBuff[max_x];
@@ -82,18 +621,19 @@ void vc_decrypt(void){
long T1=0, T2;
color c;
- const int lowResSize= mmx ? DWN_SMP : (DWN_SMP-1);
+// const int lowResSize= mmx ? DWN_SMP : (DWN_SMP-1);
-#ifdef debug
+#ifdef DEBUG2
printf("xx%f %f %f\n", PHASE_POINT/PI*180, PHASE_SEG/PI*180, PHASE_SMP/PI*180);
#endif
int vScore=0;
+ nFields++;
// showPoints=true;
const double freqPix2= double(wndx) / double(x_field) * FREQ_PIX;
-#ifdef debug
+#ifdef DEBUG2
printf("xy%d %d\n", wndx, x_field);
#endif
// 18
@@ -123,13 +663,13 @@ void vc_decrypt(void){
const int vcEndX= vcStartX + int( double(POINT_LAND + NO_POINT_LAND)
* freqPix2 / FREQ_SMP + .5);
-#ifdef debug
+#ifdef DEBUG2
printf("vcEndX %d\n",vcEndX);
#endif
if(vcEndX>wndx) error(error_code(-123));
const int vcDiff=vcEndX - vcStartX;
- const int minDist= cutP2X[0];
+// const int minDist= cutP2X[0];
cutPointX[0]=0;
@@ -141,9 +681,9 @@ void vc_decrypt(void){
int *convVec= new int[vcDiff>>(PHASE_CMP_STEP-1)];
long TCorr=0, TReSmp=0, TUVDetect=0, TPhaseDiff1=0,
- TPhaseDiff2_Drift=0, TEdgeDetect=0;
+ TPhaseDiff2_Drift=0, TEdgeDetect=0 ,TCache=0;
- if(iState){
+ if(iState==2){
T1=uclock();
}
@@ -157,7 +697,7 @@ void vc_decrypt(void){
static char sin2PerCutP[256];
static char cos2PerCutP[256];
- static int cutPs=0;
+// static int cutPs=0;
static int fields=0;
fields++;
@@ -205,18 +745,43 @@ void vc_decrypt(void){
lowRes[0] = lowRes[1];
lowRes[1] = dTemp;
- if(mmx){
+ black[line]=false; //fix this
+
+ if(mmx && DWN_SMP==1)
+ {
+ int iMean;
+ asm(//"int $3 \n\t"
+
+ "xorl %%ecx, %%ecx \n\t"
+ "1: \n\t"
+ "movzbl 2(%%esi, %%edx, 4), %%eax \n\t"
+ "movzbl 2(%%esi, %%edx, 4), %%ebx \n\t"
+ "addl %%eax, %%ebx \n\t"
+ "shrl $1, %%ebx \n\t"
+ "addl %%ebx, %%ecx \n\t"
+ "movb %%bl, (%%edi, %%edx) \n\t"
+ "incl %%edx \n\t"
+ " jnz 1b \n\t"
+
+ : "=c" (iMean)
+ : "S" ( linep + 1 + (vcStartX<<1) + (vcDiff>>1)*4 ) ,
+ "d" ( -(vcDiff>>1) ) ,
+ "D" ( lowRes[1] + (vcDiff>>1) )
+ : "%eax", "%ebx", "%edx", "%esi", "%edi");
+
+ if(double(iMean) / double(vcDiff>>1) < BAD_MEAN_THRESHOLD)
+ black[line]=true;
+ }
+ else if(mmx){
asm(//"int $3 \n\t"
"pushl %%ebp \n\t"
"1: \n\t"
- "movb (%%edi), %%al \n\t" // U load 32 byte in L1-cache
- "xorl %%ebx, %%ebx \n\t" // V 1
+ "xorl %%ebx, %%ebx \n\t"
"movl %1, %%ebp \n\t" // U
"xorl %%eax, %%eax \n\t" // V 1
"2: \n\t"
"addl %%eax, %%ebx \n\t" // U
- "xorl %%eax, %%eax \n\t" // V 1
"movb (%%esi), %%al \n\t" // U
"addl $2, %%esi \n\t" // V 1
"decl %%ebp \n\t" // U
@@ -270,9 +835,8 @@ void vc_decrypt(void){
}
- black[line]=false; //fix this
- if(iState){
+ if(iState==2){
T2=uclock();
TReSmp+=T2-T1-uclockWaste;
T1=T2;
@@ -282,63 +846,66 @@ void vc_decrypt(void){
int bestDiff=0x1FFFFFFF;
int avgDiff=0; // for detecting bad lines
- int avgDiffNum=0; // for detecting bad lines
+ int avgDiffNum=1; // for detecting bad lines
int bestCutPX=0;
- bool firstPass=true;
- for(int step=STEP_START; step>STEP_END; step>>=1){
-
- const int cutPStart= firstPass ? 0 : step>>1;
+ if(!black[line])
+ {
+ bool firstPass=true;
+ for(int step=STEP_START; step>STEP_END; step>>=1){
- for(int cutP=cutPStart; cutP<vcDiff; cutP+=step){
- if(firstPass || cutP+step>=vcDiff || cutP==step>>1
- || bestDiff+(bestDiff>>1) > addapBuff[ cutP - (step>>1) ]
- || bestDiff+(bestDiff>>1) > addapBuff[ cutP + (step>>1) ]){
+ const int cutPStart= firstPass ? 0 : step>>1;
+ for(int cutP=cutPStart; cutP<vcDiff; cutP+=step){
+ if( firstPass || cutP+step>=vcDiff || cutP==step>>1
+ || bestDiff+(bestDiff>>1) > addapBuff[ cutP - (step>>1) ]
+ || bestDiff+(bestDiff>>1) > addapBuff[ cutP + (step>>1) ]){
- int diff;
- if(mmx){
- diff = vc_corr_mmx(
- int(lowRes[1] ),
- int(lowRes[0] + (( vcDiff - cutP) >> DWN_SMP)),
- cutP >> DWN_SMP ,
- int(lowRes[1] + (( cutP ) >> DWN_SMP)),
- int(lowRes[0] ),
- (vcDiff-cutP) >> DWN_SMP );
- asm("emms\n\t");
- }
- else{
- diff = vc_corr(
- int(lowRes[1] + ((( + cutP) >> (DWN_SMP-1))&~1)),
- int(lowRes[0] + ((( vcDiff ) >> (DWN_SMP-1))&~1)),
- -(( cutP >> (DWN_SMP-1) ) & ~1),
- int(lowRes[1] + ((( vcDiff ) >> (DWN_SMP-1))&~1)),
- int(lowRes[0] + ((( vcDiff - cutP) >> (DWN_SMP-1))&~1)),
- -(( (vcDiff-cutP) >> (DWN_SMP-1) ) & ~1) );
+ int diff;
+ if(mmx){
+ diff = vc_corr_mmx(
+ int(lowRes[1] ),
+ int(lowRes[0] + (( vcDiff - cutP) >> DWN_SMP)),
+ cutP >> DWN_SMP ,
+ int(lowRes[1] + (( cutP ) >> DWN_SMP)),
+ int(lowRes[0] ),
+ (vcDiff-cutP) >> DWN_SMP );
+ }
+ else{
+ diff = vc_corr(
+ int(lowRes[1] + ((( + cutP) >> (DWN_SMP-1))&~1)),
+ int(lowRes[0] + ((( vcDiff ) >> (DWN_SMP-1))&~1)),
+ -(( cutP >> (DWN_SMP-1) ) & ~1),
+ int(lowRes[1] + ((( vcDiff ) >> (DWN_SMP-1))&~1)),
+ int(lowRes[0] + ((( vcDiff - cutP) >> (DWN_SMP-1))&~1)),
+ -(( (vcDiff-cutP) >> (DWN_SMP-1) ) & ~1) );
- }
+ }
- if(bestDiff>diff){
- bestDiff=diff;
- bestCutPX=cutP;
- }
+ if(bestDiff>diff){
+ bestDiff=diff;
+ bestCutPX=cutP;
+ }
- avgDiff+=diff;
- avgDiffNum++;
+ avgDiff+=diff;
+ avgDiffNum++;
- addapBuff[cutP]=diff;
- }
- else addapBuff[cutP]=0x1FFFFFFF;
- }
- if(firstPass) step<<=1;
- firstPass=false;
- }
+ addapBuff[cutP]=diff;
+ }
+ else addapBuff[cutP]=0x1FFFFFFF;
+ }
+ if(firstPass) step<<=1;
+ firstPass=false;
+ }
+ }
+
+ asm("emms\n\t");
if( int( avgDiff*BAD_THRESHOLD1/float(avgDiffNum) ) - BAD_THRESHOLD2
< bestDiff )
black[line]=true;
- if(iState){
+ if(iState==2){
T2=uclock();
TCorr+=T2-T1-uclockWaste;
T1=T2;
@@ -372,7 +939,7 @@ void vc_decrypt(void){
if(bestCutPX>=vcDiff) bestCutPX-=vcDiff;
cutPointX[line]=bestCutPX;
- if(iState){
+ if(iState==2){
T2=uclock();
TUVDetect+=T2-T1-uclockWaste;
T1=T2;
@@ -382,375 +949,422 @@ void vc_decrypt(void){
deleteAlign(lowRes[0]);
deleteAlign(lowRes[1]);
+ int iSumOfAbsDiff=0;
+ int iCount=1;
+ for(int xLine=1; xLine<wndy; xLine++)
+ {
+ if( black[xLine] || black[xLine-1]) continue;
+
+ iCount++;
+
+ int iCutP1= x2CutP[ cutPointX[xLine-1] ];
+ int iCutP2= x2CutP[ cutPointX[xLine ] ];
+
+ iSumOfAbsDiff+= mabs(iCutP2 - iCutP1);
+ }
+ bool bVC=true;
+ if(iSumOfAbsDiff/iCount < NOT_VC_THRESHOLD) bVC=false;
+
byte *dir=new byte[(wndy + 1)<<8];
+
int *bestDir=new int[wndy + 1];
+ for(int i=0; i<wndy+1; i++) bestDir[i]=-1;
const int driftPenalty[MAX_DRIFT*2+1]= DRIFT_TAB;
- int *newVal=new int[256], *lastVal=new int[256];
- memset(lastVal, 0, 256<<2);
-
- byte *newPhaseErr=new byte[256], *lastPhaseErr=new byte[256];
- memset(lastPhaseErr, 0, 256);
-
llinep=&actVid2MemBufp->b[ -(vgax<<2) ];
linep= &actVid2MemBufp->b[ -(vgax<<1) ];
- for(int line=0; line<wndy; line++){
- llinep+=vgax<<1;
- linep+=vgax<<1;
+ if(bVC){
+ int *newVal=new int[256], *lastVal=new int[256];
+ memset(lastVal, 0, 256<<2);
- memset(newVal, 0, 256<<2);
- memset(newPhaseErr, 0, 256);
- bool noLeft=true;
+ byte *newPhaseErr=new byte[256], *lastPhaseErr=new byte[256];
+ memset(lastPhaseErr, 0, 256);
- bestDir[line]=-1;
+ for(int line=0; line<wndy; line++){
+ llinep+=vgax<<1;
+ linep+=vgax<<1;
- if(line==0) continue;
+ memset(newVal, 0, 256<<2);
+ memset(newPhaseErr, 0, 256);
+ bool noLeft=true;
- int relCutPX= cutPointX[line] - cutPointX[line-1];
- if(relCutPX<0) relCutPX+=vcDiff;
+ bestDir[line]=-1;
- int chromAmp=1;
- for(int x=0; x<vcDiff; x+= 1<<PHASE_CMP_STEP){
- int nx= x + (relCutPX & ~1);
- if(nx>=vcDiff) nx-= (vcDiff & ~1);
- const int ul= char(llinep[ (((vcStartX & ~1) + x)<<1) + 0]);
- const int vl= char(llinep[ (((vcStartX & ~1) + x)<<1) + 2]);
- const int un= char( linep[ (((vcStartX & ~1) + nx)<<1) + 0]);
- const int vn= char( linep[ (((vcStartX & ~1) + nx)<<1) + 2]);
- const int p= x>>(PHASE_CMP_STEP-1);
- convVec[p ]= ul*un + vl*vn;
- convVec[p+1]= ul*vn - vl*un;
+ if(line==0) continue;
+
+ int relCutPX= cutPointX[line] - cutPointX[line-1];
+ if(relCutPX<0) relCutPX+=vcDiff;
+
+ int chromAmp=1;
+ for(int x=0; x<vcDiff; x+= 1<<PHASE_CMP_STEP){
+ int nx= x + (relCutPX & ~1);
+ if(nx>=vcDiff) nx-= (vcDiff & ~1);
+ const int ul= char(llinep[ (((vcStartX & ~1) + x)<<1) + 0]);
+ const int vl= char(llinep[ (((vcStartX & ~1) + x)<<1) + 2]);
+ const int un= char( linep[ (((vcStartX & ~1) + nx)<<1) + 0]);
+ const int vn= char( linep[ (((vcStartX & ~1) + nx)<<1) + 2]);
+ const int p= x>>(PHASE_CMP_STEP-1);
+ convVec[p ]= ul*un + vl*vn;
+ convVec[p+1]= ul*vn - vl*un;
/*
const float fsScale= sqrt(convVec[p ]*convVec[p ] +
convVec[p+1]*convVec[p+1] );
convVec[p ]= int(convVec[p ]/pow(fsScale + .001, .9));
convVec[p+1]= int(convVec[p+1]/pow(fsScale + .001, .9));
*/
- chromAmp+= mabs(un) + mabs(vn);
- }
- if(line<4) chromAmp=1;
+ chromAmp+= mabs(un) + mabs(vn);
+ }
+ if(line<4) chromAmp=1;
// linep[ ((vcStartX + 0)<<1) + 1]=255;
// linep[ ((vcStartX + relCutPX)<<1) + 1]=200;
- if(iState){
- T2=uclock();
- TPhaseDiff1+=T2-T1-uclockWaste;
- T1=T2;
- }
+ if(iState==2){
+ T2=uclock();
+ TPhaseDiff1+=T2-T1-uclockWaste;
+ T1=T2;
+ }
- int sumR0=0, sumI0=0;
- int sumR1=0, sumI1=0;
+ int sumR0=0, sumI0=0;
+ int sumR1=0, sumI1=0;
- {
- int x=0;
- for(; x<vcDiff-relCutPX; x+= 1<<PHASE_CMP_STEP){
- const int p= x>>(PHASE_CMP_STEP-1);
- sumR0+= convVec[p ];
- sumI0+= convVec[p+1];
- }
- for(; x<vcDiff; x+= 1<<PHASE_CMP_STEP){
- const int p= x>>(PHASE_CMP_STEP-1);
- sumR1+= convVec[p ];
- sumI1+= convVec[p+1];
- }
- }
+ {
+ int x=0;
+ for(; x<vcDiff-relCutPX; x+= 1<<PHASE_CMP_STEP){
+ const int p= x>>(PHASE_CMP_STEP-1);
+ sumR0+= convVec[p ];
+ sumI0+= convVec[p+1];
+ }
+ for(; x<vcDiff; x+= 1<<PHASE_CMP_STEP){
+ const int p= x>>(PHASE_CMP_STEP-1);
+ sumR1+= convVec[p ];
+ sumI1+= convVec[p+1];
+ }
+ }
- const float s= ( (line & 1) ^ ( vScore>0 ) ) ? -1 : 1;
+ const float s= ( (line & 1) ^ ( vScore>0 ) ) ? -1 : 1;
- int sumR0C= int( sumR0*cosSegPhase + sumI0*sinSegPhase*s);
- int sumI0C= int(-sumR0*sinSegPhase*s + sumI0*cosSegPhase);
- int sumR1C= int( sumR1*cosSegPhase + sumI1*sinSegPhase*s);
- int sumI1C= int(-sumR1*sinSegPhase*s + sumI1*cosSegPhase);
+ int sumR0C= int( sumR0*cosSegPhase + sumI0*sinSegPhase*s);
+ int sumI0C= int(-sumR0*sinSegPhase*s + sumI0*cosSegPhase);
+ int sumR1C= int( sumR1*cosSegPhase + sumI1*sinSegPhase*s);
+ int sumI1C= int(-sumR1*sinSegPhase*s + sumI1*cosSegPhase);
- int ffR0=0 , ffI0=0;
- int ssR0=sumR0, ssI0=sumI0;
- int ffR1=0 , ffI1=0;
- int ssR1=sumR1, ssI1=sumI1;
+ int ffR0=0 , ffI0=0;
+ int ssR0=sumR0, ssI0=sumI0;
+ int ffR1=0 , ffI1=0;
+ int ssR1=sumR1, ssI1=sumI1;
- int lastPhasePos=0;
+ int lastPhasePos=0;
- byte ang=0;
- if(!black[line]){
- for(int lastCutP = 0; lastCutP < 256; lastCutP++){
- if(lastVal[lastCutP]==0) continue;
+ byte ang=0;
+ if(!black[line]){
+ for(int lastCutP = 0; lastCutP < 256; lastCutP++){
+ if(lastVal[lastCutP]==0) continue;
- const int newPhasePos= cutP2X[ lastCutP ] & ((-1) << PHASE_CMP_STEP);
+ const int newPhasePos= cutP2X[ lastCutP ] & ((-1) << PHASE_CMP_STEP);
- if( newPhasePos >= lastPhasePos ){
+ if( newPhasePos >= lastPhasePos ){
- for(; lastPhasePos <= newPhasePos; lastPhasePos += (1<<PHASE_CMP_STEP)){
- const bool isLast= lastPhasePos == newPhasePos;
+ for(; lastPhasePos <= newPhasePos; lastPhasePos += (1<<PHASE_CMP_STEP)){
+ const bool isLast= lastPhasePos == newPhasePos;
- const int p= lastPhasePos>>(PHASE_CMP_STEP-1);
+ const int p= lastPhasePos>>(PHASE_CMP_STEP-1);
- if(lastPhasePos+relCutPX<vcDiff){
- ssR0-=convVec[p ];
- ssI0-=convVec[p+1];
+ if(lastPhasePos+relCutPX<vcDiff){
+ ssR0-=convVec[p ];
+ ssI0-=convVec[p+1];
- if(isLast){
- const int r= ssR0 + sumR1C + int( ffR0*cosSegPhase2 + ffI0*sinSegPhase2*s);
- const int i= ssI0 + sumI1C + int(-ffR0*sinSegPhase2*s + ffI0*cosSegPhase2);
+ if(isLast){
+ const int r= ssR0 + sumR1C
+ + int( ffR0*cosSegPhase2
+ + ffI0*sinSegPhase2*s);
+ const int i= ssI0 + sumI1C
+ + int( -ffR0*sinSegPhase2*s
+ + ffI0*cosSegPhase2);
- ang= (byte)( atan3(i, r)/PI*128 );
- }
+ ang= (byte)( atan3(i, r)/PI*128 );
+ }
- ffR0+=convVec[p ];
- ffI0+=convVec[p+1];
- }
- else{
- ssR1-=convVec[p ];
- ssI1-=convVec[p+1];
+ ffR0+=convVec[p ];
+ ffI0+=convVec[p+1];
+ }
+ else{
+ ssR1-=convVec[p ];
+ ssI1-=convVec[p+1];
- if(isLast){
- const int r= ssR1 + sumR0C + int( ffR0*cosSegPhase2 + ffI0*sinSegPhase2*s);
- const int i= ssI1 + sumI0C + int(-ffR0*sinSegPhase2*s + ffI0*cosSegPhase2);
+ if(isLast){
+ const int r= ssR1 + sumR0C
+ + int( ffR0*cosSegPhase2
+ + ffI0*sinSegPhase2*s);
+ const int i= ssI1 + sumI0C
+ + int( -ffR0*sinSegPhase2*s
+ + ffI0*cosSegPhase2);
- ang= (byte)( atan3(i, r)/PI*128 );
- }
+ ang= (byte)( atan3(i, r)/PI*128 );
+ }
- ffR1+=convVec[p ];
- ffI1+=convVec[p+1];
- }
+ ffR1+=convVec[p ];
+ ffI1+=convVec[p+1];
+ }
- }
- }
+ }
+ }
- int newXTemp= cutPointX[line] - cutPointX[line-1] + cutP2X[lastCutP];
- if(newXTemp < 0 ) newXTemp+= vcDiff;
- if(newXTemp >= vcDiff) newXTemp-= vcDiff;
- if(newXTemp >= vcDiff) newXTemp-= vcDiff;
+ int newXTemp= cutPointX[line] - cutPointX[line-1] + cutP2X[lastCutP];
+ if(newXTemp < 0 ) newXTemp+= vcDiff;
+ if(newXTemp >= vcDiff) newXTemp-= vcDiff;
+ if(newXTemp >= vcDiff) newXTemp-= vcDiff;
- const int newCutPStart= max(x2CutP[ newXTemp ] - MAX_DRIFT, 0);
- const int newCutPEnd= min(x2CutP[ newXTemp ] + MAX_DRIFT, 256);
+ const int newCutPStart= max(x2CutP[ newXTemp ] - MAX_DRIFT, 0);
+ const int newCutPEnd= min(x2CutP[ newXTemp ] + MAX_DRIFT, 256);
- int drift= newCutPStart - (x2CutP[ newXTemp ] - MAX_DRIFT);
+// const int drift= newCutPStart - (x2CutP[ newXTemp ] - MAX_DRIFT);
+ const int *piDrift=
+ &driftPenalty[newCutPStart - (x2CutP[ newXTemp ] - MAX_DRIFT)-1];
- const byte a= (line & 1) ^ ( vScore>0 ) ? -ang: ang;
+ const byte a= (line & 1) ^ ( vScore>0 ) ? -ang: ang;
- const int phase1= (a + phasePerCutP[ lastCutP ]) & 0xFF;
- const int lastPhaseErrLastCutP= lastPhaseErr[lastCutP] + 128;
+ const int phase1= (a + phasePerCutP[ lastCutP ]) & 0xFF;
+ const int lastPhaseErrLastCutP= lastPhaseErr[lastCutP] + 128;
// FIX (ASM_OPTIMIZE)
- if(chromAmp>AMP_THRESHOLD){
- for(int newCutP= newCutPStart; newCutP <= newCutPEnd; newCutP++){
- const int phaseErr= (phase1 + phasePerCutP[ newCutP ]) & 0xFF;
- const int val= lastVal[lastCutP] - driftPenalty[drift]
+ if(chromAmp>AMP_THRESHOLD){
+ for(int newCutP= newCutPStart; newCutP <= newCutPEnd; newCutP++){
+ const int phaseErr= (phase1 + phasePerCutP[ newCutP ]) & 0xFF;
+ const int val= lastVal[lastCutP] - *(++piDrift)
- phaseLut[ phaseErr ]
- phaseLut[ (phaseErr - lastPhaseErrLastCutP) & 0xFF];// useless without phase errors from decomb-filter
- if(newVal[newCutP] < val){
- newVal[newCutP]= val;
- dir[(line<<8) + newCutP]= lastCutP;
- newPhaseErr[newCutP]= phaseErr;
+ if(newVal[newCutP] < val){
+ newVal[newCutP]= val;
+ dir[(line<<8) + newCutP]= lastCutP;
+ newPhaseErr[newCutP]= phaseErr;
- noLeft=false;
- }
- drift++;
- }
- }
- else{
- linep[ ((vcStartX - 1)<<1) + 1]=255;
- for(int newCutP= newCutPStart; newCutP <= newCutPEnd; newCutP++){
- const int phaseErr= (phase1 + phasePerCutP[ newCutP ]) & 0xFF;
- const int val= lastVal[lastCutP] - driftPenalty[drift];
+ noLeft=false;
+ }
+ }
+ }
+ else{
+ linep[ ((vcStartX - 1)<<1) + 1]=255;
+ for(int newCutP= newCutPStart; newCutP <= newCutPEnd; newCutP++){
+ const int phaseErr= (phase1 + phasePerCutP[ newCutP ]) & 0xFF;
+ const int val= lastVal[lastCutP] - *(++piDrift);
- if(newVal[newCutP] < val){
- newVal[newCutP]= val;
- dir[(line<<8) + newCutP]= lastCutP;
- newPhaseErr[newCutP]= phaseErr;
+ if(newVal[newCutP] < val){
+ newVal[newCutP]= val;
+ dir[(line<<8) + newCutP]= lastCutP;
+ newPhaseErr[newCutP]= phaseErr;
- noLeft=false;
- }
- drift++;
- }
- }
- }
- }
+ noLeft=false;
+ }
+ }
+ }
+ }
+ }
- if(iState){
- T2=uclock();
- TPhaseDiff2_Drift+=T2-T1-uclockWaste;
- T1=T2;
- }
+ if(iState==2){
+ T2=uclock();
+ TPhaseDiff2_Drift+=T2-T1-uclockWaste;
+ T1=T2;
+ }
- if(!black[line]){
- int iBestVal=0;
- for(int newCutP = 0; newCutP < 256; newCutP++){
- if(!noLeft && newVal[newCutP]==0) continue;
+ if(!black[line]){
+ int iBestVal=0;
+ for(int newCutP = 0; newCutP < 256; newCutP++){
+ if(!noLeft && newVal[newCutP]==0) continue;
- const byte * const p= &linep[ ((cutP2X[ newCutP ] + vcStartX)<<1) + 1 - 4];
+ const byte * const p=
+ &linep[ ((cutP2X[ newCutP ] + vcStartX)<<1) + 1 - 4];
- const int diff=edgeLut[ mabs( + int(* p ) + int(*(p+2))
- - int(*(p+4)) - int(*(p+6)) ) ];
+ const int diff=edgeLut[ mabs( + int(* p ) + int(*(p+2))
+ - int(*(p+4)) - int(*(p+6)) ) ];
- if(newVal[newCutP]==0) newVal[newCutP] = diff + 1000000000;
- else newVal[newCutP] += diff;
+ if(newVal[newCutP]==0) newVal[newCutP] = diff + 1000000000;
+ else newVal[newCutP] += diff;
- if(iBestVal < newVal[newCutP]){
- iBestVal= newVal[newCutP];
- bestDir[line]= newCutP;
- }
+ if(iBestVal < newVal[newCutP]){
+ iBestVal= newVal[newCutP];
+ bestDir[line]= newCutP;
+ }
- }
- }
+ }
+ }
- if(iState){
- T2=uclock();
- TEdgeDetect+=T2-T1-uclockWaste;
- T1=T2;
- }
+ if(iState==2){
+ T2=uclock();
+ TEdgeDetect+=T2-T1-uclockWaste;
+ T1=T2;
+ }
- int *tempVal=lastVal;
- lastVal=newVal;
- newVal=tempVal;
+ int *tempVal=lastVal;
+ lastVal=newVal;
+ newVal=tempVal;
+
+ byte *tempErr=lastPhaseErr;
+ lastPhaseErr=newPhaseErr;
+ newPhaseErr=tempErr;
+ }
- byte *tempErr=lastPhaseErr;
- lastPhaseErr=newPhaseErr;
- newPhaseErr=tempErr;
- }
+ delete [] newVal;
+ delete [] lastVal;
+
+ delete [] newPhaseErr;
+ delete [] lastPhaseErr;
+ }
delete [] convVec;
- delete [] newVal;
- delete [] lastVal;
- delete [] newPhaseErr;
- delete [] lastPhaseErr;
-
- if(showPoints){
- int bestCutP=-1;
- for(int line=wndy-2; line>0; line--){
- if(bestDir[line]==-1){
- bestCutP=-1;
- continue;
- }
- if(bestCutP==-1) bestCutP= bestDir[line];
- if(bestCutP<0 || bestCutP>=256){
- printf("one%d\n", bestCutP);
- bestCutP=-1;
- continue;
- }
+ int piBestCutP[600];
+ int iBestCutP=-1;
+ for(int line=wndy-2; line>0; line--)
+ {
+ piBestCutP[line]=-1;
-// const int bestX= cutP2X[ bestCutP ];
- int bestX=cutP2X[ bestCutP ] + cutPointX[line-1] - cutPointX[line];
- if(bestX<0) bestX+= vcDiff;
- if(bestX>=vcDiff) bestX-= vcDiff;
- actVid2MemBufp->b[((line-1) * vgax<<1) + ((vcStartX + bestX)<<1)+1]=255;
- actVid2MemBufp->b[((line-1) * vgax<<1) + ((vcStartX + bestX)<<1)+3]=0;
+ if(bestDir[line]==-1)
+ {
+ iBestCutP=-1;
+ continue;
+ }
- bestCutP= dir[(line<<8) + bestCutP];
- }
- }
+ if(iBestCutP==-1) iBestCutP= bestDir[line];
+ if(iBestCutP<0 || iBestCutP>=256)
+ {
+ printf("one%d\n", iBestCutP);
+ iBestCutP=-1;
+ continue;
+ }
+ piBestCutP[line]= iBestCutP;
- byte cutpp[1000];
- byte copy_buff[max_x<<1];
+ iBestCutP= dir[(line<<8) + iBestCutP];
+ }
- int bestCutP=-1;
- linep= &actVid2MemBufp->b[ (wndy-1) * (vgax<<1) ];
- llinep=&actVid2MemBufp->b[ wndy * (vgax<<1) ];
- for(int line=wndy-2; line>0; line--){
- linep-= vgax<<1;
- llinep-= vgax<<1;
+#ifdef DEBUG_CUTP
+ for(int line=1; line<wndy-1; line++)
+ {
+ fprintf(pF, "%d\n", piBestCutP[line]);
+ }
+#endif
- cutpp[line]=0;
+ if(bVC) cache(piBestCutP);
- if(black[line]){
- linep[ ((vcStartX - 4)<<1) + 1 ]=255;
- linep[ ((vcStartX - 4)<<1) + 3 ]=255;
- }
+ if(iState==2)
+ {
+ T2=uclock();
+ TCache+=T2-T1-uclockWaste;
+ T1=T2;
+ }
- if(showPoints){
- linep[ (vcStartX<<1)+1 ]=255;
- linep[ (vcStartX<<1)+3 ]=0;
- }
- if(bestDir[line]==-1){
- bestCutP=-1;
- continue;
- }
- if(bestCutP==-1) bestCutP= bestDir[line];
- if(bestCutP<0 || bestCutP>=256){
- printf("two%d\n", bestCutP);
- bestCutP=-1;
- continue;
- }
+ if(showPoints)
+ {
+ for(int line=wndy-2; line>0; line--)
+ {
+ int bestCutP=piBestCutP[line];
+ if(bestCutP==-1) continue;
- cutpp[line]=bestCutP;
+// const int bestX= cutP2X[ bestCutP ];
+ int bestX=cutP2X[ bestCutP ] + cutPointX[line-1] - cutPointX[line];
+ if(bestX<0) bestX+= vcDiff;
+ if(bestX>=vcDiff) bestX-= vcDiff;
+ actVid2MemBufp->b[((line-1) * vgax<<1) + ((vcStartX + bestX)<<1)+1]=255;
+ actVid2MemBufp->b[((line-1) * vgax<<1) + ((vcStartX + bestX)<<1)+3]=0;
- const int bestX= cutP2X[ bestCutP ];
+ }
+ }
- int cutX= ((showPoints && 0) ? cutPointX[line] : bestX );
+ if(bVC){
+ byte copy_buff[max_x<<1];
- const int cutP= max(x2CutP[cutX], 0); // fix ? ness, min?
-
- const char s1= sin1PerCutP[ cutP ];
- const char c1= cos1PerCutP[ cutP ];
- const char s2= sin2PerCutP[ cutP ];
- const char c2= cos2PerCutP[ cutP ];
+ linep= &actVid2MemBufp->b[ (wndy-1) * (vgax<<1) ];
+ llinep=&actVid2MemBufp->b[ wndy * (vgax<<1) ];
+ for(int line=wndy-2; line>0; line--){
+ linep-= vgax<<1;
+ llinep-= vgax<<1;
- if( (line & 1) ^ ( vScore>0 ) ){
- char *p= (char*)( &linep[ ((vcStartX & ~1)<<1) ] );
- int x=0;
- for(; x<cutX; x+=4){
- const char u= * p;
- const char v= *(p+2);
+ if(black[line]){
+ linep[ ((vcStartX - 4)<<1) + 1 ]=255;
+ linep[ ((vcStartX - 4)<<1) + 3 ]=255;
+ }
- const char u1=(char)(( - v*c1 - u*s1)>>7);
- const char v1=(char)(( + v*s1 - u*c1)>>7);
+ if(showPoints){
+ linep[ (vcStartX<<1)+1 ]=255;
+ linep[ (vcStartX<<1)+3 ]=0;
+ }
+ int bestCutP=piBestCutP[line];
+ if(bestCutP==-1) continue;
- if( (vcDiff - cutX) & 1 ){
- * p = v1;
- *(p+2)= u1;
- *(p+4)= v1;
- *(p+6)= u1;
- }
- else{
- * p = u1;
- *(p+2)= v1;
- *(p+4)= u1;
- *(p+6)= v1;
- }
- p+=8;
- }
+ const int bestX= cutP2X[ bestCutP ];
- for(; x<vcDiff; x+=4){
- const char u= * p;
- const char v= *(p+2);
+ int cutX= ((showPoints && 0) ? cutPointX[line] : bestX );
- const char u1=(char)(( - v*c2 - u*s2)>>7);
- const char v1=(char)(( + v*s2 - u*c2)>>7);
-
- if( cutX & 1 ){
- * p = v1;
- *(p+2)= u1;
- *(p+4)= v1;
- *(p+6)= u1;
- }
- else{
- * p = u1;
- *(p+2)= v1;
- *(p+4)= u1;
- *(p+6)= v1;
- }
- p+=8;
- }
- }
+ const int cutP= max(x2CutP[cutX], 0); // fix ? ness, min?
+
+ const char s1= sin1PerCutP[ cutP ];
+ const char c1= cos1PerCutP[ cutP ];
+ const char s2= sin2PerCutP[ cutP ];
+ const char c2= cos2PerCutP[ cutP ];
+
+ if( (line & 1) ^ ( vScore>0 ) ){
+ char *p= (char*)( &linep[ ((vcStartX & ~1)<<1) ] );
+ int x=0;
+ for(; x<cutX; x+=4){
+ const char u= * p;
+ const char v= *(p+2);
+
+ const char u1=(char)(( - v*c1 - u*s1)>>7);
+ const char v1=(char)(( + v*s1 - u*c1)>>7);
+ if( (vcDiff - cutX) & 1 ){
+ * p = v1;
+ *(p+2)= u1;
+ *(p+4)= v1;
+ *(p+6)= u1;
+ }
+ else{
+ * p = u1;
+ *(p+2)= v1;
+ *(p+4)= u1;
+ *(p+6)= v1;
+ }
+ p+=8;
+ }
+ for(; x<vcDiff; x+=4){
+ const char u= * p;
+ const char v= *(p+2);
+
+ const char u1=(char)(( - v*c2 - u*s2)>>7);
+ const char v1=(char)(( + v*s2 - u*c2)>>7);
+
+ if( cutX & 1 ){
+ * p = v1;
+ *(p+2)= u1;
+ *(p+4)= v1;
+ *(p+6)= u1;
+ }
+ else{
+ * p = u1;
+ *(p+2)= v1;
+ *(p+4)= u1;
+ *(p+6)= v1;
+ }
+ p+=8;
+ }
+ }
// linep[ ((vcStartX)<<1)+1 ]= 255;
- memcpy(copy_buff, linep + (vcStartX<<1), vcDiff<<1);
+ memcpy(copy_buff, linep + (vcStartX<<1), vcDiff<<1);
- memcpy(linep + (vcStartX<<1), copy_buff + (cutX<<1), (vcDiff-cutX)<<1);
- memcpy(linep + (vcStartX<<1) + ((vcDiff-cutX)<<1), copy_buff, cutX<<1);
+ memcpy(linep + (vcStartX<<1), copy_buff + (cutX<<1), (vcDiff-cutX)<<1);
+ memcpy(linep + (vcStartX<<1) + ((vcDiff-cutX)<<1), copy_buff, cutX<<1);
- if( !( (line & 1) ^ ( vScore>0 ) ) ){
- char *pl= (char*)( &llinep[ ((vcStartX<<1) & ~3) ] );
- char *pn= (char*)( &linep[ ((vcStartX<<1) & ~3) ] );
+ if( !( (line & 1) ^ ( vScore>0 ) ) ){
+ char *pl= (char*)( &llinep[ ((vcStartX<<1) & ~3) ] );
+ char *pn= (char*)( &linep[ ((vcStartX<<1) & ~3) ] );
/* for(int x=0; x<vcDiff; x+=4){
* pn = *(pn+4)= * pl;
*(pn+2)= *(pn+6)= *(pl+2);
@@ -774,17 +1388,10 @@ void vc_decrypt(void){
"S" (int(pl) + (vcDiff<<1)) ,
"c" (-vcDiff<<1)
: "%eax", "%ebx", "%ecx");
- }
-
- bestCutP= dir[(line<<8) + bestCutP];
- }
+ }
-#ifdef debug
- for(int line=1; line<wndy-1; line++)
- {
- fprintf(pF, "%d\n", cutpp[line]);
}
-#endif
+ }
/*
float avgCutP=0;
@@ -796,35 +1403,71 @@ void vc_decrypt(void){
printf("avg%f\n", avgCutP-float(vcDiff)/2.0);
*/
-#ifdef debug
+#ifdef DEBUG2
printf("vScore %d\n", vScore);
#endif
- if(iState){
- T2=uclock();
- sprintf(textbuf[0],"%f ReSample", (float)(TReSmp)/UCLOCKS_PER_SEC);
- sprintf(textbuf[1],"%f Correlate", (float)(TCorr)/UCLOCKS_PER_SEC);
- sprintf(textbuf[2],"%f UVDetect", (float)(TUVDetect)/UCLOCKS_PER_SEC);
- sprintf(textbuf[3],"%f FindPhaseDiff1", (float)(TPhaseDiff1)/UCLOCKS_PER_SEC);
- sprintf(textbuf[4],"%f FindPhaseDiff2 / Drift", (float)(TPhaseDiff2_Drift)/UCLOCKS_PER_SEC);
- sprintf(textbuf[5],"%f EdgeDetect", (float)(TEdgeDetect)/UCLOCKS_PER_SEC);
- sprintf(textbuf[6],"%f Rotate / ColorFix", (float)(T2-T1-uclockWaste)/UCLOCKS_PER_SEC);
- c.init(255, 0, 0, false);
- gprint(infoPosX, infoPosY+=10, c.col, textbuf[0]);
- gprint(infoPosX, infoPosY+=10, c.col, textbuf[1]);
- gprint(infoPosX, infoPosY+=10, c.col, textbuf[2]);
- gprint(infoPosX, infoPosY+=10, c.col, textbuf[3]);
- gprint(infoPosX, infoPosY+=10, c.col, textbuf[4]);
- gprint(infoPosX, infoPosY+=10, c.col, textbuf[5]);
- gprint(infoPosX, infoPosY+=10, c.col, textbuf[6]);
- infoPosY+=5;
- T1=T2;
- }
-/*
- c.init(255, 0, 0, false);
- sprintf(textbuf[6],"%d l %d f", cutPs, fields);
- gprint(infoPosX, infoPosY+=10, c.col, textbuf[6]);
- */
+ if(iState==2)
+ {
+ T2=uclock();
+ sprintf(textbuf[0],"%f ReSample", (float)(TReSmp)/UCLOCKS_PER_SEC);
+ sprintf(textbuf[1],"%f Correlate", (float)(TCorr)/UCLOCKS_PER_SEC);
+ sprintf(textbuf[2],"%f UVDetect", (float)(TUVDetect)/UCLOCKS_PER_SEC);
+ sprintf(textbuf[3],"%f FindPhaseDiff1", (float)(TPhaseDiff1)/UCLOCKS_PER_SEC);
+ sprintf(textbuf[4],"%f FindPhaseDiff2 / Drift", (float)(TPhaseDiff2_Drift)/UCLOCKS_PER_SEC);
+ sprintf(textbuf[5],"%f EdgeDetect", (float)(TEdgeDetect)/UCLOCKS_PER_SEC);
+ sprintf(textbuf[6],"%f Cache", (float)(TCache)/UCLOCKS_PER_SEC);
+ sprintf(textbuf[7],"%f Rotate / ColorFix", (float)(T2-T1-uclockWaste)/UCLOCKS_PER_SEC);
+ c.init(255, 0, 0, false);
+ gprint(infoPosX, infoPosY+=10, c.col, textbuf[0]);
+ gprint(infoPosX, infoPosY+=10, c.col, textbuf[1]);
+ gprint(infoPosX, infoPosY+=10, c.col, textbuf[2]);
+ gprint(infoPosX, infoPosY+=10, c.col, textbuf[3]);
+ gprint(infoPosX, infoPosY+=10, c.col, textbuf[4]);
+ gprint(infoPosX, infoPosY+=10, c.col, textbuf[5]);
+ gprint(infoPosX, infoPosY+=10, c.col, textbuf[6]);
+ gprint(infoPosX, infoPosY+=10, c.col, textbuf[7]);
+ infoPosY+=5;
+ T1=T2;
+ }
+ if(iState>=1)
+ {
+ sprintf(textbuf[0],"%d/%d Caches, %d/%d Cached",
+ nBadCaches,
+ nGoodCaches,
+ nFieldsUnCached,
+ nFieldsCached);
+
+ c.init(255, 0, 0, false);
+ gprint(infoPosX, infoPosY+=10, c.col, textbuf[0]);
+
+ byte pbScore[100];
+ for(int i=0; i<iCurrentLUTScore; i++)
+ pbScore[i]='*';
+ for(int i=iCurrentLUTScore; i<nTEST_LINES; i++)
+ pbScore[i]='.';
+ pbScore[ nTEST_LINES ]=0;
+
+ sprintf(textbuf[1],"LUT Score %s",
+ pbScore);
+
+ gprint(infoPosX, infoPosY+=10, c.col, textbuf[1]);
+
+
+ byte pbUsed[100];
+ iCurrentUsed= min(iCurrentUsed, 20);
+ for(int i=0; i<iCurrentUsed; i++)
+ pbUsed[i]='*';
+ for(int i=iCurrentUsed; i<20; i++)
+ pbUsed[i]='.';
+ pbUsed[ 20 ]=0;
+
+ sprintf(textbuf[1],"Used %s",
+ pbUsed);
+
+ gprint(infoPosX, infoPosY+=10, c.col, textbuf[1]);
+
+ }
delete [] bestDir;
delete [] dir;
1
0
[mndiff]: r60 - in trunk/2010: 2_all.h 2_all_a.asm 2_cryp_a.asm 2_cryp_a.h 2_nag_a.asm 2_vc.h 2_vc_a.asm
by michael 04 Jul '07
by michael 04 Jul '07
04 Jul '07
Author: michael
Date: Wed Jul 4 10:42:04 2007
New Revision: 60
Log:
next version from unknown date
Modified:
trunk/2010/2_all.h
trunk/2010/2_all_a.asm
trunk/2010/2_cryp_a.asm
trunk/2010/2_cryp_a.h
trunk/2010/2_nag_a.asm
trunk/2010/2_vc.h
trunk/2010/2_vc_a.asm
Modified: trunk/2010/2_all.h
==============================================================================
--- trunk/2010/2_all.h (original)
+++ trunk/2010/2_all.h Wed Jul 4 10:42:04 2007
@@ -14,6 +14,8 @@
#define limit(a,b,c) if( (a)<(b) || (a)>(c) ) error(-201)
+#define ISTATES 3
+
#define u_char unsigned char
#define u_long unsigned long
Modified: trunk/2010/2_all_a.asm
==============================================================================
--- trunk/2010/2_all_a.asm (original)
+++ trunk/2010/2_all_a.asm Wed Jul 4 10:42:04 2007
@@ -35,6 +35,8 @@
times ge(($$-$)&3, 1) nop
%endmacro
+; lea 4 byte and 7 byte possible
+
%macro align8 0
times ge(($$-$)&7, 6) cmp ebx, 0
times ge(($$-$)&7, 5) cmp eax, 0
Modified: trunk/2010/2_cryp_a.asm
==============================================================================
--- trunk/2010/2_cryp_a.asm (original)
+++ trunk/2010/2_cryp_a.asm Wed Jul 4 10:42:04 2007
@@ -8,6 +8,7 @@ global _VSmooth1RGB1555__Fiii
global _VSmooth2RGB1555__Fiii
global _Decomb1__Fiii
global _Decomb2__Fiii
+global _SetDecombInc__Fi
%define pBuf1 par1
%define iVgaX21 par2
@@ -21,6 +22,16 @@ global _Decomb2__Fiii
%define nOp3 par2
%define pBuf3 par3
+_SetDecombInc__Fi:
+ push eax
+
+ mov eax, [par1 - 5*4]
+ mov [decombInc], eax
+ mov [decombInc+4], eax
+ pop eax
+
+ret
+
_Decomb1__Fiii:
push eax
push ebx
@@ -86,24 +97,29 @@ _Decomb2__Fiii:
movq mm7, [decombInc]
align16
Decomb2Loop:
- movq mm0, [esi + ecx] ;0p2 wMM0rESIECX 1
- movq mm1, mm0 ; p01wMM1rMM0 0 test mov mem
- pand mm1, mm6 ; p01wMM1rMM6MM1 1
- psllw mm0, 8 ;0p1 wMM0rMM0 0
- movq mm2, [edi + ecx] ; p2 wMM2rEDIECX 1
- psubsw mm0, mm2 ; p01wMM0rMM2MM0 0
- pcmpgtw mm2, mm0 ;0p01wMM2rMM0MM2 0
- pand mm2, mm7 ; p01wMM2rMM7MM2 1
- paddsw mm0, mm2 ; p01wMM0rMM2MM0 0
- movq [edi + ecx], mm0 ;0p3 rEDIECX 2 p4 rMM0 0
- psrlw mm0, 7 ; p1 wMM0rMM0 0
- por mm1, mm0 ; p01wMM1rMM0MM1 ?0
- movq [esi + ecx], mm1 ;0p3 rESIECX 2 p4 rMM1 0
- add ecx, byte 8 ; p01wECXrECX (1)
- jnc Decomb2Loop ; p1 rFLAG 0
+ movq mm0, [esi + ecx] ;4 p2 MM0 ESIECX F 0
+ movq mm1, mm0 ;3 p01 MM1 MM0 F 1
+ pand mm1, mm6 ;3 p01 MM1 MM6MM1 F 2
+ psllw mm0, 8 ;4 p1 MM0 MM0 F 0
+ movq mm2, [edi + ecx] ;4 p2 MM2 EDIECX f 0
+ psubsw mm0, mm2 ;3 p01 MM0 MM2MM0 f 1
+ pcmpgtw mm2, mm0 ;3 p01 MM2 MM0MM2 f 2
+ pand mm2, mm7 ;3 p01 MM2 MM7MM2 f 0
+ paddsw mm0, mm2 ;3 p01 MM0 MM2MM0 f 1
+ movq [edi + ecx], mm0 ;4 p3 EDIECX F 0
+ ;0 p4 MM0 F 0
+ psrlw mm0, 7 ;4 p1 MM0 MM0 F 1
+ por mm1, mm0 ;3 p01 MM1 MM0MM1 F 2
+ movq [esi + ecx], mm1 ;4 p3 ESIECX F 0
+ ;0 p4 MM1 F 0
+ add ecx, byte 8 ;3 p01 ECX ECX f 0
+ jnc Decomb2Loop ;2 p1 FLAG f 1
- ; 8 0 3 2 2 2 -> exec 6 cyc
- ; deco 5 cyc
+ ; 8 0 3 2 2 2 ->
+ ; exe 5.5
+ ; RAT 5.6...
+ ; Ret 6
+ ; Deco 7
Modified: trunk/2010/2_cryp_a.h
==============================================================================
--- trunk/2010/2_cryp_a.h (original)
+++ trunk/2010/2_cryp_a.h Wed Jul 4 10:42:04 2007
@@ -8,4 +8,6 @@ void VSmooth2RGB1555(int, int, int);
void Decomb1(int, int, int);
void Decomb2(int, int, int);
+void SetDecombInc(int);
+
#endif
Modified: trunk/2010/2_nag_a.asm
==============================================================================
--- trunk/2010/2_nag_a.asm (original)
+++ trunk/2010/2_nag_a.asm Wed Jul 4 10:42:04 2007
@@ -70,24 +70,26 @@ _nagraCorr__Fiiiii:
align16
MMXloop:
- psubusb mm2, mm1 ; p01wMM2rMM1MM2 0
- psubusb mm1, mm0 ; p01wMM1rMM0MM1 1
- por mm2, mm1 ; p01wMM2rMM1MM2 0
- movq mm0, [esp + esi + 8] ; p2 wMM0rESPESI 1
- paddusb mm2, mm6 ; p01wMM2rMM6MM2 1
- movq mm4, mm2 ; p01wMM4rMM2 0
- punpcklbw mm2, mm3 ; p1 wMM2rMM3MM2 1
- punpckhbw mm4, mm3 ; p1 wMM4rMM3MM4 (1)
- paddusw mm5, mm2 ; p01wMM5rMM2MM5 1
- paddusw mm5, mm4 ; p01wMM5rMM4MM5 (1)
- movq mm2, mm0 ; p01wMM2rMM0 0
- movq mm1, [esp + edi + 8] ; p2 wMM1rESPEDI 2
- add esp, byte 8 ; p01wESPrESP 1
- jnc MMXloop ; p1 rFLAG
- ; 5+ cyc deco
+;int3
+ psubusb mm2, mm1 ; 3p01wMM2rMM1MM2 FD0
+ psubusb mm1, mm0 ; 3p01wMM1rMM0MM1 FD1
+ por mm2, mm1 ; 3p01wMM2rMM1MM2 FD2
+ movq mm0, [esp + esi + 8] ; 5p2 wMM0rESPESI F D0
+ paddusb mm2, mm6 ; 3p01wMM2rMM6MM2 fF D0
+ movq mm4, mm2 ; 3p01wMM4rMM2 F D1
+ punpcklbw mm2, mm3 ; 3p1 wMM2rMM3MM2 F D2
+ punpckhbw mm4, mm3 ; 3p1 wMM4rMM3MM4 F D0
+ paddusw mm5, mm2 ; 3p01wMM5rMM2MM5 F D1
+ paddusw mm5, mm4 ; 3p01wMM5rMM4MM5 fF D0
+ movq mm2, mm0 ; 3p01wMM2rMM0 F D1
+ movq mm1, [esp + edi + 8] ; 5p2 wMM1rESPEDI F D2
+ add esp, byte 8 ; 3p01wESPrESP F D0
+ jnc MMXloop ; 2p1 rFLAG F D1
+ ; 6 cyc deco
; 5- cyc rat
- ; 6 cyc exec (0/1 satur)
-
+ ; 6 cyc exec (0/1 satur) 9 0 3 2 0 0
+ ; 5 cyc ret
+ ; -> 6 cyc
psubusb mm2, mm1
psubusb mm1, mm0
Modified: trunk/2010/2_vc.h
==============================================================================
--- trunk/2010/2_vc.h (original)
+++ trunk/2010/2_vc.h Wed Jul 4 10:42:04 2007
@@ -3,5 +3,20 @@
#define n2_vc_h
void vc_decrypt(void);
+void saveVCCache(void);
+
+struct CutPCache{
+ byte *pbCCutP;
+ CutPCache *pNext;
+ CutPCache *pPrev;
+ int iScore;
+ int nUsed;
+ int nbCCutP;
+};
+
+struct CutPLut{
+ CutPCache *pCutPCache;
+ CutPLut *pNext;
+};
#endif
Modified: trunk/2010/2_vc_a.asm
==============================================================================
--- trunk/2010/2_vc_a.asm (original)
+++ trunk/2010/2_vc_a.asm Wed Jul 4 10:42:04 2007
@@ -198,26 +198,32 @@ _vc_corr_mmx__Fiiiiii:
align16
MMXLoop:
- movq mm2, [ecx + esi ] ;0p2 wMM0rECXESI 1
- psubusb mm0, mm1 ; p01wMM0rMM1MM0 0
- psubusb mm1, mm2 ; p01wMM1rMM2MM1 0
- movq mm3, [ecx + edi + 8 ] ;0p2 wMM3rECXEDI 1
- por mm1, mm0 ; p01wMM1rMM0MM1 0
- movq mm0, [ecx + esi + 8 ] ; p2 wMM0rECXESI 1
- psrlq mm3, mm6 ;0p0 wMM3rMM6 1
- movq mm2, mm1 ; p01wMM2rMM1 0
- punpcklbw mm1, mm4 ; p0 wMM1rMM4MM1 1
- punpckhbw mm2, mm4 ;0p0 wMM2rMM4MM2 10
- paddusw mm7, mm1 ; p01wMM7rMM1MM7 1
- paddusw mm7, mm2 ; p01wMM7rMM2MM7 10
- movq mm1, [ecx + edi + 16] ;0p2 wMM1rECXEDI 2
- psllq mm1, mm5 ; p0 wMM1rMM5 1
- por mm1, mm3 ; p01wMM1rMM3MM1 1?
- add ecx, byte 8 ;0p01wECXrECX 1
- jnc MMXLoop ; p1 rFLAG
-; 8 4 1 4 7 cyc asy
-; 6+ cyc deco
-; 7 cyc rat
+ movq mm2, [ecx + esi ] ;4p2 wMM2rECXESI FD0 FD0
+; db 0x3E
+; dd 0x31946F0F
+; dd 0x00000000
+; db 0x3E
+
+ psubusb mm0, mm1 ;3p01wMM0rMM1MM0 FD1 FD1
+ psubusb mm1, mm2 ;3p01wMM1rMM2MM1 FD2 FD2
+ movq mm3, [ecx + edi + 8 ] ;5p2 wMM3rECXEDI F D0 FD0
+ por mm1, mm0 ;3p01wMM1rMM0MM1 fF D0 FD1
+ movq mm0, [ecx + esi + 8 ] ;5p2 wMM0rECXESI F D1 FD2
+ psrlq mm3, mm6 ;3p1 wMM3rMM6 F D2 F D0
+ movq mm2, mm1 ;3p01wMM2rMM1 F D0 F D0
+ punpcklbw mm1, mm4 ;3p1 wMM1rMM4MM1 fF D0 F D1
+ punpckhbw mm2, mm4 ;3p1 wMM2rMM4MM2 F D1 F D2
+ paddusw mm7, mm1 ;3p01wMM7rMM1MM7r F D2 F D0
+ paddusw mm7, mm2 ;3p01wMM7rMM2MM7r F D0 F D1
+ movq mm1, [ecx + edi + 16] ;5p2 wMM1rECXEDIr fF D0 fF D0
+ psllq mm1, mm5 ;3p1 wMM1rMM5 F D1 F D1
+ por mm1, mm3 ;3p01wMM1rMM3MM1 F D2 F D2
+ add ecx, byte 8 ;3p01wECXrECX F D0 F D0
+ jnc MMXLoop ;2p1 rFLAG F D1 F D1
+; 6.5 cyc exe 8 0 5 4 0 0
+; 6.7 cyc RAT
+; 8->7 cyc Deco
+; 6 cyc Ret
skipMMX1:
@@ -262,23 +268,32 @@ skipMMX1:
align16
MMXLoop2:
- movq mm2, [ecx + esi ] ;0p2 wMM0rECXESI 1
- psubusb mm0, mm1 ; p01wMM0rMM1MM0 0
- psubusb mm1, mm2 ; p01wMM1rMM2MM1 0
- movq mm3, [ecx + edi + 8 ] ;0p2 wMM3rECXEDI 1
- por mm1, mm0 ; p01wMM1rMM0MM1 0
- movq mm0, [ecx + esi + 8 ] ; p2 wMM0rECXESI 1
- psrlq mm3, mm6 ;0p0 wMM3rMM6 1
- movq mm2, mm1 ; p01wMM2rMM1 0
- punpcklbw mm1, mm4 ; p0 wMM1rMM4MM1 1
- punpckhbw mm2, mm4 ;0p0 wMM2rMM4MM2 10
- paddusw mm7, mm1 ; p01wMM7rMM1MM7 1
- paddusw mm7, mm2 ; p01wMM7rMM2MM7 10
- movq mm1, [ecx + edi + 16] ;0p2 wMM1rECXEDI 2
- psllq mm1, mm5 ; p0 wMM1rMM5 1
- por mm1, mm3 ; p01wMM1rMM3MM1 1?
- add ecx, byte 8 ;0p01wECXrECX 1
- jnc MMXLoop2 ; p1 rFLAG
+ movq mm2, [ecx + esi ] ;4p2 wMM2rECXESI FD0 FD0
+; db 0x3E
+; dd 0x31946F0F
+; dd 0x00000000
+; db 0x3E
+
+ psubusb mm0, mm1 ;3p01wMM0rMM1MM0 FD1 FD1
+ psubusb mm1, mm2 ;3p01wMM1rMM2MM1 FD2 FD2
+ movq mm3, [ecx + edi + 8 ] ;5p2 wMM3rECXEDI F D0 FD0
+ por mm1, mm0 ;3p01wMM1rMM0MM1 fF D0 FD1
+ movq mm0, [ecx + esi + 8 ] ;5p2 wMM0rECXESI F D1 FD2
+ psrlq mm3, mm6 ;3p1 wMM3rMM6 F D2 F D0
+ movq mm2, mm1 ;3p01wMM2rMM1 F D0 F D0
+ punpcklbw mm1, mm4 ;3p1 wMM1rMM4MM1 fF D0 F D1
+ punpckhbw mm2, mm4 ;3p1 wMM2rMM4MM2 F D1 F D2
+ paddusw mm7, mm1 ;3p01wMM7rMM1MM7r F D2 F D0
+ paddusw mm7, mm2 ;3p01wMM7rMM2MM7r F D0 F D1
+ movq mm1, [ecx + edi + 16] ;5p2 wMM1rECXEDIr fF D0 fF D0
+ psllq mm1, mm5 ;3p1 wMM1rMM5 F D1 F D1
+ por mm1, mm3 ;3p01wMM1rMM3MM1 F D2 F D2
+ add ecx, byte 8 ;3p01wECXrECX F D0 F D0
+ jnc MMXLoop2 ;2p1 rFLAG F D1 F D1
+; 6.5 cyc exe 8 0 5 4 0 0
+; 6.7 cyc RAT
+; 8->7 cyc Deco
+; 6 cyc Ret
skipMMX2:
1
0
[mndiff]: r59 - in trunk/2010: 2010.cpp 2_all_a.asm 2_cryp_a.asm 2_cryp_a.h 2_crypt.cpp 2_glob_a.asm 2_hw.cpp 2_hw_a.asm 2_hw_a.h 2_hw_mem.cpp 2_nag.cpp 2_nag_a.asm 2_vc.cpp 2_vc_a.asm makefile
by michael 04 Jul '07
by michael 04 Jul '07
04 Jul '07
Author: michael
Date: Wed Jul 4 10:39:35 2007
New Revision: 59
Log:
next version from unknown date
Added:
trunk/2010/2_hw_a.asm
trunk/2010/2_hw_a.h
Modified:
trunk/2010/2010.cpp
trunk/2010/2_all_a.asm
trunk/2010/2_cryp_a.asm
trunk/2010/2_cryp_a.h
trunk/2010/2_crypt.cpp
trunk/2010/2_glob_a.asm
trunk/2010/2_hw.cpp
trunk/2010/2_hw_mem.cpp
trunk/2010/2_nag.cpp
trunk/2010/2_nag_a.asm
trunk/2010/2_vc.cpp
trunk/2010/2_vc_a.asm
trunk/2010/makefile
Modified: trunk/2010/2010.cpp
==============================================================================
--- trunk/2010/2010.cpp (original)
+++ trunk/2010/2010.cpp Wed Jul 4 10:39:35 2007
@@ -1,3 +1,4 @@
+
//2010 0.1 Copyright (c) 1998 Michael Niedermayer
#include <stdlib.h>
@@ -55,7 +56,7 @@ int _crt0_startup_flags = _CRT0_FLAG_NEA
byte font[4096];
int vid=0;
int bpp;
- int *yuv2RgbLut;
+ unsigned short *yuv2RgbLut;
int edge_lut[256];
MENULEVEL menuLevel=mLNorm;
int infoPosX;
@@ -174,7 +175,8 @@ int main(int argc, char **argv){
NoFlip=1;
}
else if(stricmp(argv[i],"-NORGB")==0){
- yuvMode=2;
+ yuvMode=
+ grabYuvMode=2;
}
else if(stricmp(argv[i],"-maxBuf")==0){
i++;
@@ -228,35 +230,23 @@ int main(int argc, char **argv){
}
printf("Building YUV to RGB LookUp Tables!\n");
- yuv2RgbLut=new int[128*4*2];
- for(int i=0; i<128; i++){
- int j;
- if(i>=64) j=i-128;
- else j=i;
- double uv= double(j);
-
- int vr= int( uv * 1.375 ) & 0x1FF;
- int vg= int(-uv * 0.703125 * 2) & 0x3FF;
- int ug= int(-uv * 0.34375 * 2) & 0x3FF;
- int ub= int( uv * 1.734375 ) & 0x1FF;
- int yn= i;
- int yg= i<<1;
-
-// 565565
-// 655655
+ yuv2RgbLut=new unsigned short[256*128];
+ for(int u=-16; u<=15; u++)
+ {
+ for(int v=-16; v<=15; v++)
+ {
+ for(int y=0; y<=31; y++)
+ {
+ int r= minmax(0, int( y + double(v) * 1.375 ), 31);
+ int g= minmax(0, int((y - double(v) * 0.703 - double(u) * 0.343)*2), 63);
+ int b= minmax(0, int( y + double(u) * 1.734 ), 31);
-// B R G
-// G B R
+ const int xLut= y + ((u&0x1F)<<5) + ((v&0x1F)<<10);
+ yuv2RgbLut[ xLut ]= b + (g<<5) + (r<<11);
- yuv2RgbLut[(i<<1) ]= ub +(ug<<21) ;
- yuv2RgbLut[(i<<1) + 1 ]= ug +(ub<<11) ;
- yuv2RgbLut[(i<<1) + 256 ]= yn +(yn<<11) ;
- yuv2RgbLut[(i<<1) + 257 ]= yg ;
- yuv2RgbLut[(i<<1) + 512 ]= (vr<<11) +(vg<<21) ;
- yuv2RgbLut[(i<<1) + 513 ]= vg +(vr<<22);
- yuv2RgbLut[(i<<1) + 768 ]= +(yg<<21) ;
- yuv2RgbLut[(i<<1) + 769 ]= +(yn<<11) +(yn<<22);
- }
+ }
+ }
+ }
if((vib=get_vesa_info())==0) error(NoVESA);
if(vib->ver < 0x200) error(VESAVer);
@@ -294,11 +284,6 @@ int main(int argc, char **argv){
vgax=mib->Xres;
vgay=mib->Yres;
-/* if(yuvMode!=0) mc=1;
- else mc=2;
- if(yuvMode==2) mc2=1;
- else mc2=2;
-*/
mc=mc2=1;
xresc=vgax<<mc;
bpp=mib->bpp;
@@ -436,7 +421,7 @@ int main(int argc, char **argv){
case 'I' : iState= !iState;
break;
case 'v' :
- case 'V' : iVSmooth++; iVSmooth%=3;
+ case 'V' : iVSmooth++; iVSmooth%=3;
break;
case 'h' :
case 'H' : helpState= !helpState;
@@ -531,7 +516,7 @@ int main(int argc, char **argv){
cryptStd= vc;
if(yuvMode==0) yuvMode=1;
grabYuvMode=yuvMode;
- iVSmooth=0;
+// iVSmooth=2;
setStdScale();
contGrab();
break;
@@ -539,7 +524,7 @@ int main(int argc, char **argv){
cryptStd= nag;
if(yuvMode==0) yuvMode=1;
grabYuvMode=yuvMode;
- iVSmooth=0;
+// iVSmooth=2;
setStdScale();
contGrab();
break;
Modified: trunk/2010/2_all_a.asm
==============================================================================
--- trunk/2010/2_all_a.asm (original)
+++ trunk/2010/2_all_a.asm Wed Jul 4 10:39:35 2007
@@ -17,7 +17,38 @@
;%define int3 db 0xCC
+%define lt(a,b) ( ((a)-(b)) >>31)
+%define gt(a,b) ( ((b)-(a)) >>31)
+%define le(a,b) ( ((a)-(b)-1) >>31)
+%define ge(a,b) ( ((b)-(a)-1) >>31)
+%define eq(a,b) (ge(a,b) & le(a,b))
+
+
%define align2 times ($$-$) & 1 nop
-%define align4 times ($$-$) & 3 nop
-%define align8 times ($$-$) & 7 nop
-%define align16 times ($$-$) & 15 nop
+;%define align4 times ($$-$) & 3 nop
+;%define align8 times ($$-$) & 7 nop
+;%define align16 times ($$-$) & 15 nop
+
+%macro align4 0
+ times ge(($$-$)&3, 3) cmp ebx, byte 0
+ times ge(($$-$)&3, 2) cmp ebx, ebx
+ times ge(($$-$)&3, 1) nop
+%endmacro
+
+%macro align8 0
+ times ge(($$-$)&7, 6) cmp ebx, 0
+ times ge(($$-$)&7, 5) cmp eax, 0
+ times ge(($$-$)&7, 3) cmp ebx, byte 0
+ times ge(($$-$)&7, 2) cmp ebx, ebx
+ times ge(($$-$)&7, 1) nop
+%endmacro
+
+%macro align16 0
+ times eq(($$-$)&15, 10) cmp eax, 0
+ times ge(($$-$)&15, 6) cmp ebx, 0
+ times ge(($$-$)&15, 6) cmp ebx, 0
+ times ge(($$-$)&15, 5) cmp eax, 0
+ times ge(($$-$)&15, 3) cmp ebx, byte 0
+ times ge(($$-$)&15, 2) cmp ebx, ebx
+ times ge(($$-$)&15, 1) nop
+%endmacro
Modified: trunk/2010/2_cryp_a.asm
==============================================================================
--- trunk/2010/2_cryp_a.asm (original)
+++ trunk/2010/2_cryp_a.asm Wed Jul 4 10:39:35 2007
@@ -1,11 +1,13 @@
-;2010 0.1 Copyright (C) Michael Niedermayer 1998
+;2010 0.1 Copyright (C) Michael Niedermayer 1999
%include "2_all_a.asm"
-segment .data
+segment .data
global _VSmooth1RGB1555__Fiii
global _VSmooth2RGB1555__Fiii
+global _Decomb1__Fiii
+global _Decomb2__Fiii
%define pBuf1 par1
%define iVgaX21 par2
@@ -15,6 +17,109 @@ global _VSmooth2RGB1555__Fiii
%define iVgaX22 par3
%define nOp2 par4
+%define pYuv3 par1
+%define nOp3 par2
+%define pBuf3 par3
+
+_Decomb1__Fiii:
+ push eax
+ push ebx
+
+ push ecx
+ push edx
+
+ push esi
+ push edi
+
+ mov esi, [pYuv3]
+ mov edi, [pBuf3]
+ mov ecx, [nOp3]
+ add esi, ecx
+ add edi, ecx
+ xor ecx, byte -1
+ inc ecx
+
+ movq mm7, [decombInc]
+align16
+Decomb1Loop:
+ movq mm0, [esi + ecx]
+ psllw mm0, 8
+ movq mm2, [edi + ecx]
+ psubsw mm0, mm2
+ pcmpgtw mm2, mm0
+ pand mm2, mm7
+ paddsw mm0, mm2
+ movq [edi + ecx], mm0
+ add ecx, byte 8
+ jnc Decomb1Loop
+
+ pop edi
+ pop esi
+
+ pop edx
+ pop ecx
+
+ pop ebx
+ pop eax
+
+ret
+
+_Decomb2__Fiii:
+ push eax
+ push ebx
+
+ push ecx
+ push edx
+
+ push esi
+ push edi
+
+ mov esi, [pYuv3]
+ mov edi, [pBuf3]
+ mov ecx, [nOp3]
+ add esi, ecx
+ add edi, ecx
+ xor ecx, byte -1
+ inc ecx
+
+ movq mm6, [decombYMask]
+ movq mm7, [decombInc]
+align16
+Decomb2Loop:
+ movq mm0, [esi + ecx] ;0p2 wMM0rESIECX 1
+ movq mm1, mm0 ; p01wMM1rMM0 0 test mov mem
+ pand mm1, mm6 ; p01wMM1rMM6MM1 1
+ psllw mm0, 8 ;0p1 wMM0rMM0 0
+ movq mm2, [edi + ecx] ; p2 wMM2rEDIECX 1
+ psubsw mm0, mm2 ; p01wMM0rMM2MM0 0
+ pcmpgtw mm2, mm0 ;0p01wMM2rMM0MM2 0
+ pand mm2, mm7 ; p01wMM2rMM7MM2 1
+ paddsw mm0, mm2 ; p01wMM0rMM2MM0 0
+ movq [edi + ecx], mm0 ;0p3 rEDIECX 2 p4 rMM0 0
+ psrlw mm0, 7 ; p1 wMM0rMM0 0
+ por mm1, mm0 ; p01wMM1rMM0MM1 ?0
+ movq [esi + ecx], mm1 ;0p3 rESIECX 2 p4 rMM1 0
+ add ecx, byte 8 ; p01wECXrECX (1)
+ jnc Decomb2Loop ; p1 rFLAG 0
+
+ ; 8 0 3 2 2 2 -> exec 6 cyc
+ ; deco 5 cyc
+
+
+
+
+ pop edi
+ pop esi
+
+ pop edx
+ pop ecx
+
+ pop ebx
+ pop eax
+
+ret
+
+
_VSmooth1RGB1555__Fiii:
push eax
push ebx
@@ -26,12 +131,12 @@ _VSmooth1RGB1555__Fiii:
push edi
mov esi, [pBuf1]
- add esi, 8
+ add esi, byte 8
mov ecx, [nOp1]
add esi, ecx
- xor ecx, -1
+ xor ecx, byte -1
mov ebx, [iVgaX21]
inc ecx
@@ -51,6 +156,7 @@ _VSmooth1RGB1555__Fiii:
; more opt possible (+2reg -1psrlw)
+align16
MMXLoop1:
movq mm5, mm0
movq mm4, mm1
@@ -88,7 +194,7 @@ MMXLoop1:
movq mm1, [ebx+ecx+8]
por mm3, mm5
- add ecx, 8
+ add ecx, byte 8
jnc MMXLoop1
pop edi
@@ -100,8 +206,6 @@ MMXLoop1:
pop ebx
pop eax
- emms
-
ret
_VSmooth2RGB1555__Fiii:
@@ -118,10 +222,10 @@ _VSmooth2RGB1555__Fiii:
mov esi, [pBuf2]
- add esi, 8
+ add esi, byte 8
mov ebp, [nOp2]
- xor ebp, -1
+ xor ebp, byte -1
mov ebx, [iVgaX22]
add esi, ebx
@@ -139,7 +243,7 @@ _VSmooth2RGB1555__Fiii:
mov ecx, eax
add edi, esi
- xor ecx, -1
+ xor ecx, byte -1
inc ecx
@@ -148,6 +252,7 @@ _VSmooth2RGB1555__Fiii:
movq mm7, [mask2]
; lots of optimize possible
+align16
MMXLoop2:
;AGI
movq mm0, [esi+ecx]
@@ -199,12 +304,14 @@ MMXLoop2:
pop ebx
pop eax
- emms
-
ret
-xyz times 8 dd 0
+xyz times 8 dd 0
align8
mask1 times 2 dd 0x7C1F03E0
mask2 times 2 dd 0x03E07C1F
+decombInc times 2 dd 0x01000100
+decombYMask times 2 dd 0xFF00FF00
+
+align16
Modified: trunk/2010/2_cryp_a.h
==============================================================================
--- trunk/2010/2_cryp_a.h (original)
+++ trunk/2010/2_cryp_a.h Wed Jul 4 10:39:35 2007
@@ -5,4 +5,7 @@
void VSmooth1RGB1555(int, int, int);
void VSmooth2RGB1555(int, int, int);
+void Decomb1(int, int, int);
+void Decomb2(int, int, int);
+
#endif
Modified: trunk/2010/2_crypt.cpp
==============================================================================
--- trunk/2010/2_crypt.cpp (original)
+++ trunk/2010/2_crypt.cpp Wed Jul 4 10:39:35 2007
@@ -5,6 +5,7 @@
#include <time.h>
#include "2_all.h"
#include "2_crypt.h"
+#include "2_hw_mem.h"
#include "2_cryp_a.h"
#include "2_vc.h"
#include "2_nag.h"
@@ -30,7 +31,7 @@ extern int some;
static void VSmooth(void);
static void Decomb(int q);
-int iVSmooth=1;
+int iVSmooth=2;
bool showPoints=false;
asm("__esp: .long 0\n\t");
@@ -82,149 +83,35 @@ void decrypt(void){
static void Decomb(int q){
- int temp[max_x];
+ int *temp= (int*)newAlign(max_x * sizeof(int), 8);
const int outy1= outy>>1;
const int stride=oneField ? (vgax<<1) : (vgax<<2);
const int o=oneField ? 0 : 1;
const int end=oneField ? outy : outy1;
- for(int i=0; i<wndx; i++) temp[i]=128<<8;
+// for(int i=0; i<wndx; i++) temp[i]=128<<8;
+ for(int i=0; i<wndx; i++) temp[i]=0;
if(q==1){
int linep= stride*256;
if(o) linep+=vgax<<1;
for(int line=256; line>=0; line--){
- asm(//"int $3 \n\t"
- "pushl %%ebp \n\t" //U
- "movl %%eax, %%ebp \n\t" // V 1
- "addl %%ebp, %%edi \n\t" //U
- "addl %%ebp, %%esi \n\t" // V 1
- "addl %%ebp, %%esi \n\t" //U 1
- "negl %%ebp \n\t" //UV 1
- "1: \n\t"
- "xorl %%eax, %%eax \n\t" //U
- "xorl %%ebx, %%ebx \n\t" // V 1
- "movb (%%edi, %%ebp ), %%al \n\t" //U
- "movb 2(%%edi, %%ebp ), %%bl \n\t" // V 1
- "addb $128, %%al \n\t" //U
- "addb $128, %%bl \n\t" // V 1
- "shll $9, %%eax \n\t" //U
- "movl (%%esi, %%ebp, 2), %%ecx \n\t" // V 1
- "shll $9, %%ebx \n\t" //U
- "subl %%ecx, %%eax \n\t" // V 1
- "movl 4(%%esi, %%ebp, 2), %%edx \n\t" //U
- "cmpl %%ecx, %%eax \n\t" // V 1
- "sbbl %%ecx, %%ecx \n\t" //U
- "subl %%edx, %%ebx \n\t" // V 1
- "andl %0, %%ecx \n\t" //U
- "cmpl %%edx, %%ebx \n\t" // V 1
- "sbbl %%edx, %%edx \n\t" //U
- "addl %%ecx, %%eax \n\t" // V 1
- "andl %0, %%edx \n\t" //U
- "movl %%eax, (%%esi, %%ebp, 2) \n\t" // V 1
- "addl %%edx, %%ebx \n\t" //U 1
- "movl %%ebx, 4(%%esi, %%ebp, 2) \n\t" //U
-
- "addl $4, %%ebp \n\t" // V 1
- " jnc 1b \n\t" //U 1
- "popl %%ebp \n\t" //U
- :
- : "i" (COMB_FIX), "a" ((wndx<<1) - 2),
- "D" (actVid2MemBufp->b + linep + 2), "S" (int(temp) + 4)
- : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi");
- linep-=stride;
+ Decomb1(int(actVid2MemBufp->b + linep), (wndx<<1), int(temp));
+ linep-=stride;
}
}
int linep= 0;
if(o) linep+=vgax<<1;
for(int line=0; line<end; line++){
- asm(//"int $3 \n\t"
- "pushl %%ebp \n\t" //U
- "movl %%eax, %%ebp \n\t" // V 1
- "addl %%ebp, %%edi \n\t" //U
- "addl %%ebp, %%esi \n\t" // V 1
- "addl %%ebp, %%esi \n\t" //U 1
- "negl %%ebp \n\t" //UV 1
- "1: \n\t"
- "xorl %%eax, %%eax \n\t" //U
- "xorl %%ebx, %%ebx \n\t" // V 1
- "movb (%%edi, %%ebp ), %%al \n\t" //U
- "movb 2(%%edi, %%ebp ), %%bl \n\t" // V 1
- "addb $128, %%al \n\t" //U
- "addb $128, %%bl \n\t" // V 1
- "shll $9, %%eax \n\t" //U
- "movl (%%esi, %%ebp, 2), %%ecx \n\t" // V 1
- "shll $9, %%ebx \n\t" //U
- "subl %%ecx, %%eax \n\t" // V 1
- "movl 4(%%esi, %%ebp, 2), %%edx \n\t" //U
- "cmpl %%ecx, %%eax \n\t" // V 1
- "sbbl %%ecx, %%ecx \n\t" //U
- "subl %%edx, %%ebx \n\t" // V 1
- "andl %0, %%ecx \n\t" //U
- "cmpl %%edx, %%ebx \n\t" // V 1
- "sbbl %%edx, %%edx \n\t" //U
- "addl %%ecx, %%eax \n\t" // V 1
- "andl %0, %%edx \n\t" //U
- "movl %%eax, (%%esi, %%ebp, 2) \n\t" // V 1
- "addl %%edx, %%ebx \n\t" //U
- "subb $128, %%ah \n\t" // V 1
- "movl %%ebx, 4(%%esi, %%ebp, 2) \n\t" //U
- "subb $128, %%bh \n\t" // V 1
- "movb %%ah, (%%edi, %%ebp ) \n\t" //U
- "movb %%bh, 2(%%edi, %%ebp ) \n\t" // V 1
-
- "addl $4, %%ebp \n\t" //U
- " jnc 1b \n\t" // V 1
- "popl %%ebp \n\t" //U
- :
- : "i" (COMB_FIX), "a" ((wndx<<1) - 2),
- "D" (actVid2MemBufp->b + linep + 2), "S" (int(temp) + 4)
- : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi");
+ Decomb2(int(actVid2MemBufp->b + linep), (wndx<<1), int(temp));
linep+=stride;
}
+ asm("emms\n\t");
-
-
-/*
- asm(//"int $3 \n\t"
- "1: \n\t"
- "movl (%%esi ), %%eax \n\t" //U LINE-1
- "movl (%%esi,%%edi), %%ebx \n\t" // V 1 LINE
- "movl %%ebx, %%ecx \n\t" //U
- "andl $0x00FF00FF, %%eax \n\t" // V 1
- "andl $0x00FF00FF, %%ebx \n\t" //U
- "addl $0x00800080, %%eax \n\t" // V 1
- "xorl $0x00800080, %%eax \n\t" //U
- "addl %%ebx, %%ebx \n\t" // V 1
- "orl $0x02000200, %%ebx \n\t" //U
- "andl $0xFF00FF00, %%ecx \n\t" // V 1
- "subl %%eax, %%ebx \n\t" //U
- "addl $4, %%esi \n\t" // V 1
- "movl %%ebx, %%eax \n\t" //U
- "andl $0x01F801F8, %%ebx \n\t" // V 1
- "shrl $3, %%ebx \n\t" //U
- "nop \n\t" // V 1 FIX ME
- "addl $0x00600060, %%ebx \n\t" //U
- "nop \n\t" // V 1 FIX ME
- "xorl $0x00600060, %%ebx \n\t" //U
- "nop \n\t" // V 1 FIX ME
- "subl %%ebx, %%eax \n\t" //U
- "nop \n\t" // V 1 FIX ME
- "andl $0x00FF00FF, %%eax \n\t" //U
- "nop \n\t" // V 1 FIX ME
- "orl %%ecx, %%eax \n\t" //U
- "decl %%edx \n\t" // V 1
- "movl %%eax, -4(%%esi, %%edi)\n\t" //U
- " jnz 1b \n\t" // V 1
-
- :
- : "D" (oneField ? (vgax<<1) : (vgax<<2)), "S" (actVid2MemBufp->b),
- "d" (vgax * wndy>>1)
- : "%eax", "%ebx", "%ecx", "%edx", "%esi");
- */
+ deleteAlign(temp);
}
static void VSmooth(void){
@@ -236,40 +123,5 @@ static void VSmooth(void){
else
VSmooth2RGB1555(int(actVid2MemBufp->b), vgax<<1, vgax*(wndy-3)<<1);
}
-/*
- else{
- asm(//"int $3 \n\t"
- "1: \n\t"
- "movl (%%esi ), %%eax \n\t" //U LINE
- "movl (%%esi,%%edi,2), %%ebx \n\t" // V 1 LINE + 2
- "shrl $2, %%eax \n\t" //U
- "andl $0xFCFCFCFC, %%ebx \n\t" // V 1
- "shrl $2, %%ebx \n\t" //U
- "andl $0x3F3F3F3F, %%eax \n\t" // V 1
- "addl $0x00200020, %%eax \n\t" //U
- "addl $0x00200020, %%ebx \n\t" // V 1
- "xorl $0x00200020, %%eax \n\t" //U
- "xorl $0x00200020, %%ebx \n\t" // V 1
- "addl %%eax, %%ebx \n\t" //U
- "movl (%%esi,%%edi ), %%eax \n\t" // V 1 LINE + 1
- "shrl $1, %%eax \n\t" //U
- "andl $0x7F7F7F7F, %%ebx \n\t" // V 1
- "andl $0x7F7F7F7F, %%eax \n\t" //U
- "addl $0x00400040, %%ebx \n\t" // V 1
- "addl $0x00400040, %%eax \n\t" //U
- "xorl $0x00400040, %%ebx \n\t" // V 1
- "xorl $0x00400040, %%eax \n\t" //U
- "addl $4, %%esi \n\t" // V 1
- "addl %%eax, %%ebx \n\t" //U
- "decl %%ecx \n\t" // V 1
- "movl %%ebx, -4(%%esi ) \n\t" //U LINE
- " jnz 1b \n\t" // V 1
- :
- : "D" (vgax<<1), "S" (actVid2MemBufp->b),
- "c" (vgax * (wndy-2) >> 1)
- : "%eax", "%ebx", "%ecx", "%esi");
-
-
- }
- */
+ asm("emms\n\t");
}
Modified: trunk/2010/2_glob_a.asm
==============================================================================
--- trunk/2010/2_glob_a.asm (original)
+++ trunk/2010/2_glob_a.asm Wed Jul 4 10:39:35 2007
@@ -12,7 +12,7 @@ global _asm_temp4
segment .bss
-align4
+;align4
esp_save resd 1
_asm_temp resd 1
Modified: trunk/2010/2_hw.cpp
==============================================================================
--- trunk/2010/2_hw.cpp (original)
+++ trunk/2010/2_hw.cpp Wed Jul 4 10:39:35 2007
@@ -11,6 +11,7 @@
#include <time.h>
#include "2_all.h"
#include "2_hw.h"
+#include "2_hw_a.h"
#include "2_hw_asm.h"
#include "2_hw_mem.h"
#include "2_71x6.h"
@@ -26,13 +27,13 @@
extern volatile AllocList *alloclist;
extern volatile VID2MEMBUF *vid2MemBuf, *actVid2MemBufp;
extern volatile int grabVid2MemBuf, actVid2MemBuf;
- extern volatile int one_field;
+ extern volatile bool oneField;
extern volatile int active_meteor;
extern volatile meteor meteors[8];
extern volatile int fields;
extern byte *vidbuf;
- extern int vgax, vgay, xresc, xresvb, vb, mc, wndy, wndx;
- extern int *yuv2RgbLut;
+ extern int vgax, vgay, xresc, xresvb, vb, mc, wndy, wndx, outy;
+ extern unsigned short *yuv2RgbLut;
extern int single;
extern int in_int;
extern volatile int frames;
@@ -40,6 +41,7 @@
extern bool iState;
extern int infoPosX, infoPosY;
extern TVSTD TVStd;
+ extern int iVSmooth;
bool drop=false;
bool allowDrop=true;
@@ -51,133 +53,13 @@
int VID2MEMBUF::num;
-void mem2vid(byte *to, byte *from, int num, int bpp){
+void mem2vid(byte *to, byte *from, int num, int bpp, int y){
if(yuvMode!=0){
- asm(//"int $3 \n\t"
- "pushl %%ebp \n\t"
- "movl %%eax, %%ebp \n\t"
- "movl %%esp, (__esp) \n\t"
-
- "addl %%ecx, %%esi \n\t"
- "addl %%ecx, %%edi \n\t"
- "negl %%ecx \n\t"
- "movl (%%esi, %%ecx), %%eax \n\t"
- "movl %%esi, (__temp1) \n\t"
-
- "1: \n\t"
- "movl %%eax, %%edx \n\t"
- "andl $0xFE, %%eax \n\t"
-
- "movl %%edx, %%ebp \n\t"
- "andl $0xFE00, %%edx \n\t"
-
- "shrl $8, %%edx \n\t"
- "movl (%%ebx, %%eax, 4), %%esp \n\t"
-
- "shrl $16, %%ebp \n\t"
- "movl 4(%%ebx, %%eax, 4), %%eax \n\t"
-
- "movl 1024(%%ebx, %%edx, 4), %%esi \n\t"
- "movl 1028(%%ebx, %%edx, 4), %%edx \n\t"
-
- "addl %%esi, %%esp \n\t"
- "addl %%edx, %%eax \n\t"
-
- "movl %%ebp, %%edx \n\t"
- "andl $0xFE, %%ebp \n\t"
-
- "shrl $8, %%edx \n\t"
- "andl $0x7FEFF9FF, %%esp \n\t"
-
- "andl $0xFE, %%edx \n\t"
- "movl 2048(%%ebx, %%ebp, 4), %%esi \n\t"
-
- "andl $0x7FCFFBFF, %%eax \n\t"
- "movl 2052(%%ebx, %%ebp, 4), %%ebp \n\t"
-
- "addl %%esi, %%esp \n\t"
- "addl %%ebp, %%eax \n\t"
-
- "andl $0x7FEFF9FF, %%esp \n\t"
- "movl 3072(%%ebx, %%edx, 4), %%esi \n\t"
-
- "andl $0x7FCFFBFF, %%eax \n\t"
- "movl 3076(%%ebx, %%edx, 4), %%edx \n\t"
-
- "addl %%esi, %%esp \n\t"
- "addl %%edx, %%eax \n\t"
-
- "test $0x600C0180, %%esp \n\t"
- " jz 2f \n\t"
-
- "movl %%esp, %%esi \n\t"
- "movl %%esp, %%edx \n\t"
-
- "shrl $7, %%esi \n\t"
- "andl $0x40080100, %%edx \n\t"
-
- "shrl $8, %%edx \n\t"
- "andl $0x00400801, %%esi \n\t"
-
- "addl $0xEFDFFBFF, %%edx \n\t"
- "addl $0xEFDFFBFF, %%esi \n\t"
-
- "xorl $0x10200400, %%edx \n\t"
- "xorl $0xEFDFFBFF, %%esi \n\t"
-
- "orl %%esi, %%esp \n\t"
-
- "andl %%edx, %%esp \n\t"
-
- "2: \n\t"
- "test $0x600C0300, %%eax \n\t"
- " jz 3f \n\t"
-
- "movl %%eax, %%esi \n\t"
- "movl %%eax, %%edx \n\t"
-
- "shrl $8, %%esi \n\t"
- "andl $0x40080200, %%edx \n\t"
-
- "shrl $9, %%edx \n\t"
- "andl $0x00200401, %%esi \n\t"
-
- "addl $0xEFEFFDFF, %%edx \n\t"
- "addl $0xEFEFFDFF, %%esi \n\t"
-
- "xorl $0x10100200, %%edx \n\t"
- "xorl $0xEFEFFDFF, %%esi \n\t"
-
- "orl %%esi, %%eax \n\t"
-
- "andl %%edx, %%eax \n\t"
-
- "3: \n\t"
-
- "shrl $2, %%esp \n\t"
- "movl (__temp1), %%esi \n\t"
-
- "shll $3, %%eax \n\t"
- "andl $0x07E0F81F, %%esp \n\t"
-
- "andl $0xF81F07E0, %%eax \n\t"
-
- "orl %%eax, %%esp \n\t"
-
- "movl %%esp, (%%edi, %%ecx) \n\t"
-
- "movl 4(%%esi, %%ecx), %%eax \n\t"
- "addl $4, %%ecx \n\t"
-
- "jnc 1b \n\t"
-
- "movl (__esp), %%esp \n\t"
- "popl %%ebp \n\t"
- :
- : "b" (yuv2RgbLut), "S" (from), "D" (to), "c" (num<<1)
- : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi");
-
+ if((y&1) && !oneField && wndy==outy)
+ CopyYuv2Rgb2(int(from), int(to), num<<1, int(yuv2RgbLut));
+ else
+ CopyYuv2Rgb1(int(from), int(to), num<<1, int(yuv2RgbLut));
}else{
if(strangeRgb16){
asm("addl %%ecx, %%esi \n\t"
@@ -316,13 +198,13 @@ void copy_vidbuffer(void){
if(page_flip==0){
int p=0;
for(int y=0; y<goody; y++){
- mem2vid(vidbuf+p, actVid2MemBufp->b+p, goodx, bpp);
+ mem2vid(vidbuf+p, actVid2MemBufp->b+p, goodx, bpp, y);
p+=vgax<<1;
}
}else if(page_flip==2){
int p=0;
for(int y=0; y<goody; y++){
- mem2vid(vidbuf+xresvb*vgay+p, actVid2MemBufp->b+p, goodx, bpp);
+ mem2vid(vidbuf+xresvb*vgay+p, actVid2MemBufp->b+p, goodx, bpp, y);
p+=vgax<<1;
}
page_flip=1;
@@ -330,7 +212,7 @@ void copy_vidbuffer(void){
}else{
int p=0;
for(int y=0; y<goody; y++){
- mem2vid(vidbuf+p, actVid2MemBufp->b+p, goodx, bpp);
+ mem2vid(vidbuf+p, actVid2MemBufp->b+p, goodx, bpp, y);
p+=vgax<<1;
}
page_flip=2;
@@ -339,6 +221,8 @@ void copy_vidbuffer(void){
}
drop=false;
+ asm("emms\n\t");
+
if(iState){
T2=uclock();
}
Added: trunk/2010/2_hw_a.asm
==============================================================================
--- (empty file)
+++ trunk/2010/2_hw_a.asm Wed Jul 4 10:39:35 2007
@@ -0,0 +1,231 @@
+;2010 0.1 Copyright (C) Michael Niedermayer 1999
+
+%include "2_all_a.asm"
+
+segment .data
+
+extern esp_save
+
+global _CopyYuv2Rgb1__Fiiii
+global _CopyYuv2Rgb2__Fiiii
+
+%define pYuv par2
+%define pRgb par3
+%define nOp par4
+%define pLut par5
+%define nbX par6
+
+_CopyYuv2Rgb1__Fiiii:
+ push eax
+ push ebx
+ push ecx
+ push edx
+ push esi
+ push edi
+ push ebp
+
+ mov [esp_save], esp
+
+ mov esi, [pYuv]
+ mov edi, [pRgb]
+ mov ecx, [nOp]
+ mov esp, [pLut]
+ add esi, ecx
+ add edi, ecx
+ xor ecx, byte -1
+ inc ecx
+
+ movq mm6, [uMask]
+ movq mm7, [vMask]
+align16
+CopyLoop1:
+ movq mm0, [esi+ecx] ;4p2 wMM0rESIECX 1 0 3
+ movq mm1, [esi+ecx] ;4p2 wMM1rESIECX 10 1 4
+ movq mm2, [esi+ecx] ;4p2 wMM2rESIECX 10 2 5
+
+ psrlw mm0, 11 ;4p1 wMM0rMM0 0 1
+ ;iFetch
+ pand mm1, mm6 ;3p01wMM1rMM6MM1 1 2
+ pand mm2, mm7 ;3p01wMM2rMM7MM2 1 3
+ pslld mm1, 2 ;4p1 wMM1rMM1 0 3
+
+ psrld mm2, 9 ;4p1 wMM2rMM2 0 4
+ ;iFetch
+ por mm1, mm2 ;3p01wMM1rMM2MM1 0 5
+ movq mm2, mm1 ;3p01wMM2rMM1 0
+ pslld mm1, 16 ;4p1 wMM1rMM1 0
+
+ por mm0, mm2 ;3p01wMM0rMM2MM0 0
+ por mm0, mm1 ;3p01wMM0rMM1MM0 ?0
+ ;iFetch
+ movd eax, mm0 ;3p01wEAXrMM0 0
+ movzx ebx, ax ;3p01wEBXrEAX 0
+ shr eax, 16 ;3p0 wEAXrEAX 0
+
+ movzx eax, word [esp + eax*2] ;4p2 wEAXrESPEAX 10
+ shl eax, 16 ;3p0 wEAXrEAX 0
+ ;iFetch
+ movzx ebx, word [esp + ebx*2] ;4p2 wEBXrESPEBX 1
+ psrlq mm0, 32 ;4p1 wMM0rMM0 0
+ or eax, ebx ;2p01wEAXrEBXEAX 0
+
+ mov [edi+ecx], eax ;3p3 rEDIECX 2 0 p4 rEAX 0
+ movd eax, mm0 ;3p01wMM0rMM1MM0 ?00
+ ;iFetch
+ movzx ebx, ax ;3p01wEBXrEAX 0
+ shr eax, 16 ;3p0 wEAXrEAX 0
+ movzx ebx, word [esp + ebx*2] ;4p2 wEBXrESPEBX 1
+
+ movzx eax, word [esp + eax*2] ;4p2 wEAXrESPEAX 10
+ ;iFetch
+ shl eax, 16 ;3p0 wEAXrEAX 0
+ or eax, ebx ;2p01wEAXrEBXEAX 0
+
+ mov [edi+ecx+4], eax ;3p3 rEDIECX 2 1 p4 rEAX 0
+ add ecx, byte 8 ;3p01wECXrECX 110 0
+ jnc CopyLoop1 ;2p1 rFLAG 0
+ ; 13 4 6 7 2 2 12+ cyc
+ ; fetch/decode 14 cyc
+
+
+
+
+; movzx eax, byte [esi+ecx ] ;p2 wEAXrESIECX
+; movzx ebp, byte [esi+ecx+1] ;p2 wEBPrESIECX
+; movzx edx, byte [esi+ecx+2] ;p2 wEDXrESIECX
+; movzx ebx, byte [esi+ecx+3] ;p2 wEBXrESIECX
+; and edx, 0xF8 ;p01wEDXrEDX
+; and eax, 0xF8 ;p01wEAXrEAX
+; shr ebp, 3 ;p0 wEBPrEBP
+; shr ebx, 3 ;p0 wEBXrEBX
+; shl edx, 7 ;p0 wEDXrEDX
+; lea eax, [edx + eax*4] ;p0 wEAXrEDXEAX
+; or ebp, eax ;p01wEBPrEAXEBP
+; or ebx, eax ;p01wEBXrEAXEBX
+; movzx ebp, word [esp + ebp*2] ;p2 wEBPrESPEBP
+; movzx ebx, word [esp + ebx*2] ;p2 wEBXrESPEBX
+; shl ebx, 16 ;p0 wEBXrEBX
+; or ebp, ebx ;p01wEBPrEBXEBP
+; mov [edi+ecx], ebp ;p3 rEDIECX p4 rEBP
+; add ecx, byte 4 ;p01wECXrECX
+; jnc NEAR CopyLoop1 ;p1 rFLAG
+ ; 6 5 1 6 1 1 7+ cyc asy
+
+ mov esp, [esp_save]
+
+ pop ebp
+ pop edi
+ pop esi
+ pop edx
+ pop ecx
+ pop ebx
+ pop eax
+ret
+
+_CopyYuv2Rgb2__Fiiii:
+ push eax
+ push ebx
+ push ecx
+ push edx
+ push esi
+ push edi
+ push ebp
+
+ mov [esp_save], esp
+
+ mov esi, [pYuv]
+ mov edi, [pRgb]
+ mov ecx, [nOp]
+ mov esp, [pLut]
+ add esi, ecx
+ add edi, ecx
+ xor ecx, byte -1
+ inc ecx
+
+ movq mm7, [antiSigned]
+ movq mm6, [bit0Mask]
+ movq mm5, [bit20Mask]
+
+align16
+CopyLoop2:
+ movq mm0, [esi+ecx-1600]
+ movq mm1, [esi+ecx+1600]
+ paddb mm0, mm7
+ paddb mm1, mm7
+ pand mm0, mm6
+ pand mm1, mm6
+ psrlw mm0, 1
+ psrlw mm1, 1
+ paddb mm0, mm1
+ psubb mm0, mm7
+ pand mm0, mm5
+ movd ebx, mm0
+ psrlq mm0, 32
+
+ movzx eax, bl
+ movzx ebp, bh
+ shr ebx, 16
+ movzx edx, bl
+ movzx ebx, bh
+
+ shr ebp, 3
+ shr ebx, 3
+ shl edx, 7
+ lea eax, [edx + eax*4]
+ or ebp, eax
+ or ebx, eax
+
+ movzx ebp, word [esp + ebp*2]
+ movzx ebx, word [esp + ebx*2]
+ shl ebx, 16
+ or ebp, ebx
+
+ mov [edi+ecx], ebp
+
+
+ movd ebx, mm0
+
+ movzx eax, bl
+ movzx ebp, bh
+ shr ebx, 16
+ movzx edx, bl
+ movzx ebx, bh
+
+ shr ebp, 3
+ shr ebx, 3
+ shl edx, 7
+ lea eax, [edx + eax*4]
+ or ebp, eax
+ or ebx, eax
+
+ movzx ebp, word [esp + ebp*2]
+ movzx ebx, word [esp + ebx*2]
+ shl ebx, 16
+ or ebp, ebx
+
+ mov [edi+ecx+4], ebp
+
+ add ecx, byte 8
+ jnc NEAR CopyLoop2
+
+ mov esp, [esp_save]
+
+ pop ebp
+ pop edi
+ pop esi
+ pop edx
+ pop ecx
+ pop ebx
+ pop eax
+ret
+
+xyz times 8 dd 0
+
+align8
+antiSigned times 2 dd 0x00800080
+bit0Mask times 2 dd 0xFEFEFEFE
+bit20Mask times 2 dd 0xF8F8F8F8
+uMask times 2 dd 0x000000F8
+vMask times 2 dd 0x00F80000
+
+align16
Added: trunk/2010/2_hw_a.h
==============================================================================
--- (empty file)
+++ trunk/2010/2_hw_a.h Wed Jul 4 10:39:35 2007
@@ -0,0 +1,8 @@
+//2010 0.1 Copyright (C) Michael Niedermayer 1998
+#ifndef n2_hw_a_h
+#define n2_hw_a_h
+
+void CopyYuv2Rgb1(int, int, int, int);
+void CopyYuv2Rgb2(int, int, int, int);
+
+#endif
Modified: trunk/2010/2_hw_mem.cpp
==============================================================================
--- trunk/2010/2_hw_mem.cpp (original)
+++ trunk/2010/2_hw_mem.cpp Wed Jul 4 10:39:35 2007
@@ -25,14 +25,18 @@ bool checkAlign(void *p, int align){
void *newAlign(int size, int align){
int v= int(new char[size + align + 3]);
+#ifdef debug
printf("anew %d\n", v);
+#endif
int v2= ( (v+align-1+4) & ~(align-1) );
((int*)v2)[-1]= v;
return (void*)v2;
}
void deleteAlign(void *v){
+#ifdef debug
printf("adel %d\n", int(((char**)v)[-1]) );
+#endif
delete [] ((char**)v)[-1];
}
@@ -360,7 +364,6 @@ void vds_free(dds *vds_info){
vd=vd->next;
if(vd==vdslist && vd->vds_info.phys==vds_info->phys ){
- printf("HALLO1\n");
vdslist= vdslist->next;
delete vd;
}else if(vd!=vdslist && vd->next!=NULL){
Modified: trunk/2010/2_nag.cpp
==============================================================================
--- trunk/2010/2_nag.cpp (original)
+++ trunk/2010/2_nag.cpp Wed Jul 4 10:39:35 2007
@@ -18,7 +18,7 @@
#include "2_hw_mem.h"
#include "2010.h"
-#define dwnSmp 1
+#define dwnSmp 3
#define FREQ_CHROM 4433618.75
#define FREQ_HS 15625.0
@@ -244,9 +244,10 @@ void nag_decrypt(void){
if(nagSizeAll!=NAG_LINES) error(Nagra);
+#ifdef debug
printf("%d %d\n", sizeof(u_short), sizeof(BEST2) );
+#endif
- printf("HALLOX\n");
static bool first=true;
static char *sinPerLineMulX=new char[(NAG_LINES+32)<<8];
@@ -626,7 +627,7 @@ void nag_decrypt(void){
if(!isWss) wssLine=32;
byte * const lowRes=(byte*) newAlign( wndx>>dwnSmpSize, 8);
- for(int line=0; line<NAG_LINES; line++){
+ for(int line=0; line<NAG_LINES; line++){ // vtune some btb misspredicts
byte * const linep= actVid2MemBufp->b + nagLineLogi2Phys(line)*(vgax<<1);
// printf("%d\n", line);
doDwnSmp(lowRes, linep);
@@ -639,11 +640,9 @@ void nag_decrypt(void){
}
}
if(mmx) asm("emms\n\t");
- printf("H1\n");
deleteAlign(decoLowRes);
deleteAlign(lowRes);
- printf("H2\n");
if(iState){
T2=uclock();
@@ -678,7 +677,6 @@ void nag_decrypt(void){
keysListPos[keysListPoses]= best2[l].keyNdx;
keysListPoses++;
}
- printf("H3\n");
if(iState){
T2=uclock();
@@ -736,7 +734,9 @@ void nag_decrypt(void){
int perm[NAG_LINES];
getPerm(bestKey, perm);
+#ifdef debug
printf("%X\n", bestKey);
+#endif
delete [] bestCoeffs; // kill this
@@ -915,7 +915,6 @@ void nag_decrypt(void){
T1=T2;
}
- printf("H4\n");
/*
for(int i=0; i<NAG_LINES; i++){
const int p=nagLineLogi2Phys(i);
@@ -992,12 +991,12 @@ void nag_decrypt(void){
}
- if(outy == wndy){
+/* if(outy == wndy){
for(int i=0; i<outy; i+=2){
memcpy(actVid2MemBufp->b + ((i+1) * vgax<<1),
actVid2MemBufp->b + (i * vgax<<1) , wndx << 1);
- }
- }
+ }
+ } */
delete [] copyBuff;
Modified: trunk/2010/2_nag_a.asm
==============================================================================
--- trunk/2010/2_nag_a.asm (original)
+++ trunk/2010/2_nag_a.asm Wed Jul 4 10:39:35 2007
@@ -36,12 +36,12 @@ _nagraCorr__Fiiiii:
and edx, 0xFFFFFFF8
- sub edx, 8
+ sub edx, byte 8
add esi, edx
add edi, edx
- xor edx, -1
+ xor edx, byte -1
mov eax, [_mmx]
inc edx
@@ -68,21 +68,26 @@ _nagraCorr__Fiiiii:
movq mm6, [mmx_clip]
+align16
MMXloop:
- psubusb mm2, mm1 ; U
- psubusb mm1, mm0 ; V 1
- movq mm0, [esp + esi + 8] ; U
- por mm2, mm1 ; V 1
- movq mm1, [esp + edi + 8] ; U
- paddusb mm2, mm6 ; V 1
- movq mm4, mm2 ; U
- punpcklbw mm2, mm3 ; V 1
- punpckhbw mm4, mm3 ; U
- paddusw mm5, mm2 ; V 1
- paddusw mm5, mm4 ; U
- movq mm2, mm0 ; V 1
- add esp, 8 ; U
- jnc MMXloop ; V 1
+ psubusb mm2, mm1 ; p01wMM2rMM1MM2 0
+ psubusb mm1, mm0 ; p01wMM1rMM0MM1 1
+ por mm2, mm1 ; p01wMM2rMM1MM2 0
+ movq mm0, [esp + esi + 8] ; p2 wMM0rESPESI 1
+ paddusb mm2, mm6 ; p01wMM2rMM6MM2 1
+ movq mm4, mm2 ; p01wMM4rMM2 0
+ punpcklbw mm2, mm3 ; p1 wMM2rMM3MM2 1
+ punpckhbw mm4, mm3 ; p1 wMM4rMM3MM4 (1)
+ paddusw mm5, mm2 ; p01wMM5rMM2MM5 1
+ paddusw mm5, mm4 ; p01wMM5rMM4MM5 (1)
+ movq mm2, mm0 ; p01wMM2rMM0 0
+ movq mm1, [esp + edi + 8] ; p2 wMM1rESPEDI 2
+ add esp, byte 8 ; p01wESPrESP 1
+ jnc MMXloop ; p1 rFLAG
+ ; 5+ cyc deco
+ ; 5- cyc rat
+ ; 6 cyc exec (0/1 satur)
+
psubusb mm2, mm1
psubusb mm1, mm0
@@ -201,3 +206,5 @@ xyz times 8 dd 0
align8
mmx_clip times 8 db 0
+
+align16
Modified: trunk/2010/2_vc.cpp
==============================================================================
--- trunk/2010/2_vc.cpp (original)
+++ trunk/2010/2_vc.cpp Wed Jul 4 10:39:35 2007
@@ -37,15 +37,14 @@
#define BAD_THRESHOLD1 0.8
#define BAD_THRESHOLD2 200
#define EDGE_LIMIT 70
-#define MAX_EDGE 500
-#define EDGE_LOG_COEFF 10
+#define MAX_EDGE 500 // ? 2000 ?
#define PHASE_EXP 4
#define PHASE_LIMIT 40
#define MAX_PHASE_PENALTY 1000
#define AMP_THRESHOLD 200
#define PHASE_COEFF (MAX_PHASE_PENALTY/pow(PHASE_LIMIT, PHASE_EXP))
-#define EDGE_COEFF (MAX_EDGE/log(EDGE_LIMIT*EDGE_LOG_COEFF))
+#define EDGE_COEFF (MAX_EDGE/log(EDGE_LIMIT))
#define NUM_PHASE_SMP (vcDiff>>PHASE_CMP_STEP)
@@ -85,15 +84,18 @@ void vc_decrypt(void){
const int lowResSize= mmx ? DWN_SMP : (DWN_SMP-1);
+#ifdef debug
printf("xx%f %f %f\n", PHASE_POINT/PI*180, PHASE_SEG/PI*180, PHASE_SMP/PI*180);
+#endif
int vScore=0;
// showPoints=true;
const double freqPix2= double(wndx) / double(x_field) * FREQ_PIX;
+#ifdef debug
printf("xy%d %d\n", wndx, x_field);
-
+#endif
// 18
// const int vcStartX=int(double(16 -scales_x+3)/x_field*wndx + .5) + some - 10;
const int vcStartX=int(double(16 -scales_x+3)/x_field*wndx + .5);
@@ -121,7 +123,9 @@ void vc_decrypt(void){
const int vcEndX= vcStartX + int( double(POINT_LAND + NO_POINT_LAND)
* freqPix2 / FREQ_SMP + .5);
+#ifdef debug
printf("vcEndX %d\n",vcEndX);
+#endif
if(vcEndX>wndx) error(error_code(-123));
const int vcDiff=vcEndX - vcStartX;
@@ -147,7 +151,7 @@ void vc_decrypt(void){
static int phaseLut[256];
static bool first= true;
- static byte phasePerCutP[256];
+ static int phasePerCutP[256];
static char sin1PerCutP[256];
static char cos1PerCutP[256];
static char sin2PerCutP[256];
@@ -158,11 +162,11 @@ void vc_decrypt(void){
fields++;
if(first){
- some=10;
+ if(first) some=10;
for(int i=0; i<512; i++){
const int j= min(i+1, EDGE_LIMIT);
- edgeLut[i]=int( log(j*EDGE_LOG_COEFF)*EDGE_COEFF );
+ edgeLut[i]=int( log(j)*EDGE_COEFF );
}
for(int i=0; i<256; i++){
@@ -291,6 +295,7 @@ void vc_decrypt(void){
|| bestDiff+(bestDiff>>1) > addapBuff[ cutP - (step>>1) ]
|| bestDiff+(bestDiff>>1) > addapBuff[ cutP + (step>>1) ]){
+
int diff;
if(mmx){
diff = vc_corr_mmx(
@@ -525,14 +530,15 @@ void vc_decrypt(void){
const byte a= (line & 1) ^ ( vScore>0 ) ? -ang: ang;
- const byte phase1= a + phasePerCutP[ lastCutP ];
+ const int phase1= (a + phasePerCutP[ lastCutP ]) & 0xFF;
+ const int lastPhaseErrLastCutP= lastPhaseErr[lastCutP] + 128;
// FIX (ASM_OPTIMIZE)
if(chromAmp>AMP_THRESHOLD){
for(int newCutP= newCutPStart; newCutP <= newCutPEnd; newCutP++){
- const byte phaseErr= phase1 + phasePerCutP[ newCutP ];
+ const int phaseErr= (phase1 + phasePerCutP[ newCutP ]) & 0xFF;
const int val= lastVal[lastCutP] - driftPenalty[drift]
- phaseLut[ phaseErr ]
- - phaseLut[ (phaseErr - lastPhaseErr[lastCutP] + 128) & 0xFF];// useless without phase errors from decomb-filter
+ - phaseLut[ (phaseErr - lastPhaseErrLastCutP) & 0xFF];// useless without phase errors from decomb-filter
if(newVal[newCutP] < val){
newVal[newCutP]= val;
@@ -547,7 +553,7 @@ void vc_decrypt(void){
else{
linep[ ((vcStartX - 1)<<1) + 1]=255;
for(int newCutP= newCutPStart; newCutP <= newCutPEnd; newCutP++){
- const byte phaseErr= phase1 + phasePerCutP[ newCutP ];
+ const int phaseErr= (phase1 + phasePerCutP[ newCutP ]) & 0xFF;
const int val= lastVal[lastCutP] - driftPenalty[drift];
if(newVal[newCutP] < val){
@@ -773,10 +779,12 @@ void vc_decrypt(void){
bestCutP= dir[(line<<8) + bestCutP];
}
+#ifdef debug
for(int line=1; line<wndy-1; line++)
{
fprintf(pF, "%d\n", cutpp[line]);
}
+#endif
/*
float avgCutP=0;
@@ -788,8 +796,9 @@ void vc_decrypt(void){
printf("avg%f\n", avgCutP-float(vcDiff)/2.0);
*/
+#ifdef debug
printf("vScore %d\n", vScore);
-
+#endif
if(iState){
T2=uclock();
@@ -811,11 +820,11 @@ void vc_decrypt(void){
infoPosY+=5;
T1=T2;
}
-
+/*
c.init(255, 0, 0, false);
sprintf(textbuf[6],"%d l %d f", cutPs, fields);
gprint(infoPosX, infoPosY+=10, c.col, textbuf[6]);
-
+ */
delete [] bestDir;
delete [] dir;
Modified: trunk/2010/2_vc_a.asm
==============================================================================
--- trunk/2010/2_vc_a.asm (original)
+++ trunk/2010/2_vc_a.asm Wed Jul 4 10:39:35 2007
@@ -45,7 +45,7 @@ _vc_corr__Fiiiiii:
xor ebp, ebp
xor edx, edx
- cmp esp, 4
+ cmp esp, byte 4
jb skip1
mov eax, [esp + esi]
@@ -91,7 +91,7 @@ skip1:
mov esp, [count2]
xor edx, edx
- cmp esp, 4
+ cmp esp, byte 4
jb skip2
mov eax, [esp + esi]
@@ -123,7 +123,7 @@ NoMMXloop2:
or eax, 0x80008000 ; V 1
xor edx, ecx ; U
mov ebx, [esp + edi + 8] ; V 1
- add esp, 8 ; U
+ add esp, byte 8 ; U
jnc NoMMXloop2 ; V 1
skip2:
@@ -147,7 +147,6 @@ skip2:
ret
-
_vc_corr_mmx__Fiiiiii:
; int3
push ebx
@@ -162,29 +161,29 @@ _vc_corr_mmx__Fiiiiii:
mov ebx, edi
mov ecx, [mcount1]
- and ecx, -8
- and ebx, 7
+ and ecx, byte -8
+ and ebx, byte 7
shl ebx, 3
- and edi, -8
+ and edi, byte -8
add esi, ecx
movd mm6, ebx
pxor mm7, mm7
- xor ebx, -1
+ xor ebx, byte -1
add edi, ecx
- add ebx, 65
- xor ecx, -1
+ add ebx, byte 65
+ xor ecx, byte -1
inc ecx
movd mm5, ebx
pxor mm4,mm4
- cmp ecx, 8
+ cmp ecx, byte 8
jb skipMMX1
movq mm3, [ecx + edi ]
@@ -197,24 +196,28 @@ _vc_corr_mmx__Fiiiiii:
por mm1, mm3
+align16
MMXLoop:
- movq mm2, mm0 ; U
- psubusb mm0, mm1 ; V 1
- movq mm3, [ecx + edi + 8 ] ; U
- psubusb mm1, mm2 ; V 1
- por mm1, mm0 ; U
- psrlq mm3, mm6 ; V 1
- movq mm2, mm1 ; U
- punpcklbw mm1, mm4 ; V 1
- punpckhbw mm2, mm4 ; U
- paddusw mm7, mm1 ; V 1
- movq mm1, [ecx + edi + 16] ; U
- paddusw mm7, mm2 ; V 1
- movq mm0, [ecx + esi + 8 ] ; U
- psllq mm1, mm5 ; V 1
- por mm1, mm3 ; U
- add ecx, 8 ; V 1
- jnc MMXLoop ; U 1
+ movq mm2, [ecx + esi ] ;0p2 wMM0rECXESI 1
+ psubusb mm0, mm1 ; p01wMM0rMM1MM0 0
+ psubusb mm1, mm2 ; p01wMM1rMM2MM1 0
+ movq mm3, [ecx + edi + 8 ] ;0p2 wMM3rECXEDI 1
+ por mm1, mm0 ; p01wMM1rMM0MM1 0
+ movq mm0, [ecx + esi + 8 ] ; p2 wMM0rECXESI 1
+ psrlq mm3, mm6 ;0p0 wMM3rMM6 1
+ movq mm2, mm1 ; p01wMM2rMM1 0
+ punpcklbw mm1, mm4 ; p0 wMM1rMM4MM1 1
+ punpckhbw mm2, mm4 ;0p0 wMM2rMM4MM2 10
+ paddusw mm7, mm1 ; p01wMM7rMM1MM7 1
+ paddusw mm7, mm2 ; p01wMM7rMM2MM7 10
+ movq mm1, [ecx + edi + 16] ;0p2 wMM1rECXEDI 2
+ psllq mm1, mm5 ; p0 wMM1rMM5 1
+ por mm1, mm3 ; p01wMM1rMM3MM1 1?
+ add ecx, byte 8 ;0p01wECXrECX 1
+ jnc MMXLoop ; p1 rFLAG
+; 8 4 1 4 7 cyc asy
+; 6+ cyc deco
+; 7 cyc rat
skipMMX1:
@@ -224,27 +227,27 @@ skipMMX1:
mov ebx, edi
mov ecx, [mcount2]
- and ecx, -8
- and ebx, 7
+ and ecx, byte -8
+ and ebx, byte 7
shl ebx, 3
- and edi, -8
+ and edi, byte -8
add esi, ecx
movd mm6, ebx
- xor ebx, -1
+ xor ebx, byte -1
add edi, ecx
- add ebx, 65
- xor ecx, -1
+ add ebx, byte 65
+ xor ecx, byte -1
inc ecx
movd mm5, ebx
- cmp ecx, 8
+ cmp ecx, byte 8
jb skipMMX2
movq mm3, [ecx + edi ]
@@ -257,24 +260,25 @@ skipMMX1:
por mm1, mm3
+align16
MMXLoop2:
- movq mm2, mm0 ; U
- psubusb mm0, mm1 ; V 1
- movq mm3, [ecx + edi + 8 ] ; U
- psubusb mm1, mm2 ; V 1
- por mm1, mm0 ; U
- psrlq mm3, mm6 ; V 1
- movq mm2, mm1 ; U
- punpcklbw mm1, mm4 ; V 1
- punpckhbw mm2, mm4 ; U
- paddusw mm7, mm1 ; V 1
- movq mm1, [ecx + edi + 16] ; U
- paddusw mm7, mm2 ; V 1
- movq mm0, [ecx + esi + 8 ] ; U
- psllq mm1, mm5 ; V 1
- por mm1, mm3 ; U
- add ecx, 8 ; V 1
- jnc MMXLoop2 ; U 1
+ movq mm2, [ecx + esi ] ;0p2 wMM0rECXESI 1
+ psubusb mm0, mm1 ; p01wMM0rMM1MM0 0
+ psubusb mm1, mm2 ; p01wMM1rMM2MM1 0
+ movq mm3, [ecx + edi + 8 ] ;0p2 wMM3rECXEDI 1
+ por mm1, mm0 ; p01wMM1rMM0MM1 0
+ movq mm0, [ecx + esi + 8 ] ; p2 wMM0rECXESI 1
+ psrlq mm3, mm6 ;0p0 wMM3rMM6 1
+ movq mm2, mm1 ; p01wMM2rMM1 0
+ punpcklbw mm1, mm4 ; p0 wMM1rMM4MM1 1
+ punpckhbw mm2, mm4 ;0p0 wMM2rMM4MM2 10
+ paddusw mm7, mm1 ; p01wMM7rMM1MM7 1
+ paddusw mm7, mm2 ; p01wMM7rMM2MM7 10
+ movq mm1, [ecx + edi + 16] ;0p2 wMM1rECXEDI 2
+ psllq mm1, mm5 ; p0 wMM1rMM5 1
+ por mm1, mm3 ; p01wMM1rMM3MM1 1?
+ add ecx, byte 8 ;0p01wECXrECX 1
+ jnc MMXLoop2 ; p1 rFLAG
skipMMX2:
@@ -302,3 +306,4 @@ ret
+align16
Modified: trunk/2010/makefile
==============================================================================
--- trunk/2010/makefile (original)
+++ trunk/2010/makefile Wed Jul 4 10:39:35 2007
@@ -1,7 +1,7 @@
.SUFFIXES: .c .cc .cpp .h .o .asm .S .s
OPTS = -g
-OPTS = -O3 -mpentium -fomit-frame-pointer -g -Wall -Wstrict-prototypes -malign-double -ffast-math -funroll-loops -fno-default-inline
+OPTS = -O5 -mpentiumpro -fomit-frame-pointer -g -Wall -Wstrict-prototypes -malign-double -ffast-math -funroll-loops -fno-default-inline
AFLAGS = -f coff
.c.o: ; gcc $(CFLAGS) -c $<
@@ -14,13 +14,15 @@ AFLAGS = -f coff
.asm.o: ; nasm $(AFLAGS) $<
-O = 2010.o 2_file.o 2_grafix.o 2_hw.o 2_gfunc.o \
- 2_hw_asm.o 2_71x6.o 2_hw_mem.o 2_crypt.o\
- 2_glob_a.o 2_txt.o 2_cryp_a.o
+O = 2_glob_a.o 2_cryp_a.o 2_hw_a.o\
+ 2010.o 2_file.o 2_grafix.o 2_hw.o 2_gfunc.o \
+ 2_hw_asm.o 2_71x6.o 2_hw_mem.o 2_crypt.o 2_txt.o
+
-OC = 2010.o 2_file.o 2_grafix.o 2_hw.o 2_gfunc.o \
- 2_hw_asm.o 2_71x6.o 2_hw_mem.o 2_crypt.o 2_vc.o 2_nag.o\
- 2_nag_a.o 2_vc_a.o 2_glob_a.o 2_txt.o 2_cryp_a.o
+OC = 2_nag_a.o 2_vc_a.o 2_glob_a.o 2_cryp_a.o 2_hw_a.o\
+ 2010.o 2_file.o 2_grafix.o 2_hw.o 2_gfunc.o \
+ 2_hw_asm.o 2_71x6.o 2_hw_mem.o 2_crypt.o 2_vc.o 2_nag.o 2_txt.o
+
default: ;$(MAKE) 2010 CFLAGS="$(OPTS)"
@@ -36,7 +38,7 @@ clean: ; del $(O) 2010
2_gfunc.o : 2_gfunc.cpp 2_all.h 2_gfunc.h 2010.h
2_grafix.o : 2_grafix.cpp 2_all.h 2_grafix.h 2010.h 2_gfunc.h 2_hw.h 2_file.h
2_hw.o : 2_hw.cpp 2_all.h 2_hw.h 2010.h 2_hw_asm.h 2_hw_mem.h\
- 2_71x6.h 2_mmx.h
+ 2_71x6.h 2_mmx.h 2_hw_a.h
2_hw_mem.o : 2_hw_mem.cpp 2_all.h 2_hw_mem.h 2010.h
2_71x6.o : 2_71x6.cpp 2_all.h 2_71x6.h 2_hw.h 2_hw_mem.h 2010.h 2_hw_asm.h
2_crypt.o : 2_crypt.cpp 2_all.h 2_crypt.h 2_71x6.h 2_vc.h 2_nag.h 2_txt.h
@@ -51,4 +53,5 @@ clean: ; del $(O) 2010
2_nag_a.o : 2_nag_a.asm 2_all_a.asm
2_vc_a.o : 2_vc_a.asm 2_all_a.asm
2_cryp_a.o : 2_cryp_a.asm 2_all_a.asm
+2_hw_a.o : 2_hw_a.asm 2_all_a.asm
1
0
[mndiff]: r58 - in trunk/2010: 2010.cpp 2_cryp_a.asm 2_cryp_a.h 2_crypt.cpp 2_file.cpp 2_file.h 2_grafix.cpp 2_txt.cpp 2_vc.cpp 2_vc_a.asm makefile
by michael 04 Jul '07
by michael 04 Jul '07
04 Jul '07
Author: michael
Date: Wed Jul 4 10:15:33 2007
New Revision: 58
Log:
next version from unknown date
Added:
trunk/2010/2_cryp_a.asm
trunk/2010/2_cryp_a.h
Modified:
trunk/2010/2010.cpp
trunk/2010/2_crypt.cpp
trunk/2010/2_file.cpp
trunk/2010/2_file.h
trunk/2010/2_grafix.cpp
trunk/2010/2_txt.cpp
trunk/2010/2_vc.cpp
trunk/2010/2_vc_a.asm
trunk/2010/makefile
Modified: trunk/2010/2010.cpp
==============================================================================
--- trunk/2010/2010.cpp (original)
+++ trunk/2010/2010.cpp Wed Jul 4 10:15:33 2007
@@ -24,7 +24,7 @@
#include "2_nag.h"
extern volatile bool oneField;
- extern bool vSmoothState;
+ extern int iVSmooth;
extern int g_mode;
extern VID2MEMBUF *vid2MemBuf, *actVid2MemBufp;
extern byte *vidbuf;
@@ -33,11 +33,6 @@
extern int active_meteor;
extern int yuvMode, grabYuvMode;
extern bool mmx;
-// extern short *linesPerKeyTab;
-// extern int *best1;
-// extern BEST2 *best2;
-// extern u_short *keysList;
-// extern int *decoLine;
extern int bright, contr, satur;
extern int showCont;
extern CRYPTSTD cryptStd;
@@ -54,6 +49,7 @@
int _crt0_startup_flags = _CRT0_FLAG_NEARPTR | _CRT0_FLAG_NONMOVE_SBRK;
+ bool fShowRaw=false;
int grabf;
int fysize;
byte font[4096];
@@ -127,10 +123,11 @@ int error(error_code e){
case CommLine : printg_t("\nCommand-Line error!\n");
case Help : printg_t("\n2010 [<optons>]\n"
"options: -v n (Video-mode)\n"
- " -m n (Meteor Card) in case there are more than 1 (:\n"
+ " -m n (Meteor Card)\n"
" -NoFlip (Disable Page-Fliping)\n"
" -NoMMX (Disable MMX-Support)\n"
" -MaxBuf (num of Buffers)\n"
+ " -s <file0.raw> ... <filen.raw> (show raw pics)\n"
" -? / -h (This stuff)\n");
break;
default : printg_t("\nUnknown error!");
@@ -195,6 +192,10 @@ int main(int argc, char **argv){
else if(stricmp(argv[i],"nagra")==0) std=nagra;
else error(CommLine);
} */
+ else if(stricmp(argv[i],"-s")==0){
+ LoadRaws(argc-i-1, &argv[i+1]);
+ i=argc;
+ }
else error(CommLine);
}
@@ -340,10 +341,14 @@ int main(int argc, char **argv){
infoPosY=0;
infoPosX=10;
+ if(grabf==2 && TVStd!=TXTPAL) GrabRaw(), grabf=0;
+
+ if(fShowRaw) ShowRaw();
+
decrypt();
showStuff();
- if(grabf!=0 && TVStd!=TXTPAL) grab(), grabf=0;
+ if(grabf==1 && TVStd!=TXTPAL) GrabBmp(), grabf=0;
for(int k=0; k<delay*1000000; k++);
@@ -393,6 +398,8 @@ int main(int argc, char **argv){
case 'q' :
case 'Q' : quit=true;
break;
+ case 'S' : fShowRaw=!fShowRaw;
+ break;
case K_F1 : bright--;
showCont=10;
if(bright<0) bright=0;
@@ -423,14 +430,13 @@ int main(int argc, char **argv){
if(satur>127) satur=127;
setCont();
break;
- case 's' :
- case 'S' : menuLevel=mLTVStd, helpState=false;
+ case 's' : menuLevel=mLTVStd, helpState=false;
break;
case 'i' :
case 'I' : iState= !iState;
break;
case 'v' :
- case 'V' : vSmoothState= !vSmoothState;
+ case 'V' : iVSmooth++; iVSmooth%=3;
break;
case 'h' :
case 'H' : helpState= !helpState;
@@ -516,7 +522,7 @@ int main(int argc, char **argv){
cryptStd= nix;
if(yuvMode!=2) yuvMode=0, grabYuvMode=1;
else error(error_code(-988));
- vSmoothState=false;
+ iVSmooth=0;
setStdScale();
contGrab();
break;
@@ -525,7 +531,7 @@ int main(int argc, char **argv){
cryptStd= vc;
if(yuvMode==0) yuvMode=1;
grabYuvMode=yuvMode;
- vSmoothState=false;
+ iVSmooth=0;
setStdScale();
contGrab();
break;
@@ -533,7 +539,7 @@ int main(int argc, char **argv){
cryptStd= nag;
if(yuvMode==0) yuvMode=1;
grabYuvMode=yuvMode;
- vSmoothState=false;
+ iVSmooth=0;
setStdScale();
contGrab();
break;
Added: trunk/2010/2_cryp_a.asm
==============================================================================
--- (empty file)
+++ trunk/2010/2_cryp_a.asm Wed Jul 4 10:15:33 2007
@@ -0,0 +1,210 @@
+;2010 0.1 Copyright (C) Michael Niedermayer 1998
+
+%include "2_all_a.asm"
+
+segment .data
+
+global _VSmooth1RGB1555__Fiii
+global _VSmooth2RGB1555__Fiii
+
+%define pBuf1 par1
+%define iVgaX21 par2
+%define nOp1 par3
+
+%define pBuf2 par2
+%define iVgaX22 par3
+%define nOp2 par4
+
+_VSmooth1RGB1555__Fiii:
+ push eax
+ push ebx
+
+ push ecx
+ push edx
+
+ push esi
+ push edi
+
+ mov esi, [pBuf1]
+ add esi, 8
+
+ mov ecx, [nOp1]
+ add esi, ecx
+
+ xor ecx, -1
+ mov ebx, [iVgaX21]
+
+ inc ecx
+ mov edi, ebx
+
+ add ebx, esi
+ add edi, edi
+
+ add edi, esi
+
+ movq mm6, [mask1]
+ movq mm7, [mask2]
+
+ movq mm0, [esi+ecx]
+ movq mm1, [ebx+ecx]
+ movq mm3, [esi+ecx-8]
+
+
+ ; more opt possible (+2reg -1psrlw)
+MMXLoop1:
+ movq mm5, mm0
+ movq mm4, mm1
+
+ movq [esi+ecx-8], mm3
+ pand mm0, mm7
+
+ movq mm2, [edi+ecx]
+ pand mm1, mm6
+
+ movq mm3, mm2
+ pand mm2, mm6
+
+ pand mm5, mm6
+ pand mm4, mm7
+
+ pand mm3, mm7
+ paddw mm5, mm2
+
+ paddw mm3, mm0
+ psrlw mm5, 1
+
+ psrlw mm3, 1
+ paddw mm5, mm1
+
+ paddw mm3, mm4
+ psrlw mm5, 1
+
+ psrlw mm3, 1
+ pand mm5, mm6
+
+ movq mm0, [esi+ecx+8]
+ pand mm3, mm7
+
+ movq mm1, [ebx+ecx+8]
+ por mm3, mm5
+
+ add ecx, 8
+ jnc MMXLoop1
+
+ pop edi
+ pop esi
+
+ pop edx
+ pop ecx
+
+ pop ebx
+ pop eax
+
+ emms
+
+ret
+
+_VSmooth2RGB1555__Fiii:
+ push eax
+ push ebx
+
+ push ecx
+ push edx
+
+ push esi
+ push edi
+
+ push ebp
+
+ mov esi, [pBuf2]
+
+ add esi, 8
+ mov ebp, [nOp2]
+
+ xor ebp, -1
+ mov ebx, [iVgaX22]
+
+ add esi, ebx
+ mov edx, ebx
+
+ mov eax, ebx
+ add edx, edx
+
+ inc ebp
+ mov edi, ebx
+
+ add ebx, esi
+ add edi, edi
+
+ mov ecx, eax
+ add edi, esi
+
+ xor ecx, -1
+
+ inc ecx
+
+ movq mm6, [mask1]
+
+ movq mm7, [mask2]
+
+ ; lots of optimize possible
+MMXLoop2:
+ ;AGI
+ movq mm0, [esi+ecx]
+
+ movq mm1, [edi+ecx]
+ movq mm4, mm0
+
+ movq mm5, mm1
+ pand mm0, mm7
+
+ pand mm4, mm6
+ pand mm5, mm6
+
+ pand mm1, mm7
+ paddw mm4, mm5
+
+ paddw mm0, mm1
+ psrlw mm4, 1
+
+ psrlw mm0, 1
+ pand mm4, mm6
+
+ pand mm0, mm7
+
+ por mm4, mm0
+
+ movq [ebx+ecx], mm4
+
+ add ecx, 8
+ jnc MMXLoop2
+
+ sub ecx, eax
+ add ebx, edx
+
+ add esi, edx
+ add edi, edx
+
+ add ebp, edx
+ jnc MMXLoop2
+
+ pop ebp
+
+ pop edi
+ pop esi
+
+ pop edx
+ pop ecx
+
+ pop ebx
+ pop eax
+
+ emms
+
+ret
+
+xyz times 8 dd 0
+
+align8
+mask1 times 2 dd 0x7C1F03E0
+mask2 times 2 dd 0x03E07C1F
Added: trunk/2010/2_cryp_a.h
==============================================================================
--- (empty file)
+++ trunk/2010/2_cryp_a.h Wed Jul 4 10:15:33 2007
@@ -0,0 +1,8 @@
+//2010 0.1 Copyright (C) Michael Niedermayer 1998
+#ifndef n2_crypt_a_h
+#define n2_crypt_a_h
+
+void VSmooth1RGB1555(int, int, int);
+void VSmooth2RGB1555(int, int, int);
+
+#endif
Modified: trunk/2010/2_crypt.cpp
==============================================================================
--- trunk/2010/2_crypt.cpp (original)
+++ trunk/2010/2_crypt.cpp Wed Jul 4 10:15:33 2007
@@ -5,6 +5,7 @@
#include <time.h>
#include "2_all.h"
#include "2_crypt.h"
+#include "2_cryp_a.h"
#include "2_vc.h"
#include "2_nag.h"
#include "2_txt.h"
@@ -26,10 +27,10 @@ extern bool iState;
extern int infoPosX, infoPosY;
extern int some;
-static void vSmooth(void);
-static void decomb(int q);
+static void VSmooth(void);
+static void Decomb(int q);
-bool vSmoothState=true;
+int iVSmooth=1;
bool showPoints=false;
asm("__esp: .long 0\n\t");
@@ -37,13 +38,13 @@ bool showPoints=false;
void decrypt(void){
long T1=0, T2;
- char textbuf[2][128];
+ char textbuf[3][128];
if(iState){
T1=uclock();
}
- if( cryptStd == nag && satur!=0 ) decomb(0);
- if( cryptStd == vc && satur!=0 ) decomb(1);
+ if( cryptStd == nag && satur!=0 ) Decomb(0);
+ if( cryptStd == vc && satur!=0 ) Decomb(1);
if(iState){
T2=uclock();
@@ -60,20 +61,27 @@ void decrypt(void){
if(iState){
T2=uclock();
+ sprintf(textbuf[1],"%f DeCrypt", (float)(T2-T1)/UCLOCKS_PER_SEC);
+ T1=T2;
+ }
+
+ if(!oneField && iVSmooth) VSmooth();
+
+ if(iState){
+ T2=uclock();
color c;
c.init(255, 0, 0, false);
- sprintf(textbuf[1],"%f DeCrypt", (float)(T2-T1)/UCLOCKS_PER_SEC);
+ sprintf(textbuf[2],"%f VSmooth", (float)(T2-T1)/UCLOCKS_PER_SEC);
gprint(infoPosX, infoPosY+=10, c.col, textbuf[0]);
gprint(infoPosX, infoPosY+=10, c.col, textbuf[1]);
+ gprint(infoPosX, infoPosY+=10, c.col, textbuf[2]);
infoPosY+=5;
}
- if(!oneField && vSmoothState) vSmooth();
-
}
-static void decomb(int q){
+static void Decomb(int q){
int temp[max_x];
const int outy1= outy>>1;
@@ -219,33 +227,16 @@ static void decomb(int q){
*/
}
-static void vSmooth(void){
+static void VSmooth(void){
- if(yuvMode==0){
- /* asm(//"int $3 \n\t"
- "1: \n\t"
- "movl (%%esi ), %%eax \n\t" //U LINE
- "movl (%%esi,%%edi,2), %%ebx \n\t" // V 1 LINE + 2
- "shrl $2, %%eax \n\t" //U
- "andl $0xFCFCFCFC, %%ebx \n\t" // V 1
- "shrl $2, %%ebx \n\t" //U
- "andl $0x3F3F3F3F, %%eax \n\t" // V 1
- "addl %%eax, %%ebx \n\t" //U
- "movl (%%esi,%%edi ), %%eax \n\t" // V 1 LINE + 1
- "shrl $1, %%eax \n\t" //U
- "andl $0x7F7F7F7F, %%ebx \n\t" // V 1
- "andl $0x7F7F7F7F, %%eax \n\t" //U
- "addl $4, %%esi \n\t" // V 1
- "addl %%eax, %%ebx \n\t" //U
- "decl %%ecx \n\t" // V 1
- "movl %%ebx, -4(%%esi ) \n\t" //U LINE
- " jnz 1b \n\t" // V 1
- :
- : "D" (vgax<<2), "S" (actVid2MemBufp->b),
- "c" (vgax * (wndy-2) )
- : "%eax", "%ebx", "%ecx", "%esi");
- */
- }
+ if(yuvMode==0)
+ {
+ if(iVSmooth==1)
+ VSmooth1RGB1555(int(actVid2MemBufp->b), vgax<<1, vgax*(wndy-3)<<1);
+ else
+ VSmooth2RGB1555(int(actVid2MemBufp->b), vgax<<1, vgax*(wndy-3)<<1);
+ }
+/*
else{
asm(//"int $3 \n\t"
"1: \n\t"
@@ -280,5 +271,5 @@ static void vSmooth(void){
}
-
+ */
}
Modified: trunk/2010/2_file.cpp
==============================================================================
--- trunk/2010/2_file.cpp (original)
+++ trunk/2010/2_file.cpp Wed Jul 4 10:15:33 2007
@@ -15,7 +15,10 @@
extern int yuvMode;
extern char *yuv2rgb_lut;
-void grab(void){
+ static byte *ppbRawDat[64];
+ static int nRawDats=0;
+
+void GrabBmp(void){
int i, j;
FILE *fg;
char grab_name[16];
@@ -84,6 +87,50 @@ void grab(void){
}
+void GrabRaw(void){
+ FILE *fg;
+ char grab_name[16];
+ struct time ti;
+
+ gettime(&ti);
+ sprintf(grab_name, "G%02d%02d%02d.RAW", ti.ti_hour, ti.ti_min, ti.ti_sec);
+
+ if((fg=fopen(grab_name, "ab"))==NULL && g_mode==0) error(FileWrite);
+
+ fwrite(actVid2MemBufp->b, 1, vgax*wndy*2, fg);
+
+ fclose(fg);
+}
+
+
+void LoadRaws(int nRaws, char **ppcName){
+
+ nRawDats= nRaws;
+
+ FILE *pFRaw;
+
+ for(int i=0; i<nRaws; i++)
+ {
+ if((pFRaw=fopen(ppcName[i], "rb"))==NULL) error(FileRead);
+ const int iFileSize= fsize(pFRaw);
+ ppbRawDat[i]= new byte[iFileSize];
+ fread(ppbRawDat[i], 1, iFileSize, pFRaw);
+
+ fclose(pFRaw);
+ }
+}
+
+void ShowRaw(void){
+
+ if(!nRawDats) return;
+
+ static int i=0;
+
+ i++;
+ i%=nRawDats;
+ memcpy(actVid2MemBufp->b, ppbRawDat[i], vgax*vgay*2);
+}
+
long fsize(FILE *f){
long i,j;
i=ftell(f); //get pos
Modified: trunk/2010/2_file.h
==============================================================================
--- trunk/2010/2_file.h (original)
+++ trunk/2010/2_file.h Wed Jul 4 10:15:33 2007
@@ -20,7 +20,10 @@ struct bmp{
dword clrimp __attribute__ ((packed)) ;
};
-void grab(void);
+void GrabBmp(void);
long fsize(FILE *f);
+void LoadRaws(int, char **);
+void GrabRaw(void);
+void ShowRaw(void);
#endif
Modified: trunk/2010/2_grafix.cpp
==============================================================================
--- trunk/2010/2_grafix.cpp (original)
+++ trunk/2010/2_grafix.cpp Wed Jul 4 10:15:33 2007
@@ -35,12 +35,13 @@ void showStuff(void){
color c;
if(helpState){
- char text[14][256]={ "F1/F2 Brightness s TVStandart",
+ char text[15][256]={ "F1/F2 Brightness s TVStandart",
"F3/F4 Contrast i debugInfo",
"F5/F6 Saturation h Help",
- "g ScreenShot q Quit",
+ "g ScreenShot G SaveRaw",
"v smoothIterlace p Pause",
- "d allowDrop",
+ "d allowDrop q Quit",
+ "S ShowRaw",
" TELETXT:",
"+ Page+ - Page-",
"right subPage+ left subPage-",
@@ -50,7 +51,7 @@ void showStuff(void){
"e delUnSeen",
"f txt find F findNext"};
- for(int i=0; i<14; i++){
+ for(int i=0; i<15; i++){
c.init(255, 0, 0, false);
gprint(infoPosX, infoPosY+=10, c.col, text[i]);
}
Modified: trunk/2010/2_txt.cpp
==============================================================================
--- trunk/2010/2_txt.cpp (original)
+++ trunk/2010/2_txt.cpp Wed Jul 4 10:15:33 2007
@@ -223,11 +223,12 @@ void txt_decrypt(void){
// FIX ? optimize in fixp and lut ...
double si=0, co=0;
double ang=0;
- for(int x=0; x<10; x++){
+ for(int x=0; x<12; x++){
const int amp= actVid2MemBufp->b[linep + (x<<1) + 1];
si+= sin(ang)*(amp-avg);
co+= cos(ang)*(amp-avg);
ang+= angDelta;
+// actVid2MemBufp->b[linep + (x<<1) + 1]= 255;
}
int xFixp= int(atan3(si,co)/PI*freqPix2/FREQ_TXT*ONE_FIXP);
@@ -242,7 +243,7 @@ void txt_decrypt(void){
int score= sample( &actVid2MemBufp->b[linep + 1], xFixp );
if(score > avg) r|=1;
- actVid2MemBufp->b[linep + (x<<1) + 1]= (r&1)*255;
+// actVid2MemBufp->b[linep + (x<<1) + 1]= (r&1)*255;
xFixp+=delta;
x=xFixp>>FIXP_SH;
if(r==magic) break;
@@ -266,7 +267,7 @@ void txt_decrypt(void){
int score= sample( &actVid2MemBufp->b[linep + 1], xFixp );
if(score > avg) r|=0x80;
- actVid2MemBufp->b[linep + (x<<1) + 1]= (r&0x80)/0x80*255;
+// actVid2MemBufp->b[linep + (x<<1) + 1]= (r&0x80)/0x80*255;
if(!(decoded & 0x07)){
data[(decoded>>3) - 1]=r;
@@ -463,9 +464,12 @@ void txt_decrypt(void){
}
}
-
memset(actVid2MemBufp->b, 0, vgax*vgay<<mc);
+// if(yuvMode<2) memset(actVid2MemBufp->b, 0, vgax*vgay<<mc);
+// yuvMode++;
+// if(yuvMode>2) yuvMode=2;
+
if(txtHack>0 && txtHackState==0) txtHackState=14;
if(txtHackState>0){
@@ -475,6 +479,8 @@ void txt_decrypt(void){
if(iState || helpState) return;
+// return;
+
static int lastReqPage=-1, lastReqSubPage=-1, lastReqChanNum=-1;
// FIX reqChanStr
Modified: trunk/2010/2_vc.cpp
==============================================================================
--- trunk/2010/2_vc.cpp (original)
+++ trunk/2010/2_vc.cpp Wed Jul 4 10:15:33 2007
@@ -14,14 +14,14 @@
#include "2010.h"
#define FREQ_SMP 2.1e7
-#define POINT_LAND 765.0
-#define NO_POINT_LAND1 145.0 // GUESSED!
-#define NO_POINT_LAND2 145.0 // GUESSED!
-#define NO_POINT_LAND3 10.0 // GUESSED!
+#define POINT_LAND 765.0
+#define NO_POINT_LAND1 150.0 // GUESSED and ok
+#define NO_POINT_LAND2 150.0 // GUESSED and ok
+#define PHASE_PATCH (-28) // GUESSED ? -9, ...
// ? POINT_LAND + NO_POINT_LAND(1|2) = 910 (FIFO SIZE)
// ? NO_POINT_LAND + POINT_LAND = 1065 (PHASE ~+-60deg)
-#define NO_POINT_LAND (NO_POINT_LAND1 + NO_POINT_LAND2 + NO_POINT_LAND3)
+#define NO_POINT_LAND (NO_POINT_LAND1 + NO_POINT_LAND2)
#define PHASE_POINT (fmod(FREQ_CHROM / (FREQ_SMP/3.0), 1.0) * PI * 2.0)
#define PHASE_SMP (fmod(FREQ_CHROM / (FREQ_SMP ), 1.0) * PI * 2.0)
#define PHASE_SEG (fmod(FREQ_CHROM / FREQ_SMP \
@@ -33,9 +33,7 @@
#define DWN_SMP 1
#define MAX_DRIFT 2
#define DRIFT_TAB {1200, 400, 0, 400, 1200}
-//#define MAX_DRIFT 3
-//#define DRIFT_TAB {2400, 1200, 400, 0, 400, 1200, 2400}
-#define PHASE_CMP_STEP 3
+#define PHASE_CMP_STEP 3
#define BAD_THRESHOLD1 0.8
#define BAD_THRESHOLD2 200
#define EDGE_LIMIT 70
@@ -97,8 +95,11 @@ void vc_decrypt(void){
printf("xy%d %d\n", wndx, x_field);
// 18
+// const int vcStartX=int(double(16 -scales_x+3)/x_field*wndx + .5) + some - 10;
const int vcStartX=int(double(16 -scales_x+3)/x_field*wndx + .5);
+ static FILE *pF= fopen("out.dat", "wb");
+
static int cutP2X[256];
static int x2CutP[max_x];
@@ -107,11 +108,11 @@ void vc_decrypt(void){
for(int x=0; x<max_x; x++){
const int cutP=int( double(x) / ( 3.0 * freqPix2) * FREQ_SMP
- - (NO_POINT_LAND1 + NO_POINT_LAND3/2)/3.0 + .5);
+ - (NO_POINT_LAND1)/3.0 + .5);
x2CutP[x]= cutP;
}
for(int cutP=0; cutP<256; cutP++){
- const int x=int( double(cutP*3 + NO_POINT_LAND1 + NO_POINT_LAND3/2)
+ const int x=int( double(cutP*3 + NO_POINT_LAND1)
* freqPix2 / FREQ_SMP + .5);
cutP2X[cutP]= x;
}
@@ -152,6 +153,10 @@ void vc_decrypt(void){
static char sin2PerCutP[256];
static char cos2PerCutP[256];
+ static int cutPs=0;
+ static int fields=0;
+ fields++;
+
if(first){
some=10;
@@ -166,7 +171,7 @@ void vc_decrypt(void){
}
for(int cutP=0; cutP<256; cutP++){
- const double phase= PHASE_SMP*(NO_POINT_LAND1 + NO_POINT_LAND3) + PHASE_POINT*cutP;
+ const double phase= PHASE_SMP*(NO_POINT_LAND1 + PHASE_PATCH) + PHASE_POINT*cutP; // - some/360.0*2.0*PI;
phasePerCutP[cutP]= (byte)( phase * 128 / PI );
sin1PerCutP[cutP]= char(sin( -phase + PHASE_SEG )*127);
cos1PerCutP[cutP]= char(cos( -phase + PHASE_SEG )*127);
@@ -305,7 +310,7 @@ void vc_decrypt(void){
int(lowRes[1] + ((( vcDiff ) >> (DWN_SMP-1))&~1)),
int(lowRes[0] + ((( vcDiff - cutP) >> (DWN_SMP-1))&~1)),
-(( (vcDiff-cutP) >> (DWN_SMP-1) ) & ~1) );
-
+
}
if(bestDiff>diff){
@@ -377,8 +382,8 @@ void vc_decrypt(void){
const int driftPenalty[MAX_DRIFT*2+1]= DRIFT_TAB;
- int *newVal=new int[257], *lastVal=new int[257];
- memset(lastVal, 0, 257<<2);
+ int *newVal=new int[256], *lastVal=new int[256];
+ memset(lastVal, 0, 256<<2);
byte *newPhaseErr=new byte[256], *lastPhaseErr=new byte[256];
memset(lastPhaseErr, 0, 256);
@@ -389,7 +394,7 @@ void vc_decrypt(void){
llinep+=vgax<<1;
linep+=vgax<<1;
- memset(newVal, 0, 257<<2);
+ memset(newVal, 0, 256<<2);
memset(newPhaseErr, 0, 256);
bool noLeft=true;
@@ -411,6 +416,12 @@ void vc_decrypt(void){
const int p= x>>(PHASE_CMP_STEP-1);
convVec[p ]= ul*un + vl*vn;
convVec[p+1]= ul*vn - vl*un;
+/*
+ const float fsScale= sqrt(convVec[p ]*convVec[p ] +
+ convVec[p+1]*convVec[p+1] );
+ convVec[p ]= int(convVec[p ]/pow(fsScale + .001, .9));
+ convVec[p+1]= int(convVec[p+1]/pow(fsScale + .001, .9));
+*/
chromAmp+= mabs(un) + mabs(vn);
}
if(line<4) chromAmp=1;
@@ -559,10 +570,11 @@ void vc_decrypt(void){
}
if(!black[line]){
+ int iBestVal=0;
for(int newCutP = 0; newCutP < 256; newCutP++){
if(!noLeft && newVal[newCutP]==0) continue;
- const byte * const p= &linep[ ((cutP2X[ newCutP ] + vcStartX)<<1) + 1 - 4 ];
+ const byte * const p= &linep[ ((cutP2X[ newCutP ] + vcStartX)<<1) + 1 - 4];
const int diff=edgeLut[ mabs( + int(* p ) + int(*(p+2))
- int(*(p+4)) - int(*(p+6)) ) ];
@@ -570,8 +582,8 @@ void vc_decrypt(void){
if(newVal[newCutP]==0) newVal[newCutP] = diff + 1000000000;
else newVal[newCutP] += diff;
- if(newVal[256] < newVal[newCutP]){
- newVal[256]= newVal[newCutP];
+ if(iBestVal < newVal[newCutP]){
+ iBestVal= newVal[newCutP];
bestDir[line]= newCutP;
}
@@ -603,7 +615,7 @@ void vc_decrypt(void){
if(showPoints){
int bestCutP=-1;
- for(int line=wndy-1; line>0; line--){
+ for(int line=wndy-2; line>0; line--){
if(bestDir[line]==-1){
bestCutP=-1;
continue;
@@ -615,16 +627,18 @@ void vc_decrypt(void){
continue;
}
- const int bestX= cutP2X[ bestCutP ];
- actVid2MemBufp->b[(line * vgax<<1) + ((vcStartX + bestX)<<1)+1]=255;
- actVid2MemBufp->b[(line * vgax<<1) + ((vcStartX + bestX)<<1)+3]=0;
- actVid2MemBufp->b[(line * vgax<<1) + ((vcStartX + bestX)<<1)+5]=255;
+// const int bestX= cutP2X[ bestCutP ];
+ int bestX=cutP2X[ bestCutP ] + cutPointX[line-1] - cutPointX[line];
+ if(bestX<0) bestX+= vcDiff;
+ if(bestX>=vcDiff) bestX-= vcDiff;
+ actVid2MemBufp->b[((line-1) * vgax<<1) + ((vcStartX + bestX)<<1)+1]=255;
+ actVid2MemBufp->b[((line-1) * vgax<<1) + ((vcStartX + bestX)<<1)+3]=0;
bestCutP= dir[(line<<8) + bestCutP];
}
}
- int cutpp[1000];
+ byte cutpp[1000];
byte copy_buff[max_x<<1];
int bestCutP=-1;
@@ -649,7 +663,7 @@ void vc_decrypt(void){
bestCutP=-1;
continue;
}
- if(bestCutP==-1) bestCutP=dir[(line<<8) + 256];
+ if(bestCutP==-1) bestCutP= bestDir[line];
if(bestCutP<0 || bestCutP>=256){
printf("two%d\n", bestCutP);
@@ -657,9 +671,11 @@ void vc_decrypt(void){
continue;
}
+ cutpp[line]=bestCutP;
+
const int bestX= cutP2X[ bestCutP ];
- int cutX= (showPoints ? cutPointX[line] : bestX );
+ int cutX= ((showPoints && 0) ? cutPointX[line] : bestX );
const int cutP= max(x2CutP[cutX], 0); // fix ? ness, min?
@@ -754,16 +770,18 @@ void vc_decrypt(void){
: "%eax", "%ebx", "%ecx");
}
- cutpp[line]=cutX;
-
-
bestCutP= dir[(line<<8) + bestCutP];
}
+ for(int line=1; line<wndy-1; line++)
+ {
+ fprintf(pF, "%d\n", cutpp[line]);
+ }
+
/*
float avgCutP=0;
for(int line=50; line<200; line++){
- avgCutP+=float(cutpp[line]);
+ avgCutP+=float(cutpp[l ine]);
}
avgCutP/=(200.0-50.0);
@@ -794,6 +812,10 @@ void vc_decrypt(void){
T1=T2;
}
+ c.init(255, 0, 0, false);
+ sprintf(textbuf[6],"%d l %d f", cutPs, fields);
+ gprint(infoPosX, infoPosY+=10, c.col, textbuf[6]);
+
delete [] bestDir;
delete [] dir;
Modified: trunk/2010/2_vc_a.asm
==============================================================================
--- trunk/2010/2_vc_a.asm (original)
+++ trunk/2010/2_vc_a.asm Wed Jul 4 10:15:33 2007
@@ -52,7 +52,7 @@ _vc_corr__Fiiiiii:
mov ebx, [esp + edi]
or eax, 0x80008000
-NoMMXloop:
+NoMMXloop:
sub edx, ecx ; U
sub eax, ebx ; V 1
and edx, 0x00FF00FF ; U
Modified: trunk/2010/makefile
==============================================================================
--- trunk/2010/makefile (original)
+++ trunk/2010/makefile Wed Jul 4 10:15:33 2007
@@ -16,11 +16,11 @@ AFLAGS = -f coff
O = 2010.o 2_file.o 2_grafix.o 2_hw.o 2_gfunc.o \
2_hw_asm.o 2_71x6.o 2_hw_mem.o 2_crypt.o\
- 2_glob_a.o 2_txt.o
+ 2_glob_a.o 2_txt.o 2_cryp_a.o
OC = 2010.o 2_file.o 2_grafix.o 2_hw.o 2_gfunc.o \
2_hw_asm.o 2_71x6.o 2_hw_mem.o 2_crypt.o 2_vc.o 2_nag.o\
- 2_nag_a.o 2_vc_a.o 2_glob_a.o 2_txt.o
+ 2_nag_a.o 2_vc_a.o 2_glob_a.o 2_txt.o 2_cryp_a.o
default: ;$(MAKE) 2010 CFLAGS="$(OPTS)"
@@ -50,4 +50,5 @@ clean: ; del $(O) 2010
2_glob_a.o : 2_glob_a.asm 2_all_a.asm
2_nag_a.o : 2_nag_a.asm 2_all_a.asm
2_vc_a.o : 2_vc_a.asm 2_all_a.asm
+2_cryp_a.o : 2_cryp_a.asm 2_all_a.asm
1
0
[mndiff]: r57 - in trunk/2010: 2010.cpp 2_all.h 2_crypt.cpp 2_grafix.cpp 2_txt.cpp 2_txt.h makefile
by michael 04 Jul '07
by michael 04 Jul '07
04 Jul '07
Author: michael
Date: Wed Jul 4 10:10:37 2007
New Revision: 57
Log:
next version from unknown date
Modified:
trunk/2010/2010.cpp
trunk/2010/2_all.h
trunk/2010/2_crypt.cpp
trunk/2010/2_grafix.cpp
trunk/2010/2_txt.cpp
trunk/2010/2_txt.h
trunk/2010/makefile
Modified: trunk/2010/2010.cpp
==============================================================================
--- trunk/2010/2010.cpp (original)
+++ trunk/2010/2010.cpp Wed Jul 4 10:10:37 2007
@@ -520,7 +520,7 @@ int main(int argc, char **argv){
setStdScale();
contGrab();
break;
-#ifndef NO_CRYPT
+#ifdef CRYPT
case '5' : TVStd= PAL;
cryptStd= vc;
if(yuvMode==0) yuvMode=1;
Modified: trunk/2010/2_all.h
==============================================================================
--- trunk/2010/2_all.h (original)
+++ trunk/2010/2_all.h Wed Jul 4 10:10:37 2007
@@ -2,8 +2,6 @@
#ifndef n2_all_h
#define n2_all_h
-#define NO_CRYPT
-
#define mabs(a) ((a)<0 ? -(a) : (a))
#define sign(a) ((a)<0 ? -1 : 1)
#define is_neg(a) ((a)<0 ? 0 : -1)
Modified: trunk/2010/2_crypt.cpp
==============================================================================
--- trunk/2010/2_crypt.cpp (original)
+++ trunk/2010/2_crypt.cpp Wed Jul 4 10:10:37 2007
@@ -51,9 +51,12 @@ void decrypt(void){
T1=T2;
}
+#ifdef CRYPT
if(cryptStd==vc) vc_decrypt();
else if(cryptStd==nag) nag_decrypt();
- else if(TVStd==TXTPAL) txt_decrypt();
+#endif
+
+ if(TVStd==TXTPAL) txt_decrypt();
if(iState){
T2=uclock();
Modified: trunk/2010/2_grafix.cpp
==============================================================================
--- trunk/2010/2_grafix.cpp (original)
+++ trunk/2010/2_grafix.cpp Wed Jul 4 10:10:37 2007
@@ -71,7 +71,7 @@ void showStuff(void){
}
if(menuLevel==mLTVStd){
-#ifdef NO_CRYPT
+#ifndef CRYPT
char text[3][256]={ "1. PAL 4. PAL-TeleText",
"2. NTSC",
"3. SECAM"};
Modified: trunk/2010/2_txt.cpp
==============================================================================
--- trunk/2010/2_txt.cpp (original)
+++ trunk/2010/2_txt.cpp Wed Jul 4 10:10:37 2007
@@ -4,6 +4,7 @@
#include <stdio.h>
#include <math.h>
#include <ctype.h>
+#include <time.h>
#include "2_all.h"
#include "2010.h"
#include "2_crypt.h"
@@ -131,20 +132,54 @@ void txt_decrypt(void){
// byte rawMagic[16]={255, 0, 255, 0, 255, 0, 255, 0,
// 255, 255, 255, 0, 0, 255, 0, 0 };
+ int clocks= clock();
static CACHE1 *cache1=new CACHE1[1024];
static int cache1Size=0;
static bool first=true;
static color txtColor[8];
static MAG mag[8];
+ static GETTAB *getTab=new GETTAB[1024];
+ static getTabNum=0;
if(first){
FILE *f= fopen("chaninf.txt", "rb");
if(f==NULL) error(TxtFile);
while(!feof(f)){
- fscanf(f, "%11[^\n]\n", cache1[cache1Size].chan);
+ int s=fscanf(f, "%27[^\n\r]%*[\n\r]", cache1[cache1Size].chan);
+ if(s==0) break;
+// printf("%s\n", cache1[cache1Size].chan);
cache1[cache1Size].pt= NULL;
cache1Size++;
}
+ fclose(f);
+
+ f= fopen("get.txt", "rb");
+ if(f!=NULL){
+ while(!feof(f)){
+ int s=fscanf(f, "%X %d %14[^\n\r]%*[\n\r]", &getTab[getTabNum].page,
+ &getTab[getTabNum].clockDelta,
+ getTab[getTabNum].name);
+ if(s==0) break;
+
+ getTab[getTabNum].nextClock=0;
+ getTab[getTabNum].clockDelta*=60*CLOCKS_PER_SEC;;
+
+ for(int i=0; getTab[getTabNum].name[i]!=0; i++)
+ if(getTab[getTabNum].name[i]=='.') getTab[getTabNum].name[i]=' ';
+
+ char name[127];
+ sprintf(name, "%s.txt", getTab[getTabNum].name);
+ getTab[getTabNum].f= fopen(name, "ab");
+ if(getTab[getTabNum].f==NULL) error(error_code(-999));
+ if(ftell(getTab[getTabNum].f)==0)
+ fprintf(getTab[getTabNum].f, "5 1 1 %s\n", getTab[getTabNum].name);
+
+// printf("%X %d %d %s\n", getTab[getTabNum].page, getTab[getTabNum].nextClock, getTab[getTabNum].clockDelta,
+// getTab[getTabNum].name);
+ getTabNum++;
+ }
+ }
+ fclose(f);
for(int i=0; i<256; i++){
int j=i&0x7F;
@@ -253,7 +288,7 @@ void txt_decrypt(void){
const int magAddr= d0 & 0x7;
const int rowAddr= (d0>>3) | (d1<<1);
- printf("lrm %d %d %d\n", line, rowAddr, magAddr);
+// printf("lrm %d %d %d\n", line, rowAddr, magAddr);
if(rowAddr==0){
mag[magAddr].pt=NULL;
@@ -295,8 +330,7 @@ void txt_decrypt(void){
break;
}
if( toupper(cache1[cache1Ndx].chan[pos]) != toupper(data[tryp+pos])
- && cache1[cache1Ndx].chan[pos] != 0x20
- && cache1[cache1Ndx].chan[pos] != 0x0D) break;
+ && cache1[cache1Ndx].chan[pos] != 0x20) break;
}
}
}
@@ -350,6 +384,7 @@ void txt_decrypt(void){
mag[magAddr].pt->land=mag[magAddr].land;
mag[magAddr].pt->sub=subPage;
+ mag[magAddr].pt->page=page;
mag[magAddr].order=0;
txtCpy(&mag[magAddr].pt->text[rowAddr*40], data+10, 32);
@@ -365,9 +400,67 @@ void txt_decrypt(void){
}
txtCpy(&mag[magAddr].pt->text[rowAddr*40], data+2, 40);
- }
+ char temp[40];
+ reMapCpy(temp, &mag[magAddr].pt->text[rowAddr*40], 40, mag[magAddr].pt->land);
+ for(int i=0; i<40; i++){
+ if(temp[i]==',') temp[i]='.';
+ }
+ for(int getTabNdx=0; getTabNdx<getTabNum; getTabNdx++){
+ if(mag[magAddr].pt->page!=getTab[getTabNdx].page) continue;
+
+ if(clocks<getTab[getTabNdx].nextClock) continue;
+ int len=strlen(getTab[getTabNdx].name);
+ int p;
+ for(p=0; p<40-len; p++){
+ if(!strnicmp(&temp[p], getTab[getTabNdx].name, len)) break;
+ }
+ if(p==40) continue;
+
+ float val=-1;
+ int skip=0;
+ for(p+=len; p<40; p++){
+ const char c= temp[p];
+
+ if(c=='+' || c=='-') skip++;
+ else if(c>='0' && c<='9'){
+ if(skip>0) skip=-skip;
+ if(skip==0){
+ sscanf(&temp[p], "%f", &val);
+ break;
+ }
+ }
+ else if(c!='.'){
+ if(skip<0) skip=-skip-1;
+ }
+ }
+ if(val==-1 || val==0.0) continue;
+
+
+ for(;p<40; p++) if(temp[p]==':') break;
+ int h=-1, m=-1;
+ if(p<40){
+ sscanf(&temp[p - 2], "%d:%d", &h, &m);
+ }
+
+
+ printf("%s, %f\n", getTab[getTabNdx].name, val );
+
+ time_t t;
+ time(&t);
+ tm *tim= gmtime(&t);
+ if(h!=-1) tim->tm_hour=h;
+ if(m!=-1) tim->tm_min=m;
+
+ fprintf(getTab[getTabNdx].f, "%04d %02d %02d %02d %02d %f\n",
+ tim->tm_year+1900, tim->tm_mon+1, tim->tm_mday, tim->tm_hour, tim->tm_min ,val);
+
+ getTab[getTabNdx].nextClock= clocks + getTab[getTabNdx].clockDelta;
+
+ break;
+ }
+ }
}
@@ -418,8 +511,8 @@ void txt_decrypt(void){
while(page!=start){
p=cache1[reqChanNum].pt[page];
while(p!=NULL){
- for(int i=0; i<LINES*40; i++)
- if(!strnicmp(&findTxt[1], &p->text[i], min(LINES*40-i, len))){
+ for(int i=0; i<LINES*40-len; i++)
+ if(!strnicmp(&findTxt[1], &p->text[i], len)){
found=true;
break;
}
@@ -602,6 +695,6 @@ void txt_decrypt(void){
if(parities>9999) parities-=9000;
}
-
+
Modified: trunk/2010/2_txt.h
==============================================================================
--- trunk/2010/2_txt.h (original)
+++ trunk/2010/2_txt.h Wed Jul 4 10:10:37 2007
@@ -5,6 +5,7 @@
#define LINES 25
struct CACHE2{
+ int page;
int sub;
bool seen;
char text[LINES*40];
@@ -13,7 +14,7 @@ struct CACHE2{
};
struct CACHE1{
- char chan[12];
+ char chan[28];
CACHE2 **pt;
};
@@ -23,6 +24,15 @@ struct MAG{
int land;
};
+struct GETTAB{
+ int page;
+ char name[15];
+ FILE *f;
+ int clockDelta;
+ int nextClock;
+};
+
+
void txt_decrypt(void);
#endif
Modified: trunk/2010/makefile
==============================================================================
--- trunk/2010/makefile (original)
+++ trunk/2010/makefile Wed Jul 4 10:10:37 2007
@@ -1,38 +1,49 @@
-.SUFFIXES: .c .cc .h .o .asm .S .s
+.SUFFIXES: .c .cc .cpp .h .o .asm .S .s
-CFLAGS = -g
-CFLAGS = -O3 -mpentium -fomit-frame-pointer -g -Wall -Wstrict-prototypes -malign-double -ffast-math -funroll-loops -fno-default-inline
+OPTS = -g
+OPTS = -O3 -mpentium -fomit-frame-pointer -g -Wall -Wstrict-prototypes -malign-double -ffast-math -funroll-loops -fno-default-inline
AFLAGS = -f coff
.c.o: ; gcc $(CFLAGS) -c $<
.cc.o: ; gcc $(CFLAGS) -c $<
+.cpp.o: ; gcc $(CFLAGS) -c $<
+
.S.o: ; gcc $(CFLAGS) -c $<
.asm.o: ; nasm $(AFLAGS) $<
O = 2010.o 2_file.o 2_grafix.o 2_hw.o 2_gfunc.o \
- 2_hw_asm.o 2_71x6.o 2_hw_mem.o 2_crypt.o 2_vc.o 2_nag.o\
- 2_nag_a.o 2_vc_a.o 2_glob_a.o 2_txt.o
+ 2_hw_asm.o 2_71x6.o 2_hw_mem.o 2_crypt.o\
+ 2_glob_a.o 2_txt.o
-2010 : $(O) ; gcc $(CFLAGS) -o 2010 $(O)
+OC = 2010.o 2_file.o 2_grafix.o 2_hw.o 2_gfunc.o \
+ 2_hw_asm.o 2_71x6.o 2_hw_mem.o 2_crypt.o 2_vc.o 2_nag.o\
+ 2_nag_a.o 2_vc_a.o 2_glob_a.o 2_txt.o
+
+default: ;$(MAKE) 2010 CFLAGS="$(OPTS)"
+
+crypt: ;$(MAKE) 2010C CFLAGS="$(OPTS) -DCRYPT"
+
+2010 : $(O) ; gcc $(CFLAGS) -o 2010 $(O)
+2010C : $(OC) ; gcc $(CFLAGS) -o 2010C $(OC)
clean: ; del $(O) 2010
-2010.o : 2010.cc 2_all.h 2010.h 2_file.h 2_hw.h 2_grafix.h\
+2010.o : 2010.cpp 2_all.h 2010.h 2_file.h 2_hw.h 2_grafix.h\
2_71x6.h 2_hw_mem.h 2_nag.h
-2_file.o : 2_file.cc 2_all.h 2_file.h 2010.h 2_hw.h
-2_gfunc.o : 2_gfunc.cc 2_all.h 2_gfunc.h 2010.h
-2_grafix.o : 2_grafix.cc 2_all.h 2_grafix.h 2010.h 2_gfunc.h 2_hw.h 2_file.h
-2_hw.o : 2_hw.cc 2_all.h 2_hw.h 2010.h 2_hw_asm.h 2_hw_mem.h\
+2_file.o : 2_file.cpp 2_all.h 2_file.h 2010.h 2_hw.h
+2_gfunc.o : 2_gfunc.cpp 2_all.h 2_gfunc.h 2010.h
+2_grafix.o : 2_grafix.cpp 2_all.h 2_grafix.h 2010.h 2_gfunc.h 2_hw.h 2_file.h
+2_hw.o : 2_hw.cpp 2_all.h 2_hw.h 2010.h 2_hw_asm.h 2_hw_mem.h\
2_71x6.h 2_mmx.h
-2_hw_mem.o : 2_hw_mem.cc 2_all.h 2_hw_mem.h 2010.h
-2_71x6.o : 2_71x6.cc 2_all.h 2_71x6.h 2_hw.h 2_hw_mem.h 2010.h 2_hw_asm.h
-2_crypt.o : 2_crypt.cc 2_all.h 2_crypt.h 2_71x6.h 2_vc.h 2_nag.h 2_txt.h
-2_vc.o : 2_vc.cc 2_all.h 2_vc.h 2_crypt.h 2_gfunc.h 2_vc_a.h
-2_nag.o : 2_nag.cc 2_all.h 2_nag.h 2_crypt.h 2_gfunc.h 2_mmx.h 2_nag_a.h\
+2_hw_mem.o : 2_hw_mem.cpp 2_all.h 2_hw_mem.h 2010.h
+2_71x6.o : 2_71x6.cpp 2_all.h 2_71x6.h 2_hw.h 2_hw_mem.h 2010.h 2_hw_asm.h
+2_crypt.o : 2_crypt.cpp 2_all.h 2_crypt.h 2_71x6.h 2_vc.h 2_nag.h 2_txt.h
+2_vc.o : 2_vc.cpp 2_all.h 2_vc.h 2_crypt.h 2_gfunc.h 2_vc_a.h
+2_nag.o : 2_nag.cpp 2_all.h 2_nag.h 2_crypt.h 2_gfunc.h 2_mmx.h 2_nag_a.h\
2010.h 2_hw_mem.h
-2_txt.o : 2_txt.cc 2_all.h 2_txt.h 2_crypt.h 2_gfunc.h 2010.h
+2_txt.o : 2_txt.cpp 2_all.h 2_txt.h 2_crypt.h 2_gfunc.h 2010.h 2_71x6.h
2_hw_asm.o : 2_hw_asm.s
1
0