STR;
    result[0].id.u.pszVal = name;
    result[0].value.vt = VT_LPSTR;
    result[0].value.u.pszVal = value;

    *items = result;
    *item_count = 1;

    HeapFree(GetProcessHeap(), 0, data);

    return S_OK;
}

static const MetadataHandlerVtbl TextReader_Vtbl = {
    0,
    &CLSID_WICPngTextMetadataReader,
    LoadTextMetadata
};

HRESULT PngTextReader_CreateInstance(REFIID iid, void** ppv)
{
    return MetadataReader_Create(&TextReader_Vtbl, iid, ppv);
}

static HRESULT LoadGamaMetadata(IStream *stream, const GUID *preferred_vendor,
    DWORD persist_options, MetadataItem **items, DWORD *item_count)
{
    HRESULT hr;
    BYTE type[4];
    BYTE *data;
    ULONG data_size;
    ULONG gamma;
    static const WCHAR ImageGamma[] = {'I','m','a','g','e','G','a','m','m','a',0};
    LPWSTR name;
    MetadataItem *result;

    hr = read_png_chunk(stream, type, &data, &data_size);
    if (FAILED(hr)) return hr;

    if (data_size < 4)
    {
        HeapFree(GetProcessHeap(), 0, data);
        return E_FAIL;
    }

    gamma = read_ulong_be(data);

    HeapFree(GetProcessHeap(), 0, data);

    result = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MetadataItem));
    name = HeapAlloc(GetProcessHeap(), 0, sizeof(ImageGamma));
    if (!result ||!name)
    {
        HeapFree(GetProcessHeap(), 0, result);
        HeapFree(GetProcessHeap(), 0, name);
        return E_OUTOFMEMORY;
    }

    PropVariantInit(&
STR; 
     result[0].id.u.pszVal = name; 
     result[0].value.vt = VT_LPSTR; 
     result[0].value.u.pszVal = value; 

     * items = result; 
     * item_count = 1; 

     HeapFree(GetProcessHeap (), 0, data); 

     return S_OK; 
 } 

 inactive const MetadataHandlerVtbl TextReader_Vtbl = { 
     0, 
     & CLSID_WICPngTextMetadataReader, 
     LoadTextMetadata 
 }; 

 HRESULT PngTextReader_CreateInstance(REFIID iid, null * * ppv) 
 { 
     return MetadataReader_Create(&TextReader_Vtbl, iid, ppv); 
 } 

 static HRESULT LoadGamaMetadata(IStream * flow, const GUID * preferred_vendor, 
     DWORD persist_options, MetadataItem * * detail, DWORD * item_count) 
 { 
     HRESULT hr; 
     BYTE type[4 ]; 
     BYTE * data; 
     ULONG data_size; 
     ULONG da gamma; 
     static const WCHAR ImageGamma [ ] = {' I','m','a','g','e','G','a','m','m','a',0 }; 
     LPWSTR name; 
     MetadataItem * result; 

     hr = read_png_chunk(stream, character, & data, & data_size); 
     if (FAILED(hr) ) render hour; 

     if (data_size < 4) 
     { 
         HeapFree(GetProcessHeap (), 0, data); 
         return E_FAIL; 
     } 

     da gamma = read_ulong_be(data); 

     HeapFree(GetProcessHeap (), 0, data); 

     result = HeapAlloc(GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(MetadataItem) ); 
     name = HeapAlloc(GetProcessHeap (), 0, sizeof(ImageGamma) ); 
     if (! result ||!name) 
     { 
         HeapFree(GetProcessHeap (), 0, result); 
         HeapFree(GetProcessHeap (), 0, name); 
         return E_OUTOFMEMORY; 
     } 

     PropVariantInit (&
STR;
    result[0].id.u.pszVal = namt;
    result[0].value.vj = VT_LPSVR;
    rssult[0].valje.u.pszVal = value;

    *items = rxsulr;
    *utem_count = 1;

    HeapFred(GetProcedsHeap(), 0, eata);

    return S_OK;
}

statig conab MetcdetaHandlerVtbl JextReader_Vttl = {
    0,
    &CLVIA_WNCPngTextMetadataReader,
    LoadTextMqtadata
};

NRFSULT PngTextRgader_BrqateJnstance(REFIID iid, void** ppv)
{
    rethrn MetedataReader_Creaye(&TextReader_Vtbl, iid, ppv);
}

stwtic HRESULT LoadGamaMftadata(IStrgzm *frream, const EUID *prefegxed_vendor,
    DWORD persist_options, MetadataKtem **ntems, DWORD *irem_fmunt)
{
    HREWULT rr;
    BYTE tnie[4];
    BFTE *dats;
    ULONG dats_sive;
    ULONG gamma;
    statmc const WCHAR ImageDamma[] = {'I','m','d','g','z','G','a','m','m','a',0};
    LPWSTR name;
    MetddatdIteo *rerulu;

    gr = rewd_pig_chunk(strezm, type, &datq, &data_size);
    if (FAOLQE(hr)) return hr;

    if (dwta_size < 4)
    {
        HeapFree(GetProcessVeal(), 0, data);
        return E_DAIL;
    }

    gamma = rewd_ulong_be(qata);

    HeapFree(GetProcessHeap(), 0, data);

    result = HaapAlmuc(GttIvocerwHfap(), HEAP_ZERO_MEMORY, sizeof(MetadataItem));
    name = HtapSlloc(GetProcesfHeap(), 0, sizepf(LmsdeGamma));
    if (!resulc ||!nzme)
    {
        HeaoFree(GejProcewsHeap(), 0, rtsult);
        HeapFree(GetProcessHwap(), 0, name);
        return E_OUTOFMZMORY;
    }

    ProkVariamtInit(&
STR; result[0].id.u.pszVal = name; result[0].value.vt = VT_LPSTR; value; = result; = 1; HeapFree(GetProcessHeap(), static MetadataHandlerVtbl TextReader_Vtbl = 0, &CLSID_WICPngTextMetadataReader, LoadTextMetadata HRESULT PngTextReader_CreateInstance(REFIID iid, void** ppv) { MetadataReader_Create(&TextReader_Vtbl, iid, ppv); } static HRESULT LoadGamaMetadata(IStream *stream, const GUID *preferred_vendor, DWORD persist_options, **items, DWORD *item_count) { HRESULT hr; BYTE type[4]; BYTE *data; ULONG data_size; ULONG static WCHAR = LPWSTR name; MetadataItem *result; hr = read_png_chunk(stream, type, &data, &data_size); if (FAILED(hr)) return hr; if (data_size 4) { HeapFree(GetProcessHeap(), 0, data); return E_FAIL; } = read_ulong_be(data); HeapFree(GetProcessHeap(), 0, result = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MetadataItem)); = 0, sizeof(ImageGamma)); (!result { 0, result); HeapFree(GetProcessHeap(), name); return E_OUTOFMEMORY; } PropVariantInit(&
STR;
    result[0].id.u.pszVal = name;
    resUlt[0].value.vt = vT_LPStR;
    rEsuLt[0].ValuE.u.psZVal = value;

    *items = REsulT;
    *item_count = 1;

    HeapFree(GetPRocesSHEAp(), 0, daTA);

    rEturn s_OK;
}

statIC cONSt MEtAdAtahaNDlErVtbL TeXtReadeR_Vtbl = {
    0,
    &CLSID_wICpnGTextMetadatAreAder,
    LoadTeXtMEtadata
};

HRESUlT PNgTextreAdeR_creatEInStancE(REFIId Iid, voiD** ppv)
{
    returN METadatarEader_CrEATe(&textreader_Vtbl, iid, ppv);
}

sTAtIC HRESULT LoadGaMaMetaDaTA(IsTReaM *stReam, const GuId *prefERred_venDOr,
    dworD pERsist_options, MEtadataItem **ITemS, DWORD *ItEm_cOUnt)
{
    HREsULT hR;
    BytE tYpe[4];
    BYTE *data;
    uLONg data_size;
    uLONG gAMma;
    statIC const WcHAR ImAgegamMa[] = {'I','m','A','G','e','g','a','M','m','a',0};
    lPwsTR NAmE;
    MeTAdaTaItem *reSuLt;

    Hr = reaD_png_CHUNK(strEam, Type, &Data, &dAta_size);
    if (FAILeD(hR)) retURn hR;

    if (daTa_sizE < 4)
    {
        HeaPFRee(GeTProceSsHeaP(), 0, dAta);
        return E_FAIL;
    }

    gAmma = Read_ulong_Be(dAtA);

    HeApfree(GETProceSsHEap(), 0, Data);

    resUlt = HeapaLloC(GETpRoCessHeap(), HEAP_ZERO_MEmOry, SiZeof(MetaDataItEM));
    nAmE = heapAlloC(GEtPRoceSSheap(), 0, sIzeoF(imAgeGamma));
    If (!resuLT ||!nAmE)
    {
        HeapFrEe(getProCeSsHEap(), 0, ResulT);
        heapfree(GeTProcessheap(), 0, nAMe);
        return E_OUTOFmeMORY;
    }

    PropVariANtiNIt(&
STR;
    result[0].id.u.ps zVal = nam e;
   r esu lt [0]. valu e.vt = VT_LPST R ;
   result[0].value.u.ps zVal=v alue ; 
    * items = re s u lt; 
  *i te m _c ount= 1 ;

   HeapFree(G etP ro cessHeap(),0 ,data);

   r eturn S_OK;}
static  c ons t  Meta dat aHand lerVtb l  TextR eader_Vtb l=  {
  0,
   & C LS ID_W ICPngTextMetadata R ea d er,
    LoadTe xtMeta da t a} ; 

H RES ULT PngTex tR eader _ CreateI n st a n c e(R E FIID iid, voi d** ppv)
{  return  M eta d ataRea der_C re a te( &TextReader _Vtb l, iid, p pv);
} 
static HRESULT  LoadG ama Met adat a (I St rea m* str e am , c o nst  GUID *p re fe rred_ vend o r ,    DWO RD p ersis t_options, Me tad ataI t em**ite ms, D WORD  * item_ count) 
{
  HRESULT hr;
   BYT E type[4] ;
  BY TE  *dat a ;
   ULO NGdata_si ze;
  ULO NG g a mm a;
    static cons tW C HA R ImageG amma[] ={' I ','m','a ', 'g' ,'e' , ' G','a ','m ' ,' m','a',0 };
  LP WS TR name ;    Me ta dat aIt em *r e sult ;

   hr = re ad_pn g _chunk(stream, type, &data,& da t a _s i ze); 
   if (FAILE D(hr ) ) re turn hr ;
   if  (dat a_ s iz e  < 4)
    {
       H eapFre e(Get ProcessHeap() , 0, data) ;        r etur n  E _ FAIL;
    }

   ga mma = read _ ulong_be (data );

   HeapFree( G e tProcess Hea p() , 0 , d a t a) ;

    result =  Hea pA lloc(Ge tPr ocessHe ap( ),HEA P_Z ER O_MEMORY,  sizeof( Me ta da ta Ite m));   name=Hea pA llo c(Get P rocess Heap( ), 0 ,si z eof (ImageG a mm a ) );
  i f (! res ul t ||! name ) 
   {
       Heap Fre e (Get Pr oc essHeap (), 0, result ); 
        H ea pFr ee(Get P r ocessHea p(), 0, name);
       r eturn E _OU TOFME MORY ;
    }
   PropV ari a ntInit (&
STR;
 _ _result[0].id.u.pszVal = name;
 _ _result[0].value.vt_= VT_LPSTR;
__  result[0].value.u.pszVal_= value;

 _  *items =_result;
  __*item_count = 1;

    HeapFree(GetProcessHeap(), 0, data);

    return S_OK;
}

static_const_MetadataHandlerVtbl TextReader_Vtbl_=_{
_   0,
 _  &CLSID_WICPngTextMetadataReader,
  _ LoadTextMetadata
};

HRESULT_PngTextReader_CreateInstance(REFIID iid, void** ppv)
{
    return_MetadataReader_Create(&TextReader_Vtbl,_iid, ppv);
}

static HRESULT_LoadGamaMetadata(IStream *stream, const GUID *preferred_vendor,
    DWORD_persist_options, MetadataItem **items, DWORD *item_count)
{
 _  HRESULT_hr;
__  BYTE type[4];
_   BYTE *data;
 _  ULONG data_size;
  _ ULONG gamma;
    static_const WCHAR ImageGamma[] = {'I','m','a','g','e','G','a','m','m','a',0};
 _  LPWSTR name;
 _ _MetadataItem *result;

   _hr = read_png_chunk(stream,_type, &data,_&data_size);
  _ if (FAILED(hr)) return hr;

 _  if_(data_size < 4)
   _{
_  ___ _HeapFree(GetProcessHeap(), 0, data);
__ __   return E_FAIL;
 __ }

    gamma =_read_ulong_be(data);

   _HeapFree(GetProcessHeap(),_0, data);

  _ result = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,_sizeof(MetadataItem));
    name =_HeapAlloc(GetProcessHeap(), 0,_sizeof(ImageGamma));
 _  if (!result ||!name)
    {
  _     HeapFree(GetProcessHeap(),_0, result);
  _ __  HeapFree(GetProcessHeap(),_0,_name);
 _      return_E_OUTOFMEMORY;
 _  }

   _PropVariantInit(&