diff options
Diffstat (limited to 'converter/ppm')
21 files changed, 1077 insertions, 1055 deletions
diff --git a/converter/ppm/ppmtompeg/Makefile b/converter/ppm/ppmtompeg/Makefile index 6db72ea9..e5ad6c58 100644 --- a/converter/ppm/ppmtompeg/Makefile +++ b/converter/ppm/ppmtompeg/Makefile @@ -39,7 +39,15 @@ endif # MP_BASE_OBJS = mfwddct.o postdct.o huff.o bitio.o mheaders.o -MP_ENCODE_OBJS = iframe.o pframe.o bframe.o psearch.o bsearch.o block.o +MP_ENCODE_OBJS = \ + frames.o \ + iframe.o \ + pframe.o \ + bframe.o \ + psearch.o \ + bsearch.o \ + block.o + MP_OTHER_OBJS = mpeg.o subsample.o param.o rgbtoycc.o \ readframe.o combine.o jrevdct.o frame.o fsize.o frametype.o \ specifics.o rate.o opts.o input.o gethostname.o diff --git a/converter/ppm/ppmtompeg/bframe.c b/converter/ppm/ppmtompeg/bframe.c index 5dfb76d3..1dbc1846 100644 --- a/converter/ppm/ppmtompeg/bframe.c +++ b/converter/ppm/ppmtompeg/bframe.c @@ -84,7 +84,6 @@ static struct bframeStats { *====================*/ extern Block **dct, **dctr, **dctb; -extern dct_data_type **dct_data; #define NO_MOTION 0 #define MOTION 1 #define SKIP 2 /* used in useMotion in dct_data */ diff --git a/converter/ppm/ppmtompeg/bsearch.c b/converter/ppm/ppmtompeg/bsearch.c index 142987f5..70edfef6 100644 --- a/converter/ppm/ppmtompeg/bsearch.c +++ b/converter/ppm/ppmtompeg/bsearch.c @@ -77,6 +77,7 @@ #include "frames.h" #include "motion_search.h" #include "fsize.h" +#include "block.h" /*==================* diff --git a/converter/ppm/ppmtompeg/frames.c b/converter/ppm/ppmtompeg/frames.c new file mode 100644 index 00000000..a0764890 --- /dev/null +++ b/converter/ppm/ppmtompeg/frames.c @@ -0,0 +1,58 @@ +#include "mallocvar.h" +#include "fsize.h" + +#include "frames.h" + + +Block **dct=NULL, **dctr=NULL, **dctb=NULL; +dct_data_type **dct_data; /* used in p/bframe.c */ + + +/*===========================================================================* + * + * AllocDctBlocks + * + * allocate memory for dct blocks + * + * RETURNS: nothing + * + * SIDE EFFECTS: creates dct, dctr, dctb + * + *===========================================================================*/ +void +AllocDctBlocks(void) { + + int dctx, dcty; + int i; + + dctx = Fsize_x / DCTSIZE; + dcty = Fsize_y / DCTSIZE; + + MALLOCARRAY(dct, dcty); + ERRCHK(dct, "malloc"); + for (i = 0; i < dcty; ++i) { + dct[i] = (Block *) malloc(sizeof(Block) * dctx); + ERRCHK(dct[i], "malloc"); + } + + MALLOCARRAY(dct_data, dcty); + ERRCHK(dct_data, "malloc"); + for (i = 0; i < dcty; ++i) { + MALLOCARRAY(dct_data[i], dctx); + ERRCHK(dct[i], "malloc"); + } + + MALLOCARRAY(dctr, dcty/2); + ERRCHK(dctr, "malloc"); + MALLOCARRAY(dctb, dcty/2); + ERRCHK(dctb, "malloc"); + for (i = 0; i < dcty/2; ++i) { + MALLOCARRAY(dctr[i], dctx/2); + ERRCHK(dctr[i], "malloc"); + MALLOCARRAY(dctb[i], dctx/2); + ERRCHK(dctb[i], "malloc"); + } +} + + + diff --git a/converter/ppm/ppmtompeg/headers/bitio.h b/converter/ppm/ppmtompeg/headers/bitio.h index 89e61fbb..a24c21cd 100644 --- a/converter/ppm/ppmtompeg/headers/bitio.h +++ b/converter/ppm/ppmtompeg/headers/bitio.h @@ -60,9 +60,7 @@ #define BIT_IO_INCLUDED -/*==============* - * HEADER FILES * - *==============*/ +#include <stdio.h> #include "general.h" #include "ansi.h" diff --git a/converter/ppm/ppmtompeg/headers/block.h b/converter/ppm/ppmtompeg/headers/block.h index 46050492..22d306a1 100644 --- a/converter/ppm/ppmtompeg/headers/block.h +++ b/converter/ppm/ppmtompeg/headers/block.h @@ -1,3 +1,46 @@ +#ifndef BLOCK_H_INCLUDED + +#include "frame.h" +#include "mtypes.h" + +/* DIFFERENCE FUNCTIONS */ + +int32 +LumBlockMAD(const LumBlock * const currentBlockP, + const LumBlock * const motionBlockP, + int32 const bestSoFar); + +int32 +LumBlockMSE(const LumBlock * const currentBlockP, + const LumBlock * const motionBlockP, + int32 const bestSoFar); + +int32 +LumMotionError(const LumBlock * const currentBlockP, + MpegFrame * const prev, + int const by, + int const bx, + vector const m, + int32 const bestSoFar); + +int32 +LumAddMotionError(const LumBlock * const currentBlockP, + const LumBlock * const blockSoFarP, + MpegFrame * const prev, + int const by, + int const bx, + vector const m, + int32 const bestSoFar); + +int32 +LumMotionErrorSubSampled(const LumBlock * const currentBlockP, + MpegFrame * const prevFrame, + int const by, + int const bx, + vector const m, + int const startY, + int const startX); + void ComputeDiffDCTs(MpegFrame * const current, MpegFrame * const prev, @@ -51,3 +94,4 @@ AddBMotionBlock(Block block, void BlockifyFrame(MpegFrame * const frameP); +#endif diff --git a/converter/ppm/ppmtompeg/headers/frame.h b/converter/ppm/ppmtompeg/headers/frame.h index 1003ee15..acd74419 100644 --- a/converter/ppm/ppmtompeg/headers/frame.h +++ b/converter/ppm/ppmtompeg/headers/frame.h @@ -130,18 +130,4 @@ Frame_Resize(MpegFrame * const omf, int const outsize_x, int const outsize_y); - -extern void Frame_Free _ANSI_ARGS_((MpegFrame *frame)); -extern void Frame_Exit _ANSI_ARGS_((void)); -extern void Frame_AllocPPM _ANSI_ARGS_((MpegFrame * frame)); -extern void Frame_AllocYCC _ANSI_ARGS_((MpegFrame * mf)); -extern void Frame_AllocDecoded _ANSI_ARGS_((MpegFrame *frame, - boolean makeReference)); -extern void Frame_AllocHalf _ANSI_ARGS_((MpegFrame *frame)); -extern void Frame_AllocBlocks _ANSI_ARGS_((MpegFrame *mf)); -extern void Frame_Resize _ANSI_ARGS_((MpegFrame *omf, MpegFrame *mf, - int insize_x, int insize_y, - int outsize_x, int outsize_y)); - - -#endif /* FRAME_INCLUDED */ +#endif diff --git a/converter/ppm/ppmtompeg/headers/frames.h b/converter/ppm/ppmtompeg/headers/frames.h index 3fefaea7..8661645b 100644 --- a/converter/ppm/ppmtompeg/headers/frames.h +++ b/converter/ppm/ppmtompeg/headers/frames.h @@ -15,6 +15,7 @@ #include "ansi.h" #include "mtypes.h" #include "mheaders.h" +#include "iframe.h" #include "frame.h" @@ -85,11 +86,13 @@ typedef struct dct_data_tye_struct { int fmotionX, fmotionY, bmotionX, bmotionY; } dct_data_type; -void EncodeYDC _ANSI_ARGS_((int32 dc_term, int32 *pred_term, BitBucket *bb)); -void -EncodeCDC(int32 const dc_term, - int32 * const pred_term, - BitBucket * const bb); + +/*==================* + * GLOBAL VARIABLES * + *==================*/ + +extern Block **dct, **dctr, **dctb; +extern dct_data_type **dct_data; /*========* @@ -100,63 +103,6 @@ EncodeCDC(int32 const dc_term, #define int_ceil_div(a,b,c) ((b*(c = a/b) < a) ? (c+1) : c) #define int_floor_div(a,b,c) ((b*(c = a/b) > a) ? (c-1) : c) -/* assumes many things: - * block indices are (y,x) - * variables y_dc_pred, cr_dc_pred, and cb_dc_pred - * flat block fb exists - */ -#define GEN_I_BLOCK(frameType, frame, bb, mbAI, qscale) { \ - boolean overflow, overflowChange=FALSE; \ - int overflowValue = 0; \ - do { \ - overflow = Mpost_QuantZigBlock(dct[y][x], fb[0], \ - qscale, TRUE)==MPOST_OVERFLOW; \ - overflow |= Mpost_QuantZigBlock(dct[y][x+1], fb[1], \ - qscale, TRUE)==MPOST_OVERFLOW; \ - overflow |= Mpost_QuantZigBlock(dct[y+1][x], fb[2], \ - qscale, TRUE)==MPOST_OVERFLOW; \ - overflow |= Mpost_QuantZigBlock(dct[y+1][x+1], fb[3], \ - qscale, TRUE)==MPOST_OVERFLOW; \ - overflow |= Mpost_QuantZigBlock(dctb[y >> 1][x >> 1], \ - fb[4], qscale, TRUE)==MPOST_OVERFLOW; \ - overflow |= Mpost_QuantZigBlock(dctr[y >> 1][x >> 1], \ - fb[5], qscale, TRUE)==MPOST_OVERFLOW; \ - if ((overflow) && (qscale!=31)) { \ - overflowChange = TRUE; overflowValue++; \ - qscale++; \ - } else overflow = FALSE; \ - } while (overflow); \ - Mhead_GenMBHeader(bb, \ - frameType /* pict_code_type */, mbAI /* addr_incr */, \ - qscale /* q_scale */, \ - 0 /* forw_f_code */, 0 /* back_f_code */, \ - 0 /* horiz_forw_r */, 0 /* vert_forw_r */, \ - 0 /* horiz_back_r */, 0 /* vert_back_r */, \ - 0 /* motion_forw */, 0 /* m_horiz_forw */, \ - 0 /* m_vert_forw */, 0 /* motion_back */, \ - 0 /* m_horiz_back */, 0 /* m_vert_back */, \ - 0 /* mb_pattern */, TRUE /* mb_intra */); \ - \ - /* Y blocks */ \ - EncodeYDC(fb[0][0], &y_dc_pred, bb); \ - Mpost_RLEHuffIBlock(fb[0], bb); \ - EncodeYDC(fb[1][0], &y_dc_pred, bb); \ - Mpost_RLEHuffIBlock(fb[1], bb); \ - EncodeYDC(fb[2][0], &y_dc_pred, bb); \ - Mpost_RLEHuffIBlock(fb[2], bb); \ - EncodeYDC(fb[3][0], &y_dc_pred, bb); \ - Mpost_RLEHuffIBlock(fb[3], bb); \ - \ - /* CB block */ \ - EncodeCDC(fb[4][0], &cb_dc_pred, bb); \ - Mpost_RLEHuffIBlock(fb[4], bb); \ - \ - /* CR block */ \ - EncodeCDC(fb[5][0], &cr_dc_pred, bb); \ - Mpost_RLEHuffIBlock(fb[5], bb); \ - if (overflowChange) qscale -= overflowValue; \ - } - #define BLOCK_TO_FRAME_COORD(bx1, bx2, x1, x2) { \ x1 = (bx1)*DCTSIZE; \ x2 = (bx2)*DCTSIZE; \ @@ -253,6 +199,9 @@ encodeMotionVector(int const x, *===============================*/ void +AllocDctBlocks(void); + +void ComputeBMotionLumBlock(MpegFrame * const prev, MpegFrame * const next, int const by, @@ -270,8 +219,6 @@ BMotionSearch(const LumBlock * const currentBlockP, motion * const motionP, int const oldMode); -void GenIFrame (BitBucket * const bb, - MpegFrame * const mf); void GenPFrame (BitBucket * const bb, MpegFrame * const current, MpegFrame * const prev); @@ -279,11 +226,6 @@ void GenBFrame (BitBucket * const bb, MpegFrame * const curr, MpegFrame * const prev, MpegFrame * const next); -void AllocDctBlocks _ANSI_ARGS_((void )); - - -float -IFrameTotalTime(void); float PFrameTotalTime(void); @@ -292,11 +234,6 @@ float BFrameTotalTime(void); void -ShowIFrameSummary(unsigned int const inputFrameBits, - unsigned int const totalBits, - FILE * const fpointer); - -void ShowPFrameSummary(unsigned int const inputFrameBits, unsigned int const totalBits, FILE * const fpointer); @@ -306,87 +243,6 @@ ShowBFrameSummary(unsigned int const inputFrameBits, unsigned int const totalBits, FILE * const fpointer); -/* DIFFERENCE FUNCTIONS */ - -int32 -LumBlockMAD(const LumBlock * const currentBlockP, - const LumBlock * const motionBlockP, - int32 const bestSoFar); - -int32 -LumBlockMSE(const LumBlock * const currentBlockP, - const LumBlock * const motionBlockP, - int32 const bestSoFar); - -int32 -LumMotionError(const LumBlock * const currentBlockP, - MpegFrame * const prev, - int const by, - int const bx, - vector const m, - int32 const bestSoFar); - -int32 -LumAddMotionError(const LumBlock * const currentBlockP, - const LumBlock * const blockSoFarP, - MpegFrame * const prev, - int const by, - int const bx, - vector const m, - int32 const bestSoFar); - -int32 -LumMotionErrorA(const LumBlock * const currentBlockP, - MpegFrame * const prevFrame, - int const by, - int const bx, - vector const m, - int32 const bestSoFar); - -int32 -LumMotionErrorB(const LumBlock * const currentP, - MpegFrame * const prevFrame, - int const by, - int const bx, - vector const m, - int32 const bestSoFar); - -int32 -LumMotionErrorC(const LumBlock * const currentP, - MpegFrame * const prevFrame, - int const by, - int const bx, - vector const m, - int32 const bestSoFar); - -int32 -LumMotionErrorD(const LumBlock * const currentP, - MpegFrame * const prevFrame, - int const by, - int const bx, - vector const m, - int32 const bestSoFar); - -int32 -LumMotionErrorSubSampled(const LumBlock * const currentBlockP, - MpegFrame * const prevFrame, - int const by, - int const bx, - vector const m, - int const startY, - int const startX); - -void -BlockComputeSNR(MpegFrame * const current, - float * const snr, - float * const psnr); - -int32 -time_elapsed(void); - -void -AllocDctBlocks(void); - /*==================* * GLOBAL VARIABLES * *==================*/ @@ -412,7 +268,7 @@ extern int fCodeI,fCodeP,fCodeB; extern boolean forceEncodeLast; extern int TIME_RATE; -#endif /* FRAMES_INCLUDED */ +#endif /* diff --git a/converter/ppm/ppmtompeg/headers/iframe.h b/converter/ppm/ppmtompeg/headers/iframe.h new file mode 100644 index 00000000..c4f77c74 --- /dev/null +++ b/converter/ppm/ppmtompeg/headers/iframe.h @@ -0,0 +1,118 @@ +#ifndef IFRAME_H_INCLUDED +#define IFRAME_H_INCLUDED + +#include "frame.h" + +void +SetFCode(void); + +void +SetSlicesPerFrame(int const number); + +void +SetBlocksPerSlice(void); + +void +SetIQScale(int const qI); + +int +GetIQScale(void); + +void +GenIFrame(BitBucket * const bb, + MpegFrame * const current); + +void +ResetIFrameStats(void); + +float +IFrameTotalTime(void); + + +void +ShowIFrameSummary(unsigned int const inputFrameBits, + unsigned int const totalBits, + FILE * const fpointer); + +void +EncodeYDC(int32 const dc_term, + int32 * const pred_term, + BitBucket * const bb); + +void +EncodeCDC(int32 const dc_term, + int32 * const pred_term, + BitBucket * const bb); + +void +BlockComputeSNR(MpegFrame * const current, + float * const snr, + float * const psnr); + +void +WriteDecodedFrame(MpegFrame * const frame); + +void +PrintItoIBitRate(int const numBits, + int const frameNum); + +int32 time_elapsed(void); + +/* assumes many things: + * block indices are (y,x) + * variables y_dc_pred, cr_dc_pred, and cb_dc_pred + * flat block fb exists + */ +#define GEN_I_BLOCK(frameType, frame, bb, mbAI, qscale) { \ + boolean overflow, overflowChange=FALSE; \ + int overflowValue = 0; \ + do { \ + overflow = Mpost_QuantZigBlock(dct[y][x], fb[0], \ + qscale, TRUE)==MPOST_OVERFLOW; \ + overflow |= Mpost_QuantZigBlock(dct[y][x+1], fb[1], \ + qscale, TRUE)==MPOST_OVERFLOW; \ + overflow |= Mpost_QuantZigBlock(dct[y+1][x], fb[2], \ + qscale, TRUE)==MPOST_OVERFLOW; \ + overflow |= Mpost_QuantZigBlock(dct[y+1][x+1], fb[3], \ + qscale, TRUE)==MPOST_OVERFLOW; \ + overflow |= Mpost_QuantZigBlock(dctb[y >> 1][x >> 1], \ + fb[4], qscale, TRUE)==MPOST_OVERFLOW; \ + overflow |= Mpost_QuantZigBlock(dctr[y >> 1][x >> 1], \ + fb[5], qscale, TRUE)==MPOST_OVERFLOW; \ + if ((overflow) && (qscale!=31)) { \ + overflowChange = TRUE; overflowValue++; \ + qscale++; \ + } else overflow = FALSE; \ + } while (overflow); \ + Mhead_GenMBHeader(bb, \ + frameType /* pict_code_type */, mbAI /* addr_incr */, \ + qscale /* q_scale */, \ + 0 /* forw_f_code */, 0 /* back_f_code */, \ + 0 /* horiz_forw_r */, 0 /* vert_forw_r */, \ + 0 /* horiz_back_r */, 0 /* vert_back_r */, \ + 0 /* motion_forw */, 0 /* m_horiz_forw */, \ + 0 /* m_vert_forw */, 0 /* motion_back */, \ + 0 /* m_horiz_back */, 0 /* m_vert_back */, \ + 0 /* mb_pattern */, TRUE /* mb_intra */); \ + \ + /* Y blocks */ \ + EncodeYDC(fb[0][0], &y_dc_pred, bb); \ + Mpost_RLEHuffIBlock(fb[0], bb); \ + EncodeYDC(fb[1][0], &y_dc_pred, bb); \ + Mpost_RLEHuffIBlock(fb[1], bb); \ + EncodeYDC(fb[2][0], &y_dc_pred, bb); \ + Mpost_RLEHuffIBlock(fb[2], bb); \ + EncodeYDC(fb[3][0], &y_dc_pred, bb); \ + Mpost_RLEHuffIBlock(fb[3], bb); \ + \ + /* CB block */ \ + EncodeCDC(fb[4][0], &cb_dc_pred, bb); \ + Mpost_RLEHuffIBlock(fb[4], bb); \ + \ + /* CR block */ \ + EncodeCDC(fb[5][0], &cr_dc_pred, bb); \ + Mpost_RLEHuffIBlock(fb[5], bb); \ + if (overflowChange) qscale -= overflowValue; \ + } + +#endif diff --git a/converter/ppm/ppmtompeg/headers/motion_search.h b/converter/ppm/ppmtompeg/headers/motion_search.h index ab83cbca..62f3abab 100644 --- a/converter/ppm/ppmtompeg/headers/motion_search.h +++ b/converter/ppm/ppmtompeg/headers/motion_search.h @@ -100,6 +100,9 @@ PMotionSearch(const LumBlock * const currentBlockP, int const bx, vector * const motionP); +void +MotionSearchPreComputation(MpegFrame * const frameP); + /*==================* * GLOBAL VARIABLES * *==================*/ diff --git a/converter/ppm/ppmtompeg/headers/mpeg.h b/converter/ppm/ppmtompeg/headers/mpeg.h index d739dede..18e6c7e1 100644 --- a/converter/ppm/ppmtompeg/headers/mpeg.h +++ b/converter/ppm/ppmtompeg/headers/mpeg.h @@ -90,7 +90,6 @@ void ReadDecodedRefFrame(MpegFrame * const frameP, unsigned int const frameNumber); -extern void WriteDecodedFrame _ANSI_ARGS_((MpegFrame *frame)); extern void SetBitRateFileName _ANSI_ARGS_((char *fileName)); extern void SetFrameRate _ANSI_ARGS_((void)); diff --git a/converter/ppm/ppmtompeg/headers/mproto.h b/converter/ppm/ppmtompeg/headers/mproto.h index c3b0f4b3..d8fefd84 100644 --- a/converter/ppm/ppmtompeg/headers/mproto.h +++ b/converter/ppm/ppmtompeg/headers/mproto.h @@ -74,7 +74,6 @@ #include "bitio.h" -#define DCTSIZE2 DCTSIZE*DCTSIZE typedef short DCTELEM; typedef DCTELEM DCTBLOCK[DCTSIZE2]; @@ -111,9 +110,6 @@ void ReadEYUV _ANSI_ARGS_((MpegFrame * mf, FILE *fpointer, int width, boolean ReadPPM _ANSI_ARGS_((MpegFrame *mf, FILE *fpointer)); void PPMtoYCC _ANSI_ARGS_((MpegFrame * mf)); -void MotionSearchPreComputation _ANSI_ARGS_((MpegFrame *frame)); -boolean PMotionSearch _ANSI_ARGS_((LumBlock currentBlock, MpegFrame *prev, - int by, int bx, int *motionY, int *motionX)); void ComputeHalfPixelData _ANSI_ARGS_((MpegFrame *frame)); void mp_validate_size _ANSI_ARGS_((int *x, int *y)); void AllocYCC _ANSI_ARGS_((MpegFrame * mf)); @@ -126,7 +122,3 @@ void j_rev_dct _ANSI_ARGS_((DCTBLOCK data )); void j_rev_dct_sparse _ANSI_ARGS_((DCTBLOCK data , int pos )); void j_rev_dct _ANSI_ARGS_((DCTBLOCK data )); -/* block.c */ -void BlockToData _ANSI_ARGS_((uint8 **data, Block block, int by, int bx)); -void AddMotionBlock _ANSI_ARGS_((Block block, uint8 **prev, int by, int bx, - int my, int mx)); diff --git a/converter/ppm/ppmtompeg/headers/parallel.h b/converter/ppm/ppmtompeg/headers/parallel.h index e18d3f46..cf27ce66 100644 --- a/converter/ppm/ppmtompeg/headers/parallel.h +++ b/converter/ppm/ppmtompeg/headers/parallel.h @@ -87,7 +87,7 @@ void NoteFrameDone(int frameStart, int frameEnd); void -SetIOConvert(boolean separate); +SetIOConvert(bool const separate); void SetRemoteShell(const char * const shell); diff --git a/converter/ppm/ppmtompeg/headers/prototypes.h b/converter/ppm/ppmtompeg/headers/prototypes.h index d729aafa..b421af35 100644 --- a/converter/ppm/ppmtompeg/headers/prototypes.h +++ b/converter/ppm/ppmtompeg/headers/prototypes.h @@ -44,20 +44,15 @@ void ResetBFrameStats _ANSI_ARGS_((void)); void ResetPFrameStats _ANSI_ARGS_((void)); void SetSearchRange (int const pixelsP, int const pixelsB); -void ResetIFrameStats _ANSI_ARGS_((void)); void SetPixelSearch(const char * const searchType); -void SetIQScale _ANSI_ARGS_((int qI)); void SetPQScale _ANSI_ARGS_((int qP)); void SetBQScale _ANSI_ARGS_((int qB)); -float EstimateSecondsPerIFrame _ANSI_ARGS_((void)); float EstimateSecondsPerPFrame _ANSI_ARGS_((void)); float EstimateSecondsPerBFrame _ANSI_ARGS_((void)); void SetGOPSize _ANSI_ARGS_((int size)); void SetStatFileName(const char * const fileName); -void SetSlicesPerFrame _ANSI_ARGS_((int number)); -void SetBlocksPerSlice _ANSI_ARGS_((void)); void DCTFrame _ANSI_ARGS_((MpegFrame * mf)); @@ -69,8 +64,6 @@ void MotionSearchPreComputation _ANSI_ARGS_((MpegFrame *frame)); void ComputeHalfPixelData _ANSI_ARGS_((MpegFrame *frame)); void mp_validate_size _ANSI_ARGS_((int *x, int *y)); -extern void SetFCode _ANSI_ARGS_((void)); - /* psearch.c */ void ShowPMVHistogram _ANSI_ARGS_((FILE *fpointer)); diff --git a/converter/ppm/ppmtompeg/headers/subsample.h b/converter/ppm/ppmtompeg/headers/subsample.h new file mode 100644 index 00000000..deedf251 --- /dev/null +++ b/converter/ppm/ppmtompeg/headers/subsample.h @@ -0,0 +1,39 @@ +#ifndef SUBSAMPLE_H_INCLUDED +#define SUBSAMPLE_H_INCLUDED + +#include "frame.h" +#include "mtypes.h" + +int32 +LumMotionErrorA(const LumBlock * const currentBlockP, + MpegFrame * const prevFrame, + int const by, + int const bx, + vector const m, + int32 const bestSoFar); + +int32 +LumMotionErrorB(const LumBlock * const currentP, + MpegFrame * const prevFrame, + int const by, + int const bx, + vector const m, + int32 const bestSoFar); + +int32 +LumMotionErrorC(const LumBlock * const currentP, + MpegFrame * const prevFrame, + int const by, + int const bx, + vector const m, + int32 const bestSoFar); + +int32 +LumMotionErrorD(const LumBlock * const currentP, + MpegFrame * const prevFrame, + int const by, + int const bx, + vector const m, + int32 const bestSoFar); + +#endif diff --git a/converter/ppm/ppmtompeg/iframe.c b/converter/ppm/ppmtompeg/iframe.c index cb6d4683..c6735505 100644 --- a/converter/ppm/ppmtompeg/iframe.c +++ b/converter/ppm/ppmtompeg/iframe.c @@ -11,10 +11,9 @@ * GetIQScale * * ResetIFrameStats * * ShowIFrameSummary * - * EstimateSecondsPerIFrame * * EncodeYDC * * EncodeCDC * - * time_elapsed * + * time_elapsed * * * *===========================================================================*/ @@ -67,6 +66,8 @@ #include "specifics.h" #include "opts.h" +#include "iframe.h" + /*==================* * STATIC VARIABLES * *==================*/ @@ -128,24 +129,11 @@ int fCodeI, fCodeP, fCodeB; boolean printSNR = FALSE; boolean printMSE = FALSE; boolean decodeRefFrames = FALSE; -Block **dct=NULL, **dctr=NULL, **dctb=NULL; -dct_data_type **dct_data; /* used in p/bframe.c */ int TIME_RATE; -/*=====================* - * EXPORTED PROCEDURES * - *=====================*/ -extern void PrintItoIBitRate _ANSI_ARGS_((int numBits, int frameNum)); - -/*===============================* - * INTERNAL PROCEDURE prototypes * - *===============================*/ -void AllocDctBlocks(void ); -int SetFCodeHelper (int sr); -void CalcDistortion (MpegFrame *current, int y, int x); -int +static int SetFCodeHelper(int const SR) { int range,fCode; @@ -296,6 +284,68 @@ GetIQScale(void) { +static void +CalcDistortion(MpegFrame * const current, + int const y, + int const x) { + + int qscale, distort=0; + Block decblk; + FlatBlock fblk; + int datarate = 0; + + for (qscale = 1; qscale < 32; qscale ++) { + distort = 0; + datarate = 0; + Mpost_QuantZigBlock(dct[y][x], fblk, qscale, TRUE); + Mpost_UnQuantZigBlock(fblk, decblk, qscale, TRUE); + if (collect_distortion_detailed) datarate += CalcRLEHuffLength(fblk); + mpeg_jrevdct((int16 *)decblk); + distort += mse(current->y_blocks[y][x], decblk); + + Mpost_QuantZigBlock(dct[y][x+1], fblk, qscale, TRUE); + Mpost_UnQuantZigBlock(fblk, decblk, qscale, TRUE); + if (collect_distortion_detailed) datarate += CalcRLEHuffLength(fblk); + mpeg_jrevdct((int16 *)decblk); + distort += mse(current->y_blocks[y][x+1], decblk); + + Mpost_QuantZigBlock(dct[y+1][x], fblk, qscale, TRUE); + Mpost_UnQuantZigBlock(fblk, decblk, qscale, TRUE); + if (collect_distortion_detailed) datarate += CalcRLEHuffLength(fblk); + mpeg_jrevdct((int16 *)decblk); + distort += mse(current->y_blocks[y+1][x], decblk); + + Mpost_QuantZigBlock(dct[y+1][x+1], fblk, qscale, TRUE); + Mpost_UnQuantZigBlock(fblk, decblk, qscale, TRUE); + if (collect_distortion_detailed) datarate += CalcRLEHuffLength(fblk); + mpeg_jrevdct((int16 *)decblk); + distort += mse(current->y_blocks[y+1][x+1], decblk); + + Mpost_QuantZigBlock(dctb[y >> 1][x >> 1], fblk, qscale, TRUE); + Mpost_UnQuantZigBlock(fblk, decblk, qscale, TRUE); + if (collect_distortion_detailed) datarate += CalcRLEHuffLength(fblk); + mpeg_jrevdct((int16 *)decblk); + distort += mse(current->cb_blocks[y>>1][x>>1], decblk); + + Mpost_QuantZigBlock(dctr[y >> 1][x >> 1], fblk, qscale, TRUE); + Mpost_UnQuantZigBlock(fblk, decblk, qscale, TRUE); + if (collect_distortion_detailed) datarate += CalcRLEHuffLength(fblk); + mpeg_jrevdct((int16 *)decblk); + distort += mse(current->cr_blocks[y >> 1][x >> 1], decblk); + + if (!collect_distortion_detailed) { + fprintf(distortion_fp, "\t%d\n", distort); + } else if (collect_distortion_detailed == 1) { + fprintf(distortion_fp, "\t%d\t%d\n", distort, datarate); + } else { + fprintf(fp_table_rate[qscale-1], "%d\n", datarate); + fprintf(fp_table_dist[qscale-1], "%d\n", distort); + } + } +} + + + /*===========================================================================* * * GenIFrame @@ -618,24 +668,6 @@ ShowIFrameSummary(unsigned int const inputFrameBits, /*===========================================================================* * - * EstimateSecondsPerIFrame - * - * estimates the number of seconds required per I-frame - * - * RETURNS: seconds (floating point value) - * - * SIDE EFFECTS: none - * - *===========================================================================*/ -float -EstimateSecondsPerIFrame() -{ - return (float)totalTime/((float)TIME_RATE*(float)numFrames); -} - - -/*===========================================================================* - * * EncodeYDC * * Encode the DC portion of a DCT of a luminance block @@ -926,53 +958,6 @@ PrintItoIBitRate(int const numBits, -/*===========================================================================* - * - * AllocDctBlocks - * - * allocate memory for dct blocks - * - * RETURNS: nothing - * - * SIDE EFFECTS: creates dct, dctr, dctb - * - *===========================================================================*/ -void -AllocDctBlocks(void) { - int dctx, dcty; - int i; - - dctx = Fsize_x / DCTSIZE; - dcty = Fsize_y / DCTSIZE; - - dct = (Block **) malloc(sizeof(Block *) * dcty); - ERRCHK(dct, "malloc"); - for (i = 0; i < dcty; i++) { - dct[i] = (Block *) malloc(sizeof(Block) * dctx); - ERRCHK(dct[i], "malloc"); - } - - dct_data = (dct_data_type **) malloc(sizeof(dct_data_type *) * dcty); - ERRCHK(dct_data, "malloc"); - for (i = 0; i < dcty; i++) { - dct_data[i] = (dct_data_type *) malloc(sizeof(dct_data_type) * dctx); - ERRCHK(dct[i], "malloc"); - } - - dctr = (Block **) malloc(sizeof(Block *) * (dcty >> 1)); - dctb = (Block **) malloc(sizeof(Block *) * (dcty >> 1)); - ERRCHK(dctr, "malloc"); - ERRCHK(dctb, "malloc"); - for (i = 0; i < (dcty >> 1); i++) { - dctr[i] = (Block *) malloc(sizeof(Block) * (dctx >> 1)); - dctb[i] = (Block *) malloc(sizeof(Block) * (dctx >> 1)); - ERRCHK(dctr[i], "malloc"); - ERRCHK(dctb[i], "malloc"); - } -} - - - /*======================================================================* * * time_elapsed @@ -997,66 +982,4 @@ int32 time_elapsed(void) { -void -CalcDistortion(MpegFrame * const current, - int const y, - int const x) { - - int qscale, distort=0; - Block decblk; - FlatBlock fblk; - int datarate = 0; - - for (qscale = 1; qscale < 32; qscale ++) { - distort = 0; - datarate = 0; - Mpost_QuantZigBlock(dct[y][x], fblk, qscale, TRUE); - Mpost_UnQuantZigBlock(fblk, decblk, qscale, TRUE); - if (collect_distortion_detailed) datarate += CalcRLEHuffLength(fblk); - mpeg_jrevdct((int16 *)decblk); - distort += mse(current->y_blocks[y][x], decblk); - - Mpost_QuantZigBlock(dct[y][x+1], fblk, qscale, TRUE); - Mpost_UnQuantZigBlock(fblk, decblk, qscale, TRUE); - if (collect_distortion_detailed) datarate += CalcRLEHuffLength(fblk); - mpeg_jrevdct((int16 *)decblk); - distort += mse(current->y_blocks[y][x+1], decblk); - - Mpost_QuantZigBlock(dct[y+1][x], fblk, qscale, TRUE); - Mpost_UnQuantZigBlock(fblk, decblk, qscale, TRUE); - if (collect_distortion_detailed) datarate += CalcRLEHuffLength(fblk); - mpeg_jrevdct((int16 *)decblk); - distort += mse(current->y_blocks[y+1][x], decblk); - - Mpost_QuantZigBlock(dct[y+1][x+1], fblk, qscale, TRUE); - Mpost_UnQuantZigBlock(fblk, decblk, qscale, TRUE); - if (collect_distortion_detailed) datarate += CalcRLEHuffLength(fblk); - mpeg_jrevdct((int16 *)decblk); - distort += mse(current->y_blocks[y+1][x+1], decblk); - - Mpost_QuantZigBlock(dctb[y >> 1][x >> 1], fblk, qscale, TRUE); - Mpost_UnQuantZigBlock(fblk, decblk, qscale, TRUE); - if (collect_distortion_detailed) datarate += CalcRLEHuffLength(fblk); - mpeg_jrevdct((int16 *)decblk); - distort += mse(current->cb_blocks[y>>1][x>>1], decblk); - - Mpost_QuantZigBlock(dctr[y >> 1][x >> 1], fblk, qscale, TRUE); - Mpost_UnQuantZigBlock(fblk, decblk, qscale, TRUE); - if (collect_distortion_detailed) datarate += CalcRLEHuffLength(fblk); - mpeg_jrevdct((int16 *)decblk); - distort += mse(current->cr_blocks[y >> 1][x >> 1], decblk); - - if (!collect_distortion_detailed) { - fprintf(distortion_fp, "\t%d\n", distort); - } else if (collect_distortion_detailed == 1) { - fprintf(distortion_fp, "\t%d\t%d\n", distort, datarate); - } else { - fprintf(fp_table_rate[qscale-1], "%d\n", datarate); - fprintf(fp_table_dist[qscale-1], "%d\n", distort); - } - } -} - - - diff --git a/converter/ppm/ppmtompeg/mheaders.c b/converter/ppm/ppmtompeg/mheaders.c index 2a5f2c63..4cfe49ac 100644 --- a/converter/ppm/ppmtompeg/mheaders.c +++ b/converter/ppm/ppmtompeg/mheaders.c @@ -278,24 +278,350 @@ const double VidRateNum[9]={1.0, 23.976, 24.0, 25.0, 29.97, 30.0, 50.0 ,59.94, 60.0}; -/*===============================* - * INTERNAL PROCEDURE prototypes * - *===============================*/ - -static void GenMBAddrIncr _ANSI_ARGS_((BitBucket *bb, uint32 addr_incr)); -static void GenPictHead _ANSI_ARGS_((BitBucket *bb, uint32 temp_ref, - uint32 code_type, uint32 vbv_delay, - int32 full_pel_forw_flag, uint32 forw_f_code, - int32 full_pel_back_flag, uint32 back_f_code, - uint8 *extra_info, uint32 extra_info_size, - uint8 *ext_data, uint32 ext_data_size, - uint8 *user_data, uint32 user_data_size)); -static void GenMBType _ANSI_ARGS_((BitBucket *bb, uint32 pict_code_type, - uint32 mb_quant, uint32 motion_forw, uint32 motion_back, - uint32 mb_pattern, uint32 mb_intra)); -static void GenMotionCode _ANSI_ARGS_((BitBucket *bb, int32 vector)); -static void GenBlockPattern _ANSI_ARGS_((BitBucket *bb, - uint32 mb_pattern)); +/*=====================* + * INTERNAL PROCEDURES * + *=====================*/ + +/*===========================================================================* + * + * GenMBType + * + * generate macroblock type with given attributes + * append result to the specified bitstream + * + * RETURNS: nothing + * + * SIDE EFFECTS: none + * + *===========================================================================*/ +static void +GenMBType(bbPtr, pict_code_type, mb_quant, motion_forw, motion_back, + mb_pattern, mb_intra) + BitBucket *bbPtr; + uint32 pict_code_type; + uint32 mb_quant; + uint32 motion_forw; + uint32 motion_back; + uint32 mb_pattern; + uint32 mb_intra; +{ + int code; + + switch (pict_code_type) { + case 1: + if ((motion_forw != 0) || (motion_back != 0) || (mb_pattern != 0) || (mb_intra != 1)) { + perror("Illegal parameters for macroblock type."); + exit(-1); + } + if (mb_quant) { + Bitio_Write(bbPtr, 0x1, 2); + } else { + Bitio_Write(bbPtr, 0x1, 1); + } + break; + + case 2: + code = 0; + if (mb_quant) { + code += 16; + } + if (motion_forw) { + code += 8; + } + if (motion_back) { + code += 4; + } + if (mb_pattern) { + code += 2; + } + if (mb_intra) { + code += 1; + } + + switch (code) { + case 1: + Bitio_Write(bbPtr, 0x3, 5); + break; + case 2: + Bitio_Write(bbPtr, 0x1, 2); + break; + case 8: + Bitio_Write(bbPtr, 0x1, 3); + break; + case 10: + Bitio_Write(bbPtr, 0x1, 1); + break; + case 17: + Bitio_Write(bbPtr, 0x1, 6); + break; + case 18: + Bitio_Write(bbPtr, 0x1, 5); + break; + case 26: + Bitio_Write(bbPtr, 0x2, 5); + break; + default: + perror("Illegal parameters for macroblock type."); + exit(-1); + break; + } + break; + + case 3: + code = 0; + if (mb_quant) { + code += 16; + } + if (motion_forw) { + code += 8; + } + if (motion_back) { + code += 4; + } + if (mb_pattern) { + code += 2; + } + if (mb_intra) { + code += 1; + } + + switch (code) { + case 12: + Bitio_Write(bbPtr, 0x2, 2); + break; + case 14: + Bitio_Write(bbPtr, 0x3, 2); + break; + case 4: + Bitio_Write(bbPtr, 0x2, 3); + break; + case 6: + Bitio_Write(bbPtr, 0x3, 3); + break; + case 8: + Bitio_Write(bbPtr, 0x2, 4); + break; + case 10: + Bitio_Write(bbPtr, 0x3, 4); + break; + case 1: + Bitio_Write(bbPtr, 0x3, 5); + break; + case 30: + Bitio_Write(bbPtr, 0x2, 5); + break; + case 26: + Bitio_Write(bbPtr, 0x3, 6); + break; + case 22: + Bitio_Write(bbPtr, 0x2, 6); + break; + case 17: + Bitio_Write(bbPtr, 0x1, 6); + break; + default: + perror("Illegal parameters for macroblock type."); + exit(-1); + break; + } + break; + } +} + + +/*===========================================================================* + * + * GenMotionCode + * + * generate motion vector output with given value + * append result to the specified bitstream + * + * RETURNS: nothing + * + * SIDE EFFECTS: none + * + *===========================================================================*/ +static void +GenMotionCode(BitBucket * const bbPtr, + int32 const vector) { + + uint32 code, num; + + if ((vector < -16) || (vector > 16)) { + perror("Motion vector out of range."); + fprintf(stderr, "Motion vector out of range: vector = %d\n", vector); + exit(-1); + } + code = mbMotionVectorTable[vector + 16][0]; + num = mbMotionVectorTable[vector + 16][1]; + + Bitio_Write(bbPtr, code, num); +} + + +/*===========================================================================* + * + * GenBlockPattern + * + * generate macroblock pattern output + * append result to the specified bitstream + * + * RETURNS: nothing + * + * SIDE EFFECTS: none + * + *===========================================================================*/ +static void +GenBlockPattern(bbPtr, mb_pattern) + BitBucket *bbPtr; + uint32 mb_pattern; +{ + uint32 code, num; + + code = mbPatTable[mb_pattern][0]; + num = mbPatTable[mb_pattern][1]; + + Bitio_Write(bbPtr, code, num); +} + + +/*===========================================================================* + * + * GenMBAddrIncr + * + * generate macroblock address increment output + * append result to the specified bitstream + * + * RETURNS: nothing + * + * SIDE EFFECTS: none + * + *===========================================================================*/ +static void +GenMBAddrIncr(bbPtr, addr_incr) + BitBucket *bbPtr; + uint32 addr_incr; +{ + uint32 code; + uint32 num; + + code = mbAddrIncrTable[addr_incr][0]; + num = mbAddrIncrTable[addr_incr][1]; + + Bitio_Write(bbPtr, code, num); +} + + +/*===========================================================================* + * + * GenPictHead + * + * generate picture header with given attributes + * append result to the specified bitstream + * + * RETURNS: nothing + * + * SIDE EFFECTS: none + * + *===========================================================================*/ +static void +GenPictHead(bbPtr, temp_ref, code_type, vbv_delay, full_pel_forw_flag, + forw_f_code, full_pel_back_flag, back_f_code, extra_info, + extra_info_size, ext_data, ext_data_size, user_data, + user_data_size) + BitBucket *bbPtr; + uint32 temp_ref; + uint32 code_type; + uint32 vbv_delay; + int32 full_pel_forw_flag; + uint32 forw_f_code; + int32 full_pel_back_flag; + uint32 back_f_code; + uint8 *extra_info; + uint32 extra_info_size; + uint8 *ext_data; + uint32 ext_data_size; + uint8 *user_data; + uint32 user_data_size; +{ + /* Write picture start code. */ + Bitio_Write(bbPtr, PICT_START_CODE, 32); + + /* Temp reference. */ + Bitio_Write(bbPtr, temp_ref, 10); + + /* Code_type. */ + if (code_type == 0) + code_type = 1; + + Bitio_Write(bbPtr, code_type, 3); + + /* vbv_delay. */ + vbv_delay = 0xffff; /* see page 36 (section 2.4.3.4) */ + Bitio_Write(bbPtr, vbv_delay, 16); + + if ((code_type == 2) || (code_type == 3)) { + + /* Full pel forw flag. */ + + if (full_pel_forw_flag) + Bitio_Write(bbPtr, 0x01, 1); + else + Bitio_Write(bbPtr, 0x00, 1); + + /* Forw f code. */ + + Bitio_Write(bbPtr, forw_f_code, 3); + } + if (code_type == 3) { + + /* Full pel back flag. */ + + if (full_pel_back_flag) + Bitio_Write(bbPtr, 0x01, 1); + else + Bitio_Write(bbPtr, 0x00, 1); + + /* Back f code. */ + + Bitio_Write(bbPtr, back_f_code, 3); + } + /* Extra bit picture info. */ + + if (extra_info != NULL) { + unsigned int i; + for (i = 0; i < extra_info_size; ++i) { + Bitio_Write(bbPtr, 0x01, 1); + Bitio_Write(bbPtr, extra_info[i], 8); + } + } + Bitio_Write(bbPtr, 0x00, 1); + + /* next start code */ + Bitio_BytePad(bbPtr); + + /* Write ext data if present. */ + + if (ext_data != NULL) { + unsigned int i; + + Bitio_Write(bbPtr, EXT_START_CODE, 32); + + for (i = 0; i < ext_data_size; ++i) + Bitio_Write(bbPtr, ext_data[i], 8); + Bitio_BytePad(bbPtr); + } + /* Write user data if present. */ + if (user_data != NULL) { + unsigned int i; + Bitio_Write(bbPtr, USER_START_CODE, 32); + + for (i = 0; i < user_data_size; ++i) + Bitio_Write(bbPtr, user_data[i], 8); + + Bitio_BytePad(bbPtr); + } +} /*=====================* @@ -767,7 +1093,8 @@ if ( addr_incr != 1 ) } /* Generate mb type code. */ - GenMBType(bbPtr, pict_code_type, mb_quant, motion_forw, motion_back, mb_pattern, mb_intra); + GenMBType(bbPtr, pict_code_type, mb_quant, + motion_forw, motion_back, mb_pattern, mb_intra); /* MB quant. */ if (mb_quant) { @@ -831,353 +1158,6 @@ if ( addr_incr != 1 ) } -/*=====================* - * INTERNAL PROCEDURES * - *=====================*/ - -/*===========================================================================* - * - * GenMBType - * - * generate macroblock type with given attributes - * append result to the specified bitstream - * - * RETURNS: nothing - * - * SIDE EFFECTS: none - * - *===========================================================================*/ -static void -GenMBType(bbPtr, pict_code_type, mb_quant, motion_forw, motion_back, - mb_pattern, mb_intra) - BitBucket *bbPtr; - uint32 pict_code_type; - uint32 mb_quant; - uint32 motion_forw; - uint32 motion_back; - uint32 mb_pattern; - uint32 mb_intra; -{ - int code; - - switch (pict_code_type) { - case 1: - if ((motion_forw != 0) || (motion_back != 0) || (mb_pattern != 0) || (mb_intra != 1)) { - perror("Illegal parameters for macroblock type."); - exit(-1); - } - if (mb_quant) { - Bitio_Write(bbPtr, 0x1, 2); - } else { - Bitio_Write(bbPtr, 0x1, 1); - } - break; - - case 2: - code = 0; - if (mb_quant) { - code += 16; - } - if (motion_forw) { - code += 8; - } - if (motion_back) { - code += 4; - } - if (mb_pattern) { - code += 2; - } - if (mb_intra) { - code += 1; - } - - switch (code) { - case 1: - Bitio_Write(bbPtr, 0x3, 5); - break; - case 2: - Bitio_Write(bbPtr, 0x1, 2); - break; - case 8: - Bitio_Write(bbPtr, 0x1, 3); - break; - case 10: - Bitio_Write(bbPtr, 0x1, 1); - break; - case 17: - Bitio_Write(bbPtr, 0x1, 6); - break; - case 18: - Bitio_Write(bbPtr, 0x1, 5); - break; - case 26: - Bitio_Write(bbPtr, 0x2, 5); - break; - default: - perror("Illegal parameters for macroblock type."); - exit(-1); - break; - } - break; - - case 3: - code = 0; - if (mb_quant) { - code += 16; - } - if (motion_forw) { - code += 8; - } - if (motion_back) { - code += 4; - } - if (mb_pattern) { - code += 2; - } - if (mb_intra) { - code += 1; - } - - switch (code) { - case 12: - Bitio_Write(bbPtr, 0x2, 2); - break; - case 14: - Bitio_Write(bbPtr, 0x3, 2); - break; - case 4: - Bitio_Write(bbPtr, 0x2, 3); - break; - case 6: - Bitio_Write(bbPtr, 0x3, 3); - break; - case 8: - Bitio_Write(bbPtr, 0x2, 4); - break; - case 10: - Bitio_Write(bbPtr, 0x3, 4); - break; - case 1: - Bitio_Write(bbPtr, 0x3, 5); - break; - case 30: - Bitio_Write(bbPtr, 0x2, 5); - break; - case 26: - Bitio_Write(bbPtr, 0x3, 6); - break; - case 22: - Bitio_Write(bbPtr, 0x2, 6); - break; - case 17: - Bitio_Write(bbPtr, 0x1, 6); - break; - default: - perror("Illegal parameters for macroblock type."); - exit(-1); - break; - } - break; - } -} - - -/*===========================================================================* - * - * GenMotionCode - * - * generate motion vector output with given value - * append result to the specified bitstream - * - * RETURNS: nothing - * - * SIDE EFFECTS: none - * - *===========================================================================*/ -static void -GenMotionCode(BitBucket * const bbPtr, - int32 const vector) { - - uint32 code, num; - - if ((vector < -16) || (vector > 16)) { - perror("Motion vector out of range."); - fprintf(stderr, "Motion vector out of range: vector = %d\n", vector); - exit(-1); - } - code = mbMotionVectorTable[vector + 16][0]; - num = mbMotionVectorTable[vector + 16][1]; - - Bitio_Write(bbPtr, code, num); -} - - -/*===========================================================================* - * - * GenBlockPattern - * - * generate macroblock pattern output - * append result to the specified bitstream - * - * RETURNS: nothing - * - * SIDE EFFECTS: none - * - *===========================================================================*/ -static void -GenBlockPattern(bbPtr, mb_pattern) - BitBucket *bbPtr; - uint32 mb_pattern; -{ - uint32 code, num; - - code = mbPatTable[mb_pattern][0]; - num = mbPatTable[mb_pattern][1]; - - Bitio_Write(bbPtr, code, num); -} - - -/*===========================================================================* - * - * GenMBAddrIncr - * - * generate macroblock address increment output - * append result to the specified bitstream - * - * RETURNS: nothing - * - * SIDE EFFECTS: none - * - *===========================================================================*/ -static void -GenMBAddrIncr(bbPtr, addr_incr) - BitBucket *bbPtr; - uint32 addr_incr; -{ - uint32 code; - uint32 num; - - code = mbAddrIncrTable[addr_incr][0]; - num = mbAddrIncrTable[addr_incr][1]; - - Bitio_Write(bbPtr, code, num); -} - - -/*===========================================================================* - * - * GenPictHead - * - * generate picture header with given attributes - * append result to the specified bitstream - * - * RETURNS: nothing - * - * SIDE EFFECTS: none - * - *===========================================================================*/ -static void -GenPictHead(bbPtr, temp_ref, code_type, vbv_delay, full_pel_forw_flag, - forw_f_code, full_pel_back_flag, back_f_code, extra_info, - extra_info_size, ext_data, ext_data_size, user_data, - user_data_size) - BitBucket *bbPtr; - uint32 temp_ref; - uint32 code_type; - uint32 vbv_delay; - int32 full_pel_forw_flag; - uint32 forw_f_code; - int32 full_pel_back_flag; - uint32 back_f_code; - uint8 *extra_info; - uint32 extra_info_size; - uint8 *ext_data; - uint32 ext_data_size; - uint8 *user_data; - uint32 user_data_size; -{ - int i; - - /* Write picture start code. */ - Bitio_Write(bbPtr, PICT_START_CODE, 32); - - /* Temp reference. */ - Bitio_Write(bbPtr, temp_ref, 10); - - /* Code_type. */ - if (code_type == 0) { - code_type = 1; - } - Bitio_Write(bbPtr, code_type, 3); - - /* vbv_delay. */ - vbv_delay = 0xffff; /* see page 36 (section 2.4.3.4) */ - Bitio_Write(bbPtr, vbv_delay, 16); - - if ((code_type == 2) || (code_type == 3)) { - - /* Full pel forw flag. */ - - if (full_pel_forw_flag) { - Bitio_Write(bbPtr, 0x01, 1); - } else { - Bitio_Write(bbPtr, 0x00, 1); - } - - /* Forw f code. */ - - Bitio_Write(bbPtr, forw_f_code, 3); - } - if (code_type == 3) { - - /* Full pel back flag. */ - - if (full_pel_back_flag) { - Bitio_Write(bbPtr, 0x01, 1); - } else { - Bitio_Write(bbPtr, 0x00, 1); - } - - /* Back f code. */ - - Bitio_Write(bbPtr, back_f_code, 3); - } - /* Extra bit picture info. */ - - if (extra_info != NULL) { - for (i = 0; i < extra_info_size; i++) { - Bitio_Write(bbPtr, 0x01, 1); - Bitio_Write(bbPtr, extra_info[i], 8); - } - } - Bitio_Write(bbPtr, 0x00, 1); - - /* next start code */ - Bitio_BytePad(bbPtr); - - /* Write ext data if present. */ - - if (ext_data != NULL) { - Bitio_Write(bbPtr, EXT_START_CODE, 32); - - for (i = 0; i < ext_data_size; i++) { - Bitio_Write(bbPtr, ext_data[i], 8); - } - Bitio_BytePad(bbPtr); - } - /* Write user data if present. */ - if (user_data != NULL) { - Bitio_Write(bbPtr, USER_START_CODE, 32); - - for (i = 0; i < user_data_size; i++) { - Bitio_Write(bbPtr, user_data[i], 8); - } - Bitio_BytePad(bbPtr); - } -} - - #ifdef UNUSED_PROCEDURES /* GenMBEnd only used for `D` pictures. Shouldn't really ever be called. */ diff --git a/converter/ppm/ppmtompeg/pframe.c b/converter/ppm/ppmtompeg/pframe.c index e72fe5d6..de91e32c 100644 --- a/converter/ppm/ppmtompeg/pframe.c +++ b/converter/ppm/ppmtompeg/pframe.c @@ -60,8 +60,6 @@ static int32 totalTime = 0; static int qscaleP; static float totalSNR = 0.0; static float totalPSNR = 0.0; -extern Block **dct, **dctr, **dctb; -extern dct_data_type **dct_data; /*=====================* * INTERNAL PROCEDURES * diff --git a/converter/ppm/ppmtompeg/psearch.c b/converter/ppm/ppmtompeg/psearch.c index aea1a29b..83c62d04 100644 --- a/converter/ppm/ppmtompeg/psearch.c +++ b/converter/ppm/ppmtompeg/psearch.c @@ -16,6 +16,8 @@ #include "prototypes.h" #include "fsize.h" #include "param.h" +#include "subsample.h" +#include "block.h" /*==================* diff --git a/converter/ppm/ppmtompeg/subsample.c b/converter/ppm/ppmtompeg/subsample.c index 5ec71814..69401a1d 100644 --- a/converter/ppm/ppmtompeg/subsample.c +++ b/converter/ppm/ppmtompeg/subsample.c @@ -43,6 +43,7 @@ #include "bitio.h" #include "prototypes.h" +#include "subsample.h" static void diff --git a/converter/ppm/sldtoppm.c b/converter/ppm/sldtoppm.c index 7da6d592..e0760448 100644 --- a/converter/ppm/sldtoppm.c +++ b/converter/ppm/sldtoppm.c @@ -66,15 +66,9 @@ struct svector { struct spoint t; /* To point */ }; -static int extend ARGS((smallint ch)); -static int sli ARGS((void)); -static int slib ARGS((void)); -static void vscale ARGS((int *px, int *py)); -static void slider ARGS((void (*slvec) ARGS((struct svector *vec, int color)), - void (*slflood) ARGS((struct spolygon *poly, int color)) )); -static void slidefind ARGS((char *sname, int dironly, int ucasen)); -static void draw ARGS((struct svector *vec, int color)); -static void flood ARGS((struct spolygon *poly, int color)); +typedef void (slvecfn)(struct svector * vec, int color); +typedef void (slfloodfn)(struct spolygon * poly, int color); + static int ixdots, iydots; /* Screen size in dots */ static FILE *slfile; /* Slide file descriptor */ @@ -104,21 +98,26 @@ static int adjust = FALSE; /* Adjust to correct aspect ratio ? */ static struct slhead slfrof; /* Slide file header */ static long xfac, yfac; /* Aspect ratio scale factors */ -static int sdrawkcab; /* Slide drawing kinematic conversion of - ass-backwards data flag */ +static int sdrawkcab; + /* Slide drawing kinematic conversion of ass-backwards data flag */ + + /* EXTEND -- Turn a smallint into an int with sign extension, whether - or not that happens automatically. */ + or not that happens automatically. +*/ -static int extend(smallint ch) -{ +static int +extend(smallint ch) { return ((int) ((ch & 0x80) ? (ch | ~0xFF) : ch)); } + + /* SLI -- Input word from slide file */ -static int sli() -{ +static int +sli(void) { short wd; if (fread(&wd, sizeof wd, 1, slfile) != 1) { @@ -131,10 +130,12 @@ static int sli() return wd; } + + /* SLIB -- Input byte from slide file */ -static int slib() -{ +static int +slib(void) { smallint ch = 0; if (fread(&ch, sizeof ch, 1, slfile) != 1) { @@ -143,25 +144,171 @@ static int slib() return extend(ch); } + + /* VSCALE -- scale screen coordinates for mismatched display. */ -static void vscale(px, py) - int *px, *py; -{ +static void +vscale(int * const px, + int * const py) { + *px = (((unsigned) *px) * xfac) >> 16; *py = (((unsigned) *py) * yfac) >> 16; } + + +/* SLIDEFIND -- Find a slide in a library or, if DIRONLY is + nonzero, print a directory listing of the library. + If UCASEN is nonzero, the requested slide name is + converted to upper case. */ + +static void +slidefind(const char * const sname, + bool const dironly, + bool const ucasen) { + + char uname[32]; + unsigned char libent[36]; + long pos; + + if (dironly) + pm_message("Slides in library:"); + else { + int i; + const char * ip; + + ip = sname; /* initial value */ + + for (i = 0; i < 31; i++) { + char ch = *ip++; + if (ch == EOS) + break; + if (ucasen && ISLOWER(ch)) + ch = TOUPPER(ch); + uname[i] = ch; + } + uname[i] = EOS; + } + + /* Read slide library header and verify. */ + + if ((fread(libent, 32, 1, slfile) != 1) || + (!STREQ((char *)libent, "AutoCAD Slide Library 1.0\015\012\32"))) { + pm_error("not an AutoCAD slide library file."); + } + pos = 32; + + /* Search for a slide with the requested name. */ + + while (TRUE) { + if ((fread(libent, 36, 1, slfile) != 1) || + (strlen((char *)libent) == 0)) { + if (dironly) { + return; + } + pm_error("slide %s not in library.", sname); + } + pos += 36; + if (dironly) { + pm_message(" %s", libent); + } else if (STREQ((char *)libent, uname)) { + long dpos = (((((libent[35] << 8) | libent[34]) << 8) | + libent[33]) << 8) | libent[32]; + if ((slfile == stdin) || (fseek(slfile, dpos, 0) == -1)) { + dpos -= pos; + + while (dpos-- > 0) + getc(slfile); + } + break; + } + } +} + + + +/* DRAW -- Draw a vector in the given AutoCAD color. */ + +static slvecfn draw; + +static void +draw(struct svector * vec, + int color) { + + pixel rgbcolor; + + if (blither) { + pm_message("Vector (%d, %d) - (%d, %d) Color %d", + vec->f.x, vec->f.y, vec->t.x, vec->t.y, color); + } + assert(vec->f.x >= 0 && vec->f.x < pixcols); + assert(vec->f.y >= 0 && vec->f.y < pixrows); + assert(vec->t.x >= 0 && vec->t.x < pixcols); + assert(vec->t.y >= 0 && vec->t.y < pixrows); + PPM_ASSIGN(rgbcolor, + acadcol[color][0], acadcol[color][1], acadcol[color][2]); + ppmd_line(pixels, pixcols, pixrows, pixmaxval, + vec->f.x, iydots - vec->f.y, vec->t.x, iydots - vec->t.y, + PPMD_NULLDRAWPROC, + (char *) &rgbcolor); +} + + + +/* FLOOD -- Draw a filled polygon. */ + +static slfloodfn flood; + +static void +flood(struct spolygon * const poly, + int const color) { + + unsigned int i; + struct fillobj * handle; + pixel rgbcolor; + + handle = ppmd_fill_create(); + + if (blither) { + unsigned int i; + pm_message("Polygon: %d points, fill type %d, color %d", + poly->npoints, poly->fill, color); + for (i = 0; i < poly->npoints; i++) { + pm_message(" Point %d: (%d, %d)", i + 1, + poly->pt[i].x, poly->pt[i].y); + } + } + + PPM_ASSIGN(rgbcolor, + acadcol[color][0], acadcol[color][1], acadcol[color][2]); + for (i = 0; i < poly->npoints; i++) { + assert(poly->pt[i].x >= 0 && poly->pt[i].x < pixcols); + assert(poly->pt[i].y >= 0 && poly->pt[i].y < pixrows); + ppmd_line(pixels, pixcols, pixrows, pixmaxval, + poly->pt[i].x, iydots - poly->pt[i].y, + poly->pt[(i + 1) % poly->npoints].x, + iydots - poly->pt[(i + 1) % poly->npoints].y, + ppmd_fill_drawproc, handle); + } + ppmd_fill(pixels, pixcols, pixrows, pixmaxval, + handle, PPMD_NULLDRAWPROC, (char *) &rgbcolor); + + ppmd_fill_destroy(handle); +} + + + /* SLIDER -- Read slide file. This is called with the name of the file to be read and function pointers to the routines which process vectors and polygon fill requests respectively. */ -static void slider(slvec, slflood) - void (*slvec) ARGS((struct svector *vec, int color)); - void (*slflood) ARGS((struct spolygon *poly, int color)); -{ +static void +slider(slvecfn slvec, + slfloodfn slflood) { + int i, rescale; unsigned char ubfr[4]; /* Utility character buffer */ int lx, ly; /* Last x and y point */ @@ -174,14 +321,14 @@ static void slider(slvec, slflood) short rtest; /* Value to test byte reversal */ short btest = 0x1234; /* Value to test byte-reversal */ static struct slhead slhi = /* Master slide header sample */ - {"AutoCAD Slide\r\n\32", 86,2, 0,0, 0.0, 0}; + {"AutoCAD Slide\r\n\32", 86,2, 0,0, 0.0, 0}; int curcolor = 7; /* Current vector color */ pixel rgbcolor; /* Pixel used to clear pixmap */ - + lx = ly = 32000; - + /* Process the header of the slide file. */ - + sdrawkcab = FALSE; /* Initially guess byte order is OK */ fread(slfrof.slh, 17, 1, slfile); fread(&slfrof.sntype, sizeof(char), 1, slfile); @@ -194,48 +341,46 @@ static void slider(slvec, slflood) /* Verify that slide format is compatible with this program. */ - if (STREQ(slfrof.slh, slhi.slh)) { + if (STREQ(slfrof.slh, slhi.slh)) pm_error("this is not an AutoCAD slide file."); - } /* Verify that the number format and file level in the header are compatible. All slides written by versions of AutoCAD released since September of 1987 are compatible with this format. */ - if ((slfrof.sntype != slhi.sntype) || (slfrof.slevel != slhi.slevel)) { + if ((slfrof.sntype != slhi.sntype) || (slfrof.slevel != slhi.slevel)) pm_error("incompatible slide file format"); - } /* Build SDSAR value from long scaled version. */ - + ldsar = 0L; - for (i = 3; i >= 0; i--) { - ldsar = (ldsar << 8) | ubfr[i]; - } + for (i = 3; i >= 0; --i) + ldsar = (ldsar << 8) | ubfr[i]; slfrof.sdsar = ((double) ldsar) / 1E7; - + /* Examine the byte order test value. If it's backwards, set the byte-reversal flag and correct all of the values we've read in - so far. */ + so far. + */ if (btest != rtest) { - sdrawkcab = TRUE; + sdrawkcab = TRUE; #define rshort(x) x = ((x >> 8) & 0xFF) | (x << 8) - rshort(slfrof.sxdots); - rshort(slfrof.sydots); - rshort(slfrof.shwfill); + rshort(slfrof.sxdots); + rshort(slfrof.sydots); + rshort(slfrof.shwfill); #undef rshort } - + /* Dump the header if we're blithering. */ if (blither || info) { pm_message("Slide file type %d, level %d, hwfill type %d.", - slfrof.sntype, slfrof.slevel, slfrof.shwfill); + slfrof.sntype, slfrof.slevel, slfrof.shwfill); pm_message("Original screen size %dx%d, aspect ratio %.3f.", - slfrof.sxdots + 1, slfrof.sydots + 1, slfrof.sdsar); + slfrof.sxdots + 1, slfrof.sydots + 1, slfrof.sdsar); pm_message("Byte order is %s.", - sdrawkcab ? "being reversed" : "the same"); + sdrawkcab ? "being reversed" : "the same"); } /* If the display aspect ratio indicates that the pixels on the @@ -246,405 +391,284 @@ static void slider(slvec, slflood) We always correct the aspect ratio by adjusting the width of the image. This guarantees that output from the SHADE command, which is essentially scan-line data written in vector form, - will not be corrupted. */ + will not be corrupted. + */ dsar = ((double) slfrof.sxdots) / slfrof.sydots; if (fabs(slfrof.sdsar - dsar) > 0.0001) { - if (adjust) { - ixdots = slfrof.sxdots * (slfrof.sdsar / dsar) + 0.5; - iydots = slfrof.sydots; - dsar = ((double) ixdots) / iydots; + if (adjust) { + ixdots = slfrof.sxdots * (slfrof.sdsar / dsar) + 0.5; + iydots = slfrof.sydots; + dsar = ((double) ixdots) / iydots; + } else { + pm_message("Warning - pixels on source screen were non-square. " + "Specifying -adjust will correct image width " + "to compensate."); + ixdots = slfrof.sxdots; + iydots = slfrof.sydots; + dsar = slfrof.sdsar; + } } else { - pm_message("Warning - pixels on source screen were non-square."); - pm_message(" Specifying -adjust will correct image width to compensate."); + /* Source pixels were square. */ ixdots = slfrof.sxdots; iydots = slfrof.sydots; dsar = slfrof.sdsar; - } - } else { - /* Source pixels were square. */ - ixdots = slfrof.sxdots; - iydots = slfrof.sydots; - dsar = slfrof.sdsar; - adjust = FALSE; /* Mark no adjustment needed */ + adjust = FALSE; /* Mark no adjustment needed */ } /* If there's a uniform scale factor specified, apply it. */ if (uscale > 0) { - ixdots = (ixdots * uscale) + 0.5; - iydots = (iydots * uscale) + 0.5; + ixdots = (ixdots * uscale) + 0.5; + iydots = (iydots * uscale) + 0.5; } /* If the image is to be stretched to a given width, set the output image sizes accordingly. If only a height or width is given, scale the other direction proportionally to preserve the - aspect ratio. */ + aspect ratio. + */ if (sxsize > 0) { - if (sysize > 0) { - iydots = sysize - 1; - } else { - iydots = ((((long) iydots) * (sxsize - 1)) + - (iydots / 2)) / ixdots; - } - ixdots = sxsize - 1; - } else if (sysize > 0) { - if (sxsize > 0) { + if (sysize > 0) { + iydots = sysize - 1; + } else { + iydots = ((((long) iydots) * (sxsize - 1)) + + (iydots / 2)) / ixdots; + } ixdots = sxsize - 1; - } else { - ixdots = ((((long) ixdots) * (sysize - 1)) + - (ixdots / 2)) / iydots; - } - iydots = sysize - 1; + } else if (sysize > 0) { + if (sxsize > 0) { + ixdots = sxsize - 1; + } else { + ixdots = ((((long) ixdots) * (sysize - 1)) + + (ixdots / 2)) / iydots; + } + iydots = sysize - 1; } - + if (adjust) { - pm_message( + pm_message( "Resized from %dx%d to %dx%d to correct pixel aspect ratio.", - slfrof.sxdots + 1, slfrof.sydots + 1, ixdots + 1, iydots + 1); + slfrof.sxdots + 1, slfrof.sydots + 1, ixdots + 1, iydots + 1); } - + /* Allocate image buffer and clear it to black. */ - + pixels = ppm_allocarray(pixcols = ixdots + 1, pixrows = iydots + 1); PPM_ASSIGN(rgbcolor, 0, 0, 0); ppmd_filledrectangle(pixels, pixcols, pixrows, pixmaxval, 0, 0, pixcols, pixrows, PPMD_NULLDRAWPROC, (char *) &rgbcolor); - + if ((rescale = slfrof.sxdots != ixdots || - slfrof.sydots != iydots || - slfrof.sdsar != dsar) != 0) { - + slfrof.sydots != iydots || + slfrof.sdsar != dsar) != 0) { + /* Rescale all coords. so they'll look (more or less) - right on this display. */ - - xfac = (ixdots + 1) * 0x10000L; - xfac /= (long) (slfrof.sxdots + 1); - yfac = (iydots + 1) * 0x10000L; - yfac /= (long) (slfrof.sydots + 1); - if (dsar < slfrof.sdsar) { - yfac = yfac * dsar / slfrof.sdsar; - } else { - xfac = xfac * slfrof.sdsar / dsar; - } + right on this display. + */ + + xfac = (ixdots + 1) * 0x10000L; + xfac /= (long) (slfrof.sxdots + 1); + yfac = (iydots + 1) * 0x10000L; + yfac /= (long) (slfrof.sydots + 1); + if (dsar < slfrof.sdsar) { + yfac = yfac * dsar / slfrof.sdsar; + } else { + xfac = xfac * slfrof.sdsar / dsar; + } } poly.npoints = 0; /* No flood in progress. */ - + while ((cw = sli()) != 0xFC00) { - switch (cw & 0xFF00) { + switch (cw & 0xFF00) { case 0xFB00: /* Short vector compressed */ - vec.f.x = lx + extend(cw & 0xFF); - vec.f.y = ly + slib(); - vec.t.x = lx + slib(); - vec.t.y = ly + slib(); - lx = vec.f.x; - ly = vec.f.y; - if (rescale) { - vscale(&vec.f.x, &vec.f.y); - vscale(&vec.t.x, &vec.t.y); - } - (*slvec)(&vec, curcolor);/* Draw vector on screen */ - slx = vec.f.x; /* Save scaled point */ - sly = vec.f.y; - break; - + vec.f.x = lx + extend(cw & 0xFF); + vec.f.y = ly + slib(); + vec.t.x = lx + slib(); + vec.t.y = ly + slib(); + lx = vec.f.x; + ly = vec.f.y; + if (rescale) { + vscale(&vec.f.x, &vec.f.y); + vscale(&vec.t.x, &vec.t.y); + } + (*slvec)(&vec, curcolor);/* Draw vector on screen */ + slx = vec.f.x; /* Save scaled point */ + sly = vec.f.y; + break; + case 0xFC00: /* End of file */ - break; - + break; + case 0xFD00: /* Flood command */ - vec.f.x = sli(); - vec.f.y = sli(); - if ((int) vec.f.y < 0) { /* start or end */ - if (poly.npoints != 0) { /* end? */ - if (poly.npoints > 2 && poly.npoints < 11) { - (*slflood)(&poly, curcolor); - } else { - pm_error("Bad polygon vertex count (%d)", - poly.npoints); - } - poly.npoints = 0; - } else { - poly.fill = -vec.f.y; /* Start */ + vec.f.x = sli(); + vec.f.y = sli(); + if ((int) vec.f.y < 0) { /* start or end */ + if (poly.npoints != 0) { /* end? */ + if (poly.npoints > 2 && poly.npoints < 11) { + (*slflood)(&poly, curcolor); + } else { + pm_error("Bad polygon vertex count (%d)", + poly.npoints); + } + poly.npoints = 0; + } else { + poly.fill = -vec.f.y; /* Start */ + } + } else { /* Polygon vertex */ + if (poly.npoints < 10) { + if (rescale) { + vscale(&vec.f.x, &vec.f.y); + } + poly.pt[poly.npoints].x = vec.f.x; + poly.pt[poly.npoints].y = vec.f.y; + } + poly.npoints++; } - } else { /* Polygon vertex */ - if (poly.npoints < 10) { + break; + + case 0xFE00: /* Common endpoint compressed */ + vec.f.x = lx + extend(cw & 0xFF); + vec.f.y = ly + slib(); + lx = vec.f.x; + ly = vec.f.y; + vec.t.x = slx; + vec.t.y = sly; if (rescale) { vscale(&vec.f.x, &vec.f.y); } - poly.pt[poly.npoints].x = vec.f.x; - poly.pt[poly.npoints].y = vec.f.y; - } - poly.npoints++; - } - break; - - case 0xFE00: /* Common endpoint compressed */ - vec.f.x = lx + extend(cw & 0xFF); - vec.f.y = ly + slib(); - lx = vec.f.x; - ly = vec.f.y; - vec.t.x = slx; - vec.t.y = sly; - if (rescale) { - vscale(&vec.f.x, &vec.f.y); - } - (*slvec)(&vec, curcolor);/* Draw vector */ - slx = vec.f.x; /* Save scaled point */ - sly = vec.f.y; - break; - + (*slvec)(&vec, curcolor);/* Draw vector */ + slx = vec.f.x; /* Save scaled point */ + sly = vec.f.y; + break; + case 0xFF00: /* Change color */ - curcolor = cw & 0xFF; - break; + curcolor = cw & 0xFF; + break; default: /* Co-ordinates */ - lx = vec.f.x = cw; - ly = vec.f.y = sli(); - vec.t.x = sli(); - vec.t.y = sli(); - if (rescale) { - vscale(&vec.f.x, &vec.f.y); - vscale(&vec.t.x, &vec.t.y); - } - (*slvec)(&vec, curcolor); - slx = vec.f.x; /* Save scaled point */ - sly = vec.f.y; - break; - } - } -} - -/* SLIDEFIND -- Find a slide in a library or, if DIRONLY is - nonzero, print a directory listing of the library. - If UCASEN is nonzero, the requested slide name is - converted to upper case. */ - -static void slidefind(sname, dironly, ucasen) - char *sname; - int dironly, ucasen; -{ - char uname[32]; - unsigned char libent[36]; - long pos; - - if (dironly) { - pm_message("Slides in library:"); - } else { - int i; - char *ip = sname; - - for (i = 0; i < 31; i++) { - char ch = *ip++; - if (ch == EOS) { - break; - } - if (ucasen && ISLOWER(ch)) { - ch = TOUPPER(ch); - } - uname[i] = ch; - } - uname[i] = EOS; - } - - /* Read slide library header and verify. */ - - if ((fread(libent, 32, 1, slfile) != 1) || - (!STREQ((char *)libent, "AutoCAD Slide Library 1.0\015\012\32"))) { - pm_error("not an AutoCAD slide library file."); - } - pos = 32; - - /* Search for a slide with the requested name. */ - - while (TRUE) { - if ((fread(libent, 36, 1, slfile) != 1) || - (strlen((char *)libent) == 0)) { - if (dironly) { - return; - } - pm_error("slide %s not in library.", sname); - } - pos += 36; - if (dironly) { - pm_message(" %s", libent); - } else if (STREQ((char *)libent, uname)) { - long dpos = (((((libent[35] << 8) | libent[34]) << 8) | - libent[33]) << 8) | libent[32]; - if ((slfile == stdin) || (fseek(slfile, dpos, 0) == -1)) { - dpos -= pos; - - while (dpos-- > 0) { - (void) getc(slfile); - } + lx = vec.f.x = cw; + ly = vec.f.y = sli(); + vec.t.x = sli(); + vec.t.y = sli(); + if (rescale) { + vscale(&vec.f.x, &vec.f.y); + vscale(&vec.t.x, &vec.t.y); + } + (*slvec)(&vec, curcolor); + slx = vec.f.x; /* Save scaled point */ + sly = vec.f.y; + break; } - break; - } } } -/* DRAW -- Draw a vector in the given AutoCAD color. */ -static void draw(vec, color) - struct svector *vec; - int color; -{ - pixel rgbcolor; - - if (blither) { - pm_message("Vector (%d, %d) - (%d, %d) Color %d", - vec->f.x, vec->f.y, vec->t.x, vec->t.y, color); - } - assert(vec->f.x >= 0 && vec->f.x < pixcols); - assert(vec->f.y >= 0 && vec->f.y < pixrows); - assert(vec->t.x >= 0 && vec->t.x < pixcols); - assert(vec->t.y >= 0 && vec->t.y < pixrows); - PPM_ASSIGN(rgbcolor, - acadcol[color][0], acadcol[color][1], acadcol[color][2]); - ppmd_line(pixels, pixcols, pixrows, pixmaxval, - vec->f.x, iydots - vec->f.y, vec->t.x, iydots - vec->t.y, - PPMD_NULLDRAWPROC, - (char *) &rgbcolor); -} - -/* FLOOD -- Draw a filled polygon. */ - -static void -flood(struct spolygon * const poly, - int const color) { - - int i; - struct fillobj * handle; - pixel rgbcolor; - - handle = ppmd_fill_create(); - - if (blither) { - pm_message("Polygon: %d points, fill type %d, color %d", - poly->npoints, poly->fill, color); - for (i = 0; i < poly->npoints; i++) { - pm_message(" Point %d: (%d, %d)", i + 1, - poly->pt[i].x, poly->pt[i].y); - } - } - - PPM_ASSIGN(rgbcolor, - acadcol[color][0], acadcol[color][1], acadcol[color][2]); - for (i = 0; i < poly->npoints; i++) { - assert(poly->pt[i].x >= 0 && poly->pt[i].x < pixcols); - assert(poly->pt[i].y >= 0 && poly->pt[i].y < pixrows); - ppmd_line(pixels, pixcols, pixrows, pixmaxval, - poly->pt[i].x, iydots - poly->pt[i].y, - poly->pt[(i + 1) % poly->npoints].x, - iydots - poly->pt[(i + 1) % poly->npoints].y, - ppmd_fill_drawproc, handle); - } - ppmd_fill(pixels, pixcols, pixrows, pixmaxval, - handle, PPMD_NULLDRAWPROC, (char *) &rgbcolor); - - ppmd_fill_destroy(handle); -} /* Main program. */ -int main(argc, argv) - int argc; - char *argv[]; -{ +int +main(int argc, + char * argv[]) { + int argn; const char * const usage = "[-verbose] [-info] [-adjust] [-scale <s>]\n\ - [-dir] [-lib|-Lib <name>]\n\ - [-xsize|-width <x>] [-ysize|-height <y>] [sldfile]"; +[-dir] [-lib|-Lib <name>]\n\ +[-xsize|-width <x>] [-ysize|-height <y>] [sldfile]"; int scalespec = FALSE, widspec = FALSE, hgtspec = FALSE, dironly = FALSE, - ucasen; - char *slobber = (char *) 0; /* Slide library item */ + ucasen; + const char * slobber; /* Slide library item */ + slobber = NULL; + ppm_init(&argc, argv); argn = 1; while (argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0') { if (pm_keymatch(argv[argn], "-verbose", 2)) { - blither = TRUE; + blither = TRUE; } else if (pm_keymatch(argv[argn], "-adjust", 2)) { - adjust = TRUE; + adjust = TRUE; } else if (pm_keymatch(argv[argn], "-dir", 2)) { - dironly = TRUE; + dironly = TRUE; } else if (pm_keymatch(argv[argn], "-info", 2)) { - info = TRUE; + info = TRUE; } else if (pm_keymatch(argv[argn], "-lib", 2)) { - if (slobber != (char *) 0) { + if (slobber) pm_error("already specified a library item"); - } ucasen = argv[argn][1] != 'L'; - argn++; - if (argn == argc) { - pm_usage(usage); - } - slobber = argv[argn]; + argn++; + if (argn == argc) { + pm_usage(usage); + } + slobber = argv[argn]; } else if (pm_keymatch(argv[argn], "-scale", 2)) { - if (scalespec) { + if (scalespec) { pm_error("already specified a scale factor"); - } - argn++; + } + argn++; if ((argn == argc) || (sscanf(argv[argn], "%lf", &uscale) != 1)) - pm_usage(usage); - if (uscale <= 0.0) { + pm_usage(usage); + if (uscale <= 0.0) { pm_error("scale factor must be greater than 0"); - } - scalespec = TRUE; + } + scalespec = TRUE; } else if (pm_keymatch(argv[argn], "-xsize", 2) || pm_keymatch(argv[argn], "-width", 2)) { - if (widspec) { + if (widspec) { pm_error("already specified a width/xsize"); - } - argn++; + } + argn++; if ((argn == argc) || (sscanf(argv[argn], "%d", &sxsize) != 1)) - pm_usage(usage); - widspec = TRUE; + pm_usage(usage); + widspec = TRUE; } else if (pm_keymatch(argv[argn], "-ysize", 2) || pm_keymatch(argv[argn], "-height", 2)) { - if (hgtspec) { + if (hgtspec) { pm_error("already specified a height/ysize"); + } + argn++; + if ((argn == argc) || (sscanf(argv[argn], "%d", &sysize) != 1)) + pm_usage(usage); + hgtspec = TRUE; + } else { + pm_usage(usage); } argn++; - if ((argn == argc) || (sscanf(argv[argn], "%d", &sysize) != 1)) - pm_usage(usage); - hgtspec = TRUE; - } else { - pm_usage(usage); - } - argn++; } /* If a file name is specified, open it. Otherwise read from - standard input. */ + standard input. + */ if (argn < argc) { - slfile = pm_openr(argv[argn]); - argn++; + slfile = pm_openr(argv[argn]); + argn++; } else { - slfile = stdin; + slfile = stdin; } - + if (argn != argc) { /* Extra bogus arguments ? */ - pm_usage(usage); + pm_usage(usage); } - + /* If we're extracting an item from a slide library, position the - input stream to the start of the chosen slide. */ - - if (dironly || (slobber != (char *) 0)) { - slidefind(slobber, dironly, ucasen); - } - + input stream to the start of the chosen slide. + */ + + if (dironly || slobber) + slidefind(slobber, dironly, ucasen); + if (!dironly) { - slider(draw, flood); - ppm_writeppm(stdout, pixels, pixcols, pixrows, pixmaxval, FALSE); + slider(draw, flood); + ppm_writeppm(stdout, pixels, pixcols, pixrows, pixmaxval, FALSE); } pm_close(slfile); pm_close(stdout); - exit(0); + + return 0; } |