Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / osx / PictToBmpFlt.cxx
blob77c67a654107a750613535f196ce7a636a64d4d4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <premac.h>
21 #include <Carbon/Carbon.h>
22 #include <QuickTime/QuickTime.h>
23 #include <postmac.h>
25 #include <string.h>
27 #include "PictToBmpFlt.hxx"
29 bool ImageToPNG( com::sun::star::uno::Sequence<sal_Int8>& rImgData,
30 com::sun::star::uno::Sequence<sal_Int8>& rPngData,
31 NSBitmapImageFileType eInFormat)
33 (void) eInFormat; // Really not needed? Weird.
35 NSData* pData = [NSData dataWithBytesNoCopy: (void*)rImgData.getConstArray() length: rImgData.getLength() freeWhenDone: 0];
36 if( !pData)
37 return false;
39 NSBitmapImageRep* pRep =[NSBitmapImageRep imageRepWithData: pData];
40 if( !pRep)
41 return false;
43 NSData* pOut = [pRep representationUsingType: NSPNGFileType properties: nil];
44 if( !pOut)
45 return false;
47 const size_t nPngSize = [pOut length];
48 rPngData.realloc( nPngSize);
49 [pOut getBytes: rPngData.getArray() length: nPngSize];
50 return (nPngSize > 0);
53 bool PNGToImage( com::sun::star::uno::Sequence<sal_Int8>& rPngData,
54 com::sun::star::uno::Sequence<sal_Int8>& rImgData,
55 NSBitmapImageFileType eOutFormat
58 NSData* pData = [NSData dataWithBytesNoCopy: const_cast<sal_Int8*>(rPngData.getConstArray()) length: rPngData.getLength() freeWhenDone: 0];
59 if( !pData)
60 return false;
62 NSBitmapImageRep* pRep = [NSBitmapImageRep imageRepWithData: pData];
63 if( !pRep)
64 return false;
66 NSData* pOut = [pRep representationUsingType: eOutFormat properties: nil];
67 if( !pOut)
68 return false;
70 const size_t nImgSize = [pOut length];
71 rImgData.realloc( nImgSize);
72 [pOut getBytes: rImgData.getArray() length: nImgSize];
73 return (nImgSize > 0);
76 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */