Changeset 45
- Timestamp:
- 05/04/08 16:52:40
(4 months ago)
- Author:
- sip
- Message:
Fixed overlaped image on mosaic
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r42 |
r45 |
|
| 10 | 10 | public: |
|---|
| 11 | 11 | FrameScaler(); |
|---|
| | 12 | ~FrameScaler(); |
|---|
| 12 | 13 | int SetResize(int srcWidth,int srcHeight,int srcLineWidth,int dstWidth,int dstHeight,int dstLineWidth); |
|---|
| 13 | 14 | int Resize(BYTE *srcY,BYTE *srcU,BYTE *srcV,BYTE *dstY, BYTE *dstU, BYTE *dstV); |
|---|
| … | … | |
| 19 | 20 | int resizeDstWidth; |
|---|
| 20 | 21 | int resizeDstHeight; |
|---|
| | 22 | int resizeDstLineWidth; |
|---|
| 21 | 23 | int resizeSrc[3]; |
|---|
| 22 | 24 | int resizeDst[3]; |
|---|
| 23 | 25 | int resizeFlags; |
|---|
| | 26 | int tmpWidth; |
|---|
| | 27 | int tmpHeight; |
|---|
| | 28 | int tmpBufferSize; |
|---|
| | 29 | BYTE* tmpBuffer; |
|---|
| | 30 | BYTE* tmpY; |
|---|
| | 31 | BYTE* tmpU; |
|---|
| | 32 | BYTE* tmpV; |
|---|
| | 33 | |
|---|
| 24 | 34 | }; |
|---|
| 25 | 35 | |
|---|
| r29 |
r45 |
|
| 1 | 1 | #include <framescaler.h> |
|---|
| | 2 | #include <stdlib.h> |
|---|
| | 3 | #include <stdio.h> |
|---|
| | 4 | #include <string.h> |
|---|
| | 5 | |
|---|
| 2 | 6 | |
|---|
| 3 | 7 | FrameScaler::FrameScaler() |
|---|
| … | … | |
| 9 | 13 | resizeDstWidth = 0; |
|---|
| 10 | 14 | resizeDstHeight = 0; |
|---|
| | 15 | resizeDstLineWidth = 0; |
|---|
| | 16 | |
|---|
| | 17 | //tmp buffer |
|---|
| | 18 | tmpWidth = 0; |
|---|
| | 19 | tmpHeight = 0; |
|---|
| | 20 | tmpBuffer = NULL; |
|---|
| | 21 | tmpBufferSize = 0; |
|---|
| | 22 | tmpY = NULL; |
|---|
| | 23 | tmpU = NULL; |
|---|
| | 24 | tmpV = NULL; |
|---|
| 11 | 25 | |
|---|
| 12 | 26 | // Bicubic by default |
|---|
| 13 | 27 | resizeFlags = SWS_BICUBIC; |
|---|
| | 28 | } |
|---|
| | 29 | FrameScaler::~FrameScaler() |
|---|
| | 30 | { |
|---|
| | 31 | //Free mem |
|---|
| | 32 | if (tmpBuffer) |
|---|
| | 33 | //free |
|---|
| | 34 | free(tmpBuffer); |
|---|
| | 35 | //Close resizer |
|---|
| | 36 | //?? |
|---|
| 14 | 37 | } |
|---|
| 15 | 38 | |
|---|
| … | … | |
| 38 | 61 | resizeDstWidth = dstWidth; |
|---|
| 39 | 62 | resizeDstHeight = dstHeight; |
|---|
| | 63 | resizeDstLineWidth = dstLineWidth; |
|---|
| | 64 | |
|---|
| | 65 | |
|---|
| | 66 | //to use MM2 we need the width and heinght to be multiple of 32 |
|---|
| | 67 | tmpWidth = (resizeDstWidth/32 +1)*32; |
|---|
| | 68 | tmpHeight = (resizeDstHeight/32 +1)*32; |
|---|
| | 69 | |
|---|
| | 70 | //Get tmp buffer size |
|---|
| | 71 | tmpBufferSize = tmpWidth*tmpHeight*3/2; |
|---|
| | 72 | |
|---|
| | 73 | //Check if we had it already |
|---|
| | 74 | if (tmpBuffer) |
|---|
| | 75 | //Free it |
|---|
| | 76 | free(tmpBuffer); |
|---|
| | 77 | |
|---|
| | 78 | //Allocate it |
|---|
| | 79 | tmpBuffer = (BYTE*)malloc(tmpBufferSize); |
|---|
| 40 | 80 | |
|---|
| 41 | 81 | // Set values for line sizes |
|---|
| … | … | |
| 43 | 83 | resizeSrc[1] = srcLineWidth/2; |
|---|
| 44 | 84 | resizeSrc[2] = srcLineWidth/2; |
|---|
| 45 | | resizeDst[0] = dstLineWidth; |
|---|
| | 85 | /*resizeDst[0] = dstLineWidth; |
|---|
| 46 | 86 | resizeDst[1] = dstLineWidth/2; |
|---|
| 47 | | resizeDst[2] = dstLineWidth/2; |
|---|
| | 87 | resizeDst[2] = dstLineWidth/2;*/ |
|---|
| | 88 | resizeDst[0] = tmpWidth; |
|---|
| | 89 | resizeDst[1] = tmpWidth/2; |
|---|
| | 90 | resizeDst[2] = tmpWidth/2; |
|---|
| | 91 | |
|---|
| | 92 | //Get tmp planes |
|---|
| | 93 | tmpY = tmpBuffer; |
|---|
| | 94 | tmpU = tmpBuffer+tmpWidth*tmpHeight; |
|---|
| | 95 | tmpV = tmpU+tmpWidth*tmpHeight/4; |
|---|
| 48 | 96 | |
|---|
| 49 | 97 | // exit |
|---|
| … | … | |
| 62 | 110 | return 0; |
|---|
| 63 | 111 | |
|---|
| 64 | | // Set input picture data |
|---|
| 65 | | int numPixels = resizeWidth*resizeHeight; |
|---|
| 66 | | int resPixels = resizeDstWidth; |
|---|
| 67 | | |
|---|
| 68 | 112 | // Set pointers |
|---|
| 69 | 113 | src[0] = srcY; |
|---|
| 70 | 114 | src[1] = srcU; |
|---|
| 71 | 115 | src[2] = srcV; |
|---|
| 72 | | dst[0] = dstY; |
|---|
| | 116 | /*dst[0] = dstY; |
|---|
| 73 | 117 | dst[1] = dstU; |
|---|
| 74 | | dst[2] = dstV; |
|---|
| | 118 | dst[2] = dstV;*/ |
|---|
| | 119 | dst[0] = tmpY; |
|---|
| | 120 | dst[1] = tmpU; |
|---|
| | 121 | dst[2] = tmpV; |
|---|
| 75 | 122 | |
|---|
| 76 | 123 | // Resize frame |
|---|
| 77 | 124 | sws_scale(resizeCtx, src, resizeSrc, 0, resizeHeight, dst, resizeDst); |
|---|
| 78 | 125 | |
|---|
| | 126 | //Copy to destination |
|---|
| | 127 | for (int i=0;i<resizeDstHeight;++i) |
|---|
| | 128 | //Copy |
|---|
| | 129 | memcpy(dstY+resizeDstLineWidth*i,tmpY+tmpWidth*i,resizeDstWidth); |
|---|
| | 130 | |
|---|
| | 131 | //Copy to destination |
|---|
| | 132 | for (int i=0;i<resizeDstHeight/2;++i) |
|---|
| | 133 | { |
|---|
| | 134 | //Copy |
|---|
| | 135 | memcpy(dstU+resizeDstLineWidth*i/2,tmpU+tmpWidth*i/2,resizeDstWidth/2); |
|---|
| | 136 | memcpy(dstV+resizeDstLineWidth*i/2,tmpV+tmpWidth*i/2,resizeDstWidth/2); |
|---|
| | 137 | } |
|---|
| | 138 | |
|---|
| 79 | 139 | //Done |
|---|
| 80 | 140 | return 1; |
|---|
| r31 |
r45 |
|
| 101 | 101 | //Get offsets |
|---|
| 102 | 102 | offset = (mosaicTotalWidth*mosaicHeight*i) + mosaicWidth*j; |
|---|
| 103 | | offset2 = (mosaicTotalWidth*mosaicHeight*i)/4+(mosaicWidth*j)/2; |
|---|
| | 103 | offset2 = (mosaicTotalWidth*mosaicHeight/4)*i+(mosaicWidth/2)*j; |
|---|
| 104 | 104 | |
|---|
| 105 | 105 | //Get plane pointers |
|---|
Download in other formats:
|
|