[MN-dev] [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
michael
subversion at mplayerhq.hu
Wed Jul 4 11:27:16 CEST 2007
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
More information about the Mndiff-dev
mailing list