Commit 765e1fd8 authored by Ilya.Kirillov's avatar Ilya.Kirillov Committed by Alexander Trofimov

Изменения для компиляции под linux.

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@62542 954022d7-b5bf-4e40-9824-e11837661b57
parent 833ead66
#pragma once #pragma once
#include "Types.h" #include "Types.h"
#include "Utils.h" #include "Utils.h"
...@@ -7,7 +7,7 @@ namespace Jpeg2000 ...@@ -7,7 +7,7 @@ namespace Jpeg2000
{ {
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// (. Annex C Table C-2) // Данный массив содержит все возможные состояния (см. Annex C Table C-2)
static MQCoderState aoMQCoderStates[47 * 2] = static MQCoderState aoMQCoderStates[47 * 2] =
{ {
{ 0x5601, 0, &aoMQCoderStates[2], &aoMQCoderStates[3] }, { 0x5601, 0, &aoMQCoderStates[2], &aoMQCoderStates[3] },
...@@ -107,7 +107,7 @@ namespace Jpeg2000 ...@@ -107,7 +107,7 @@ namespace Jpeg2000
}; };
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// // Вспомогательные функции
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
static void MQC_ByteOut(MQCoder *pMQCoder) static void MQC_ByteOut(MQCoder *pMQCoder)
{ {
...@@ -305,7 +305,7 @@ namespace Jpeg2000 ...@@ -305,7 +305,7 @@ namespace Jpeg2000
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// // Основные функции
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
MQCoder* MQC_Create() MQCoder* MQC_Create()
{ {
...@@ -383,7 +383,7 @@ namespace Jpeg2000 ...@@ -383,7 +383,7 @@ namespace Jpeg2000
} }
void MQC_BypassInitEncoder(MQCoder *pMQCoder) void MQC_BypassInitEncoder(MQCoder *pMQCoder)
{ {
// TO DO: // TO DO: Данная функция не польностью протестирована
pMQCoder->nCregister = 0; pMQCoder->nCregister = 0;
pMQCoder->nCt = 8; pMQCoder->nCt = 8;
...@@ -394,7 +394,7 @@ namespace Jpeg2000 ...@@ -394,7 +394,7 @@ namespace Jpeg2000
} }
void MQC_BypassEncoder(MQCoder *pMQCoder, int nValue) void MQC_BypassEncoder(MQCoder *pMQCoder, int nValue)
{ {
// TO DO: // TO DO: Данная функция не польностью протестирована
pMQCoder->nCt--; pMQCoder->nCt--;
pMQCoder->nCregister = pMQCoder->nCregister + (nValue << pMQCoder->nCt); pMQCoder->nCregister = pMQCoder->nCregister + (nValue << pMQCoder->nCt);
...@@ -414,7 +414,7 @@ namespace Jpeg2000 ...@@ -414,7 +414,7 @@ namespace Jpeg2000
int MQC_BypassFlushEncoder(MQCoder *pMQCoder) int MQC_BypassFlushEncoder(MQCoder *pMQCoder)
{ {
// TO DO: // TO DO: Данная функция не польностью протестирована
unsigned char nBitPadding = 0; unsigned char nBitPadding = 0;
if (pMQCoder->nCt != 0) if (pMQCoder->nCt != 0)
......
#pragma once #pragma once
#include "Types.h" #include "Types.h"
#include "Utils.h" #include "Utils.h"
...@@ -17,7 +17,7 @@ namespace Jpeg2000 ...@@ -17,7 +17,7 @@ namespace Jpeg2000
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// 5-3 - // Таблицы норм для обратимого 5-3 веэвлет-преобразования
static const double c_aDWT_NormsRev[4][10] = static const double c_aDWT_NormsRev[4][10] =
{ {
{ 1.000, 1.500, 2.750, 5.375, 10.68, 21.34, 42.67, 85.33, 170.7, 341.3 }, { 1.000, 1.500, 2.750, 5.375, 10.68, 21.34, 42.67, 85.33, 170.7, 341.3 },
...@@ -26,7 +26,7 @@ namespace Jpeg2000 ...@@ -26,7 +26,7 @@ namespace Jpeg2000
{ .7186, .9218, 1.586, 3.043, 6.019, 12.01, 24.00, 47.97, 95.93 } { .7186, .9218, 1.586, 3.043, 6.019, 12.01, 24.00, 47.97, 95.93 }
}; };
// 9-7 - // Таблицы норм для необратимого 9-7 веэвлет-преобразования
static const double c_aDWT_NormsIrr[4][10] = static const double c_aDWT_NormsIrr[4][10] =
{ {
{ 1.000, 1.965, 4.177, 8.403, 16.90, 33.84, 67.69, 135.3, 270.6, 540.9 }, { 1.000, 1.965, 4.177, 8.403, 16.90, 33.84, 67.69, 135.3, 270.6, 540.9 },
...@@ -36,7 +36,7 @@ namespace Jpeg2000 ...@@ -36,7 +36,7 @@ namespace Jpeg2000
}; };
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// // Вспомогательные функции
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
static void DWT_DeinterleaveHor(int *pA, int *pB, int nDn, int nSn, int nCase) static void DWT_DeinterleaveHor(int *pA, int *pB, int nDn, int nSn, int nCase)
...@@ -236,7 +236,7 @@ namespace Jpeg2000 ...@@ -236,7 +236,7 @@ namespace Jpeg2000
} }
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// // Основные функции
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
void DWT_EncodeRev(TileComp *pTileComponent) void DWT_EncodeRev(TileComp *pTileComponent)
{ {
...@@ -249,10 +249,10 @@ namespace Jpeg2000 ...@@ -249,10 +249,10 @@ namespace Jpeg2000
for (int nIndex = 0; nIndex < nLevel; nIndex++) for (int nIndex = 0; nIndex < nLevel; nIndex++)
{ {
int nResW; // int nResW; // Ширина для данного уровня разрешения
int nResH; // int nResH; // Высота для данного уровня разрешения
int nResW1; // 1 , int nResW1; // Ширина для уровня разрешения на 1 меньше, чем данный
int nResH1; // 1 , int nResH1; // Высота для уровня разрешения на 1 меньше, чем данный
int nCaseCol; // 0 = non inversion on horizontal filtering, 1 = inversion between low-pass and high-pass filtering int nCaseCol; // 0 = non inversion on horizontal filtering, 1 = inversion between low-pass and high-pass filtering
int nCaseRow; // 0 = non inversion on vertical filtering, 1 = inversion between low-pass and high-pass filtering int nCaseRow; // 0 = non inversion on vertical filtering, 1 = inversion between low-pass and high-pass filtering
...@@ -315,10 +315,10 @@ namespace Jpeg2000 ...@@ -315,10 +315,10 @@ namespace Jpeg2000
for (int nIndex = nLevel - 1; nIndex >= nStop; nIndex--) for (int nIndex = nLevel - 1; nIndex >= nStop; nIndex--)
{ {
int nResW; // int nResW; // Ширина для данного уровня разрешения
int nResH; // int nResH; // Высота для данного уровня разрешения
int nResW1; // 1 , int nResW1; // Ширина для уровня разрешения на 1 меньше, чем данный
int nResH1; // 1 , int nResH1; // Высота для уровня разрешения на 1 меньше, чем данный
int nCaseCol; // 0 = non inversion on horizontal filtering, 1 = inversion between low-pass and high-pass filtering int nCaseCol; // 0 = non inversion on horizontal filtering, 1 = inversion between low-pass and high-pass filtering
int nCaseRow; // 0 = non inversion on vertical filtering, 1 = inversion between low-pass and high-pass filtering int nCaseRow; // 0 = non inversion on vertical filtering, 1 = inversion between low-pass and high-pass filtering
...@@ -395,10 +395,10 @@ namespace Jpeg2000 ...@@ -395,10 +395,10 @@ namespace Jpeg2000
for (int nIndex = 0; nIndex < nLevel; nIndex++) for (int nIndex = 0; nIndex < nLevel; nIndex++)
{ {
int nResW; // int nResW; // Ширина для данного уровня разрешения
int nResH; // int nResH; // Высота для данного уровня разрешения
int nResW1; // 1 , int nResW1; // Ширина для уровня разрешения на 1 меньше, чем данный
int nResH1; // 1 , int nResH1; // Высота для уровня разрешения на 1 меньше, чем данный
int nCaseCol; // 0 = non inversion on horizontal filtering, 1 = inversion between low-pass and high-pass filtering int nCaseCol; // 0 = non inversion on horizontal filtering, 1 = inversion between low-pass and high-pass filtering
int nCaseRow; // 0 = non inversion on vertical filtering, 1 = inversion between low-pass and high-pass filtering int nCaseRow; // 0 = non inversion on vertical filtering, 1 = inversion between low-pass and high-pass filtering
...@@ -461,10 +461,10 @@ namespace Jpeg2000 ...@@ -461,10 +461,10 @@ namespace Jpeg2000
for (int nIndex = nLevel - 1; nIndex >= nStop; nIndex--) for (int nIndex = nLevel - 1; nIndex >= nStop; nIndex--)
{ {
int nResW; // int nResW; // Ширина для данного уровня разрешения
int nResH; // int nResH; // Высота для данного уровня разрешения
int nResW1; // 1 , int nResW1; // Ширина для уровня разрешения на 1 меньше, чем данный
int nResH1; // 1 , int nResH1; // Высота для уровня разрешения на 1 меньше, чем данный
int nCaseCol; // 0 = non inversion on horizontal filtering, 1 = inversion between low-pass and high-pass filtering int nCaseCol; // 0 = non inversion on horizontal filtering, 1 = inversion between low-pass and high-pass filtering
int nCaseRow; // 0 = non inversion on vertical filtering, 1 = inversion between low-pass and high-pass filtering int nCaseRow; // 0 = non inversion on vertical filtering, 1 = inversion between low-pass and high-pass filtering
......
#pragma once #pragma once
#include "Types.h" #include "Types.h"
#include "Utils.h" #include "Utils.h"
...@@ -42,7 +42,7 @@ namespace Jpeg2000 ...@@ -42,7 +42,7 @@ namespace Jpeg2000
pImage->eColorSpace = eColorSpace; pImage->eColorSpace = eColorSpace;
pImage->nCsiz = nComponentsCount; pImage->nCsiz = nComponentsCount;
// // Выделяем память под компоненты
pImage->pComponents = (ImageComponent*)Malloc(pImage->nCsiz * sizeof(ImageComponent)); pImage->pComponents = (ImageComponent*)Malloc(pImage->nCsiz * sizeof(ImageComponent));
if (!pImage->pComponents) if (!pImage->pComponents)
...@@ -75,7 +75,7 @@ namespace Jpeg2000 ...@@ -75,7 +75,7 @@ namespace Jpeg2000
} }
else else
{ {
// TO DO: // TO DO: Выдать сообщение об ошибке
} }
return pImage; return pImage;
......
#pragma once #pragma once
// / JPEG2000-codestream: // Функции в данном файле предназначены для чтения/записи различных частей JPEG2000-codestream: маркеры и данные
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
#include "math.h" #include "math.h"
...@@ -98,7 +98,7 @@ namespace Jpeg2000 ...@@ -98,7 +98,7 @@ namespace Jpeg2000
} }
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// // Вспомогательные функции
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
static void J2k_WriteSOC(J2kCodestream *pJ2k) static void J2k_WriteSOC(J2kCodestream *pJ2k)
{ {
...@@ -188,7 +188,7 @@ namespace Jpeg2000 ...@@ -188,7 +188,7 @@ namespace Jpeg2000
pImage->pComponents[nIndex].nFactorDiv2 = 0; pImage->pComponents[nIndex].nFactorDiv2 = 0;
} }
// Y // Считаем количество тайлов по Х и Y
pCodingParams->nXTilesCount = CeilDiv(pImage->nXsiz - pCodingParams->nXTOsiz, pCodingParams->nXTsiz); pCodingParams->nXTilesCount = CeilDiv(pImage->nXsiz - pCodingParams->nXTOsiz, pCodingParams->nXTsiz);
pCodingParams->nYTilesCount = CeilDiv(pImage->nYsiz - pCodingParams->nYTOsiz, pCodingParams->nYTsiz); pCodingParams->nYTilesCount = CeilDiv(pImage->nYsiz - pCodingParams->nYTOsiz, pCodingParams->nYTsiz);
...@@ -218,7 +218,7 @@ namespace Jpeg2000 ...@@ -218,7 +218,7 @@ namespace Jpeg2000
pCodingParams->pTCP[nIndex].nFirst = 1; pCodingParams->pTCP[nIndex].nFirst = 1;
} }
// PPM // Обнуляем данные для PPM маркера
pCodingParams->nPPM = 0; pCodingParams->nPPM = 0;
pCodingParams->pPPMData = NULL; pCodingParams->pPPMData = NULL;
pCodingParams->pPPMDataFirst = NULL; pCodingParams->pPPMDataFirst = NULL;
...@@ -315,7 +315,7 @@ namespace Jpeg2000 ...@@ -315,7 +315,7 @@ namespace Jpeg2000
int nLen = pStream->Read(2); int nLen = pStream->Read(2);
// TO DO: // TO DO: Сделать нормальное чтение
pStream->Skip(nLen - 2); pStream->Skip(nLen - 2);
} }
...@@ -665,7 +665,7 @@ namespace Jpeg2000 ...@@ -665,7 +665,7 @@ namespace Jpeg2000
pTCCP->aoStepSizes[nCurBand].nMantissa = nMantissa; pTCCP->aoStepSizes[nCurBand].nMantissa = nMantissa;
} }
// Add : ScalarImplicit, Subbands // Add : Если тип квантования ScalarImplicit, тогда вычислим коэффициенты квантования для остальных Subbands
if (pTCCP->nQuantStyle == J2K_CCP_QNTSTY_SIQNT) if (pTCCP->nQuantStyle == J2K_CCP_QNTSTY_SIQNT)
{ {
for (int nCurBand = 1; nCurBand < J2K_MAXBANDS; nCurBand++) for (int nCurBand = 1; nCurBand < J2K_MAXBANDS; nCurBand++)
...@@ -853,7 +853,7 @@ namespace Jpeg2000 ...@@ -853,7 +853,7 @@ namespace Jpeg2000
nPacketLen = (nPacketLen << 7) + nAdd; // Iplm_ij nPacketLen = (nPacketLen << 7) + nAdd; // Iplm_ij
if ((nAdd & 0x80) == 0) if ((nAdd & 0x80) == 0)
{ {
// packet // новый packet
nPacketLen = 0; nPacketLen = 0;
} }
if (nLen <= 0) if (nLen <= 0)
...@@ -877,7 +877,7 @@ namespace Jpeg2000 ...@@ -877,7 +877,7 @@ namespace Jpeg2000
nPacketLen = (nPacketLen << 7) + nAdd; // Iplt_i nPacketLen = (nPacketLen << 7) + nAdd; // Iplt_i
if ((nAdd & 0x80) == 0) if ((nAdd & 0x80) == 0)
{ {
// packet // новый packet
nPacketLen = 0; nPacketLen = 0;
} }
} }
...@@ -909,7 +909,7 @@ namespace Jpeg2000 ...@@ -909,7 +909,7 @@ namespace Jpeg2000
} }
int nStore = pCodingParams->nPPMStore; int nStore = pCodingParams->nPPMStore;
if (nZppm == 0) // PPM if (nZppm == 0) // Первый PPM маркер
{ {
pCodingParams->pPPMData = (unsigned char *)Malloc(nNppm * sizeof(unsigned char)); pCodingParams->pPPMData = (unsigned char *)Malloc(nNppm * sizeof(unsigned char));
if (!pCodingParams->pPPMData) if (!pCodingParams->pPPMData)
...@@ -920,7 +920,7 @@ namespace Jpeg2000 ...@@ -920,7 +920,7 @@ namespace Jpeg2000
pCodingParams->pPPMDataFirst = pCodingParams->pPPMData; pCodingParams->pPPMDataFirst = pCodingParams->pPPMData;
pCodingParams->nPPMLength = nNppm; pCodingParams->nPPMLength = nNppm;
} }
else // PPM else // Не первый PPM маркер
{ {
BYTE *pPPMData_new = (BYTE *)Malloc((nNppm + pCodingParams->nPPMStore) * sizeof(unsigned char)); BYTE *pPPMData_new = (BYTE *)Malloc((nNppm + pCodingParams->nPPMStore) * sizeof(unsigned char));
if (!pPPMData_new) if (!pPPMData_new)
...@@ -936,14 +936,14 @@ namespace Jpeg2000 ...@@ -936,14 +936,14 @@ namespace Jpeg2000
pCodingParams->nPPMLength = nNppm + pCodingParams->nPPMStore; pCodingParams->nPPMLength = nNppm + pCodingParams->nPPMStore;
} }
// // Считываем остальные данные
int nIndex; int nIndex;
for (nIndex = nNppm; nIndex > 0; nIndex--) for (nIndex = nNppm; nIndex > 0; nIndex--)
{ {
pCodingParams->pPPMData[nStore] = pStream->Read(1); pCodingParams->pPPMData[nStore] = pStream->Read(1);
nStore++; nStore++;
nLen--; nLen--;
if (nLen == 0) // , packet header , if (nLen == 0) // Случай, когда packet header не закончился в текущем маркере, но закончится в следующем
break; break;
} }
pCodingParams->nPPMPrevious = nIndex - 1; pCodingParams->nPPMPrevious = nIndex - 1;
...@@ -961,7 +961,7 @@ namespace Jpeg2000 ...@@ -961,7 +961,7 @@ namespace Jpeg2000
int nZppt = pStream->Read(1); // Zppt int nZppt = pStream->Read(1); // Zppt
pTCP->nPPT = 1; pTCP->nPPT = 1;
if (nZppt == 0) // PPT if (nZppt == 0) // Первый PPT маркер
{ {
pTCP->pPPTData = (unsigned char *)Malloc((nLen - 3) * sizeof(unsigned char)); pTCP->pPPTData = (unsigned char *)Malloc((nLen - 3) * sizeof(unsigned char));
if (!pTCP->pPPTData) if (!pTCP->pPPTData)
...@@ -973,7 +973,7 @@ namespace Jpeg2000 ...@@ -973,7 +973,7 @@ namespace Jpeg2000
pTCP->nPPTStore = 0; pTCP->nPPTStore = 0;
pTCP->nPPTLength = nLen - 3; pTCP->nPPTLength = nLen - 3;
} }
else // PPT else // Не первый PPT маркер
{ {
BYTE *pPPTData_new = (unsigned char *)Malloc((nLen - 3 + pTCP->nPPTStore) * sizeof(unsigned char)); BYTE *pPPTData_new = (unsigned char *)Malloc((nLen - 3 + pTCP->nPPTStore) * sizeof(unsigned char));
if (!pPPTData_new) if (!pPPTData_new)
...@@ -1010,7 +1010,7 @@ namespace Jpeg2000 ...@@ -1010,7 +1010,7 @@ namespace Jpeg2000
pStream->Skip(2); pStream->Skip(2);
pStream->Write(pJ2k->nCurTileIndex, 2); // Isot pStream->Write(pJ2k->nCurTileIndex, 2); // Isot
pStream->Skip(4); // Psot ( , J2k_WriteSOD) pStream->Skip(4); // Psot (пока оставляем место, сюда пишем в функции J2k_WriteSOD)
pStream->Write(0, 1); // TPsot pStream->Write(0, 1); // TPsot
pStream->Write(1, 1); // TNsot pStream->Write(1, 1); // TNsot
...@@ -1066,7 +1066,7 @@ namespace Jpeg2000 ...@@ -1066,7 +1066,7 @@ namespace Jpeg2000
TileCodingParams *pTCP = &pCodingParams->pTCP[pJ2k->nCurTileIndex]; TileCodingParams *pTCP = &pCodingParams->pTCP[pJ2k->nCurTileIndex];
if (pTCP->nFirst == 1) // PPT if (pTCP->nFirst == 1) // Инициализируем PPT
{ {
TileCompCodingParams *pTemp = pTCP->pTCCP; TileCompCodingParams *pTemp = pTCP->pTCCP;
memcpy(pTCP, pJ2k->pDefaultTCP, sizeof(TileCodingParams)); memcpy(pTCP, pJ2k->pDefaultTCP, sizeof(TileCodingParams));
...@@ -1116,7 +1116,7 @@ namespace Jpeg2000 ...@@ -1116,7 +1116,7 @@ namespace Jpeg2000
int nTileDataLen = TCD_EncodeTile(pTCD, pJ2k->nCurTileIndex, (BYTE*)pStream->GetOwner() + pStream->Tell(), pStream->GetLeftSize() - 2, pImageInfo); int nTileDataLen = TCD_EncodeTile(pTCD, pJ2k->nCurTileIndex, (BYTE*)pStream->GetOwner() + pStream->Tell(), pStream->GetLeftSize() - 2, pImageInfo);
// Psot SOT // Записываем поле Psot в маркере SOT
int nTotalLen = pStream->Tell() + nTileDataLen - pJ2k->nSOTStartPos; int nTotalLen = pStream->Tell() + nTileDataLen - pJ2k->nSOTStartPos;
pStream->Seek(pJ2k->nSOTStartPos + 6); pStream->Seek(pJ2k->nSOTStartPos + 6);
pStream->Write(nTotalLen, 4); // Psot pStream->Write(nTotalLen, 4); // Psot
...@@ -1134,7 +1134,7 @@ namespace Jpeg2000 ...@@ -1134,7 +1134,7 @@ namespace Jpeg2000
if (nLen == pStream->GetLeftSize() + 1) if (nLen == pStream->GetLeftSize() + 1)
{ {
nTruncate = 1; // codestream nTruncate = 1; // Обрезанный codestream
} }
unsigned char *pData = (unsigned char *)Malloc((pJ2k->pTileLen[nCurTileIndex] + nLen) * sizeof(unsigned char)); unsigned char *pData = (unsigned char *)Malloc((pJ2k->pTileLen[nCurTileIndex] + nLen) * sizeof(unsigned char));
...@@ -1152,7 +1152,7 @@ namespace Jpeg2000 ...@@ -1152,7 +1152,7 @@ namespace Jpeg2000
unsigned char *pDataPointer = pData + pJ2k->pTileLen[nCurTileIndex]; unsigned char *pDataPointer = pData + pJ2k->pTileLen[nCurTileIndex];
//for ( int nIndex = 0; nIndex < nLen; nIndex++ ) //for ( int nIndex = 0; nIndex < nLen; nIndex++ )
//{ //{
// pDataPointer[nIndex] = pStream->Read( 1 ); // // pDataPointer[nIndex] = pStream->Read( 1 ); // Считываем закодированные данные текущего тайла
//} //}
pStream->Read(pDataPointer, nLen); pStream->Read(pDataPointer, nLen);
...@@ -1197,7 +1197,7 @@ namespace Jpeg2000 ...@@ -1197,7 +1197,7 @@ namespace Jpeg2000
int nLen = pStream->Read(2); // Lrgn int nLen = pStream->Read(2); // Lrgn
int nCurComponent = pStream->Read(nComponentsCount <= 256 ? 1 : 2); // Crgn int nCurComponent = pStream->Read(nComponentsCount <= 256 ? 1 : 2); // Crgn
int nROIStyle = pStream->Read(1); // Srgn int nROIStyle = pStream->Read(1); // Srgn
// TO DO: nROIStyle == 0 // TO DO: Вставить проверку nROIStyle == 0
pTCP->pTCCP[nCurComponent].nROIShift = pStream->Read(1); // SPrgn pTCP->pTCCP[nCurComponent].nROIShift = pStream->Read(1); // SPrgn
} }
...@@ -1247,8 +1247,8 @@ namespace Jpeg2000 ...@@ -1247,8 +1247,8 @@ namespace Jpeg2000
} }
static void J2k_ReadUNK(J2kCodestream *pJ2k) static void J2k_ReadUNK(J2kCodestream *pJ2k)
{ {
// , , , , // Предполагаем, что неизвестный маркер не пустой, а, значит,
// - . // у него следующие два байта - длина маркера.
CReader *pStream = pJ2k->pStreamIO; CReader *pStream = pJ2k->pStreamIO;
int nLen = pStream->Read(2); int nLen = pStream->Read(2);
...@@ -1262,12 +1262,12 @@ namespace Jpeg2000 ...@@ -1262,12 +1262,12 @@ namespace Jpeg2000
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// - - () // Таблица связывающая прочтенный маркер - состояние декодера - действие(функция) декодера при прочтении данного маркера
typedef struct TDecoderMSTableEntry typedef struct TDecoderMSTableEntry
{ {
int nID; // int nID; // Значение маркера
int nStates; // , int nStates; // Состояние декодера, когда появляется данный маркер
void(*pHandler) (J2kCodestream *pJ2k); // void(*pHandler) (J2kCodestream *pJ2k); // Действие связанное с данным маркером
} DecoderMSTableEntry; } DecoderMSTableEntry;
DecoderMSTableEntry c_aoJ2k_DecoderMSTable[] = DecoderMSTableEntry c_aoJ2k_DecoderMSTable[] =
...@@ -1317,7 +1317,7 @@ namespace Jpeg2000 ...@@ -1317,7 +1317,7 @@ namespace Jpeg2000
} }
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// J2K / JPT // Декодирование потоков J2K / JPT
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
J2kCodestream* J2k_CreateDecompress(PCommon pCodecInfo) J2kCodestream* J2k_CreateDecompress(PCommon pCodecInfo)
...@@ -1381,7 +1381,7 @@ namespace Jpeg2000 ...@@ -1381,7 +1381,7 @@ namespace Jpeg2000
{ {
if (pJ2k && pParameters) if (pJ2k && pParameters)
{ {
// CodingParams // Создаем и инициализируем структуру CodingParams
CodingParams *pCodingParams = (CodingParams*)Malloc(sizeof(CodingParams)); CodingParams *pCodingParams = (CodingParams*)Malloc(sizeof(CodingParams));
if (!pCodingParams) if (!pCodingParams)
{ {
...@@ -1401,7 +1401,7 @@ namespace Jpeg2000 ...@@ -1401,7 +1401,7 @@ namespace Jpeg2000
pJ2k->pStreamIO = pStream; pJ2k->pStreamIO = pStream;
// // Создаем пустую картинку
Image *pImage = Image_CreateEmpty(); Image *pImage = Image_CreateEmpty();
if (!pImage) if (!pImage)
{ {
...@@ -1433,7 +1433,7 @@ namespace Jpeg2000 ...@@ -1433,7 +1433,7 @@ namespace Jpeg2000
return 0; return 0;
} }
// // Проверяем ограничение на декодирование
if (pEntry->nID == J2K_MS_SOT && pJ2k->pCodingParams->eLimitDecoding == declimLimitToMainHeader) if (pEntry->nID == J2K_MS_SOT && pJ2k->pCodingParams->eLimitDecoding == declimLimitToMainHeader)
{ {
Event_Message(EVT_INFO, "Main Header decoded.\n"); Event_Message(EVT_INFO, "Main Header decoded.\n");
...@@ -1461,7 +1461,7 @@ namespace Jpeg2000 ...@@ -1461,7 +1461,7 @@ namespace Jpeg2000
pCodecInfo->nErrorCode = JP2_ERROR_NO_ERROR; pCodecInfo->nErrorCode = JP2_ERROR_NO_ERROR;
break; break;
} }
// // Проверяем не появилась ли ошибка
if (JP2_ERROR_NO_ERROR != pCodecInfo->nErrorCode) if (JP2_ERROR_NO_ERROR != pCodecInfo->nErrorCode)
{ {
Image_Destroy(pImage); Image_Destroy(pImage);
...@@ -1489,7 +1489,7 @@ namespace Jpeg2000 ...@@ -1489,7 +1489,7 @@ namespace Jpeg2000
pJ2k->pStreamIO = pStream; pJ2k->pStreamIO = pStream;
// // Создем пустую картинку
Image *pImage = Image_CreateEmpty(); Image *pImage = Image_CreateEmpty();
if (!pImage) if (!pImage)
{ {
...@@ -1499,10 +1499,10 @@ namespace Jpeg2000 ...@@ -1499,10 +1499,10 @@ namespace Jpeg2000
pJ2k->nState = j2kstateMHSOC; pJ2k->nState = j2kstateMHSOC;
// // Инициализируем заголовок
JPTMessageHeader oHeader; JPTMessageHeader oHeader;
JPT_InitMessageHeader(&oHeader); JPT_InitMessageHeader(&oHeader);
// // Читаем первый заголовок сообщения
JPT_ReadMessageHeader(pCodecInfo, pStream, &oHeader); JPT_ReadMessageHeader(pCodecInfo, pStream, &oHeader);
int nPosition = pStream->Tell(); int nPosition = pStream->Tell();
...@@ -1574,7 +1574,7 @@ namespace Jpeg2000 ...@@ -1574,7 +1574,7 @@ namespace Jpeg2000
} }
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// J2K // Кодирование в поток J2K
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
J2kCodestream* J2k_CreateCompress(PCommon pCodecInfo) J2kCodestream* J2k_CreateCompress(PCommon pCodecInfo)
...@@ -1637,7 +1637,7 @@ namespace Jpeg2000 ...@@ -1637,7 +1637,7 @@ namespace Jpeg2000
return; return;
} }
// Coding parameters // Создаем и инициализируем структуру Coding parameters
CodingParams *pCodingParams = (CodingParams*)Malloc(sizeof(CodingParams)); CodingParams *pCodingParams = (CodingParams*)Malloc(sizeof(CodingParams));
if (!pCodingParams) if (!pCodingParams)
{ {
...@@ -1649,7 +1649,7 @@ namespace Jpeg2000 ...@@ -1649,7 +1649,7 @@ namespace Jpeg2000
pCodingParams->nXTilesCount = 1; pCodingParams->nXTilesCount = 1;
pCodingParams->nYTilesCount = 1; pCodingParams->nYTilesCount = 1;
// // Копируем заданные параметры
pCodingParams->nDistoAlloc = pParameters->nDistoAlloc; pCodingParams->nDistoAlloc = pParameters->nDistoAlloc;
pCodingParams->nFixedAlloc = pParameters->nFixedAlloc; pCodingParams->nFixedAlloc = pParameters->nFixedAlloc;
...@@ -1669,7 +1669,7 @@ namespace Jpeg2000 ...@@ -1669,7 +1669,7 @@ namespace Jpeg2000
memcpy(pCodingParams->pMatrix, pParameters->pMatrix, array_size); memcpy(pCodingParams->pMatrix, pParameters->pMatrix, array_size);
} }
// ? // Создаем ли файл индексации?
pCodingParams->nIndexOn = pParameters->nIndexOn; pCodingParams->nIndexOn = pParameters->nIndexOn;
if (pCodingParams->nIndexOn) if (pCodingParams->nIndexOn)
{ {
...@@ -1702,7 +1702,7 @@ namespace Jpeg2000 ...@@ -1702,7 +1702,7 @@ namespace Jpeg2000
} }
} }
// // Вычисляем другие параметры кодирования
if (pParameters->bTileSizeOn) if (pParameters->bTileSizeOn)
{ {
...@@ -1790,7 +1790,7 @@ namespace Jpeg2000 ...@@ -1790,7 +1790,7 @@ namespace Jpeg2000
for (int nComponentIndex = 0; nComponentIndex < pImage->nCsiz; nComponentIndex++) for (int nComponentIndex = 0; nComponentIndex < pImage->nCsiz; nComponentIndex++)
{ {
TileCompCodingParams *pTCCP = &pTCP->pTCCP[nComponentIndex]; TileCompCodingParams *pTCCP = &pTCP->pTCCP[nComponentIndex];
pTCCP->nCodingStyle = pParameters->nCodingStyle & 0x01; // 0 => || 1 => pTCCP->nCodingStyle = pParameters->nCodingStyle & 0x01; // 0 => одна область || 1 => призвольное количество областей
pTCCP->nResolutionsCount = pParameters->nResolutionsCount; pTCCP->nResolutionsCount = pParameters->nResolutionsCount;
pTCCP->nCodeBlockWidth = FloorLog2(pParameters->nCodeBlockWidthInit); pTCCP->nCodeBlockWidth = FloorLog2(pParameters->nCodeBlockWidthInit);
pTCCP->nCodeBlockHeight = FloorLog2(pParameters->nCodeBlockHeightInit); pTCCP->nCodeBlockHeight = FloorLog2(pParameters->nCodeBlockHeightInit);
...@@ -1959,7 +1959,7 @@ namespace Jpeg2000 ...@@ -1959,7 +1959,7 @@ namespace Jpeg2000
{ {
for (int nResolutionIndex = 0; nResolutionIndex < pImageInfo->nDecompCount + 1; nResolutionIndex++) for (int nResolutionIndex = 0; nResolutionIndex < pImageInfo->nDecompCount + 1; nResolutionIndex++)
{ {
// , XRsiz, YRsiz // Предполагаем, что значения XRsiz, YRsiz одинаковые для всех компонент
int nX0 = pImageInfo->nXTOsiz + nTileIndex - (int)floor((float)nTileIndex / (float)pImageInfo->nXTilesCount) * pImageInfo->nXTilesCount * pImageInfo->nXTsiz; int nX0 = pImageInfo->nXTOsiz + nTileIndex - (int)floor((float)nTileIndex / (float)pImageInfo->nXTilesCount) * pImageInfo->nXTilesCount * pImageInfo->nXTsiz;
int nY0 = pImageInfo->nXTOsiz + (int)floor((float)nTileIndex / (float)pImageInfo->nXTilesCount) * pImageInfo->nYTsiz; int nY0 = pImageInfo->nXTOsiz + (int)floor((float)nTileIndex / (float)pImageInfo->nXTilesCount) * pImageInfo->nYTsiz;
int nX1 = nX0 + pImageInfo->nXTsiz; int nX1 = nX0 + pImageInfo->nXTsiz;
...@@ -2001,7 +2001,7 @@ namespace Jpeg2000 ...@@ -2001,7 +2001,7 @@ namespace Jpeg2000
} }
else if (pImageInfo->eProgOrder == poPCRL) else if (pImageInfo->eProgOrder == poPCRL)
{ {
// , XRsiz, YRsiz // Предполагаем, что значения XRsiz, YRsiz одинаковые для всех компонент
int nX0 = pImageInfo->nXTOsiz + nTileIndex - (int)floor((float)nTileIndex / (float)pImageInfo->nXTilesCount) * pImageInfo->nXTilesCount * pImageInfo->nXTsiz; int nX0 = pImageInfo->nXTOsiz + nTileIndex - (int)floor((float)nTileIndex / (float)pImageInfo->nXTilesCount) * pImageInfo->nXTilesCount * pImageInfo->nXTsiz;
int nY0 = pImageInfo->nXTOsiz + (int)floor((float)nTileIndex / (float)pImageInfo->nXTilesCount) * pImageInfo->nYTsiz; int nY0 = pImageInfo->nXTOsiz + (int)floor((float)nTileIndex / (float)pImageInfo->nXTilesCount) * pImageInfo->nYTsiz;
int nX1 = nX0 + pImageInfo->nXTsiz; int nX1 = nX0 + pImageInfo->nXTsiz;
...@@ -2047,7 +2047,7 @@ namespace Jpeg2000 ...@@ -2047,7 +2047,7 @@ namespace Jpeg2000
{ {
for (int nComponentIndex = 0; nComponentIndex < pImageInfo->nCompCount; nComponentIndex++) for (int nComponentIndex = 0; nComponentIndex < pImageInfo->nCompCount; nComponentIndex++)
{ {
// , XRsiz, YRsiz // Предполагаем, что значения XRsiz, YRsiz одинаковые для всех компонент
int nX0 = pImageInfo->nXTOsiz + nTileIndex - (int)floor((float)nTileIndex / (float)pImageInfo->nXTilesCount) * pImageInfo->nXTilesCount * pImageInfo->nXTsiz; int nX0 = pImageInfo->nXTOsiz + nTileIndex - (int)floor((float)nTileIndex / (float)pImageInfo->nXTilesCount) * pImageInfo->nXTilesCount * pImageInfo->nXTsiz;
int nY0 = pImageInfo->nXTOsiz + (int)floor((float)nTileIndex / (float)pImageInfo->nXTilesCount) * pImageInfo->nYTsiz; int nY0 = pImageInfo->nXTOsiz + (int)floor((float)nTileIndex / (float)pImageInfo->nXTilesCount) * pImageInfo->nYTsiz;
int nX1 = nX0 + pImageInfo->nXTsiz; int nX1 = nX0 + pImageInfo->nXTsiz;
...@@ -2113,7 +2113,7 @@ namespace Jpeg2000 ...@@ -2113,7 +2113,7 @@ namespace Jpeg2000
} }
#endif #endif
// // Индексация
ImageInfo *pImageInfo = pJ2k->pImageInfo; ImageInfo *pImageInfo = pJ2k->pImageInfo;
if (pImageInfo && pCodingParams->nIndexOn) if (pImageInfo && pCodingParams->nIndexOn)
{ {
...@@ -2151,24 +2151,24 @@ namespace Jpeg2000 ...@@ -2151,24 +2151,24 @@ namespace Jpeg2000
J2k_WriteCOM(pJ2k); J2k_WriteCOM(pJ2k);
} }
// // Индексация
if (pImageInfo && pImageInfo->nIndexOn) if (pImageInfo && pImageInfo->nIndexOn)
{ {
pImageInfo->nMainHeadEnd = pStream->Tell() - 1; pImageInfo->nMainHeadEnd = pStream->Tell() - 1;
} }
//------------- //-------------
// // Создаем струкртуру для кодирования тайлов
TCD *pTCD = TCD_Create(pJ2k->pCodecInfo); TCD *pTCD = TCD_Create(pJ2k->pCodecInfo);
// // Кодируем каждый тайл
for (int nTileIndex = 0; nTileIndex < pCodingParams->nXTilesCount * pCodingParams->nYTilesCount; nTileIndex++) for (int nTileIndex = 0; nTileIndex < pCodingParams->nXTilesCount * pCodingParams->nYTilesCount; nTileIndex++)
{ {
Event_Message(EVT_INFO, "tile number %d / %d\n", nTileIndex + 1, pCodingParams->nXTilesCount * pCodingParams->nYTilesCount); Event_Message(EVT_INFO, "tile number %d / %d\n", nTileIndex + 1, pCodingParams->nXTilesCount * pCodingParams->nYTilesCount);
pJ2k->nCurTileIndex = nTileIndex; pJ2k->nCurTileIndex = nTileIndex;
// // Инициализируем перед кодированием
if (0 == nTileIndex) if (0 == nTileIndex)
{ {
TCD_MallocEncode(pTCD, pImage, pCodingParams, pJ2k->nCurTileIndex); TCD_MallocEncode(pTCD, pImage, pCodingParams, pJ2k->nCurTileIndex);
...@@ -2177,14 +2177,14 @@ namespace Jpeg2000 ...@@ -2177,14 +2177,14 @@ namespace Jpeg2000
{ {
TCD_InitEncode(pTCD, pImage, pCodingParams, pJ2k->nCurTileIndex); TCD_InitEncode(pTCD, pImage, pCodingParams, pJ2k->nCurTileIndex);
} }
// // Проверяем ошибку
if (JP2_ERROR_NO_ERROR != pTCD->pCodecInfo->nErrorCode) if (JP2_ERROR_NO_ERROR != pTCD->pCodecInfo->nErrorCode)
{ {
TCD_Destroy(pTCD); TCD_Destroy(pTCD);
return false; return false;
} }
// // Индексация
if (pImageInfo && pImageInfo->nIndexOn) if (pImageInfo && pImageInfo->nIndexOn)
{ {
pImageInfo->pTile[pJ2k->nCurTileIndex].nTileCount = pJ2k->nCurTileIndex; pImageInfo->pTile[pJ2k->nCurTileIndex].nTileCount = pJ2k->nCurTileIndex;
...@@ -2206,7 +2206,7 @@ namespace Jpeg2000 ...@@ -2206,7 +2206,7 @@ namespace Jpeg2000
J2k_WriteSOD(pJ2k, pTCD); J2k_WriteSOD(pJ2k, pTCD);
// // Индексация
if (pImageInfo && pImageInfo->nIndexOn) if (pImageInfo && pImageInfo->nIndexOn)
{ {
pImageInfo->pTile[pJ2k->nCurTileIndex].nEndPos = pStream->Tell() + pJ2k->nPosCorrection - 1; pImageInfo->pTile[pJ2k->nCurTileIndex].nEndPos = pStream->Tell() + pJ2k->nPosCorrection - 1;
...@@ -2215,13 +2215,13 @@ namespace Jpeg2000 ...@@ -2215,13 +2215,13 @@ namespace Jpeg2000
} }
// // Удаляем структуру кодирующую тайлы
TCD_FreeEncode(pTCD); TCD_FreeEncode(pTCD);
TCD_Destroy(pTCD); TCD_Destroy(pTCD);
J2k_WriteEOC(pJ2k); J2k_WriteEOC(pJ2k);
// // Создаем файл с индексацией
if (pImageInfo && pImageInfo->nIndexOn) if (pImageInfo && pImageInfo->nIndexOn)
{ {
if (!J2k_CreateIndex(pJ2k, pStream, pImageInfo, sIndex)) if (!J2k_CreateIndex(pJ2k, pStream, pImageInfo, sIndex))
......
#include "J2kFile.h" #include "J2kFile.h"
#include "J2kIncludes.h" #include "J2kIncludes.h"
#include "Utils.h" #include "Utils.h"
namespace Jpeg2000 namespace Jpeg2000
{ {
extern Image* Jp2ToImage(const std::wstring& wsFileName, DecoderParams* pDecoderParams); //extern Image* Jp2ToImage(const std::wstring& wsFileName, DecoderParams* pDecoderParams);
extern Image* J2kToImage(const std::wstring& wsFileName, DecoderParams* pDecoderParams); //extern Image* J2kToImage(const std::wstring& wsFileName, DecoderParams* pDecoderParams);
extern Image* JptToImage(const std::wstring& wsFileName, DecoderParams* pDecoderParams); //extern Image* JptToImage(const std::wstring& wsFileName, DecoderParams* pDecoderParams);
extern Image* Mj2ToImage(const std::wstring& wsFileName, DecoderParams* pDecoderParams); //extern Image* Mj2ToImage(const std::wstring& wsFileName, DecoderParams* pDecoderParams);
extern bool ImageToJ2k(Image *pImage, const std::wstring& wsFilePath, EncoderParams* pEncoderParams); //extern bool ImageToJ2k(Image *pImage, const std::wstring& wsFilePath, EncoderParams* pEncoderParams);
extern bool ImageToJ2p(Image *pImage, const std::wstring& wsFilePath, EncoderParams* pEncoderParams); //extern bool ImageToJ2p(Image *pImage, const std::wstring& wsFilePath, EncoderParams* pEncoderParams);
extern void Image_Destroy(Image *pImage); //extern void Image_Destroy(Image *pImage);
extern Image* Image_Create(int nComponentsCount, ImageComponentParams *pCompParams, ColorSpace eColorSpace); //extern Image* Image_Create(int nComponentsCount, ImageComponentParams *pCompParams, ColorSpace eColorSpace);
void* Malloc(size_t nSize) void* Malloc(size_t nSize)
{ {
...@@ -90,7 +90,7 @@ namespace Jpeg2000 ...@@ -90,7 +90,7 @@ namespace Jpeg2000
DecoderParams oParameters; DecoderParams oParameters;
// // Установим стандартные значения параметров
ApplyDecoderOptions(&oParameters, wsXmlOptions); ApplyDecoderOptions(&oParameters, wsXmlOptions);
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
...@@ -149,7 +149,7 @@ namespace Jpeg2000 ...@@ -149,7 +149,7 @@ namespace Jpeg2000
unsigned char* pBufferPtr = (unsigned char*)pData; unsigned char* pBufferPtr = (unsigned char*)pData;
long nCreatedBufferSize = nBufferSize; long nCreatedBufferSize = nBufferSize;
// pBufferPtr // Пишем данные в pBufferPtr
if (pImage->nCsiz == 3 && pImage->pComponents[0].nXRsiz == pImage->pComponents[1].nXRsiz && pImage->pComponents[1].nXRsiz == pImage->pComponents[2].nXRsiz if (pImage->nCsiz == 3 && pImage->pComponents[0].nXRsiz == pImage->pComponents[1].nXRsiz && pImage->pComponents[1].nXRsiz == pImage->pComponents[2].nXRsiz
&& pImage->pComponents[0].nYRsiz == pImage->pComponents[1].nYRsiz && pImage->pComponents[1].nYRsiz == pImage->pComponents[2].nYRsiz && pImage->pComponents[0].nYRsiz == pImage->pComponents[1].nYRsiz && pImage->pComponents[1].nYRsiz == pImage->pComponents[2].nYRsiz
&& pImage->pComponents[0].nPrecision == pImage->pComponents[1].nPrecision && pImage->pComponents[1].nPrecision == pImage->pComponents[2].nPrecision) && pImage->pComponents[0].nPrecision == pImage->pComponents[1].nPrecision && pImage->pComponents[1].nPrecision == pImage->pComponents[2].nPrecision)
...@@ -216,7 +216,7 @@ namespace Jpeg2000 ...@@ -216,7 +216,7 @@ namespace Jpeg2000
} }
bool CJ2kFile::Save(CBgraFrame* pFrame, const std::wstring& wsDstPath, const std::wstring& wsXmlOptions) bool CJ2kFile::Save(CBgraFrame* pFrame, const std::wstring& wsDstPath, const std::wstring& wsXmlOptions)
{ {
// TODO: , . // TODO: Запись не реализована, надо доделать.
return false; return false;
if (!pFrame) if (!pFrame)
...@@ -227,12 +227,12 @@ namespace Jpeg2000 ...@@ -227,12 +227,12 @@ namespace Jpeg2000
BYTE* pSourceBuffer = pFrame->get_Data(); BYTE* pSourceBuffer = pFrame->get_Data();
LONG lBufferSize = 4 * lWidth * lHeight; LONG lBufferSize = 4 * lWidth * lHeight;
// Xml // Далее обрабатываем Xml с параметрами компрессии
EncoderParams oParameters; EncoderParams oParameters;
int nFormat = ApplyEncoderOptions(&oParameters, wsXmlOptions); int nFormat = ApplyEncoderOptions(&oParameters, wsXmlOptions);
// TODO: - // TODO: Добавить возможность записи альфа-канала
ImageComponentParams aComponentParams[3]; // (RGB) ImageComponentParams aComponentParams[3]; // Пока пусть будет максимально три компоненты (RGB)
Image *pImage = NULL; Image *pImage = NULL;
int nComponentsCount = oParameters.nComponentsCount; int nComponentsCount = oParameters.nComponentsCount;
...@@ -248,7 +248,7 @@ namespace Jpeg2000 ...@@ -248,7 +248,7 @@ namespace Jpeg2000
aComponentParams[nIndex].nHeight = (int)lHeight; aComponentParams[nIndex].nHeight = (int)lHeight;
} }
// Image // Создаем структуру Image
pImage = Image_Create(nComponentsCount, &aComponentParams[0], csRGB); pImage = Image_Create(nComponentsCount, &aComponentParams[0], csRGB);
if (!pImage) if (!pImage)
return false; return false;
......
// J2kFile.h : Declaration of the CJ2kFile // J2kFile.h : Declaration of the CJ2kFile
#pragma once #pragma once
...@@ -23,7 +23,7 @@ namespace Jpeg2000 ...@@ -23,7 +23,7 @@ namespace Jpeg2000
pParameters->nReduce = 0; pParameters->nReduce = 0;
pParameters->nLayer = 0; pParameters->nLayer = 0;
// TODO: // TODO: Сделать чтение параметров декодирования
//if (sXml.GetLength() > 0) //if (sXml.GetLength() > 0)
//{ //{
// XmlUtils::CXmlNode oMainNode; // XmlUtils::CXmlNode oMainNode;
...@@ -64,20 +64,20 @@ namespace Jpeg2000 ...@@ -64,20 +64,20 @@ namespace Jpeg2000
long ApplyEncoderOptions(EncoderParams *pParameters, const std::wstring& sXml) long ApplyEncoderOptions(EncoderParams *pParameters, const std::wstring& sXml)
{ {
int nFormat = 0; // J2k int nFormat = 0; // J2k
// // Сначала выставляем стандартные значения параметров
memset(pParameters, 0, sizeof(EncoderParams)); memset(pParameters, 0, sizeof(EncoderParams));
pParameters->nComponentsCount = 3; pParameters->nComponentsCount = 3;
pParameters->nResolutionsCount = 6; pParameters->nResolutionsCount = 6;
pParameters->nCodeBlockHeightInit = 64; pParameters->nCodeBlockHeightInit = 64;
pParameters->nCodeBlockWidthInit = 64; pParameters->nCodeBlockWidthInit = 64;
pParameters->eProgOrder = poLRCP; pParameters->eProgOrder = poLRCP;
pParameters->nROIComponentIndex = -1; // ROI pParameters->nROIComponentIndex = -1; // Нет ROI
pParameters->nSubSamplingDx = 1; pParameters->nSubSamplingDx = 1;
pParameters->nSubSamplingDy = 1; pParameters->nSubSamplingDy = 1;
pParameters->bTileSizeOn = false; pParameters->bTileSizeOn = false;
pParameters->sComment = "Manufactured by Online Media Technologies Ltd."; pParameters->sComment = "Manufactured by Online Media Technologies Ltd.";
// TODO: // TODO: Сделать чтение параметров кодирования
//if (sXml.GetLength() > 0) //if (sXml.GetLength() > 0)
//{ //{
// XmlUtils::CXmlNode oMainNode; // XmlUtils::CXmlNode oMainNode;
...@@ -187,7 +187,7 @@ namespace Jpeg2000 ...@@ -187,7 +187,7 @@ namespace Jpeg2000
// // SOPmarker // // SOPmarker
// if (oSaveNode.GetNode(_T("SOPmarker"), oCurNode)) // if (oSaveNode.GetNode(_T("SOPmarker"), oCurNode))
// { // {
// // , - ImageInfo // // Пока отключим, потом надо будет добавить - для этого нужно выделять память для стрктуры ImageInfo
// //pParameters->nCodingStyle |= 0x02; // //pParameters->nCodingStyle |= 0x02;
// } // }
...@@ -211,7 +211,7 @@ namespace Jpeg2000 ...@@ -211,7 +211,7 @@ namespace Jpeg2000
// if (oSaveNode.GetNode(_T("Comment"), oCurNode)) // if (oSaveNode.GetNode(_T("Comment"), oCurNode))
// { // {
// sValue = oCurNode.GetAttribute(_T("value")); // sValue = oCurNode.GetAttribute(_T("value"));
// // TO DO: // // TO DO: Неправильное копирование строки
// USES_CONVERSION; // USES_CONVERSION;
// pParameters->sComment = W2A(sValue.GetBuffer()); // pParameters->sComment = W2A(sValue.GetBuffer());
// } // }
...@@ -320,13 +320,13 @@ namespace Jpeg2000 ...@@ -320,13 +320,13 @@ namespace Jpeg2000
//} //}
// // Проверим кооректность введенных параметров
// nDistoAlloc, nFixedQuality, nFixedAlloc // Параметры nDistoAlloc, nFixedQuality, nFixedAlloc нельзя использовать вместе
if ((pParameters->nDistoAlloc || pParameters->nFixedAlloc || pParameters->nFixedQuality) && (!(pParameters->nDistoAlloc ^ pParameters->nFixedAlloc ^ pParameters->nFixedQuality))) if ((pParameters->nDistoAlloc || pParameters->nFixedAlloc || pParameters->nFixedQuality) && (!(pParameters->nDistoAlloc ^ pParameters->nFixedAlloc ^ pParameters->nFixedQuality)))
return -1; return -1;
// , // Если параметры не заданы, тогда по умолчанию ставим компрессию без потерь
if (0 == pParameters->nLayersCount) if (0 == pParameters->nLayersCount)
{ {
pParameters->afRates[0] = 0; pParameters->afRates[0] = 0;
...@@ -340,7 +340,7 @@ namespace Jpeg2000 ...@@ -340,7 +340,7 @@ namespace Jpeg2000
{ {
if (-1 == pParameters->aoPOC[nIndex].ePpoc) if (-1 == pParameters->aoPOC[nIndex].ePpoc)
{ {
// TO DO: , // TO DO: Выдать ошибку, что порядок не задан
} }
} }
......
#pragma once #pragma once
#include "Types.h" #include "Types.h"
#include "ArithmeticCoder.h" #include "ArithmeticCoder.h"
...@@ -59,7 +59,7 @@ namespace Jpeg2000 ...@@ -59,7 +59,7 @@ namespace Jpeg2000
return NULL; return NULL;
} }
Image *pImage = Jp2_Decode((Jp2Stream*)pDInfo->pJp2, pStream); // pImage = NULL Image *pImage = Jp2_Decode((Jp2Stream*)pDInfo->pJp2, pStream); // в случае ошибки pImage = NULL
delete (pStream); delete (pStream);
Jp2_DestroyDecompress((Jp2Stream*)pDInfo->pJp2); Jp2_DestroyDecompress((Jp2Stream*)pDInfo->pJp2);
...@@ -100,7 +100,7 @@ namespace Jpeg2000 ...@@ -100,7 +100,7 @@ namespace Jpeg2000
return NULL; return NULL;
} }
Image *pImage = J2k_Decode((J2kCodestream*)pDInfo->pJ2k, pStream); // pImage = NULL Image *pImage = J2k_Decode((J2kCodestream*)pDInfo->pJ2k, pStream); // в случае ошибки pImage = NULL
delete (pStream); delete (pStream);
J2k_DestroyDecompress((J2kCodestream*)pDInfo->pJ2k); J2k_DestroyDecompress((J2kCodestream*)pDInfo->pJ2k);
...@@ -141,7 +141,7 @@ namespace Jpeg2000 ...@@ -141,7 +141,7 @@ namespace Jpeg2000
return NULL; return NULL;
} }
Image *pImage = J2k_DecodeJptStream((J2kCodestream*)pDInfo->pJ2k, pStream); // pImage = NULL Image *pImage = J2k_DecodeJptStream((J2kCodestream*)pDInfo->pJ2k, pStream); // в случае ошибки pImage = NULL
delete (pStream); delete (pStream);
J2k_DestroyDecompress((J2kCodestream*)pDInfo->pJ2k); J2k_DestroyDecompress((J2kCodestream*)pDInfo->pJ2k);
...@@ -181,7 +181,7 @@ namespace Jpeg2000 ...@@ -181,7 +181,7 @@ namespace Jpeg2000
return NULL; return NULL;
} }
Image *pImage = Mj2_Decode((Mj2_Movie*)pDInfo->pMj2, pStream); // pImage = NULL Image *pImage = Mj2_Decode((Mj2_Movie*)pDInfo->pMj2, pStream); // в случае ошибки pImage = NULL
delete (pStream); delete (pStream);
Mj2_DestroyDecompress((Mj2_Movie*)pDInfo->pMj2); Mj2_DestroyDecompress((Mj2_Movie*)pDInfo->pMj2);
......
#pragma once #pragma once
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
#include "Types.h" #include "Types.h"
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
namespace Jpeg2000 namespace Jpeg2000
{ {
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// // Вспомогательные функции
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
static bool Jp2_ReadBoxHeader(PCommon pCodecInfo, CReader *pStream, Jp2Box *pBox) static bool Jp2_ReadBoxHeader(PCommon pCodecInfo, CReader *pStream, Jp2Box *pBox)
{ {
...@@ -111,7 +111,7 @@ namespace Jpeg2000 ...@@ -111,7 +111,7 @@ namespace Jpeg2000
pStream->Write(pJp2->nWidth, 4); // WIDTH pStream->Write(pJp2->nWidth, 4); // WIDTH
pStream->Write(pJp2->nComponentsCount, 2); // NC pStream->Write(pJp2->nComponentsCount, 2); // NC
pStream->Write(pJp2->nBPC, 1); // BPC pStream->Write(pJp2->nBPC, 1); // BPC
pStream->Write(pJp2->nCompressionType, 1); // C ( 7 ) pStream->Write(pJp2->nCompressionType, 1); // C ( это значение всегда равно 7 )
pStream->Write(pJp2->nColorSpaceUnk, 1); // UnkC, colorspace unknown pStream->Write(pJp2->nColorSpaceUnk, 1); // UnkC, colorspace unknown
pStream->Write(pJp2->nIPR, 1); // IPR pStream->Write(pJp2->nIPR, 1); // IPR
...@@ -228,12 +228,13 @@ namespace Jpeg2000 ...@@ -228,12 +228,13 @@ namespace Jpeg2000
{ {
pJp2->nEnumCS = pStream->Read(4); // EnumCS pJp2->nEnumCS = pStream->Read(4); // EnumCS
pJp2->oColor.has_colr = TRUE; pJp2->oColor.has_colr = true;
} }
else if (pJp2->nMethod == 2) { else if (pJp2->nMethod == 2)
{
/* ICC profile */ /* ICC profile */
__int32 it_icc_value = 0; int it_icc_value = 0;
__int32 icc_len = oBox.nLength - 3; int icc_len = oBox.nLength - 3;
pJp2->oColor.icc_profile_len = icc_len; pJp2->oColor.icc_profile_len = icc_len;
pJp2->oColor.icc_profile_buf = (BYTE*)Malloc(icc_len); pJp2->oColor.icc_profile_buf = (BYTE*)Malloc(icc_len);
...@@ -249,14 +250,14 @@ namespace Jpeg2000 ...@@ -249,14 +250,14 @@ namespace Jpeg2000
pJp2->oColor.icc_profile_buf[it_icc_value] = (BYTE)pStream->Read(1); /* icc values */ pJp2->oColor.icc_profile_buf[it_icc_value] = (BYTE)pStream->Read(1); /* icc values */
} }
pJp2->oColor.has_colr = TRUE; pJp2->oColor.has_colr = true;
} }
else// if (jp2->meth > 2) else// if (jp2->meth > 2)
{ {
/* ISO/IEC 15444-1:2004 (E), Table I.9 Legal METH values: /* ISO/IEC 15444-1:2004 (E), Table I.9 ­ Legal METH values:
conforming JP2 reader shall ignore the entire Colour Specification box.*/ conforming JP2 reader shall ignore the entire Colour Specification box.*/
//"COLR BOX meth value is not a regular value (%d), so we will ignore the entire Colour Specification box. \n", jp2->meth); //"COLR BOX meth value is not a regular value (%d), so we will ignore the entire Colour Specification box. \n", jp2->meth);
// PROFILE // Пропускаем PROFILE
int nSkipLen = oBox.nInitPos + oBox.nLength - pStream->Tell(); int nSkipLen = oBox.nInitPos + oBox.nLength - pStream->Tell();
if (nSkipLen < 0) if (nSkipLen < 0)
{ {
...@@ -363,8 +364,8 @@ namespace Jpeg2000 ...@@ -363,8 +364,8 @@ namespace Jpeg2000
{ {
// return false; // return false;
// Box , - // По спецификации данный Box является необходимым, но мы все-таки
// . // попробуем прочитать изображение со стандартными параметрами.
pStream->Seek(nCurPos); pStream->Seek(nCurPos);
pJp2->nApprox = 0; pJp2->nApprox = 0;
...@@ -546,7 +547,7 @@ namespace Jpeg2000 ...@@ -546,7 +547,7 @@ namespace Jpeg2000
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// Jp2 // Декодирование потока Jp2
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
void Jp2_DestroyDecompress(Jp2Stream *pJp2) void Jp2_DestroyDecompress(Jp2Stream *pJp2)
{ {
...@@ -596,27 +597,27 @@ namespace Jpeg2000 ...@@ -596,27 +597,27 @@ namespace Jpeg2000
PCommon pCodecInfo = pJp2->pCodecInfo; PCommon pCodecInfo = pJp2->pCodecInfo;
// JP2 // Декодируем JP2
if (!Jp2_ReadStruct(pJp2, pStream)) if (!Jp2_ReadStruct(pJp2, pStream))
{ {
Event_Message(EVT_ERROR, "Failed to decode jp2 structure\n"); Event_Message(EVT_ERROR, "Failed to decode jp2 structure\n");
return NULL; return NULL;
} }
// J2K // Декодируем J2K
Image *pImage = J2k_Decode(pJp2->pJ2k, pStream); Image *pImage = J2k_Decode(pJp2->pJ2k, pStream);
if (!pImage) if (!pImage)
{ {
Event_Message(EVT_ERROR, "Failed to decode J2K image\n"); Event_Message(EVT_ERROR, "Failed to decode J2K image\n");
} }
//// ..???? ////приведение цветовой схемы..????
return pImage; return pImage;
} }
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// Jp2 // Кодирование в поток Jp2
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
void Jp2_DestroyCompress(Jp2Stream *pJp2) void Jp2_DestroyCompress(Jp2Stream *pJp2)
{ {
...@@ -700,7 +701,7 @@ namespace Jpeg2000 ...@@ -700,7 +701,7 @@ namespace Jpeg2000
if (nDepth0 != depth) if (nDepth0 != depth)
pJp2->nBPC = 255; pJp2->nBPC = 255;
} }
pJp2->nCompressionType = 7; // C ( 7) pJp2->nCompressionType = 7; // C (всегда 7)
pJp2->nColorSpaceUnk = 0; // UnkC pJp2->nColorSpaceUnk = 0; // UnkC
pJp2->nIPR = 0; // IRP pJp2->nIPR = 0; // IRP
...@@ -722,7 +723,7 @@ namespace Jpeg2000 ...@@ -722,7 +723,7 @@ namespace Jpeg2000
if (pJp2->nMethod == 1) if (pJp2->nMethod == 1)
{ {
if (pImage->eColorSpace == 1) if (pImage->eColorSpace == 1)
pJp2->nEnumCS = 16; // sRGB ( 6196621 ) pJp2->nEnumCS = 16; // sRGB ( 61966–2–1 )
else if (pImage->eColorSpace == 2) else if (pImage->eColorSpace == 2)
pJp2->nEnumCS = 17; // Greyscale pJp2->nEnumCS = 17; // Greyscale
else if (pImage->eColorSpace == 3) else if (pImage->eColorSpace == 3)
......
#pragma once #pragma once
#include "Types.h" #include "Types.h"
...@@ -12,15 +12,6 @@ namespace Jpeg2000 ...@@ -12,15 +12,6 @@ namespace Jpeg2000
{ {
if (sFormatString != NULL) if (sFormatString != NULL)
{ {
char sMessage[MSG_SIZE]={};
va_list sArg;
memset(sMessage, 0, MSG_SIZE);
va_start(sArg, sFormatString);
int nLength = (strlen(sFormatString) > MSG_SIZE) ? MSG_SIZE : strlen(sFormatString);
vsprintf(sMessage, sFormatString, sArg);
va_end(sArg);
// TODO: print sMessage/*, pCodecInfo->pClientData*/ // TODO: print sMessage/*, pCodecInfo->pClientData*/
} }
......
#pragma once #pragma once
#include "Types.h" #include "Types.h"
#include "Reader.h" #include "Reader.h"
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
namespace Jpeg2000 namespace Jpeg2000
{ {
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// // Вспомогательные функции
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
static unsigned int JPT_ReadVBASInfo(CReader *pStream, unsigned int nValue) static unsigned int JPT_ReadVBASInfo(CReader *pStream, unsigned int nValue)
{ {
...@@ -34,7 +34,7 @@ namespace Jpeg2000 ...@@ -34,7 +34,7 @@ namespace Jpeg2000
} }
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// // Основные функции
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
void JPT_InitMessageHeader(JPTMessageHeader *pHeader) void JPT_InitMessageHeader(JPTMessageHeader *pHeader)
{ {
......
#pragma once #pragma once
#include "Types.h" #include "Types.h"
namespace Jpeg2000 namespace Jpeg2000
{ {
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// Motion JPEG 2000 (MJ2) // Данные функции предназначены для чтения Motion JPEG 2000 (MJ2)
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
static bool Mj2_ReadBoxHeader(Mj2_Box* pBox, CReader * pStream) static bool Mj2_ReadBoxHeader(Mj2_Box* pBox, CReader * pStream)
...@@ -104,7 +104,7 @@ namespace Jpeg2000 ...@@ -104,7 +104,7 @@ namespace Jpeg2000
//>>>> //>>>>
// MDAT // Достаем первую картинку в потоке MDAT
Jp2Box oTempBox; Jp2Box oTempBox;
Jp2_ReadBoxHeader(pMovie->pCodecInfo, pStream, &oTempBox); Jp2_ReadBoxHeader(pMovie->pCodecInfo, pStream, &oTempBox);
do do
...@@ -124,7 +124,7 @@ namespace Jpeg2000 ...@@ -124,7 +124,7 @@ namespace Jpeg2000
int nJ2kCodestreamOffset = pStream->Tell(); int nJ2kCodestreamOffset = pStream->Tell();
int nJ2kCodestreamLength = oTempBox.nLength - 8; int nJ2kCodestreamLength = oTempBox.nLength - 8;
// J2K // Декодируем J2K
*ppImage = J2k_Decode(pMovie->pJ2k, pStream); *ppImage = J2k_Decode(pMovie->pJ2k, pStream);
if (!*ppImage) if (!*ppImage)
{ {
...@@ -159,8 +159,8 @@ namespace Jpeg2000 ...@@ -159,8 +159,8 @@ namespace Jpeg2000
Event_Message(EVT_ERROR, "Error: Only Version 0 handled in MVHD box\n"); Event_Message(EVT_ERROR, "Error: Only Version 0 handled in MVHD box\n");
} }
// TO DO: // TO DO: Здесь в зависимости от версии разное число байт должно читаться
// . fcd15444-3.pdf .15 // см. fcd15444-3.pdf стр.15
pMovie->unCreationTime = pStream->Read(4); // Creation Time pMovie->unCreationTime = pStream->Read(4); // Creation Time
pMovie->unModificationTime = pStream->Read(4); // Modification Time pMovie->unModificationTime = pStream->Read(4); // Modification Time
...@@ -206,8 +206,8 @@ namespace Jpeg2000 ...@@ -206,8 +206,8 @@ namespace Jpeg2000
return false; return false;
} }
// TO DO: // TO DO: Здесь в зависимости от версии разное число байт должно читаться
// . fcd15444-3.pdf .16 // см. fcd15444-3.pdf стр.16
if (0 != pStream->Read(1)) // Version = 0 if (0 != pStream->Read(1)) // Version = 0
{ {
...@@ -217,7 +217,7 @@ namespace Jpeg2000 ...@@ -217,7 +217,7 @@ namespace Jpeg2000
int nFlag = pStream->Read(3); int nFlag = pStream->Read(3);
if (!(1 == nFlag || 2 == nFlag || 3 == nFlag || 4 == nFlag)) // nFlags = 1, 2, 3 4 if (!(1 == nFlag || 2 == nFlag || 3 == nFlag || 4 == nFlag)) // nFlags = 1, 2, 3 или 4
{ {
Event_Message(EVT_ERROR, "Error with flag in TKHD box: Expected flag 1,2,3 or 4\n"); Event_Message(EVT_ERROR, "Error with flag in TKHD box: Expected flag 1,2,3 or 4\n");
return false; return false;
...@@ -268,7 +268,7 @@ namespace Jpeg2000 ...@@ -268,7 +268,7 @@ namespace Jpeg2000
return 1; return 1;
} }
// TO DO: Version = 1 // TO DO: Сделать поодержку Version = 1
if (0 != pStream->Read(1)) // Version = 0 if (0 != pStream->Read(1)) // Version = 0
{ {
Event_Message(EVT_ERROR, "Error: Only Version 0 handled in MDHD box\n"); Event_Message(EVT_ERROR, "Error: Only Version 0 handled in MDHD box\n");
...@@ -486,9 +486,9 @@ namespace Jpeg2000 ...@@ -486,9 +486,9 @@ namespace Jpeg2000
return false; return false;
} }
if (1 != pStream->Read(3)) // flags = 1, if (1 != pStream->Read(3)) // Если flags = 1, то медиа данные в файле
{ {
// TO DO: // TO DO: Сделать нормальное чтение строк
pTrack->pUrl[nUrlNum].anLocation[0] = pStream->Read(4); pTrack->pUrl[nUrlNum].anLocation[0] = pStream->Read(4);
pTrack->pUrl[nUrlNum].anLocation[1] = pStream->Read(4); pTrack->pUrl[nUrlNum].anLocation[1] = pStream->Read(4);
pTrack->pUrl[nUrlNum].anLocation[2] = pStream->Read(4); pTrack->pUrl[nUrlNum].anLocation[2] = pStream->Read(4);
...@@ -525,9 +525,9 @@ namespace Jpeg2000 ...@@ -525,9 +525,9 @@ namespace Jpeg2000
return false; return false;
} }
if (1 != pStream->Read(3)) // flags = 1, if (1 != pStream->Read(3)) // Если flags = 1, то медиа данные в файле
{ {
// TO DO: // TO DO: Сделать нормальное чтение строк
pTrack->pUrn[nUrnNum].anName[0] = pStream->Read(4); pTrack->pUrn[nUrnNum].anName[0] = pStream->Read(4);
pTrack->pUrn[nUrnNum].anName[1] = pStream->Read(4); pTrack->pUrn[nUrnNum].anName[1] = pStream->Read(4);
pTrack->pUrn[nUrnNum].anName[2] = pStream->Read(4); pTrack->pUrn[nUrnNum].anName[2] = pStream->Read(4);
...@@ -778,7 +778,7 @@ namespace Jpeg2000 ...@@ -778,7 +778,7 @@ namespace Jpeg2000
int nSampleSize = pStream->Read(4); // SampleSize int nSampleSize = pStream->Read(4); // SampleSize
if (0 != nSampleSize) // if (0 != nSampleSize) // У всех самплов одинаковый размер
{ {
pTrack->unSameSampleSize = 1; pTrack->unSameSampleSize = 1;
...@@ -857,7 +857,7 @@ namespace Jpeg2000 ...@@ -857,7 +857,7 @@ namespace Jpeg2000
static bool Mj2_ReadSTCO(Mj2_TrackParams* pTrack, CReader * pStream) static bool Mj2_ReadSTCO(Mj2_TrackParams* pTrack, CReader * pStream)
{ {
// TO DO: 'co64' // TO DO: Сделать чтение 'co64'
Mj2_Box oBox; Mj2_Box oBox;
Mj2_ReadBoxHeader(&oBox, pStream); Mj2_ReadBoxHeader(&oBox, pStream);
if (MJ2_STCO != oBox.nType) if (MJ2_STCO != oBox.nType)
...@@ -1185,13 +1185,13 @@ namespace Jpeg2000 ...@@ -1185,13 +1185,13 @@ namespace Jpeg2000
} }
else if (1 == pTrack->nTrackType) else if (1 == pTrack->nTrackType)
{ {
// TO DO: // TO DO: Релизовать
int nSkipLen = pStream->Read(4); int nSkipLen = pStream->Read(4);
pStream->Skip(nSkipLen - 4); pStream->Skip(nSkipLen - 4);
} }
else if (2 == pTrack->nTrackType) else if (2 == pTrack->nTrackType)
{ {
// TO DO: // TO DO: Реализовать
int nSkipLen = pStream->Read(4); int nSkipLen = pStream->Read(4);
pStream->Skip(nSkipLen - 4); pStream->Skip(nSkipLen - 4);
} }
...@@ -1403,7 +1403,7 @@ namespace Jpeg2000 ...@@ -1403,7 +1403,7 @@ namespace Jpeg2000
{ {
case MJ2_MDAT: case MJ2_MDAT:
// TO DO: MDAT MOOV // TO DO: Связать данные в MDAT с данными MOOV
if (!Mj2_ReadMDAT(pMovie, pStream, ppImage, oBox)) if (!Mj2_ReadMDAT(pMovie, pStream, ppImage, oBox))
return false; return false;
...@@ -1440,7 +1440,7 @@ namespace Jpeg2000 ...@@ -1440,7 +1440,7 @@ namespace Jpeg2000
} }
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// Mj2 // Декодирование потока Mj2
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
void Mj2_DestroyDecompress(Mj2_Movie* pMovie) void Mj2_DestroyDecompress(Mj2_Movie* pMovie)
{ {
...@@ -1531,7 +1531,7 @@ namespace Jpeg2000 ...@@ -1531,7 +1531,7 @@ namespace Jpeg2000
PCommon pCodecInfo = pMovie->pCodecInfo; PCommon pCodecInfo = pMovie->pCodecInfo;
Image *pImage = NULL; Image *pImage = NULL;
// JP2 // Декодируем JP2
if (!Mj2_ReadStruct(pMovie, pStream, &pImage)) if (!Mj2_ReadStruct(pMovie, pStream, &pImage))
{ {
Event_Message(EVT_ERROR, "Failed to decode jp2 structure\n"); Event_Message(EVT_ERROR, "Failed to decode jp2 structure\n");
......
#pragma once #pragma once
#include "Types.h" #include "Types.h"
#include "Utils.h" #include "Utils.h"
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
namespace Jpeg2000 namespace Jpeg2000
{ {
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// // Вспомогательные функции
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
static bool PI_NextLRCP(PacketIterator *pPI) static bool PI_NextLRCP(PacketIterator *pPI)
{ {
...@@ -53,7 +53,6 @@ namespace Jpeg2000 ...@@ -53,7 +53,6 @@ namespace Jpeg2000
return false; return false;
} }
static bool PI_NextRLCP(PacketIterator *pPI) static bool PI_NextRLCP(PacketIterator *pPI)
{ {
PacketComponent *pComponent = NULL; PacketComponent *pComponent = NULL;
...@@ -99,12 +98,12 @@ namespace Jpeg2000 ...@@ -99,12 +98,12 @@ namespace Jpeg2000
return false; return false;
} }
static bool PI_NextRPCL(PacketIterator *pPI) static bool PI_NextRPCL(PacketIterator *pPI)
{ {
PacketComponent *pComponent = NULL; PacketComponent *pComponent = NULL;
PacketResolution *pResolution = NULL; PacketResolution *pResolution = NULL;
long nIndex = 0; long nIndex = 0;
int nLevel, nTileResX0, nTileResY0, nTileResX1, nTileResY1, nResPX, nResPY, nPCR_i, nPCR_j;
if (!pPI->nFirst) if (!pPI->nFirst)
{ {
...@@ -144,21 +143,21 @@ namespace Jpeg2000 ...@@ -144,21 +143,21 @@ namespace Jpeg2000
continue; continue;
} }
pResolution = &pComponent->pResolutions[pPI->nIndexResolution]; pResolution = &pComponent->pResolutions[pPI->nIndexResolution];
int nLevel = pComponent->nResolutionsCount - 1 - pPI->nIndexResolution; nLevel = pComponent->nResolutionsCount - 1 - pPI->nIndexResolution;
int nTileResX0 = CeilDiv(pPI->nTileX0, pComponent->nDx << nLevel); nTileResX0 = CeilDiv(pPI->nTileX0, pComponent->nDx << nLevel);
int nTileResY0 = CeilDiv(pPI->nTileY0, pComponent->nDy << nLevel); nTileResY0 = CeilDiv(pPI->nTileY0, pComponent->nDy << nLevel);
int nTileResX1 = CeilDiv(pPI->nTileX1, pComponent->nDx << nLevel); nTileResX1 = CeilDiv(pPI->nTileX1, pComponent->nDx << nLevel);
int nTileResY1 = CeilDiv(pPI->nTileY1, pComponent->nDy << nLevel); nTileResY1 = CeilDiv(pPI->nTileY1, pComponent->nDy << nLevel);
int nResPX = pResolution->nDx + nLevel; nResPX = pResolution->nDx + nLevel;
int nResPY = pResolution->nDy + nLevel; nResPY = pResolution->nDy + nLevel;
if ((!(pPI->nX % (pComponent->nDx << nResPX) == 0) || (pPI->nX == pPI->nTileX0 && (nTileResX0 << nLevel) % (1 << nResPX)))) if ((!(pPI->nX % (pComponent->nDx << nResPX) == 0) || (pPI->nX == pPI->nTileX0 && (nTileResX0 << nLevel) % (1 << nResPX))))
{ {
continue; continue;
} }
// TO DO: (1 << nResPX) // TO DO: Проверить здесь последнее деление на (1 << nResPX)
if ((!(pPI->nY % (pComponent->nDy << nResPY) == 0) || (pPI->nY == pPI->nTileY0 && (nTileResY0 << nLevel) % (1 << nResPX)))) if ((!(pPI->nY % (pComponent->nDy << nResPY) == 0) || (pPI->nY == pPI->nTileY0 && (nTileResY0 << nLevel) % (1 << nResPX))))
{ {
continue; continue;
...@@ -171,8 +170,8 @@ namespace Jpeg2000 ...@@ -171,8 +170,8 @@ namespace Jpeg2000
if ((nTileResX0 == nTileResX1) || (nTileResY0 == nTileResY1)) if ((nTileResX0 == nTileResX1) || (nTileResY0 == nTileResY1))
continue; continue;
int nPCR_i = FloorDivPow2(CeilDiv(pPI->nX, pComponent->nDx << nLevel), pResolution->nDx) - FloorDivPow2(nTileResX0, pResolution->nDx); nPCR_i = FloorDivPow2(CeilDiv(pPI->nX, pComponent->nDx << nLevel), pResolution->nDx) - FloorDivPow2(nTileResX0, pResolution->nDx);
int nPCR_j = FloorDivPow2(CeilDiv(pPI->nY, pComponent->nDy << nLevel), pResolution->nDy) - FloorDivPow2(nTileResY0, pResolution->nDy); nPCR_j = FloorDivPow2(CeilDiv(pPI->nY, pComponent->nDy << nLevel), pResolution->nDy) - FloorDivPow2(nTileResY0, pResolution->nDy);
pPI->nIndexPrecinct = nPCR_i + nPCR_j * pResolution->nWidth; pPI->nIndexPrecinct = nPCR_i + nPCR_j * pResolution->nWidth;
for (pPI->nIndexLayer = 0; pPI->nIndexLayer < pPI->oPOC.nLYEpoc; pPI->nIndexLayer++) for (pPI->nIndexLayer = 0; pPI->nIndexLayer < pPI->oPOC.nLYEpoc; pPI->nIndexLayer++)
...@@ -192,12 +191,12 @@ namespace Jpeg2000 ...@@ -192,12 +191,12 @@ namespace Jpeg2000
return false; return false;
} }
static bool PI_NextPCRL(PacketIterator *pPI) static bool PI_NextPCRL(PacketIterator *pPI)
{ {
PacketComponent *pComponent = NULL; PacketComponent *pComponent = NULL;
PacketResolution *pResolution = NULL; PacketResolution *pResolution = NULL;
long nIndex = 0; long nIndex = 0;
int nLevel, nTileResX0, nTileResY0, nTileResX1, nTileResY1, nResPX, nResPY, nPRC_i, nPRC_j;
if (!pPI->nFirst) if (!pPI->nFirst)
{ {
...@@ -234,21 +233,21 @@ namespace Jpeg2000 ...@@ -234,21 +233,21 @@ namespace Jpeg2000
for (pPI->nIndexResolution = pPI->oPOC.nRSpoc; pPI->nIndexResolution < min(pPI->oPOC.nREpoc, pComponent->nResolutionsCount); pPI->nIndexResolution++) for (pPI->nIndexResolution = pPI->oPOC.nRSpoc; pPI->nIndexResolution < min(pPI->oPOC.nREpoc, pComponent->nResolutionsCount); pPI->nIndexResolution++)
{ {
pResolution = &pComponent->pResolutions[pPI->nIndexResolution]; pResolution = &pComponent->pResolutions[pPI->nIndexResolution];
int nLevel = pComponent->nResolutionsCount - 1 - pPI->nIndexResolution; nLevel = pComponent->nResolutionsCount - 1 - pPI->nIndexResolution;
int nTileResX0 = CeilDiv(pPI->nTileX0, pComponent->nDx << nLevel); nTileResX0 = CeilDiv(pPI->nTileX0, pComponent->nDx << nLevel);
int nTileResY0 = CeilDiv(pPI->nTileY0, pComponent->nDy << nLevel); nTileResY0 = CeilDiv(pPI->nTileY0, pComponent->nDy << nLevel);
int nTileResX1 = CeilDiv(pPI->nTileX1, pComponent->nDx << nLevel); nTileResX1 = CeilDiv(pPI->nTileX1, pComponent->nDx << nLevel);
int nTileResY1 = CeilDiv(pPI->nTileY1, pComponent->nDy << nLevel); nTileResY1 = CeilDiv(pPI->nTileY1, pComponent->nDy << nLevel);
int nResPX = pResolution->nDx + nLevel; nResPX = pResolution->nDx + nLevel;
int nResPY = pResolution->nDy + nLevel; nResPY = pResolution->nDy + nLevel;
if ((!(pPI->nX % (pComponent->nDx << nResPX) == 0) || (pPI->nX == pPI->nTileX0 && (nTileResX0 << nLevel) % (1 << nResPX)))) if ((!(pPI->nX % (pComponent->nDx << nResPX) == 0) || (pPI->nX == pPI->nTileX0 && (nTileResX0 << nLevel) % (1 << nResPX))))
{ {
continue; continue;
} }
// TO DO: (1 << nResPX) // TO DO: Проверить здесь последнее деление на (1 << nResPX)
if ((!(pPI->nY % (pComponent->nDy << nResPY) == 0) || (pPI->nY == pPI->nTileY0 && (nTileResY0 << nLevel) % (1 << nResPX)))) if ((!(pPI->nY % (pComponent->nDy << nResPY) == 0) || (pPI->nY == pPI->nTileY0 && (nTileResY0 << nLevel) % (1 << nResPX))))
{ {
continue; continue;
...@@ -261,8 +260,8 @@ namespace Jpeg2000 ...@@ -261,8 +260,8 @@ namespace Jpeg2000
if ((nTileResX0 == nTileResX1) || (nTileResY0 == nTileResY1)) if ((nTileResX0 == nTileResX1) || (nTileResY0 == nTileResY1))
continue; continue;
int nPRC_i = FloorDivPow2(CeilDiv(pPI->nX, pComponent->nDx << nLevel), pResolution->nDx) - FloorDivPow2(nTileResX0, pResolution->nDx); nPRC_i = FloorDivPow2(CeilDiv(pPI->nX, pComponent->nDx << nLevel), pResolution->nDx) - FloorDivPow2(nTileResX0, pResolution->nDx);
int nPRC_j = FloorDivPow2(CeilDiv(pPI->nY, pComponent->nDy << nLevel), pResolution->nDy) - FloorDivPow2(nTileResY0, pResolution->nDy); nPRC_j = FloorDivPow2(CeilDiv(pPI->nY, pComponent->nDy << nLevel), pResolution->nDy) - FloorDivPow2(nTileResY0, pResolution->nDy);
pPI->nIndexPrecinct = nPRC_i + nPRC_j * pResolution->nWidth; pPI->nIndexPrecinct = nPRC_i + nPRC_j * pResolution->nWidth;
for (pPI->nIndexLayer = 0; pPI->nIndexLayer < pPI->oPOC.nLYEpoc; pPI->nIndexLayer++) for (pPI->nIndexLayer = 0; pPI->nIndexLayer < pPI->oPOC.nLYEpoc; pPI->nIndexLayer++)
...@@ -282,12 +281,12 @@ namespace Jpeg2000 ...@@ -282,12 +281,12 @@ namespace Jpeg2000
return false; return false;
} }
static bool PI_NextCPRL(PacketIterator *pPI) static bool PI_NextCPRL(PacketIterator *pPI)
{ {
PacketComponent *pComponent = NULL; PacketComponent *pComponent = NULL;
PacketResolution *pResolution = NULL; PacketResolution *pResolution = NULL;
long nIndex = 0; long nIndex = 0;
int nLevel, nTileResX0, nTileResY0, nTileResX1, nTileResY1, nResPX, nResPY, nPRC_i, nPRC_j;
if (!pPI->nFirst) if (!pPI->nFirst)
{ {
...@@ -320,20 +319,20 @@ namespace Jpeg2000 ...@@ -320,20 +319,20 @@ namespace Jpeg2000
for (pPI->nIndexResolution = pPI->oPOC.nRSpoc; pPI->nIndexResolution < min(pPI->oPOC.nREpoc, pComponent->nResolutionsCount); pPI->nIndexResolution++) for (pPI->nIndexResolution = pPI->oPOC.nRSpoc; pPI->nIndexResolution < min(pPI->oPOC.nREpoc, pComponent->nResolutionsCount); pPI->nIndexResolution++)
{ {
pResolution = &pComponent->pResolutions[pPI->nIndexResolution]; pResolution = &pComponent->pResolutions[pPI->nIndexResolution];
int nLevel = pComponent->nResolutionsCount - 1 - pPI->nIndexResolution; nLevel = pComponent->nResolutionsCount - 1 - pPI->nIndexResolution;
int nTileResX0 = CeilDiv(pPI->nTileX0, pComponent->nDx << nLevel); nTileResX0 = CeilDiv(pPI->nTileX0, pComponent->nDx << nLevel);
int nTileResY0 = CeilDiv(pPI->nTileY0, pComponent->nDy << nLevel); nTileResY0 = CeilDiv(pPI->nTileY0, pComponent->nDy << nLevel);
int nTileResX1 = CeilDiv(pPI->nTileX1, pComponent->nDx << nLevel); nTileResX1 = CeilDiv(pPI->nTileX1, pComponent->nDx << nLevel);
int nTileResY1 = CeilDiv(pPI->nTileY1, pComponent->nDy << nLevel); nTileResY1 = CeilDiv(pPI->nTileY1, pComponent->nDy << nLevel);
int nResPX = pResolution->nDx + nLevel; nResPX = pResolution->nDx + nLevel;
int nResPY = pResolution->nDy + nLevel; nResPY = pResolution->nDy + nLevel;
if ((!(pPI->nX % (pComponent->nDx << nResPX) == 0) || (pPI->nX == pPI->nTileX0 && (nTileResX0 << nLevel) % (1 << nResPX)))) if ((!(pPI->nX % (pComponent->nDx << nResPX) == 0) || (pPI->nX == pPI->nTileX0 && (nTileResX0 << nLevel) % (1 << nResPX))))
{ {
continue; continue;
} }
// TO DO: (1 << nResPX) // TO DO: Проверить здесь последнее деление на (1 << nResPX)
if ((!(pPI->nY % (pComponent->nDy << nResPY) == 0) || (pPI->nY == pPI->nTileY0 && (nTileResY0 << nLevel) % (1 << nResPX)))) if ((!(pPI->nY % (pComponent->nDy << nResPY) == 0) || (pPI->nY == pPI->nTileY0 && (nTileResY0 << nLevel) % (1 << nResPX))))
{ {
continue; continue;
...@@ -346,8 +345,8 @@ namespace Jpeg2000 ...@@ -346,8 +345,8 @@ namespace Jpeg2000
if ((nTileResX0 == nTileResX1) || (nTileResY0 == nTileResY1)) if ((nTileResX0 == nTileResX1) || (nTileResY0 == nTileResY1))
continue; continue;
int nPRC_i = FloorDivPow2(CeilDiv(pPI->nX, pComponent->nDx << nLevel), pResolution->nDx) - FloorDivPow2(nTileResX0, pResolution->nDx); nPRC_i = FloorDivPow2(CeilDiv(pPI->nX, pComponent->nDx << nLevel), pResolution->nDx) - FloorDivPow2(nTileResX0, pResolution->nDx);
int nPRC_j = FloorDivPow2(CeilDiv(pPI->nY, pComponent->nDy << nLevel), pResolution->nDy) - FloorDivPow2(nTileResY0, pResolution->nDy); nPRC_j = FloorDivPow2(CeilDiv(pPI->nY, pComponent->nDy << nLevel), pResolution->nDy) - FloorDivPow2(nTileResY0, pResolution->nDy);
pPI->nIndexPrecinct = nPRC_i + nPRC_j * pResolution->nWidth; pPI->nIndexPrecinct = nPRC_i + nPRC_j * pResolution->nWidth;
for (pPI->nIndexLayer = 0; pPI->nIndexLayer < pPI->oPOC.nLYEpoc; pPI->nIndexLayer++) for (pPI->nIndexLayer = 0; pPI->nIndexLayer < pPI->oPOC.nLYEpoc; pPI->nIndexLayer++)
...@@ -367,9 +366,8 @@ namespace Jpeg2000 ...@@ -367,9 +366,8 @@ namespace Jpeg2000
return false; return false;
} }
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// // Основные функции
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
void PI_Destroy(PacketIterator *pPI, CodingParams *pCodingParams, int nTileIndex) void PI_Destroy(PacketIterator *pPI, CodingParams *pCodingParams, int nTileIndex)
{ {
......
#pragma once #pragma once
#include "Types.h" #include "Types.h"
#include "Utils.h" #include "Utils.h"
......
#include "Types.h" #include "Types.h"
#include "Reader.h" #include "Reader.h"
namespace Jpeg2000 namespace Jpeg2000
...@@ -42,7 +42,7 @@ namespace Jpeg2000 ...@@ -42,7 +42,7 @@ namespace Jpeg2000
return *pStream->pCurPos++; return *pStream->pCurPos++;
} }
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// // Основные функции
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
ByteIO* ByteIO_Open(PCommon pInfo, unsigned char *pBuffer, int nLength) ByteIO* ByteIO_Open(PCommon pInfo, unsigned char *pBuffer, int nLength)
{ {
...@@ -62,7 +62,7 @@ namespace Jpeg2000 ...@@ -62,7 +62,7 @@ namespace Jpeg2000
} }
else if (!pBuffer && !nLength && pInfo) else if (!pBuffer && !nLength && pInfo)
{ {
// // Выделяем память для закодировнного изображения
pStream->nMode = STREAM_WRITE; pStream->nMode = STREAM_WRITE;
switch (pInfo->eCodecFormat) switch (pInfo->eCodecFormat)
{ {
...@@ -90,7 +90,7 @@ namespace Jpeg2000 ...@@ -90,7 +90,7 @@ namespace Jpeg2000
return NULL; return NULL;
} }
// // Инициализируем поток
pStream->pStart = pStream->pBuffer; pStream->pStart = pStream->pBuffer;
pStream->pEnd = pStream->pBuffer + pStream->nLength; pStream->pEnd = pStream->pBuffer + pStream->nLength;
pStream->pCurPos = pStream->pBuffer; pStream->pCurPos = pStream->pBuffer;
......
#pragma once #pragma once
#include "../../common/File.h" #include "../../common/File.h"
...@@ -8,18 +8,18 @@ namespace Jpeg2000 ...@@ -8,18 +8,18 @@ namespace Jpeg2000
// Byte input-output (Stream IO) // Byte input-output (Stream IO)
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
#define STREAM_READ 0x0001 // #define STREAM_READ 0x0001 // Поток открыт для чтения
#define STREAM_WRITE 0x0002 // #define STREAM_WRITE 0x0002 // Поток открыт для записи
typedef struct TByteIO typedef struct TByteIO
{ {
int nMode; // ( STREAM_READ OPJ_STREAM_WRITE ) int nMode; // Чтение или запись ( STREAM_READ или OPJ_STREAM_WRITE )
unsigned char *pBuffer; // unsigned char *pBuffer; // Указатель на начало буфера
int nLength; // int nLength; // Размер буфера в байтах
unsigned char *pStart; // unsigned char *pStart; // Указатель на начало потока
unsigned char *pEnd; // unsigned char *pEnd; // Указатель на конец потока
unsigned char *pCurPos; // unsigned char *pCurPos; // Указатель не текущую позицию в потоке
} ByteIO; } ByteIO;
......
#pragma once #pragma once
#include "Types.h" #include "Types.h"
#include "JpgEvent.h" #include "JpgEvent.h"
...@@ -11,7 +11,7 @@ namespace Jpeg2000 ...@@ -11,7 +11,7 @@ namespace Jpeg2000
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// // Вспомогательные функции
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
static int BitIO_ByteOut(BitIO *pBIO) static int BitIO_ByteOut(BitIO *pBIO)
{ {
...@@ -61,7 +61,7 @@ namespace Jpeg2000 ...@@ -61,7 +61,7 @@ namespace Jpeg2000
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// // Основные функции
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
BitIO* BitIO_Create() BitIO* BitIO_Create()
{ {
......
#pragma once #pragma once
#include "Stream.h" #include "Stream.h"
...@@ -39,7 +39,7 @@ namespace Jpeg2000 ...@@ -39,7 +39,7 @@ namespace Jpeg2000
anVer[nLevelsCount + 1] = (anVer[nLevelsCount] + 1) / 2; anVer[nLevelsCount + 1] = (anVer[nLevelsCount] + 1) / 2;
pTree->nNodesCount += nCurLevelCount; pTree->nNodesCount += nCurLevelCount;
++nLevelsCount; ++nLevelsCount;
// TO DO: ( nLevelsCount + 1 < 32 ) // TO DO: ѕоставить дополнительную проверку ( nLevelsCount + 1 < 32 )
} while (nCurLevelCount > 1); } while (nCurLevelCount > 1);
// ADD // ADD
......
#pragma once #pragma once
#include "DWT.h" #include "DWT.h"
#include "ArithmeticCoder.h" #include "ArithmeticCoder.h"
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
namespace Jpeg2000 namespace Jpeg2000
{ {
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// // Вспомогательные функции
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
static int Tier1_GetContextIndexZC(Tier1 *pTier1, int nF, int nOrient) static int Tier1_GetContextIndexZC(Tier1 *pTier1, int nF, int nOrient)
...@@ -273,6 +273,7 @@ namespace Jpeg2000 ...@@ -273,6 +273,7 @@ namespace Jpeg2000
{ {
MQCoder *pMQCoder = pTier1->pMQCoder; MQCoder *pMQCoder = pTier1->pMQCoder;
int nFlag = nVSC ? ((*pFlags) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*pFlags); int nFlag = nVSC ? ((*pFlags) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*pFlags);
int nValue = 0;
if (nPartial) if (nPartial)
{ {
goto LABEL_PARTIAL; goto LABEL_PARTIAL;
...@@ -280,7 +281,7 @@ namespace Jpeg2000 ...@@ -280,7 +281,7 @@ namespace Jpeg2000
if (!(*pFlags & (T1_SIG | T1_VISIT))) if (!(*pFlags & (T1_SIG | T1_VISIT)))
{ {
MQC_SetCurContext(pMQCoder, Tier1_GetContextIndexZC(pTier1, nFlag, nOrient)); MQC_SetCurContext(pMQCoder, Tier1_GetContextIndexZC(pTier1, nFlag, nOrient));
int nValue = abs(*pData) & nOne ? 1 : 0; nValue = abs(*pData) & nOne ? 1 : 0;
MQC_Encode(pMQCoder, nValue); MQC_Encode(pMQCoder, nValue);
if (nValue) if (nValue)
{ {
...@@ -295,11 +296,11 @@ namespace Jpeg2000 ...@@ -295,11 +296,11 @@ namespace Jpeg2000
} }
*pFlags &= ~T1_VISIT; *pFlags &= ~T1_VISIT;
} }
static void Tier1_DecoderClnPassStep(Tier1 *pTier1, int *pFlags, int *pData, int nOrient, int nOnePlusHalf, int nPartial, int nVSC) static void Tier1_DecoderClnPassStep(Tier1 *pTier1, int *pFlags, int *pData, int nOrient, int nOnePlusHalf, int nPartial, int nVSC)
{ {
MQCoder *pMQCoder = pTier1->pMQCoder; MQCoder *pMQCoder = pTier1->pMQCoder;
int nFlag = nVSC ? ((*pFlags) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*pFlags); int nFlag = nVSC ? ((*pFlags) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*pFlags);
int nValue = 0;
if (nPartial) if (nPartial)
{ {
goto LABEL_PARTIAL; goto LABEL_PARTIAL;
...@@ -311,7 +312,7 @@ namespace Jpeg2000 ...@@ -311,7 +312,7 @@ namespace Jpeg2000
{ {
LABEL_PARTIAL: LABEL_PARTIAL:
MQC_SetCurContext(pMQCoder, Tier1_GetContextIndexSC(pTier1, nFlag)); MQC_SetCurContext(pMQCoder, Tier1_GetContextIndexSC(pTier1, nFlag));
int nValue = MQC_Decode(pMQCoder) ^ Tier1_GetSPB(pTier1, nFlag); nValue = MQC_Decode(pMQCoder) ^ Tier1_GetSPB(pTier1, nFlag);
*pData = nValue ? -nOnePlusHalf : nOnePlusHalf; *pData = nValue ? -nOnePlusHalf : nOnePlusHalf;
Tier1_UpdateFlags(pFlags, nValue); Tier1_UpdateFlags(pFlags, nValue);
*pFlags |= T1_SIG; *pFlags |= T1_SIG;
...@@ -903,7 +904,7 @@ namespace Jpeg2000 ...@@ -903,7 +904,7 @@ namespace Jpeg2000
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// // Основные функции
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
Tier1* Tier1_Create(PCommon pCodecInfo) Tier1* Tier1_Create(PCommon pCodecInfo)
{ {
...@@ -932,7 +933,7 @@ namespace Jpeg2000 ...@@ -932,7 +933,7 @@ namespace Jpeg2000
return NULL; return NULL;
} }
// // Инициализируем таблицы
Tier1_InitLuts(pTier1); Tier1_InitLuts(pTier1);
} }
return pTier1; return pTier1;
......
#pragma once #pragma once
#include "Reader.h" #include "Reader.h"
#include "PacketIterator.h" #include "PacketIterator.h"
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
namespace Jpeg2000 namespace Jpeg2000
{ {
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// // Вспомогательные функции
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
static void Tier2_PutCommaCode(BitIO *pBIO, int nLen) static void Tier2_PutCommaCode(BitIO *pBIO, int nLen)
{ {
...@@ -83,7 +83,7 @@ namespace Jpeg2000 ...@@ -83,7 +83,7 @@ namespace Jpeg2000
unsigned char *pSOP = (unsigned char *)Malloc(6 * sizeof(unsigned char)); unsigned char *pSOP = (unsigned char *)Malloc(6 * sizeof(unsigned char));
pSOP[0] = 255; // ff pSOP[0] = 255; // ff
pSOP[1] = 145; // 91 pSOP[1] = 145; // 91
pSOP[2] = 0; // 4 pSOP[2] = 0; // Длина всегда 4 байта
pSOP[3] = 4; // pSOP[3] = 4; //
pSOP[4] = (pImageInfo->nPacketCount % 65536) / 256; pSOP[4] = (pImageInfo->nPacketCount % 65536) / 256;
pSOP[5] = (pImageInfo->nPacketCount % 65536) % 256; pSOP[5] = (pImageInfo->nPacketCount % 65536) % 256;
...@@ -148,13 +148,13 @@ namespace Jpeg2000 ...@@ -148,13 +148,13 @@ namespace Jpeg2000
BitIO_Write(pBitStream, pLayer->nPassesCount != 0, 1); BitIO_Write(pBitStream, pLayer->nPassesCount != 0, 1);
} }
// CodeBlock , CodeBlock // Если CodeBlock не включен, тогда переходми к следующему CodeBlock
if (!pLayer->nPassesCount) if (!pLayer->nPassesCount)
{ {
continue; continue;
} }
// CodeBlock --> Zero bit-planes // Если это первое появление CodeBlock --> тогда обрабытываем информацию о Zero bit-planes
if (!pCodeBlock->nPassesCount) if (!pCodeBlock->nPassesCount)
{ {
pCodeBlock->nLenBitsCount = 3; pCodeBlock->nLenBitsCount = 3;
...@@ -319,7 +319,7 @@ namespace Jpeg2000 ...@@ -319,7 +319,7 @@ namespace Jpeg2000
} }
} }
// SOP // SOP маркер
if (pTCP->nCodingStyle & J2K_CP_CSTY_SOP) if (pTCP->nCodingStyle & J2K_CP_CSTY_SOP)
{ {
if ((*pSrcPointer) != 0xff || (*(pSrcPointer + 1) != 0x91)) if ((*pSrcPointer) != 0xff || (*(pSrcPointer + 1) != 0x91))
...@@ -331,10 +331,10 @@ namespace Jpeg2000 ...@@ -331,10 +331,10 @@ namespace Jpeg2000
pSrcPointer += 6; pSrcPointer += 6;
} }
// TO DO : Nsop // TO DO : Добавить проверку значения Nsop
} }
// PPT/PPM, Packet header PPT/PPM. // Когда используются пакеты PPT/PPM, Packet header хранится в маркерах PPT/PPM.
BitIO *pBitStream = BitIO_Create(); BitIO *pBitStream = BitIO_Create();
if (!pBitStream) if (!pBitStream)
...@@ -350,7 +350,7 @@ namespace Jpeg2000 ...@@ -350,7 +350,7 @@ namespace Jpeg2000
pBuffer = pTCP->pPPTData; pBuffer = pTCP->pPPTData;
BitIO_InitDecoder(pBitStream, pBuffer, pTCP->nPPTLength); BitIO_InitDecoder(pBitStream, pBuffer, pTCP->nPPTLength);
} }
else // else // Обычный случай
{ {
pBuffer = pSrcPointer; pBuffer = pSrcPointer;
BitIO_InitDecoder(pBitStream, pBuffer, pSrc + nLen - pBuffer); BitIO_InitDecoder(pBitStream, pBuffer, pSrc + nLen - pBuffer);
...@@ -364,7 +364,7 @@ namespace Jpeg2000 ...@@ -364,7 +364,7 @@ namespace Jpeg2000
pBuffer += BitIO_WrittenBytesCount(pBitStream); pBuffer += BitIO_WrittenBytesCount(pBitStream);
BitIO_Destroy(pBitStream); BitIO_Destroy(pBitStream);
// EPH // EPH маркер
if (pTCP->nCodingStyle & J2K_CP_CSTY_EPH) if (pTCP->nCodingStyle & J2K_CP_CSTY_EPH)
{ {
if ((*pBuffer) != 0xff || (*(pBuffer + 1) != 0x92)) if ((*pBuffer) != 0xff || (*(pBuffer + 1) != 0x92))
...@@ -407,7 +407,7 @@ namespace Jpeg2000 ...@@ -407,7 +407,7 @@ namespace Jpeg2000
CodeBlock *pCodeBlock = &pPrecinct->pCodeBlocks[nCodeBlockIndex]; CodeBlock *pCodeBlock = &pPrecinct->pCodeBlocks[nCodeBlockIndex];
TCDSegment *pSegment = NULL; TCDSegment *pSegment = NULL;
// CodeBlock --> TagTree // Если CodeBlock не был включен ранее --> TagTree
if (!pCodeBlock->nSegmentsCount) if (!pCodeBlock->nSegmentsCount)
{ {
nIncluded = TGT_Decode(pBitStream, pPrecinct->pInclTree, nCodeBlockIndex, nLayerIndex + 1); nIncluded = TGT_Decode(pBitStream, pPrecinct->pInclTree, nCodeBlockIndex, nLayerIndex + 1);
...@@ -423,7 +423,7 @@ namespace Jpeg2000 ...@@ -423,7 +423,7 @@ namespace Jpeg2000
continue; continue;
} }
// CodeBlock --> zero-bitplane tagtree // Если CodeBlock не был включен ранее --> zero-bitplane tagtree
if (!pCodeBlock->nSegmentsCount) if (!pCodeBlock->nSegmentsCount)
{ {
int nIndex; int nIndex;
...@@ -475,7 +475,7 @@ namespace Jpeg2000 ...@@ -475,7 +475,7 @@ namespace Jpeg2000
pBuffer += BitIO_WrittenBytesCount(pBitStream); pBuffer += BitIO_WrittenBytesCount(pBitStream);
BitIO_Destroy(pBitStream); BitIO_Destroy(pBitStream);
// EPH // EPH маркер
if (pTCP->nCodingStyle & J2K_CP_CSTY_EPH) if (pTCP->nCodingStyle & J2K_CP_CSTY_EPH)
{ {
if ((*pBuffer) != 0xff || (*(pBuffer + 1) != 0x92)) if ((*pBuffer) != 0xff || (*(pBuffer + 1) != 0x92))
...@@ -568,7 +568,7 @@ namespace Jpeg2000 ...@@ -568,7 +568,7 @@ namespace Jpeg2000
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// // Основные функции
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
int Tier2_EncodePackets(Tier2 *pTier2, int nTileIndex, Tile *pTile, int nMaxLayers, unsigned char *pDst, int nLen, ImageInfo *pImageInfo) int Tier2_EncodePackets(Tier2 *pTier2, int nTileIndex, Tile *pTile, int nMaxLayers, unsigned char *pDst, int nLen, ImageInfo *pImageInfo)
{ {
...@@ -605,7 +605,7 @@ namespace Jpeg2000 ...@@ -605,7 +605,7 @@ namespace Jpeg2000
pDstPointer += nShift; pDstPointer += nShift;
} }
// // Индексация
if (pImageInfo && pImageInfo->nIndexOn) if (pImageInfo && pImageInfo->nIndexOn)
{ {
if (pImageInfo->nIndexWrite) if (pImageInfo->nIndexWrite)
......
#pragma once #pragma once
#include "DWT.h" #include "DWT.h"
#include "Tier1.h" #include "Tier1.h"
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
namespace Jpeg2000 namespace Jpeg2000
{ {
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// // Основные функции
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
void TCD_Dump(FILE *pFile, TCD *pTCD, TCDImage *pTCDImage) void TCD_Dump(FILE *pFile, TCD *pTCD, TCDImage *pTCDImage)
...@@ -157,13 +157,13 @@ namespace Jpeg2000 ...@@ -157,13 +157,13 @@ namespace Jpeg2000
{ {
TileCodingParams *pTCP = &pCodingParams->pTCP[nCurTileIndex]; TileCodingParams *pTCP = &pCodingParams->pTCP[nCurTileIndex];
// . 59 ISO/IEC FDIS15444-1 // См. стр 59 ISO/IEC FDIS15444-1
int nP = nCurTileIndex % pCodingParams->nXTilesCount; int nP = nCurTileIndex % pCodingParams->nXTilesCount;
int nQ = nCurTileIndex / pCodingParams->nXTilesCount; int nQ = nCurTileIndex / pCodingParams->nXTilesCount;
Tile *pTile = pTCD->pTCDImage->pTiles; Tile *pTile = pTCD->pTCDImage->pTiles;
// ( , ) // Границы тайла (маштабированные относительно размеров изображения, если необходимо)
pTile->nX0 = max(pCodingParams->nXTOsiz + nP * pCodingParams->nXTsiz, pImage->nXOsiz); pTile->nX0 = max(pCodingParams->nXTOsiz + nP * pCodingParams->nXTsiz, pImage->nXOsiz);
pTile->nY0 = max(pCodingParams->nYTOsiz + nQ * pCodingParams->nYTsiz, pImage->nYOsiz); pTile->nY0 = max(pCodingParams->nYTOsiz + nQ * pCodingParams->nYTsiz, pImage->nYOsiz);
pTile->nX1 = min(pCodingParams->nXTOsiz + (nP + 1) * pCodingParams->nXTsiz, pImage->nXsiz); pTile->nX1 = min(pCodingParams->nXTOsiz + (nP + 1) * pCodingParams->nXTsiz, pImage->nXsiz);
...@@ -203,7 +203,7 @@ namespace Jpeg2000 ...@@ -203,7 +203,7 @@ namespace Jpeg2000
TileCompCodingParams *pTCCP = &pTCP->pTCCP[nComponentIndex]; TileCompCodingParams *pTCCP = &pTCP->pTCCP[nComponentIndex];
TileComp *pTileComp = &pTile->pComponents[nComponentIndex]; TileComp *pTileComp = &pTile->pComponents[nComponentIndex];
// - () // Границы каждой тайл-компоненты (глобальные)
pTileComp->nX0 = CeilDiv(pTile->nX0, pImage->pComponents[nComponentIndex].nXRsiz); pTileComp->nX0 = CeilDiv(pTile->nX0, pImage->pComponents[nComponentIndex].nXRsiz);
pTileComp->nY0 = CeilDiv(pTile->nY0, pImage->pComponents[nComponentIndex].nYRsiz); pTileComp->nY0 = CeilDiv(pTile->nY0, pImage->pComponents[nComponentIndex].nYRsiz);
pTileComp->nX1 = CeilDiv(pTile->nX1, pImage->pComponents[nComponentIndex].nXRsiz); pTileComp->nX1 = CeilDiv(pTile->nX1, pImage->pComponents[nComponentIndex].nXRsiz);
...@@ -232,7 +232,7 @@ namespace Jpeg2000 ...@@ -232,7 +232,7 @@ namespace Jpeg2000
Resolution *pResolution = &pTileComp->pResolutions[nResolutionIndex]; Resolution *pResolution = &pTileComp->pResolutions[nResolutionIndex];
// () // Границы для каждого уровня (глобальные)
pResolution->nX0 = CeilDivPow2(pTileComp->nX0, nLevel); pResolution->nX0 = CeilDivPow2(pTileComp->nX0, nLevel);
pResolution->nY0 = CeilDivPow2(pTileComp->nY0, nLevel); pResolution->nY0 = CeilDivPow2(pTileComp->nY0, nLevel);
pResolution->nX1 = CeilDivPow2(pTileComp->nX1, nLevel); pResolution->nX1 = CeilDivPow2(pTileComp->nX1, nLevel);
...@@ -240,7 +240,7 @@ namespace Jpeg2000 ...@@ -240,7 +240,7 @@ namespace Jpeg2000
pResolution->nBandsCount = (nResolutionIndex == 0 ? 1 : 3); pResolution->nBandsCount = (nResolutionIndex == 0 ? 1 : 3);
// . . 35, A-23 ISO/IEC FDIS154444-1 // См. стр. 35, таблица A-23 ISO/IEC FDIS154444-1
int nPPx, nPPy; int nPPx, nPPy;
if (pTCCP->nCodingStyle & J2K_CCP_CSTY_PRT) if (pTCCP->nCodingStyle & J2K_CCP_CSTY_PRT)
{ {
...@@ -253,7 +253,7 @@ namespace Jpeg2000 ...@@ -253,7 +253,7 @@ namespace Jpeg2000
nPPy = 15; nPPy = 15;
} }
// . . 64, Annex-B.6, ISO/IEC FDIS15444-1 // См. стр. 64, Annex-B.6, ISO/IEC FDIS15444-1
int nFloorTRX0 = FloorDivPow2(pResolution->nX0, nPPx) << nPPx; int nFloorTRX0 = FloorDivPow2(pResolution->nX0, nPPx) << nPPx;
int nFloorTRY0 = FloorDivPow2(pResolution->nY0, nPPy) << nPPy; int nFloorTRY0 = FloorDivPow2(pResolution->nY0, nPPy) << nPPy;
int nCeilTRX1 = CeilDivPow2(pResolution->nX1, nPPx) << nPPx; int nCeilTRX1 = CeilDivPow2(pResolution->nX1, nPPx) << nPPx;
...@@ -340,7 +340,7 @@ namespace Jpeg2000 ...@@ -340,7 +340,7 @@ namespace Jpeg2000
Precinct *pPrecinct = &pBand->pPrecincts[nPrecinctIndex]; Precinct *pPrecinct = &pBand->pPrecincts[nPrecinctIndex];
// (Precinct) // Размеры области (Precinct)
pPrecinct->nX0 = max(nGlobalCodeBlockStartX, pBand->nX0); pPrecinct->nX0 = max(nGlobalCodeBlockStartX, pBand->nX0);
pPrecinct->nY0 = max(nGlobalCodeBlockStartY, pBand->nY0); pPrecinct->nY0 = max(nGlobalCodeBlockStartY, pBand->nY0);
pPrecinct->nX1 = min(nGlobalCodeBlockEndX, pBand->nX1); pPrecinct->nX1 = min(nGlobalCodeBlockEndX, pBand->nX1);
...@@ -373,7 +373,7 @@ namespace Jpeg2000 ...@@ -373,7 +373,7 @@ namespace Jpeg2000
CodeBlock *pCodeBlock = &pPrecinct->pCodeBlocks[nCodeBlockIndex]; CodeBlock *pCodeBlock = &pPrecinct->pCodeBlocks[nCodeBlockIndex];
// CodeBlock () // Границы CodeBlock (глобальные)
pCodeBlock->nX0 = max(nCodeBlockStartX, pPrecinct->nX0); pCodeBlock->nX0 = max(nCodeBlockStartX, pPrecinct->nX0);
pCodeBlock->nY0 = max(nCodeBlockStartY, pPrecinct->nY0); pCodeBlock->nY0 = max(nCodeBlockStartY, pPrecinct->nY0);
pCodeBlock->nX1 = min(nCodeBlockEndX, pPrecinct->nX1); pCodeBlock->nX1 = min(nCodeBlockEndX, pPrecinct->nX1);
...@@ -401,13 +401,13 @@ namespace Jpeg2000 ...@@ -401,13 +401,13 @@ namespace Jpeg2000
{ {
TileCodingParams *pTCP = &pCodingParams->pTCP[nCurTileIndex]; TileCodingParams *pTCP = &pCodingParams->pTCP[nCurTileIndex];
// . 59 ISO/IEC FDIS15444-1 // См. стр 59 ISO/IEC FDIS15444-1
int nP = nCurTileIndex % pCodingParams->nXTilesCount; int nP = nCurTileIndex % pCodingParams->nXTilesCount;
int nQ = nCurTileIndex / pCodingParams->nXTilesCount; int nQ = nCurTileIndex / pCodingParams->nXTilesCount;
Tile *pTile = pTCD->pTCDImage->pTiles; Tile *pTile = pTCD->pTCDImage->pTiles;
// ( , ) // Границы тайла (маштабированные относительно размеров изображения, если необходимо)
pTile->nX0 = max(pCodingParams->nXTOsiz + nP * pCodingParams->nXTsiz, pImage->nXOsiz); pTile->nX0 = max(pCodingParams->nXTOsiz + nP * pCodingParams->nXTsiz, pImage->nXOsiz);
pTile->nY0 = max(pCodingParams->nYTOsiz + nQ * pCodingParams->nYTsiz, pImage->nYOsiz); pTile->nY0 = max(pCodingParams->nYTOsiz + nQ * pCodingParams->nYTsiz, pImage->nYOsiz);
pTile->nX1 = min(pCodingParams->nXTOsiz + (nP + 1) * pCodingParams->nXTsiz, pImage->nXsiz); pTile->nX1 = min(pCodingParams->nXTOsiz + (nP + 1) * pCodingParams->nXTsiz, pImage->nXsiz);
...@@ -440,7 +440,7 @@ namespace Jpeg2000 ...@@ -440,7 +440,7 @@ namespace Jpeg2000
TileCompCodingParams *pTCCP = &pTCP->pTCCP[nComponentIndex]; TileCompCodingParams *pTCCP = &pTCP->pTCCP[nComponentIndex];
TileComp *pTileComp = &pTile->pComponents[nComponentIndex]; TileComp *pTileComp = &pTile->pComponents[nComponentIndex];
// - () // Границы каждой тайл-компоненты (глобальные)
pTileComp->nX0 = CeilDiv(pTile->nX0, pImage->pComponents[nComponentIndex].nXRsiz); pTileComp->nX0 = CeilDiv(pTile->nX0, pImage->pComponents[nComponentIndex].nXRsiz);
pTileComp->nY0 = CeilDiv(pTile->nY0, pImage->pComponents[nComponentIndex].nYRsiz); pTileComp->nY0 = CeilDiv(pTile->nY0, pImage->pComponents[nComponentIndex].nYRsiz);
pTileComp->nX1 = CeilDiv(pTile->nX1, pImage->pComponents[nComponentIndex].nXRsiz); pTileComp->nX1 = CeilDiv(pTile->nX1, pImage->pComponents[nComponentIndex].nXRsiz);
...@@ -462,14 +462,14 @@ namespace Jpeg2000 ...@@ -462,14 +462,14 @@ namespace Jpeg2000
Resolution *pResolution = &pTileComp->pResolutions[nResolutionIndex]; Resolution *pResolution = &pTileComp->pResolutions[nResolutionIndex];
// () // Границы для каждого уровня (глобальные)
pResolution->nX0 = CeilDivPow2(pTileComp->nX0, nLevel); pResolution->nX0 = CeilDivPow2(pTileComp->nX0, nLevel);
pResolution->nY0 = CeilDivPow2(pTileComp->nY0, nLevel); pResolution->nY0 = CeilDivPow2(pTileComp->nY0, nLevel);
pResolution->nX1 = CeilDivPow2(pTileComp->nX1, nLevel); pResolution->nX1 = CeilDivPow2(pTileComp->nX1, nLevel);
pResolution->nY1 = CeilDivPow2(pTileComp->nY1, nLevel); pResolution->nY1 = CeilDivPow2(pTileComp->nY1, nLevel);
pResolution->nBandsCount = (nResolutionIndex == 0 ? 1 : 3); pResolution->nBandsCount = (nResolutionIndex == 0 ? 1 : 3);
// . . 35, A-23 ISO/IEC FDIS154444-1 // См. стр. 35, таблица A-23 ISO/IEC FDIS154444-1
int nPPx, nPPy; int nPPx, nPPy;
if (pTCCP->nCodingStyle & J2K_CCP_CSTY_PRT) if (pTCCP->nCodingStyle & J2K_CCP_CSTY_PRT)
{ {
...@@ -482,7 +482,7 @@ namespace Jpeg2000 ...@@ -482,7 +482,7 @@ namespace Jpeg2000
nPPy = 15; nPPy = 15;
} }
// . . 64, Annex-B.6, ISO/IEC FDIS15444-1 // См. стр. 64, Annex-B.6, ISO/IEC FDIS15444-1
int nFloorTRX0 = FloorDivPow2(pResolution->nX0, nPPx) << nPPx; int nFloorTRX0 = FloorDivPow2(pResolution->nX0, nPPx) << nPPx;
int nFloorTRY0 = FloorDivPow2(pResolution->nY0, nPPy) << nPPy; int nFloorTRY0 = FloorDivPow2(pResolution->nY0, nPPy) << nPPy;
int nCeilTRX1 = CeilDivPow2(pResolution->nX1, nPPx) << nPPx; int nCeilTRX1 = CeilDivPow2(pResolution->nX1, nPPx) << nPPx;
...@@ -556,7 +556,7 @@ namespace Jpeg2000 ...@@ -556,7 +556,7 @@ namespace Jpeg2000
Precinct *pPrecinct = &pBand->pPrecincts[nPrecinctIndex]; Precinct *pPrecinct = &pBand->pPrecincts[nPrecinctIndex];
// (Precinct) // Размеры области (Precinct)
pPrecinct->nX0 = max(nGlobalCodeBlockStartX, pBand->nX0); pPrecinct->nX0 = max(nGlobalCodeBlockStartX, pBand->nX0);
pPrecinct->nY0 = max(nGlobalCodeBlockStartY, pBand->nY0); pPrecinct->nY0 = max(nGlobalCodeBlockStartY, pBand->nY0);
pPrecinct->nX1 = min(nGlobalCodeBlockEndX, pBand->nX1); pPrecinct->nX1 = min(nGlobalCodeBlockEndX, pBand->nX1);
...@@ -599,7 +599,7 @@ namespace Jpeg2000 ...@@ -599,7 +599,7 @@ namespace Jpeg2000
CodeBlock *pCodeBlock = &pPrecinct->pCodeBlocks[nCodeBlockIndex]; CodeBlock *pCodeBlock = &pPrecinct->pCodeBlocks[nCodeBlockIndex];
// CodeBlock () // Границы CodeBlock (глобальные)
pCodeBlock->nX0 = max(nCodeBlockStartX, pPrecinct->nX0); pCodeBlock->nX0 = max(nCodeBlockStartX, pPrecinct->nX0);
pCodeBlock->nY0 = max(nCodeBlockStartY, pPrecinct->nY0); pCodeBlock->nY0 = max(nCodeBlockStartY, pPrecinct->nY0);
pCodeBlock->nX1 = min(nCodeBlockEndX, pPrecinct->nX1); pCodeBlock->nX1 = min(nCodeBlockEndX, pPrecinct->nX1);
...@@ -699,12 +699,12 @@ namespace Jpeg2000 ...@@ -699,12 +699,12 @@ namespace Jpeg2000
TileCodingParams *pTCP = &(pCodingParams->pTCP[pCodingParams->pTileIndex[nIndex]]); TileCodingParams *pTCP = &(pCodingParams->pTCP[pCodingParams->pTileIndex[nIndex]]);
Tile *pTile = &(pTCD->pTCDImage->pTiles[pCodingParams->pTileIndex[nIndex]]); Tile *pTile = &(pTCD->pTCDImage->pTiles[pCodingParams->pTileIndex[nIndex]]);
// . 59 ISO/IEC FDIS15444-1 // См. стр 59 ISO/IEC FDIS15444-1
int nTileIndex = pCodingParams->pTileIndex[nIndex]; int nTileIndex = pCodingParams->pTileIndex[nIndex];
int nP = nTileIndex % pCodingParams->nXTilesCount; int nP = nTileIndex % pCodingParams->nXTilesCount;
int nQ = nTileIndex / pCodingParams->nXTilesCount; int nQ = nTileIndex / pCodingParams->nXTilesCount;
// ( , ) // Границы тайла (маштабированные относительно размеров изображения, если необходимо)
pTile->nX0 = max(pCodingParams->nXTOsiz + nP * pCodingParams->nXTsiz, pImage->nXOsiz); pTile->nX0 = max(pCodingParams->nXTOsiz + nP * pCodingParams->nXTsiz, pImage->nXOsiz);
pTile->nY0 = max(pCodingParams->nYTOsiz + nQ * pCodingParams->nYTsiz, pImage->nYOsiz); pTile->nY0 = max(pCodingParams->nYTOsiz + nQ * pCodingParams->nYTsiz, pImage->nYOsiz);
pTile->nX1 = min(pCodingParams->nXTOsiz + (nP + 1) * pCodingParams->nXTsiz, pImage->nXsiz); pTile->nX1 = min(pCodingParams->nXTOsiz + (nP + 1) * pCodingParams->nXTsiz, pImage->nXsiz);
...@@ -724,7 +724,7 @@ namespace Jpeg2000 ...@@ -724,7 +724,7 @@ namespace Jpeg2000
TileCompCodingParams *pTCCP = &pTCP->pTCCP[nComponentIndex]; TileCompCodingParams *pTCCP = &pTCP->pTCCP[nComponentIndex];
TileComp *pTileComp = &pTile->pComponents[nComponentIndex]; TileComp *pTileComp = &pTile->pComponents[nComponentIndex];
// - () // Границы каждой тайл-компоненты (глобальные)
pTileComp->nX0 = CeilDiv(pTile->nX0, pImage->pComponents[nComponentIndex].nXRsiz); pTileComp->nX0 = CeilDiv(pTile->nX0, pImage->pComponents[nComponentIndex].nXRsiz);
pTileComp->nY0 = CeilDiv(pTile->nY0, pImage->pComponents[nComponentIndex].nYRsiz); pTileComp->nY0 = CeilDiv(pTile->nY0, pImage->pComponents[nComponentIndex].nYRsiz);
pTileComp->nX1 = CeilDiv(pTile->nX1, pImage->pComponents[nComponentIndex].nXRsiz); pTileComp->nX1 = CeilDiv(pTile->nX1, pImage->pComponents[nComponentIndex].nXRsiz);
...@@ -753,14 +753,14 @@ namespace Jpeg2000 ...@@ -753,14 +753,14 @@ namespace Jpeg2000
Resolution *pResolution = &pTileComp->pResolutions[nResolutionIndex]; Resolution *pResolution = &pTileComp->pResolutions[nResolutionIndex];
// () // Границы для каждого уровня (глобальные)
pResolution->nX0 = CeilDivPow2(pTileComp->nX0, nLevel); pResolution->nX0 = CeilDivPow2(pTileComp->nX0, nLevel);
pResolution->nY0 = CeilDivPow2(pTileComp->nY0, nLevel); pResolution->nY0 = CeilDivPow2(pTileComp->nY0, nLevel);
pResolution->nX1 = CeilDivPow2(pTileComp->nX1, nLevel); pResolution->nX1 = CeilDivPow2(pTileComp->nX1, nLevel);
pResolution->nY1 = CeilDivPow2(pTileComp->nY1, nLevel); pResolution->nY1 = CeilDivPow2(pTileComp->nY1, nLevel);
pResolution->nBandsCount = (nResolutionIndex == 0 ? 1 : 3); pResolution->nBandsCount = (nResolutionIndex == 0 ? 1 : 3);
// . . 35, A-23 ISO/IEC FDIS154444-1 // См. стр. 35, таблица A-23 ISO/IEC FDIS154444-1
int nPPx, nPPy; int nPPx, nPPy;
if (pTCCP->nCodingStyle & J2K_CCP_CSTY_PRT) if (pTCCP->nCodingStyle & J2K_CCP_CSTY_PRT)
{ {
...@@ -773,7 +773,7 @@ namespace Jpeg2000 ...@@ -773,7 +773,7 @@ namespace Jpeg2000
nPPy = 15; nPPy = 15;
} }
// . . 64, Annex-B.6, ISO/IEC FDIS15444-1 // См. стр. 64, Annex-B.6, ISO/IEC FDIS15444-1
int nFlootTRX0 = FloorDivPow2(pResolution->nX0, nPPx) << nPPx; int nFlootTRX0 = FloorDivPow2(pResolution->nX0, nPPx) << nPPx;
int nFloorTRY0 = FloorDivPow2(pResolution->nY0, nPPy) << nPPy; int nFloorTRY0 = FloorDivPow2(pResolution->nY0, nPPy) << nPPy;
int nCeilTRX1 = CeilDivPow2(pResolution->nX1, nPPx) << nPPx; int nCeilTRX1 = CeilDivPow2(pResolution->nX1, nPPx) << nPPx;
...@@ -853,7 +853,7 @@ namespace Jpeg2000 ...@@ -853,7 +853,7 @@ namespace Jpeg2000
int nGlobalCodeBlockEndY = nGlobalCodeBlockStartY + (1 << nCBHeightExpn); int nGlobalCodeBlockEndY = nGlobalCodeBlockStartY + (1 << nCBHeightExpn);
Precinct *pPrecinct = &pBand->pPrecincts[nPrecinctIndex]; Precinct *pPrecinct = &pBand->pPrecincts[nPrecinctIndex];
// (Precinct) // Размеры области (Precinct)
pPrecinct->nX0 = max(nGlobalCodeBlockStartX, pBand->nX0); pPrecinct->nX0 = max(nGlobalCodeBlockStartX, pBand->nX0);
pPrecinct->nY0 = max(nGlobalCodeBlockStartY, pBand->nY0); pPrecinct->nY0 = max(nGlobalCodeBlockStartY, pBand->nY0);
pPrecinct->nX1 = min(nGlobalCodeBlockEndX, pBand->nX1); pPrecinct->nX1 = min(nGlobalCodeBlockEndX, pBand->nX1);
...@@ -884,7 +884,7 @@ namespace Jpeg2000 ...@@ -884,7 +884,7 @@ namespace Jpeg2000
int nCodeBlockEndX = nCodeBlockStartX + (1 << nXCBa); int nCodeBlockEndX = nCodeBlockStartX + (1 << nXCBa);
int nCodeBlockEndY = nCodeBlockStartY + (1 << nYCBa); int nCodeBlockEndY = nCodeBlockStartY + (1 << nYCBa);
// CodeBlock () // Границы CodeBlock (глобальные)
CodeBlock *pCodeBlock = &pPrecinct->pCodeBlocks[nCodeBlockIndex]; CodeBlock *pCodeBlock = &pPrecinct->pCodeBlocks[nCodeBlockIndex];
pCodeBlock->nX0 = max(nCodeBlockStartX, pPrecinct->nX0); pCodeBlock->nX0 = max(nCodeBlockStartX, pPrecinct->nX0);
pCodeBlock->nY0 = max(nCodeBlockStartY, pPrecinct->nY0); pCodeBlock->nY0 = max(nCodeBlockStartY, pPrecinct->nY0);
...@@ -907,7 +907,7 @@ namespace Jpeg2000 ...@@ -907,7 +907,7 @@ namespace Jpeg2000
// } // }
//#endif //#endif
// ( = ). // Выделяем место для хранения закодированных данных ( = окончательное изображение ).
unsigned int nX0 = 0, nY0 = 0, nX1 = 0, nY1 = 0, nWidth, nHeight; unsigned int nX0 = 0, nY0 = 0, nX1 = 0, nY1 = 0, nWidth, nHeight;
...@@ -981,7 +981,7 @@ namespace Jpeg2000 ...@@ -981,7 +981,7 @@ namespace Jpeg2000
CodeBlock *pCodeBlock = &pPrecinct->pCodeBlocks[nCodeBlockIndex]; CodeBlock *pCodeBlock = &pPrecinct->pCodeBlocks[nCodeBlockIndex];
Layer *pLayer = &pCodeBlock->aLayers[nLayerIndex]; Layer *pLayer = &pCodeBlock->aLayers[nLayerIndex];
int nIMSB = pTCD->pImage->pComponents[nComponentIndex].nPrecision - pCodeBlock->nBPSCount; // bit-plan 0 int nIMSB = pTCD->pImage->pComponents[nComponentIndex].nPrecision - pCodeBlock->nBPSCount; // Количество bit-plan равных 0
if (0 == nLayerIndex) if (0 == nLayerIndex)
{ {
...@@ -1245,7 +1245,7 @@ namespace Jpeg2000 ...@@ -1245,7 +1245,7 @@ namespace Jpeg2000
int nSuccess = 0; int nSuccess = 0;
// TO DO: nMaxLen // TO DO: Убрать nMaxLen
int nMaxLen = pTCP->afRates[nLayerIndex] ? min(((int)ceil(pTCP->afRates[nLayerIndex])), nLen) : nLen; int nMaxLen = pTCP->afRates[nLayerIndex] ? min(((int)ceil(pTCP->afRates[nLayerIndex])), nLen) : nLen;
double dGoodThreshold = 0; double dGoodThreshold = 0;
double dDistoTarget = pTile->dDistoTile - ((c_dK * dMaxSE) / pow((float)10, pTCP->afDistoRatio[nLayerIndex] / 10)); double dDistoTarget = pTile->dDistoTile - ((c_dK * dMaxSE) / pow((float)10, pTCP->afDistoRatio[nLayerIndex] / 10));
...@@ -1347,7 +1347,7 @@ namespace Jpeg2000 ...@@ -1347,7 +1347,7 @@ namespace Jpeg2000
// << INDEX // << INDEX
//---------------TILE-DATA-------------- //---------------TILE-DATA--------------
double dEncodingTime = Clock(); // double dEncodingTime = Clock(); // Засекаем сколько потребовалось времени для кодирования тайла
for (int nComponentIndex = 0; nComponentIndex < pTile->nComponentsCount; nComponentIndex++) for (int nComponentIndex = 0; nComponentIndex < pTile->nComponentsCount; nComponentIndex++)
{ {
...@@ -1359,15 +1359,15 @@ namespace Jpeg2000 ...@@ -1359,15 +1359,15 @@ namespace Jpeg2000
int nTileWidth = pTileComp->nX1 - pTileComp->nX0; int nTileWidth = pTileComp->nX1 - pTileComp->nX0;
int nWidth = CeilDiv(pImage->nXsiz - pImage->nXOsiz, pImage->pComponents[nComponentIndex].nXRsiz); int nWidth = CeilDiv(pImage->nXsiz - pImage->nXOsiz, pImage->pComponents[nComponentIndex].nXRsiz);
// // Извлекаем данные тайла
if (pTCD_TCP->pTCCP[nComponentIndex].nTransformID == 1) if (pTCD_TCP->pTCCP[nComponentIndex].nTransformID == 1)
{ {
for (int nY = pTileComp->nY0; nY < pTileComp->nY1; nY++) for (int nY = pTileComp->nY0; nY < pTileComp->nY1; nY++)
{ {
// // Иходные данные
int *pData = &pImage->pComponents[nComponentIndex].pData[(pTileComp->nX0 - nOffsetX) + (nY - nOffsety) * nWidth]; int *pData = &pImage->pComponents[nComponentIndex].pData[(pTileComp->nX0 - nOffsetX) + (nY - nOffsety) * nWidth];
// // Результат
int *pTileData = &pTileComp->pData[(nY - pTileComp->nY0) * nTileWidth]; int *pTileData = &pTileComp->pData[(nY - pTileComp->nY0) * nTileWidth];
for (int nX = pTileComp->nX0; nX < pTileComp->nX1; nX++) for (int nX = pTileComp->nX0; nX < pTileComp->nX1; nX++)
{ {
...@@ -1379,9 +1379,9 @@ namespace Jpeg2000 ...@@ -1379,9 +1379,9 @@ namespace Jpeg2000
{ {
for (int nY = pTileComp->nY0; nY < pTileComp->nY1; nY++) for (int nY = pTileComp->nY0; nY < pTileComp->nY1; nY++)
{ {
// // Иходные данные
int *pData = &pImage->pComponents[nComponentIndex].pData[(pTileComp->nX0 - nOffsetX) + (nY - nOffsety) * nWidth]; int *pData = &pImage->pComponents[nComponentIndex].pData[(pTileComp->nX0 - nOffsetX) + (nY - nOffsety) * nWidth];
// // Результат
int *pTileData = &pTileComp->pData[(nY - pTileComp->nY0) * nTileWidth]; int *pTileData = &pTileComp->pData[(nY - pTileComp->nY0) * nTileWidth];
for (int nX = pTileComp->nX0; nX < pTileComp->nX1; nX++) for (int nX = pTileComp->nX0; nX < pTileComp->nX1; nX++)
{ {
...@@ -1460,7 +1460,7 @@ namespace Jpeg2000 ...@@ -1460,7 +1460,7 @@ namespace Jpeg2000
Event_Message(EVT_INFO, "- tile encoded in %f s\n", dEncodingTime); Event_Message(EVT_INFO, "- tile encoded in %f s\n", dEncodingTime);
// // Освобождаем память
for (int nComponentIndex = 0; nComponentIndex < pTile->nComponentsCount; nComponentIndex++) for (int nComponentIndex = 0; nComponentIndex < pTile->nComponentsCount; nComponentIndex++)
{ {
TileComp *pTileComp = &pTile->pComponents[nComponentIndex]; TileComp *pTileComp = &pTile->pComponents[nComponentIndex];
...@@ -1479,7 +1479,7 @@ namespace Jpeg2000 ...@@ -1479,7 +1479,7 @@ namespace Jpeg2000
pTCD->pTCP = &(pTCD->pCodingParams->pTCP[nTileIndex]); pTCD->pTCP = &(pTCD->pCodingParams->pTCP[nTileIndex]);
Tile *pTile = pTCD->pTCDTile; Tile *pTile = pTCD->pTCDTile;
double dDecodeTime = Clock(); // , double dDecodeTime = Clock(); // Время, затраченное на декодирование тайла
Event_Message(EVT_INFO, "tile %d of %d\n", nTileIndex + 1, pTCD->pCodingParams->nXTilesCount * pTCD->pCodingParams->nYTilesCount); Event_Message(EVT_INFO, "tile %d of %d\n", nTileIndex + 1, pTCD->pCodingParams->nXTilesCount * pTCD->pCodingParams->nYTilesCount);
//--------------TIER2--------------------- //--------------TIER2---------------------
......
#pragma once #pragma once
#include "Reader.h" #include "Reader.h"
#include "../../graphics/Defines.h" #include "../../graphics/Defines.h"
#ifndef max
#define max(a,b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif
namespace Jpeg2000 namespace Jpeg2000
{ {
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// Constant definitions // Constant definitions
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
#define MAX_PATH_LEN 4096 // #define MAX_PATH_LEN 4096 // Максимальная длина для имен файлов
#define J2K_MAXRLVLS 33 // #define J2K_MAXRLVLS 33 // Максимальное число уровней разложения
#define J2K_MAXBANDS (3 * J2K_MAXRLVLS - 2) // , #define J2K_MAXBANDS (3 * J2K_MAXRLVLS - 2) // Максимальное число обастей, связанных с уровнями разложения
#define J2K_MAXSSFTR 2 // Max SubSampling Factor ( 2 ) #define J2K_MAXSSFTR 2 // Max SubSampling Factor (Значения больше 2 могут привести к ошибке)
void* Malloc(size_t nSize); void* Malloc(size_t nSize);
void Free(void* pMem); void Free(void* pMem);
...@@ -24,7 +32,7 @@ namespace Jpeg2000 ...@@ -24,7 +32,7 @@ namespace Jpeg2000
// Progression order // Progression order
typedef enum EProgressionOrder typedef enum EProgressionOrder
{ {
poUnknown = -1, // poUnknown = -1, // Неизвестный порядок
poLRCP = 0, // layer-resolution-component-precinct poLRCP = 0, // layer-resolution-component-precinct
poRLCP = 1, // resolution-layer-component-precinct poRLCP = 1, // resolution-layer-component-precinct
poRPCL = 2, // resolution-precinct-component-layer poRPCL = 2, // resolution-precinct-component-layer
...@@ -32,48 +40,48 @@ namespace Jpeg2000 ...@@ -32,48 +40,48 @@ namespace Jpeg2000
poCPRL = 4 // component-precinct-resolution-layer poCPRL = 4 // component-precinct-resolution-layer
} ProgressionOrder; } ProgressionOrder;
// // Поддерживаемые цветовые пространства
typedef enum EColorSpace typedef enum EColorSpace
{ {
csUnknown = -1, // csUnknown = -1, // цветовое пространство неопределенно
csRGB = 1, // sRGB csRGB = 1, // sRGB
csGray = 2, // Grayscale csGray = 2, // Grayscale
csYUV = 3 // YUV csYUV = 3 // YUV
} ColorSpace; } ColorSpace;
// // Поддерживаемые форматы
typedef enum ECodecFormat typedef enum ECodecFormat
{ {
codecUnknown = -1, // codecUnknown = -1, // неизвестный кодек
codecJ2K = 0, // JPEG-2000 codestream : / codecJ2K = 0, // JPEG-2000 codestream : чтение/запись
codecJPT = 1, // JPT-stream (JPEG 2000, JPIP) : codecJPT = 1, // JPT-stream (JPEG 2000, JPIP) : только чтение
codecJP2 = 2, // JPEG-2000 file format (Jp2-wrapper) : / codecJP2 = 2, // JPEG-2000 file format (Jp2-wrapper) : чтение/запись
codecMj2 = 3, // Motion JPEG-2000 codecMj2 = 3, // Motion JPEG-2000
} CodecFormat; } CodecFormat;
// Jpeg2000-Codestream // Ограничения по декодированию Jpeg2000-Codestream
typedef enum ELimitDecoding typedef enum ELimitDecoding
{ {
declimNoLimitation = 0, // . Jpeg2000-codestream declimNoLimitation = 0, // Нет ограничений при декодировании. Декодируем Jpeg2000-codestream полностью
declimLimitToMainHeader = 1 // Main Header declimLimitToMainHeader = 1 // Декодируем только Main Header
} LimitDecoding; } LimitDecoding;
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// Event ( ) // Event (Обработка сообщений)
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
#define EVT_ERROR 1 // Error #define EVT_ERROR 1 // Error
#define EVT_WARNING 2 // Warning #define EVT_WARNING 2 // Warning
#define EVT_INFO 4 // Debug event #define EVT_INFO 4 // Debug event
#define MSG_SIZE 512 // #define MSG_SIZE 512 // Максимальный размер сообщения
#define JP2_ERROR_NO_ERROR 0x0000 #define JP2_ERROR_NO_ERROR 0x0000
#define JP2_ERROR_NOT_ENOUGH_MEMORY 0x0001 #define JP2_ERROR_NOT_ENOUGH_MEMORY 0x0001
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// (/) // Параметры кодека (компрессии/декомпрессии)
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// Progression order changes (POC) (Annex A.6.6 Table A-32) // Progression order changes (POC) (Annex A.6.6 Table A-32)
...@@ -89,10 +97,10 @@ namespace Jpeg2000 ...@@ -89,10 +97,10 @@ namespace Jpeg2000
char sProgOrder[4]; char sProgOrder[4];
} POC; } POC;
// // Параметры компрессии
typedef struct TEncoderParams typedef struct TEncoderParams
{ {
bool bTileSizeOn; // False: , true: bool bTileSizeOn; // False: размеры тайлов не указаны, true: размеры тайлов указаны
int nXTOsiz; // XTOsiz int nXTOsiz; // XTOsiz
int nYTOsiz; // YTOsiz int nYTOsiz; // YTOsiz
int nXTsiz; // XTsiz int nXTsiz; // XTsiz
...@@ -101,64 +109,64 @@ namespace Jpeg2000 ...@@ -101,64 +109,64 @@ namespace Jpeg2000
int nFixedAlloc; // allocation by fixed layer int nFixedAlloc; // allocation by fixed layer
int nFixedQuality; // fixed_quality int nFixedQuality; // fixed_quality
int *pMatrix; // fixed layer int *pMatrix; // fixed layer
char *sComment; // char *sComment; // Комментарий
int nCodingStyle; // CodingStyle int nCodingStyle; // CodingStyle
ProgressionOrder eProgOrder; // Progression order (default LRCP) ProgressionOrder eProgOrder; // Progression order (default LRCP)
POC aoPOC[32]; // Progression order changes POC aoPOC[32]; // Progression order changes
int nPOCsCount; // progression order changes (POC), default to 0 int nPOCsCount; // Количество progression order changes (POC), default to 0
int nLayersCount; // int nLayersCount; // Количество лэйеров
float afRates[100]; // float afRates[100]; // Массив норм
float afDistoratio[100]; // float afDistoratio[100]; // Массив искажений
int nResolutionsCount; // ( ) int nResolutionsCount; // Число разрешений(уровней разложения)
int nCodeBlockWidthInit; // ( 64) int nCodeBlockWidthInit; // Исходная ширина блока (по стандарту 64)
int nCodeBlockHeightInit; // ( 64) int nCodeBlockHeightInit; // Исходная высота блока (по стандарту 64)
int nCodeBlockStyle; // CodeBlockStyle int nCodeBlockStyle; // CodeBlockStyle
int nTransformId; // 1: ( Irreversible DTW ), 0: ( ) int nTransformId; // 1: необратимое вэйвлет преобразование ( Irreversible DTW ), 0: компрессия без потерь (по стандарту)
int nROIComponentIndex; // Region of interest: [0..3], -1 , ROI int nROIComponentIndex; // Region of interest: затрагиваемые компоненты [0..3], -1 означает, что ROI отсутствует
int nROIShift; // Region of interest: shift int nROIShift; // Region of interest: shift
int nPrecinctCount; // int nPrecinctCount; // Количество областей
int anPrecinctWidthInit[J2K_MAXRLVLS]; // int anPrecinctWidthInit[J2K_MAXRLVLS]; // Исходные ширины областей
int anPrecinctHeightInit[J2K_MAXRLVLS]; // int anPrecinctHeightInit[J2K_MAXRLVLS]; // Исходные высоты областей
int nComponentsCount; // int nComponentsCount; // Количество компонент в исходном файле
char sInFile[MAX_PATH_LEN]; // char sInFile[MAX_PATH_LEN]; // Имя исходного файла
char sOutfile[MAX_PATH_LEN]; // char sOutfile[MAX_PATH_LEN]; // Имя результируещего файла
int nIndexOn; // ( 0) int nIndexOn; // Создаем ли файл с индексайией (по стандарту 0)
char sIndex[MAX_PATH_LEN]; // char sIndex[MAX_PATH_LEN]; // Файл индексации
int nImageOffsetX0; // int nImageOffsetX0; // Сдиг исходной картинки по Х
int nImageOffsetY0; // Y int nImageOffsetY0; // Сдиг исходной картинки по Y
int nSubSamplingDx; // SubSampling X int nSubSamplingDx; // SubSampling X
int nSubSamplingDy; // SubSampling Y int nSubSamplingDy; // SubSampling Y
int nDecoderFormat; // . 0: PGX, 1: PxM, 2: BMP int nDecoderFormat; // Формат исходного файла. 0: PGX, 1: PxM, 2: BMP
int nEncoderFormat; // . 0: J2K, 1: JP2, 2: JPT int nEncoderFormat; // Формат выходного файла. 0: J2K, 1: JP2, 2: JPT
} EncoderParams; } EncoderParams;
// // Параметры декомпрессии
typedef struct TDecoderParams typedef struct TDecoderParams
{ {
int nReduce; // != 0, 2^(nReduce). == 0, , . int nReduce; // Если != 0, тогда разрешение исходного изображения делится на 2^(nReduce). Если == 0, или не используется, тогда изображение декодируется с полным разрешением.
int nLayer; // , . int nLayer; // Устанавливаем максимальное число лэеров, которые мы будем декодировать.
LimitDecoding eLimitDecoding; // , . LimitDecoding eLimitDecoding; // Будем декодировать полностью файл, или только заголовок.
char sInFile[MAX_PATH_LEN]; // char sInFile[MAX_PATH_LEN]; // Имя исходного файла
char sOutfile[MAX_PATH_LEN]; // char sOutfile[MAX_PATH_LEN]; // Имя результируещего файла
int nDecoderFormat; // . 0: J2k, 1: Jp2, 2: Jpt int nDecoderFormat; // Формат исходного файла. 0: J2k, 1: Jp2, 2: Jpt
int nEncoderFormat; // . 0: PGX, 1: PxM, 2: BMP int nEncoderFormat; // Формат выходного файла. 0: PGX, 1: PxM, 2: BMP
} DecoderParams; } DecoderParams;
// JPEG-2000 // Общие поля для JPEG-2000 компрессии и декомпресии
//EventManager *pEventManager; /* (events) */\ //EventManager *pEventManager; /* Указатель на обработчик сообщений (events) */\
//void *pClientData; /* */\ //void *pClientData; /* */\
#define CommonFields \ #define CommonFields \
bool bIsDecompressor; /* */\ bool bIsDecompressor; /* Чтобы узнать компрессия или декомпрессия */\
ECodecFormat eCodecFormat; /* */\ ECodecFormat eCodecFormat; /* Выбранный кодек */\
void *pJ2k; /* J2K */\ void *pJ2k; /* Указатель на J2K кодек */\
void *pJp2; /* JP2 */\ void *pJp2; /* Указатель на JP2 кодек */\
void *pMj2; /* JP2 */\ void *pMj2; /* Указатель на JP2 кодек */\
int nErrorCode /* */ int nErrorCode /* Номер ошибки */
// , , // Поля, которые исользуются как для чтения, так и для записи
typedef struct TCommonStruct typedef struct TCommonStruct
{ {
CommonFields; CommonFields;
...@@ -166,18 +174,18 @@ namespace Jpeg2000 ...@@ -166,18 +174,18 @@ namespace Jpeg2000
typedef CommonStruct* PCommon; typedef CommonStruct* PCommon;
// // Параметры компрессии
typedef struct TCInfo typedef struct TCInfo
{ {
CommonFields; // CommonFields; // Общие поля
// // Поля характерные только для компрессии
} CInfo; } CInfo;
// // Параметры декомпрессии
typedef struct TDInfo typedef struct TDInfo
{ {
CommonFields; // CommonFields; // Общие поля
// // Поля характерные только для декомпрессии
} DInfo; } DInfo;
...@@ -187,39 +195,39 @@ namespace Jpeg2000 ...@@ -187,39 +195,39 @@ namespace Jpeg2000
typedef struct TImageComponent typedef struct TImageComponent
{ {
int nXRsiz; // XRsiz: i- int nXRsiz; // XRsiz: горизонтальное разделение i-ой компоненты
int nYRsiz; // YRsiz: i- int nYRsiz; // YRsiz: вертикальное разделение i-ой компоненты
int nWidth; // int nWidth; // Ширина картинки
int nHeight; // int nHeight; // Высота картинки
int nXOsiz; // int nXOsiz; // Сдвиг компоненты по Х по отношению ко всему изображению
int nYOsiz; // int nYOsiz; // Сдвиг компоненты по У по отношению ко всему изображению
int nPrecision; // Precision int nPrecision; // Precision
int nBPP; // Bits Per Pixel int nBPP; // Bits Per Pixel
int nSigned; // Signed - 1, unsigned - 0 int nSigned; // Signed - 1, unsigned - 0
int nDecodedResCount; // Resolutions int nDecodedResCount; // Количество Resolutions в кодированном изображении
int nFactorDiv2; // 2 , int nFactorDiv2; // Количество делений на 2 результирующей картинки, по сравнению с размером исходной
int *pData; // i- int *pData; // Данные изображения для i-ой компоненты
} ImageComponent; } ImageComponent;
typedef struct TImage typedef struct TImage
{ {
int nXOsiz; // XOsiz: c int nXOsiz; // XOsiz: горизонтальный cдвиг от начальной точки всей сетки к области с реальным изображением
int nYOsiz; // YOsiz: int nYOsiz; // YOsiz: вертикальный сдвиг от начальной точки всей сетки к области с реальным изображением
int nXsiz; // Xsiz: int nXsiz; // Xsiz: ширина сетки
int nYsiz; // Ysiz: int nYsiz; // Ysiz: высота сетки
int nCsiz; // Csiz: int nCsiz; // Csiz: количество компонент в изображении
ColorSpace eColorSpace; // : sRGB, Greyscale YUV ColorSpace eColorSpace; // Цветовое пространство: sRGB, Greyscale или YUV
ImageComponent *pComponents; // ImageComponent *pComponents; // Компоненты изображения
} Image; } Image;
typedef struct TImageComponentParams typedef struct TImageComponentParams
{ {
int nXRsiz; // XRsiz: i- int nXRsiz; // XRsiz: горизонтальное разделение i-ой компоненты
int nYRsiz; // YRsiz: i- int nYRsiz; // YRsiz: вертикальное разделение i-ой компоненты
int nWidth; // int nWidth; // Ширина
int nHeight; // int nHeight; // Высота картинки
int nXoffset; // int nXoffset; // Сдвиг компоненты по Х по отношению ко всему изображению
int nYoffset; // int nYoffset; // Сдвиг компоненты по У по отношению ко всему изображению
int nPrecision; // Precision int nPrecision; // Precision
int nBPP; // Bits Per Pixel int nBPP; // Bits Per Pixel
int nSigned; // Signed - 1, unsigned - 0 int nSigned; // Signed - 1, unsigned - 0
...@@ -301,21 +309,21 @@ namespace Jpeg2000 ...@@ -301,21 +309,21 @@ namespace Jpeg2000
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// ( Main Header) // Значения определяющие статус декодирования(когда декодируется Main Header)
typedef enum EJ2kStatus typedef enum EJ2kStatus
{ {
j2kstateMHSOC = 0x0001, // SOC j2kstateMHSOC = 0x0001, // SOC маркер
j2kstateMHSIZ = 0x0002, // SIZ j2kstateMHSIZ = 0x0002, // SIZ маркер
j2kstateMH = 0x0004, // Main Header j2kstateMH = 0x0004, // Процесс декодирования находится в Main Header
j2kstateTPHSOT = 0x0008, // Tile Part Header, SOT j2kstateTPHSOT = 0x0008, // Процесс декодирования находится в Tile Part Header, и сейчас читается маркер SOT
j2kstateTPH = 0x0010, // Tile Part Header j2kstateTPH = 0x0010, // Процесс декодирования находится в Tile Part Header
j2kstateMT = 0x0020, // EOC j2kstateMT = 0x0020, // Только что был прочитан маркер EOC
j2kstateNEOC = 0x0040 // EOC, odestream j2kstateNEOC = 0x0040 // При декодировании не воспринимаем маркер EOC, потому что Сodestream сокращенный
} J2kStatus; } J2kStatus;
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// // Размер шага квантования
typedef struct TQuantStepSize typedef struct TQuantStepSize
{ {
int nExponent; int nExponent;
...@@ -330,34 +338,34 @@ namespace Jpeg2000 ...@@ -330,34 +338,34 @@ namespace Jpeg2000
int nCodeBlockWidth; // Code-block size width int nCodeBlockWidth; // Code-block size width
int nCodeBlockHeight; // Code-block size height int nCodeBlockHeight; // Code-block size height
int nCodeBlockStyle; // Code-block context int nCodeBlockStyle; // Code-block context
int nTransformID; // Wavelet- int nTransformID; // Wavelet-преобразвание
int nQuantStyle; // int nQuantStyle; // Тип квантования
QuantStepSize aoStepSizes[J2K_MAXBANDS]; // , QuantStepSize aoStepSizes[J2K_MAXBANDS]; // Размер шага, используемый для квантования
int nGuardBitsCount; // Number of guard bits int nGuardBitsCount; // Number of guard bits
int nROIShift; // SPrgn: Region Of Interest shift (Table A-25) int nROIShift; // SPrgn: Region Of Interest shift (Table A-25)
int anPrecinctWidth[J2K_MAXRLVLS]; // Precinct width int anPrecinctWidth[J2K_MAXRLVLS]; // Precinct width
int anPrecinctHeight[J2K_MAXRLVLS]; // Precinct height int anPrecinctHeight[J2K_MAXRLVLS]; // Precinct height
} TileCompCodingParams; } TileCompCodingParams;
// Tile coding parameters : / // Tile coding parameters : данная структура используется для хранения параметров кодирования/декодирования одинаковых для всех
// (tiles) ( COD, COC Main Header ) // ячеек(tiles) ( подобно информации COD, COC в Main Header )
typedef struct TTileCodingParams typedef struct TTileCodingParams
{ {
int nFirst; // . 1 : part-tile tile int nFirst; // Флаг. 1 : первый part-tile данного tile
int nCodingStyle; // Scod: Coding style (Table A-12) int nCodingStyle; // Scod: Coding style (Table A-12)
ProgressionOrder eProgOrder; // SPcod, Ppod: Progression order ProgressionOrder eProgOrder; // SPcod, Ppod: Progression order
int nLayersCount; // SPcod: Number of layers int nLayersCount; // SPcod: Number of layers
int nMCT; // SPcod: Multiple component transform int nMCT; // SPcod: Multiple component transform
float afRates[100]; // layers float afRates[100]; // Размеры layers
int nPOCsCount; // POC ( progression order changes ) int nPOCsCount; // Количество POC ( progression order changes )
int nUsePOC; // ; POC. 0 - , 1 - . int nUsePOC; // Флаг; используем ли маркер POC. 0 - нет, 1 - да.
POC aoPOC[32]; // Progression order changes POC aoPOC[32]; // Progression order changes
unsigned char *pPPTData; // Packet header, Tire2 unsigned char *pPPTData; // Храним указатель на Packet header, чтобы испольщовать его в Tire2 декодировании
unsigned char *pPPTDataFirst; // PacketHeader, PPT unsigned char *pPPTDataFirst; // Указатель на начало первого пакета в PacketHeader, если PPT используется
int nPPT; // . Tile PPT, 1. int nPPT; // Флаг. Если для текущего Tile нашли маркер PPT, тогда флаг равен 1.
int nPPTStore; // , PPT ( ) int nPPTStore; // Используем, если нашли несколько маркеров PPT (храним их общую длину в байтах здесь)
int nPPTLength; // PPM bug 1 int nPPTLength; // PPM bug 1
float afDistoRatio[100]; // Fixed quality float afDistoRatio[100]; // Добавляем Fixed quality
TileCompCodingParams *pTCCP; // Tile-component coding parameters TileCompCodingParams *pTCCP; // Tile-component coding parameters
} TileCodingParams; } TileCodingParams;
...@@ -366,94 +374,94 @@ namespace Jpeg2000 ...@@ -366,94 +374,94 @@ namespace Jpeg2000
{ {
int nDistoAlloc; // allocation by rate/distortion int nDistoAlloc; // allocation by rate/distortion
int nFixedAlloc; // allocation by fixed layer int nFixedAlloc; // allocation by fixed layer
int nFixedQuality; // Fixed quality int nFixedQuality; // Добавляем Fixed quality
int nReduceFactor; // 0, 2^(nReduceFactor); 0, , int nReduceFactor; // Если данное значение отлично от 0, тогда исходное разрешение делим на 2^(nReduceFactor); если равно 0, или не используется, декодируем изображение с полным разрешением
int nLayerFactor; // 0, "layer"; 0, , "layers" int nLayerFactor; // Если данное значение отлично от 0, тогда декодируем только первый "layer"; если равно 0, или не используется, декодируем все "layers"
LimitDecoding eLimitDecoding; // . LimitDecoding eLimitDecoding; // Ограничения на декодирование.
int nIndexOn; // 0 - , 1 - . int nIndexOn; // 0 - нет нумерации, 1 - есть.
int nXTOsiz; // XTOsiz: Tile int nXTOsiz; // XTOsiz: свдиг по горизонтали первого Tile
int nYTOsiz; // YTOsiz: Tile int nYTOsiz; // YTOsiz: сдвиг по вертикали первого Tile
int nXTsiz; // XTsiz: Tile int nXTsiz; // XTsiz: ширина одного Tile по отношению к общей сетке
int nYTsiz; // YTsiz: Tile int nYTsiz; // YTsiz: высота одного Tile по отношению к общей сетке
char *sComment; // char *sComment; // Комментарий
int nXTilesCount; // Tiles int nXTilesCount; // Количество Tiles по горизонтали
int nYTilesCount; // Tiles int nYTilesCount; // Количество Tiles по вертикали
int *pTileIndex; // Tiles codestream int *pTileIndex; // Порядковые номера Tiles в codestream
int nTileIndexSize; // pTileIndex int nTileIndexSize; // Размер массива pTileIndex
unsigned char *pPPMData; // Packet header, Tire2 unsigned char *pPPMData; // Храним указатель на Packet header, чтобы испольщовать его в Tire2 декодировании
unsigned char *pPPMDataFirst; // PacketHeader, PPM unsigned char *pPPMDataFirst; // Указатель на начало первого пакета в PacketHeader, если PPM используется
int nPPM; // . Tile PPM, 1. int nPPM; // Флаг. Если для текущего Tile нашли маркер PPM, тогда флаг равен 1.
int nPPMStore; // , PPM ( ) int nPPMStore; // Используем, если нашли несколько маркеров PPM (храним их общую длину в байтах здесь)
int nPPMPrevious; // , PPM (, PPM ) int nPPMPrevious; // Используем, если нашли несколько маркеров PPM (случай, если предыдущий маркер PPM был еще не закончен)
int nPPMLength; // PPM bug 1 int nPPMLength; // PPM bug 1
TileCodingParams *pTCP; // Tile coding parameters TileCodingParams *pTCP; // Tile coding parameters
int *pMatrix; // Fixed layer int *pMatrix; // Fixed layer
} CodingParams; } CodingParams;
// Tile // Информация относительно пакета в Tile
typedef struct TPacketInfo typedef struct TPacketInfo
{ {
int nStartPos; // int nStartPos; // Начальная позиция
int nEndPos; // int nEndPos; // Конечная позиция
double dDisto; double dDisto;
} PacketInfo; } PacketInfo;
// , Tiles // Информация, относящаяся к Tiles внутри изображения
typedef struct TTileInfo typedef struct TTileInfo
{ {
double *pdThreshold; // layer double *pdThreshold; // Значение порога для каждого layer
int nTileCount; // Tiles int nTileCount; // Общее количество Tiles
int nStartPos; // int nStartPos; // Начальная позиция
int nEndHeader; // int nEndHeader; // Конечная позиция для заголовка
int nEndPos; // int nEndPos; // Конечная позиция
int anXPrecinctCount[33]; // (precinct) (resolution level) int anXPrecinctCount[33]; // Количество областей (precinct) по Х для каждого уровня разрешения (resolution level)
int anYPrecinctCount[33]; // (precinct) Y (resolution level) int anYPrecinctCount[33]; // Количество областей (precinct) по Y для каждого уровня разрешения (resolution level)
int anPrecinctWidth[33]; // ( 2), int anPrecinctWidth[33]; // Ширина области (в степени 2), для какждого уровня разрешения
int anPrecinctHeight[33]; // ( 2), int anPrecinctHeight[33]; // Высота области (в степени 2), для какждого уровня разрешения
PacketInfo *pPacket; // PacketInfo PacketInfo *pPacket; // PacketInfo
int nNBPix; // Fixed Quality int nNBPix; // Добавляем Fixed Quality
double dDistoTile; // Fixed Quality double dDistoTile; // Добавляем Fixed Quality
} TileInfo; } TileInfo;
typedef struct TImageInfo typedef struct TImageInfo
{ {
int nIndexOn; // 0 - , 1 - . int nIndexOn; // 0 - нет нумерации, 1 - есть.
double dDistoMax; // double dDistoMax; // Максимальный уровень сокращения искажений для всего изображения
int nPacketCount; // int nPacketCount; // Количество пакетов
int nIndexWrite; // int nIndexWrite; //
int nImageWidth; // int nImageWidth; // Ширина картинки
int nImageHeight; // int nImageHeight; // Высота картинки
ProgressionOrder eProgOrder; // Progression Order ProgressionOrder eProgOrder; // Progression Order
int nXTsiz; // tile int nXTsiz; // Размер tile по Х
int nYTsiz; // tile Y int nYTsiz; // Размер tile по Y
int nXTOsiz; // int nXTOsiz; // Сдвиг первого тайла по Х
int nYTOsiz; // Y int nYTOsiz; // Сдвиг первого тайла по Y
int nXTilesCount; // int nXTilesCount; // Количество тайлов по Х
int nYTilesCount; // Y int nYTilesCount; // Количество тайлов по Y
int nCompCount; // int nCompCount; // Количество компонент
int nLayersCount; // layers int nLayersCount; // Количество layers
int nDecompCount; // int nDecompCount; // Количество уровней разложения
int nMainHeadEnd; // Main Header int nMainHeadEnd; // Позиция окончания Main Header
int nCodestreamSize; // codestream int nCodestreamSize; // Размер codestream
TileInfo *pTile; // TileInfo TileInfo *pTile; // TileInfo
} ImageInfo; } ImageInfo;
// JPEG-2000 codestream reader/writer // JPEG-2000 codestream reader/writer
typedef struct TJ2kCodestream typedef struct TJ2kCodestream
{ {
PCommon pCodecInfo; // PCommon pCodecInfo; // Общая информация для кодирования и декодирования
int nState; // Codestream'a ( Main header, Tile header, ) int nState; // Здесь хранам текущую позицию декодера Codestream'a ( Main header, Tile header, конец декодирования )
int nCurTileIndex; // (.. /) int nCurTileIndex; // Номер текущего тайла (т.е. который в данный момент кодируется/декодируется)
//unsigned char *pEndOfTile; // codestream ( codestream) //unsigned char *pEndOfTile; // Используется для определения позиции конца тайла в codestream (чтобы определить нормальный ли codestream)
int nSizeOfTile; int nSizeOfTile;
int nSOTStartPos; // SOT, int nSOTStartPos; // Сохраняем начальную позицию маркера SOT, чтобы после кодирования текущего тайла мы могли вернуться и записать длину данного маркера
int nSODStartPos; // , SOD int nSODStartPos; // Аналогично, для маркера SOD
int nPosCorrection; // , J2k- , int nPosCorrection; // Необходимо для корректировки позиции, поскольку J2k-файл пишется в несколько частей, во время кодирования
unsigned char **ppTileData; // unsigned char **ppTileData; // Массив с данными всех тайлов
int *pTileLen; // , int *pTileLen; // Массив, хранящий размер данных для каждого тайла
TileCodingParams *pDefaultTCP; // : ( COD, COC ) TileCodingParams *pDefaultTCP; // Используется только при декомпрессии: храним общую информацию для всех тайлов ( COD, COC )
Image *pImage; // , , Image *pImage; // Указатель на изображения, которое мы либо кодируем, либо декодируем
CodingParams *pCodingParams; // , CodingParams *pCodingParams; // Указатель на структуру, хранящую информацию о кодировании
ImageInfo *pImageInfo; // ImageInfo *pImageInfo; //
CReader *pStreamIO; // Input / Output stream CReader *pStreamIO; // Input / Output stream
} J2kCodestream; } J2kCodestream;
...@@ -482,89 +490,89 @@ namespace Jpeg2000 ...@@ -482,89 +490,89 @@ namespace Jpeg2000
typedef struct TLayer typedef struct TLayer
{ {
int nPassesCount; // int nPassesCount; // Количество проходов
int nLen; // int nLen; // Длина информации
double dDisto; // double dDisto; // Отклонение
unsigned char *pData; // unsigned char *pData; // Данные
} Layer; } Layer;
typedef struct TCodeBlock typedef struct TCodeBlock
{ {
int nX0; // CodeBlock int nX0; // Размеры CodeBlock
int nY0; // (x0, y0) - int nY0; // (x0, y0) - левый верхний угол
int nX1; // (1, 1) - int nX1; // (х1, у1) - правый нижний угол
int nY1; // int nY1; //
int nBPSCount; // int nBPSCount; //
int nLenBitsCount; // int nLenBitsCount; //
int nLen; // int nLen; // Длина
int nPassesCount; // CodeBlock int nPassesCount; // Количество уже завершенных проходов для данного CodeBlock
int nNewPassesCount; // CodeBlock int nNewPassesCount; // Количество проходов добавленных к данному CodeBlock
int nSegmentsCount; // int nSegmentsCount; // Количество сегментов
TCDSegment aSegments[100]; // TCDSegment aSegments[100]; // Сами сегменты
unsigned char aData[8192]; // unsigned char aData[8192]; // Данные
int nPassesCountInLayers; // int nPassesCountInLayers; // Количество проходов в лэйре
Layer aLayers[100]; // Layer aLayers[100]; // Информация о лэйерах
int nTotalPassesCount; // int nTotalPassesCount; // Общее число проходов
TCDPass aPasses[100]; // TCDPass aPasses[100]; // Информация о проходах
} CodeBlock; } CodeBlock;
typedef struct TPrecinct typedef struct TPrecinct
{ {
int nX0; // Precinct int nX0; // Размеры Precinct
int nY0; // (x0, y0) - int nY0; // (x0, y0) - левый верхний угол
int nX1; // (1, 1) - int nX1; // (х1, у1) - правый нижний угол
int nY1; // int nY1; //
int nCountInWidth; // int nCountInWidth; // Количество блоков в ширину
int nCountInHeight; // int nCountInHeight; // Количество блоков в высоту
CodeBlock *pCodeBlocks; // CodeBlocks CodeBlock *pCodeBlocks; // CodeBlocks
TagTree *pInclTree; // TagTree *pInclTree; // Дерево включения
TagTree *pIMSBTree; // IMSB TagTree *pIMSBTree; // Дерево IMSB
} Precinct; } Precinct;
typedef struct TBand typedef struct TBand
{ {
int nX0; // Band int nX0; // Размеры Band
int nY0; // (x0, y0) - int nY0; // (x0, y0) - левый верхний угол
int nX1; // (1, 1) - int nX1; // (х1, у1) - правый нижний угол
int nY1; // int nY1; //
int nBandIndex; // Band int nBandIndex; // Номер текущего Band
Precinct *pPrecincts; // (Precinct), Band Precinct *pPrecincts; // Информация о областях(Precinct), входящий в данный Band
int nBPSCount; // int nBPSCount; //
float fStepSize; // float fStepSize; //
} Band; } Band;
typedef struct TResolution typedef struct TResolution
{ {
int nX0; // Resolution int nX0; // Размеры Resolution
int nY0; // (x0, y0) - int nY0; // (x0, y0) - левый верхний угол
int nX1; // (1, 1) - int nX1; // (х1, у1) - правый нижний угол
int nY1; // int nY1; //
int nPrecCountW; // (Precinct) int nPrecCountW; // Количество областей (Precinct) по ширине
int nPrecCountH; // (Precinct) int nPrecCountH; // Количество областей (Precinct) по высоте
int nBandsCount; // Sub-band int nBandsCount; // Количество Sub-band
Band aBands[3]; // Sub-bands Band aBands[3]; // Sub-bands
} Resolution; } Resolution;
typedef struct TTileComp typedef struct TTileComp
{ {
int nX0; // TileComp int nX0; // Размеры TileComp
int nY0; // (x0, y0) - int nY0; // (x0, y0) - левый верхний угол
int nX1; // (1, 1) - int nX1; // (х1, у1) - правый нижний угол
int nY1; // int nY1; //
int nResolutionsCount; // int nResolutionsCount; // Число разрешений
Resolution *pResolutions; // (Resolutions) Resolution *pResolutions; // Разрешения (Resolutions)
int *pData; // int *pData; // Данные компоненты
int nNBPix; // Fixed_quality int nNBPix; // Fixed_quality
} TileComp; } TileComp;
typedef struct TTile typedef struct TTile
{ {
int nX0; // Tile int nX0; // Размеры Tile
int nY0; // (x0, y0) - int nY0; // (x0, y0) - левый верхний угол
int nX1; // (1, 1) - int nX1; // (х1, у1) - правый нижний угол
int nY1; // int nY1; //
int nComponentsCount; // int nComponentsCount; // Количество компонент
TileComp *pComponents; // TileComp *pComponents; // Компоненты
int nNBPix; // Fixed_quality int nNBPix; // Fixed_quality
double dDistoTile; // Fixed_quality double dDistoTile; // Fixed_quality
double adDistoLayer[100]; // Fixed_quality double adDistoLayer[100]; // Fixed_quality
...@@ -572,20 +580,20 @@ namespace Jpeg2000 ...@@ -572,20 +580,20 @@ namespace Jpeg2000
typedef struct TTCDImage typedef struct TTCDImage
{ {
int nTilesCountW; // int nTilesCountW; // Количество тайлов по ширине
int nTilesCountH; // int nTilesCountH; // Количество тайлов по высоте
Tile *pTiles; // Tile *pTiles; // Тайлы
} TCDImage; } TCDImage;
typedef struct TTCD typedef struct TTCD
{ {
PCommon pCodecInfo; // PCommon pCodecInfo; // Информация о кодеке
TCDImage *pTCDImage; // TCDImage *pTCDImage; // Кодированное Изображение
Image *pImage; // Image *pImage; // Изображение
CodingParams *pCodingParams; // CodingParams *pCodingParams; // Параметры
Tile *pTCDTile; // / Tile *pTCDTile; // Указатель на текущий кодируемый/декодируемый тайл
TileCodingParams *pTCP; // / TileCodingParams *pTCP; // Параметры кодирования/декодирования для всех тайлов
int nTCDTileIndex; // / int nTCDTileIndex; // Номер текущего кодируемого/декодируемого тайла
} TCD; } TCD;
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
...@@ -626,18 +634,18 @@ namespace Jpeg2000 ...@@ -626,18 +634,18 @@ namespace Jpeg2000
//opj_jp2_cdef_t *jp2_cdef; //opj_jp2_cdef_t *jp2_cdef;
//opj_jp2_pclr_t *jp2_pclr; //opj_jp2_pclr_t *jp2_pclr;
BOOL has_colr; bool has_colr;
} Jp2Color; } Jp2Color;
// Jp2 file format reader/writer // Jp2 file format reader/writer
typedef struct TJp2Stream typedef struct TJp2Stream
{ {
PCommon pCodecInfo; // PCommon pCodecInfo; // Общая информация для кодирования и декодирования
J2kCodestream *pJ2k; // / JPEG2000 Codestream J2kCodestream *pJ2k; // Указатель на структуру для чтения/записи JPEG2000 Codestream
unsigned int nWidth; // unsigned int nWidth; // Ширина изображения
unsigned int nHeight; // unsigned int nHeight; // Высота изображения
unsigned int nComponentsCount; // unsigned int nComponentsCount; // Число компонент
unsigned int nBPC; // Bits per component unsigned int nBPC; // Bits per component
unsigned int nCompressionType; // CompressionType unsigned int nCompressionType; // CompressionType
unsigned int nColorSpaceUnk; // Colourspace Unknown unsigned int nColorSpaceUnk; // Colourspace Unknown
...@@ -650,7 +658,7 @@ namespace Jpeg2000 ...@@ -650,7 +658,7 @@ namespace Jpeg2000
unsigned int nBrand; // Brand unsigned int nBrand; // Brand
unsigned int nMinVersion; // MinVersion unsigned int nMinVersion; // MinVersion
unsigned int nCompListLength; // Compatibility list unsigned int nCompListLength; // Длина списка Compatibility list
unsigned int *pCompList; // Compatibility list unsigned int *pCompList; // Compatibility list
Jp2Component *pComponents; Jp2Component *pComponents;
...@@ -672,16 +680,16 @@ namespace Jpeg2000 ...@@ -672,16 +680,16 @@ namespace Jpeg2000
// MQ-coder (ArithmeticCoder.h) // MQ-coder (ArithmeticCoder.h)
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// . Annex C. fcd15444-1.pdf ( MQ-coder Encoder/Decoder ) // См. Annex C. fcd15444-1.pdf ( MQ-coder Encoder/Decoder )
#define MQC_NUMCTXS 32 #define MQC_NUMCTXS 32
typedef struct TMQCoderState typedef struct TMQCoderState
{ {
unsigned int nLPSValue; // (Least Probable Symbol) (0.75->0x8000, 1.5->0xffff) unsigned int nLPSValue; // вероятность для наименьшего вероятностного символа (Least Probable Symbol) (0.75->0x8000, 1.5->0xffff)
int nMPS; // ( 0 1 ) (Most Probable Symbol) int nMPS; // наибольший вероятностный символ ( 0 или 1 ) (Most Probable Symbol)
struct TMQCoderState *pNextMPS; // , MPS struct TMQCoderState *pNextMPS; // Указатель на следующее состояние, если следующий закодированный символ MPS
struct TMQCoderState *pNextLPS; // , LPS struct TMQCoderState *pNextLPS; // Указатель на следующее состояние, если следующий закодированный символ LPS
} MQCoderState; } MQCoderState;
// MQ-coder // MQ-coder
...@@ -704,13 +712,13 @@ namespace Jpeg2000 ...@@ -704,13 +712,13 @@ namespace Jpeg2000
typedef struct TRaw typedef struct TRaw
{ {
unsigned char nBuffer; // , / unsigned char nBuffer; // Временный буфер, в котором происходит побитовое кодирование/декодирование
unsigned int nFreeBitsCount; // , unsigned int nFreeBitsCount; // Количество бит, свободных для чтения или записи
unsigned int nMaxLen; // unsigned int nMaxLen; // Максимальная длина для декодирования
unsigned int nLen; // unsigned int nLen; // Длина декодированной информации
unsigned char *pBufferPointer; // unsigned char *pBufferPointer; // Указатель на текущую позицию в буфере
unsigned char *pBufferStart; // unsigned char *pBufferStart; // Указатель на начало буфера
unsigned char *pBufferEnd; // unsigned char *pBufferEnd; // Указатель на конец буфера
} Raw; } Raw;
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
...@@ -751,24 +759,24 @@ namespace Jpeg2000 ...@@ -751,24 +759,24 @@ namespace Jpeg2000
typedef struct TPacketIterator typedef struct TPacketIterator
{ {
short int *pInclude; // , ( POC) short int *pInclude; // Флаг, сигнализирующий использовался ли данный пакет (используется в POC)
int nStepLayer; // LayerStep pInclude int nStepLayer; // LayerStep используется для локализации пакета в pInclude
int nStepResolution; // ResoultionStep pInclude int nStepResolution; // ResoultionStep используется для локализации пакета в pInclude
int nStepComponent; // ComponentStep pInclude int nStepComponent; // ComponentStep используется для локализации пакета в pInclude
int nStepPrecinct; // PrecinctStep pInclude int nStepPrecinct; // PrecinctStep используется для локализации пакета в pInclude
int nIndexComponent; // int nIndexComponent; // Номер компоненты для определения пакета
int nIndexResolution; // int nIndexResolution; // Номер уровня детализации для определения пакета
int nIndexPrecinct; // int nIndexPrecinct; // Номер области для определения пакета
int nIndexLayer; // int nIndexLayer; // Номер лэйера для определения пакета
int nFirst; // , int nFirst; // Флаг, определяющий первый ли это пакет
POC oPOC; // Progression Order Change POC oPOC; // Progression Order Change
int nComponentsCount; // int nComponentsCount; // Число компонент
PacketComponent *pComponents; PacketComponent *pComponents;
int nTileX0; // int nTileX0; //
int nTileY0; // int nTileY0; // Границы текущего тайла
int nTileX1; // int nTileX1; //
int nTileY1; // int nTileY1; //
int nX; int nX;
...@@ -778,22 +786,22 @@ namespace Jpeg2000 ...@@ -778,22 +786,22 @@ namespace Jpeg2000
} PacketIterator; } PacketIterator;
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// Tier-1 coding ( ) // Tier-1 coding (кодирование коэффициентов)
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
#define T1_NMSEDEC_BITS 7 #define T1_NMSEDEC_BITS 7
#define T1_MAXCBLKW 1024 // CodeBlock ( ) #define T1_MAXCBLKW 1024 // Максимальный размер CodeBlock (по ширине)
#define T1_MAXCBLKH 1024 // CodeBlock ( ) #define T1_MAXCBLKH 1024 // Максимальный размер CodeBlock (по высоте)
#define T1_SIG_NE 0x0001 // : - #define T1_SIG_NE 0x0001 // Ориентация контекста : Северо-восточное направление
#define T1_SIG_SE 0x0002 // : - #define T1_SIG_SE 0x0002 // Ориентация контекста : юго-восточное направление
#define T1_SIG_SW 0x0004 // : - #define T1_SIG_SW 0x0004 // Ориентация контекста : юго-западное направление
#define T1_SIG_NW 0x0008 // : - #define T1_SIG_NW 0x0008 // Ориентация контекста : северо-западное направление
#define T1_SIG_N 0x0010 // : #define T1_SIG_N 0x0010 // Ориентация контекста : северное направление
#define T1_SIG_E 0x0020 // : #define T1_SIG_E 0x0020 // Ориентация контекста : восточное направление
#define T1_SIG_S 0x0040 // : #define T1_SIG_S 0x0040 // Ориентация контекста : южное направление
#define T1_SIG_W 0x0080 // : #define T1_SIG_W 0x0080 // Ориентация контекста : западное направление
#define T1_SIG_OTH (T1_SIG_N|T1_SIG_NE|T1_SIG_E|T1_SIG_SE|T1_SIG_S|T1_SIG_SW|T1_SIG_W|T1_SIG_NW) #define T1_SIG_OTH (T1_SIG_N|T1_SIG_NE|T1_SIG_E|T1_SIG_SE|T1_SIG_S|T1_SIG_SW|T1_SIG_W|T1_SIG_NW)
#define T1_SIG_PRIM (T1_SIG_N|T1_SIG_E|T1_SIG_S|T1_SIG_W) #define T1_SIG_PRIM (T1_SIG_N|T1_SIG_E|T1_SIG_S|T1_SIG_W)
...@@ -822,16 +830,16 @@ namespace Jpeg2000 ...@@ -822,16 +830,16 @@ namespace Jpeg2000
#define T1_NMSEDEC_FRACBITS (T1_NMSEDEC_BITS - 1) #define T1_NMSEDEC_FRACBITS (T1_NMSEDEC_BITS - 1)
#define T1_TYPE_MQ 0 // , Arithmetic entropy coding (Annex C) #define T1_TYPE_MQ 0 // Нормальное кодирование, с использованием Arithmetic entropy coding (Annex C)
#define T1_TYPE_RAW 1 // , Codestream #define T1_TYPE_RAW 1 // Нет никакого кодирования, информация в Codestream содержится в сыром виде
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
typedef struct TTier1 typedef struct TTier1
{ {
PCommon pCodecInfo; // PCommon pCodecInfo; // Информация о кодеке
MQCoder *pMQCoder; // / MQ- MQCoder *pMQCoder; // Указатель на структуру для чтения/записи MQ-кодированных данных
Raw *pRaw; // / Raw *pRaw; // Указатель на структуру для чтения/записи некодированных данных
int lut_ctxno_zc[1024]; int lut_ctxno_zc[1024];
int lut_ctxno_sc[256]; int lut_ctxno_sc[256];
...@@ -842,8 +850,8 @@ namespace Jpeg2000 ...@@ -842,8 +850,8 @@ namespace Jpeg2000
int lut_nmsedec_ref[1 << T1_NMSEDEC_BITS]; int lut_nmsedec_ref[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS]; int lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS];
int aData[T1_MAXCBLKH][T1_MAXCBLKW]; // codeblock int aData[T1_MAXCBLKH][T1_MAXCBLKW]; // Данные codeblock
int aFlags[T1_MAXCBLKH + 2][T1_MAXCBLKH + 2]; // int aFlags[T1_MAXCBLKH + 2][T1_MAXCBLKH + 2]; // Флаги
} Tier1; } Tier1;
...@@ -854,7 +862,7 @@ namespace Jpeg2000 ...@@ -854,7 +862,7 @@ namespace Jpeg2000
typedef struct TTier2 typedef struct TTier2
{ {
PCommon pCodecInfo; PCommon pCodecInfo;
Image *pImage; // Encoding: . Decoding: . Image *pImage; // Encoding: указатель на исходную картинку. Decoding: указатель на результирующую картинку.
CodingParams *pCodingParams; CodingParams *pCodingParams;
} Tier2; } Tier2;
...@@ -1075,11 +1083,11 @@ namespace Jpeg2000 ...@@ -1075,11 +1083,11 @@ namespace Jpeg2000
typedef struct TBitIO typedef struct TBitIO
{ {
unsigned char *pStart; // unsigned char *pStart; // Указатель на начало буфера
unsigned char *pEnd; // unsigned char *pEnd; // Указатель на конец буфера
unsigned char *pCurPos; // unsigned char *pCurPos; // Указатель на текущую позицию в буфере
unsigned int nBuffer; // unsigned int nBuffer; // Буфер
int nValidBitsCount; // Coder : int nValidBitsCount; // Coder : число свободных бит для записи
// Decoder : // Decoder : число доступных бит для чтения
} BitIO; } BitIO;
} }
\ No newline at end of file
#pragma once #pragma once
namespace Jpeg2000 namespace Jpeg2000
{ {
...@@ -7,9 +7,9 @@ namespace Jpeg2000 ...@@ -7,9 +7,9 @@ namespace Jpeg2000
return 0; return 0;
// LARGE_INTEGER oFreq, oTime; // LARGE_INTEGER oFreq, oTime;
//// oFreq - CPU //// oFreq - скорость часов у CPU
// QueryPerformanceFrequency( &oFreq ); // QueryPerformanceFrequency( &oFreq );
// // oTime - ( oFreq) // // oTime - текущее время(в смысле oFreq)
// QueryPerformanceCounter ( &oTime ) ; // QueryPerformanceCounter ( &oTime ) ;
// return ( oTime.QuadPart /(double) oFreq.QuadPart ) ; // return ( oTime.QuadPart /(double) oFreq.QuadPart ) ;
} }
...@@ -30,25 +30,25 @@ namespace Jpeg2000 ...@@ -30,25 +30,25 @@ namespace Jpeg2000
return nValue; return nValue;
} }
// nA nB // Делим nA на nB и округляем в большую сторону
static __inline int CeilDiv(int nA, int nB) static __inline int CeilDiv(int nA, int nB)
{ {
return (nA + nB - 1) / nB; return (nA + nB - 1) / nB;
} }
// nA 2^nB // Делим nA на 2^nB и округляем в большую сторону
static __inline int CeilDivPow2(int nA, int nB) static __inline int CeilDivPow2(int nA, int nB)
{ {
return (nA + (1 << nB) - 1) >> nB; return (nA + (1 << nB) - 1) >> nB;
} }
// nA 2^nB // Делим nA на 2^nB и округляем в меньшую сторону
static __inline int FloorDivPow2(int nA, int nB) static __inline int FloorDivPow2(int nA, int nB)
{ {
return nA >> nB; return nA >> nB;
} }
// 2 nA // Берем логарифм по основанию 2 от числа nA и округляем в меньшую сторону
static __inline int FloorLog2(int nA) static __inline int FloorLog2(int nA)
{ {
int nL; int nL;
...@@ -67,7 +67,7 @@ namespace Jpeg2000 ...@@ -67,7 +67,7 @@ namespace Jpeg2000
static const double c_adNormRCT[3] ={ 1.732, .8292, .8292 }; static const double c_adNormRCT[3] ={ 1.732, .8292, .8292 };
static const double c_adNormICT[3] ={ 1.732, 1.805, 1.573 }; static const double c_adNormICT[3] ={ 1.732, 1.805, 1.573 };
// - (Annex G.2.1) // Применяем обратимое много-компонентное преобразование к изображению (Annex G.2.1)
static void ForwardRCT(int *pRed, int *pGreen, int *pBlue, int nSamplesCount) static void ForwardRCT(int *pRed, int *pGreen, int *pBlue, int nSamplesCount)
{ {
for (int nIndex = 0; nIndex < nSamplesCount; nIndex++) for (int nIndex = 0; nIndex < nSamplesCount; nIndex++)
...@@ -85,7 +85,7 @@ namespace Jpeg2000 ...@@ -85,7 +85,7 @@ namespace Jpeg2000
} }
} }
// - (Annex G.2.2) // Применяем обратимое много-компонентное обратное преобазование к изображению (Annex G.2.2)
static void InverseRCT(int *pRed, int *pGreen, int *pBlue, int nSamplesCount) static void InverseRCT(int *pRed, int *pGreen, int *pBlue, int nSamplesCount)
{ {
for (int nIndex = 0; nIndex < nSamplesCount; nIndex++) for (int nIndex = 0; nIndex < nSamplesCount; nIndex++)
...@@ -109,7 +109,7 @@ namespace Jpeg2000 ...@@ -109,7 +109,7 @@ namespace Jpeg2000
return c_adNormRCT[nComponentIndex]; return c_adNormRCT[nComponentIndex];
} }
// - (Annex G.3.1) // Применяем необратимое много-компонентное преобразование к изображению (Annex G.3.1)
static void ForwardICT(int *pRed, int *pGreen, int *pBlue, int nSamplesCount) static void ForwardICT(int *pRed, int *pGreen, int *pBlue, int nSamplesCount)
{ {
for (int nIndex = 0; nIndex < nSamplesCount; nIndex++) for (int nIndex = 0; nIndex < nSamplesCount; nIndex++)
...@@ -127,7 +127,7 @@ namespace Jpeg2000 ...@@ -127,7 +127,7 @@ namespace Jpeg2000
} }
} }
// - (Annex G.3.2) // Применяем необратимое много-компонентное обратное преобазование к изображению (Annex G.3.2)
static void InverseICT(int *pRed, int *pGreen, int *pBlue, int nSamplesCount) static void InverseICT(int *pRed, int *pGreen, int *pBlue, int nSamplesCount)
{ {
for (int nIndex = 0; nIndex < nSamplesCount; nIndex++) for (int nIndex = 0; nIndex < nSamplesCount; nIndex++)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment