Path: blob/master/libs/jxr/image/sys/windowsmediaphoto.h
4393 views
//*@@@+++@@@@******************************************************************1//2// Copyright © Microsoft Corp.3// All rights reserved.4//5// Redistribution and use in source and binary forms, with or without6// modification, are permitted provided that the following conditions are met:7//8// • Redistributions of source code must retain the above copyright notice,9// this list of conditions and the following disclaimer.10// • Redistributions in binary form must reproduce the above copyright notice,11// this list of conditions and the following disclaimer in the documentation12// and/or other materials provided with the distribution.13//14// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"15// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE18// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR19// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF20// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS21// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN22// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)23// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE24// POSSIBILITY OF SUCH DAMAGE.25//26//*@@@---@@@@******************************************************************2728#ifndef WMI_WINDOWSMEDIAPHOTO_H29#define WMI_WINDOWSMEDIAPHOTO_H3031//================================================================32#include <assert.h>33#include <stdio.h>34#include <stdlib.h>35#include <string.h>3637#if defined(__cplusplus) && !defined(EXTERN_C)38#define EXTERN_C extern "C"39#elif !defined(EXTERN_C)// __cplusplus40#define EXTERN_C extern41#endif // __cplusplus4243/********************************************************************************44Type definitions45********************************************************************************/46typedef int Bool;47typedef char Char;48typedef double Double;49typedef int Int;50typedef signed char I8;51typedef short I16; // 16 bit int52typedef int I32;53typedef long Long;54typedef unsigned char PixelC;55typedef int PixelI;56typedef unsigned int UInt;57typedef unsigned long ULong;58typedef unsigned char U8; // 8 bit uint59typedef unsigned short U16;60typedef unsigned int U32; // 32 bit uint61typedef void Void;6263typedef void* CTXSTRCODEC;646566#define REENTRANT_MODE 167/*68DESCRIPTION OF COMPILER FLAG REENTRANT_MODE:6970//#define REENTRANT_MODE 17172This compiler flag is related to the capability of banded decode73(decoding only one MB row of the source JPEG XR image at a time).7475With REENTRANT_MODE defined, the decoder decodes one MB row on each call to76ImageStrDecDecode().7778The decoder acts as if it can only write to the single MBRow whose pointer was passed to it.79This acts as a proof of concept that the API would work if you passed it a small buffer80on each call to ImageStrDecDecode().8182The REENTRANT_MODE flag only works when the output image is in Orientations 0, 183(vertically flipped) or 2 (horizontally flipped).8485With REENTRANT_MODE defined, the function PKImageDecode_Copy_WMP()86decodes only as far as the pRect parameter indicates. The width of the rectangle must be the width87of the image, but on each call, this function will decode the image up to the end of the MB Row88which contains the i-th pixel row, where i = pRect->Y.8990A target use of this version would be to have PKImageDecode_Copy_WMP() called in a loop, once for91each MB row. On each call, pRect would specify a 1-MB-Row-tall rectangle that is the width of the92image. The decoder state is preserved until the Decoder finishes decoding the image.9394If, at a certain point, a request is made for a rectangle _above_ the last row decoded, then the95decoder instance is terminated and re-initiated, and decoding re-starts, going from the beginning96of the image to the end of the current rectangle.9798***99100We've chosen to uncomment-out this definition in this header file. An alternate method would be101to allow the user to define this in the PREPROCESSOR DEFINITIONS section of the properties page102for each of the following projects: CommonLib, DecodeLib, JXRDecApp and JXRGlueLib.103104*/105/*************************************************************************106enums107*************************************************************************/108typedef enum {109ICERR_OK = 0, ICERR_ERROR = -1110} ERR_CODE;111112typedef enum BITDEPTH {113BD_SHORT, BD_LONG,114115/* add new BITDEPTH here */ BD_MAX116} BITDEPTH;117118typedef enum BITDEPTH_BITS {119// regular ones120BD_1, //White is foreground121BD_8, BD_16, BD_16S, BD_16F, BD_32, BD_32S, BD_32F,122123// irregular ones124BD_5, BD_10, BD_565,125126/* add new BITDEPTH_BITS here */ BDB_MAX,127128BD_1alt = 0xf, //Black is foreground129} BITDEPTH_BITS;130131typedef enum OVERLAP {132OL_NONE = 0, OL_ONE, OL_TWO,133134/* add new OVERLAP here */ OL_MAX135} OVERLAP;136137typedef enum BITSTREAMFORMAT {138SPATIAL = 0, // spatial order139FREQUENCY, // frequency order140} BITSTREAMFORMAT;141142typedef enum COLORFORMAT {143Y_ONLY = 0,144YUV_420 = 1,145YUV_422 = 2,146YUV_444 = 3,147CMYK = 4,148//CMYKDIRECT = 5,149NCOMPONENT = 6,150151// these are external-only152CF_RGB = 7,153CF_RGBE = 8,154155/* add new COLORFORMAT here */ CFT_MAX156} COLORFORMAT;157158// rotation and flip159typedef enum ORIENTATION {160// CRW: Clock Wise 90% Rotation; FlipH: Flip Horizontally; FlipV: Flip Vertically161// Peform rotation FIRST!162// CRW FlipH FlipV163O_NONE = 0, // 0 0 0164O_FLIPV, // 0 0 1165O_FLIPH, // 0 1 0166O_FLIPVH, // 0 1 1167O_RCW, // 1 0 0168O_RCW_FLIPV, // 1 0 1169O_RCW_FLIPH, // 1 1 0170O_RCW_FLIPVH, // 1 1 1171/* add new ORIENTATION here */ O_MAX172} ORIENTATION;173174typedef enum SUBBAND {175SB_ALL = 0, // keep all subbands176SB_NO_FLEXBITS, // skip flex bits177SB_NO_HIGHPASS, // skip highpass178SB_DC_ONLY, // skip lowpass and highpass, DC only179SB_ISOLATED, // not decodable180/* add new SUBBAND here */ SB_MAX181} SUBBAND;182183enum { RAW = 0, BMP = 1, PPM = 2, TIF = 3, HDR = 4, IYUV = 5, YUV422 = 6, YUV444 = 7};184185typedef enum {ERROR_FAIL = -1, SUCCESS_DONE, PRE_READ_HDR, PRE_SETUP, PRE_DECODE, POST_READ_HDR } WMIDecoderStatus;186187#ifndef FALSE188#define FALSE 0189#endif // FALSE190191#ifndef TRUE192#define TRUE 1193#endif // TRUE194195#define MAX_CHANNELS 16196#define LOG_MAX_TILES 12197#define MAX_TILES (1 << LOG_MAX_TILES)198199200//================================================================201// Codec-specific constants202#define MB_WIDTH_PIXEL 16203#define MB_HEIGHT_PIXEL 16204205#define BLK_WIDTH_PIXEL 4206#define BLK_HEIGHT_PIXEL 4207208#define MB_WIDTH_BLK 4209#define MB_HEIGHT_BLK 4210211// The codec operates most efficiently when the framebuffers for encoder input212// and decoder output are: 1) aligned on a particular boundary, and 2) the stride213// is also aligned to this boundary (so that each scanline is also aligned).214// This boundary is defined below.215#define FRAMEBUFFER_ALIGNMENT 128216217218//================================================================219#define WMP_errSuccess 0220221#define WMP_errFail -1222#define WMP_errNotYetImplemented -2223#define WMP_errAbstractMethod -3224225#define WMP_errOutOfMemory -101226#define WMP_errFileIO -102227#define WMP_errBufferOverflow -103228#define WMP_errInvalidParameter -104229#define WMP_errInvalidArgument -105230#define WMP_errUnsupportedFormat -106231#define WMP_errIncorrectCodecVersion -107232#define WMP_errIndexNotFound -108233#define WMP_errOutOfSequence -109234#define WMP_errNotInitialized -110235#define WMP_errMustBeMultipleOf16LinesUntilLastCall -111236#define WMP_errPlanarAlphaBandedEncRequiresTempFile -112237#define WMP_errAlphaModeCannotBeTranscoded -113238#define WMP_errIncorrectCodecSubVersion -114239240241//================================================================242typedef long ERR;243244#define Failed(err) ((err)<0)245246#define CRLF "\r\n"247248#define CT_ASSERT(exp, uniq) typedef char __CT_ASSERT__##uniq[(exp) ? 1 : -1] // Caller must provide a unique tag, or this fails to compile under GCC249250#if defined(_DEBUG) || defined(DBG)251#define Report(err, szExp, szFile, nLine) \252fprintf(stderr, "FAILED: %ld=%s" CRLF, (err), (szExp)); \253fprintf(stderr, " %s:%ld" CRLF, (szFile), (nLine)); \254255#else256#define Report(err, szExp, szFile, lLine) err = err257#endif258259#define Call(exp) do { \260if (Failed(err = (exp))) \261{ \262Report(err, #exp, __FILE__, (long)__LINE__); \263goto Cleanup; \264} \265else err = err; \266} while(0)267268#define CallIgnoreError(errTmp, exp) do { \269if (Failed(errTmp = (exp))) \270{ \271Report(errTmp, #exp, __FILE__, (long)__LINE__); \272} \273else errTmp = errTmp; \274} while(0)275276277#define Test(exp, err) Call((exp) ? WMP_errSuccess : (err))278#define FailIf(exp, err) Call((exp) ? (err) : WMP_errSuccess)279280//================================================================281// WMPStream interface282//================================================================283struct WMPStream284{285union286{287struct tagFile288{289FILE* pFile;290} file;291292struct tagBuf293{294U8* pbBuf;295size_t cbBuf;296size_t cbCur;297size_t cbBufCount;298} buf;299300void* pvObj;301} state;302303Bool fMem;304305ERR (*Close)(struct WMPStream** pme);306307Bool (*EOS)(struct WMPStream* me);308309ERR (*Read)(struct WMPStream* me, void* pv, size_t cb);310ERR (*Write)(struct WMPStream* me, const void* pv, size_t cb);311//ERR (*GetLine)(struct WMPStream* me, void* pv, size_t cb);312313ERR (*SetPos)(struct WMPStream* me, size_t offPos);314ERR (*GetPos)(struct WMPStream* me, size_t* poffPos);315};316317EXTERN_C ERR CreateWS_File(struct WMPStream** ppWS, const char* szFilename, const char* szMode);318EXTERN_C ERR CloseWS_File(struct WMPStream** ppWS);319320EXTERN_C ERR CreateWS_Memory(struct WMPStream** ppWS, void* pv, size_t cb);321EXTERN_C ERR CloseWS_Memory(struct WMPStream** ppWS);322323324//================================================================325// Enc/Dec data structure326//================================================================327typedef struct tagCWMImageInfo {328size_t cWidth;329size_t cHeight;330COLORFORMAT cfColorFormat;331BITDEPTH_BITS bdBitDepth;332size_t cBitsPerUnit;333size_t cLeadingPadding; // number of leading padding334Bool bRGB; // true: RGB; false: BGR335U8 cChromaCenteringX; // Relative location of Chroma w.r.t Luma336U8 cChromaCenteringY; // Relative location of Chroma w.r.t Luma337338// Region of interest decoding339size_t cROILeftX;340size_t cROIWidth;341size_t cROITopY;342size_t cROIHeight;343344// thumbnail decode345Bool bSkipFlexbits;346size_t cThumbnailWidth;347size_t cThumbnailHeight;348349// image orientation350ORIENTATION oOrientation;351352// post processing353U8 cPostProcStrength; // 0(none) 1(light) 2(medium) 3(strong) 4(very strong)354355// user buffer is always padded to whole MB356Bool fPaddedUserBuffer;357} CWMImageInfo;358359typedef struct tagCWMIStrCodecParam {360Bool bVerbose;361362// for macroblock quantization (DQUANT)363U8 uiDefaultQPIndex;364U8 uiDefaultQPIndexYLP;365U8 uiDefaultQPIndexYHP;366U8 uiDefaultQPIndexU;367U8 uiDefaultQPIndexULP;368U8 uiDefaultQPIndexUHP;369U8 uiDefaultQPIndexV;370U8 uiDefaultQPIndexVLP;371U8 uiDefaultQPIndexVHP;372U8 uiDefaultQPIndexAlpha;373374COLORFORMAT cfColorFormat;375BITDEPTH bdBitDepth;376OVERLAP olOverlap;377BITSTREAMFORMAT bfBitstreamFormat;378size_t cChannel; // number of color channels including alpha379U8 uAlphaMode; // 0:no alpha 1: alpha only else: something + alpha380SUBBAND sbSubband; // which subbands to keep381U8 uiTrimFlexBits;382383struct WMPStream* pWStream;384size_t cbStream;385386// tiling info387U32 cNumOfSliceMinus1V; // # of vertical slices388U32 uiTileX[MAX_TILES]; // width in MB of each veritical slice389U32 cNumOfSliceMinus1H; // # of horizontal slices390U32 uiTileY[MAX_TILES]; // height in MB of each horizontal slice391392//32f and 32s conversion parameters393U8 nLenMantissaOrShift;394I8 nExpBias;395396Bool bBlackWhite;397398Bool bUseHardTileBoundaries; //default is soft tile boundaries399400Bool bProgressiveMode; //default is sequential mode401402Bool bYUVData; //default is cfColorFormat data403404Bool bUnscaledArith; //force unscaled arithmetic405406// Perf measurement407Bool fMeasurePerf;408} CWMIStrCodecParam;409410typedef struct tagCWMImageBufferInfo {411void* pv; // pointer to scanline buffer412size_t cLine; // count of scanlines413size_t cbStride; // count of BYTE for stride414#ifdef REENTRANT_MODE415unsigned int uiFirstMBRow; // Current First MB Row being decoded416unsigned int uiLastMBRow; // Current Last MB Row being decoded417size_t cLinesDecoded; // Number of lines decoded and returned in low-mem mode418#endif // REENTRANT_MODE419} CWMImageBufferInfo;420421422423424/****************************************************************/425/* Encode API */426/****************************************************************/427EXTERN_C Int ImageStrEncInit(428CWMImageInfo* pII,429CWMIStrCodecParam *pSCP,430CTXSTRCODEC* pctxSC);431432EXTERN_C Int ImageStrEncEncode(433CTXSTRCODEC ctxSC,434const CWMImageBufferInfo* pBI);435436EXTERN_C Int ImageStrEncTerm(437CTXSTRCODEC ctxSC);438439440/****************************************************************/441/* Decode API */442/****************************************************************/443struct CWMImageStrCodec;444445EXTERN_C Int ImageStrDecGetInfo(446CWMImageInfo* pII,447CWMIStrCodecParam *pSCP);448449EXTERN_C Int ImageStrDecInit(450CWMImageInfo* pII,451CWMIStrCodecParam *pSCP,452CTXSTRCODEC* pctxSC);453454EXTERN_C Int ImageStrDecDecode(455CTXSTRCODEC ctxSC,456const CWMImageBufferInfo* pBI457#ifdef REENTRANT_MODE458, size_t *pcDecodedLines459#endif460);461462EXTERN_C Int ImageStrDecTerm(463CTXSTRCODEC ctxSC);464465EXTERN_C Int WMPhotoValidate(466CWMImageInfo * pII,467CWMIStrCodecParam * pSCP);468469470/****************************************************************/471/* Transcoding API */472/****************************************************************/473typedef struct tagCWMTranscodingParam {474size_t cLeftX;475size_t cWidth;476size_t cTopY;477size_t cHeight; // interested region478479BITSTREAMFORMAT bfBitstreamFormat; // desired bitstream format480// COLORFORMAT cfColorFormat; // desired color format481U8 uAlphaMode; // 0:no alpha 1: alpha only else: something + alpha482SUBBAND sbSubband; // which subbands to keep483ORIENTATION oOrientation; // flip / right angle rotation484Bool bIgnoreOverlap;485} CWMTranscodingParam;486487EXTERN_C Int WMPhotoTranscode(488struct WMPStream* pStreamDec, // input bitstrean489struct WMPStream* pStreamEnc, // output bitstream490CWMTranscodingParam* pParam // transcoding parameters491);492493typedef struct tagCWMDetilingParam {494size_t cWidth;495size_t cHeight; // image size496size_t cChannel; // # of channels497OVERLAP olOverlap; // overlap498BITDEPTH_BITS bdBitdepth; // bit depth499500// tiling info501U32 cNumOfSliceMinus1V; // # of vertical slices502U32 uiTileX[MAX_TILES]; // position in MB of each veritical slice503U32 cNumOfSliceMinus1H; // # of horizontal slices504U32 uiTileY[MAX_TILES]; // position in MB of each horizontal slice505506// image info507void * pImage;508size_t cbStride;509} CWMDetilingParam;510511EXTERN_C Int WMPhotoDetile(512CWMDetilingParam * pParam // detiling parameters513);514515#endif // WMI_WINDOWSMEDIAPHOTO_H516517518