/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a license // agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// #include "OdaCommon.h" #include "BmpFileCreator.h" #include "MemoryStream.h" #include "OdPlatformStreamer.h" #include "RxRasterServices.h" #include "Gi/GiRasterImage.h" #include "RxInit.h" /*static*/ OdStreamBufPtr BmpFileCreator::createBmpFromSource(const OdUInt8 * data, int width, int height, int byteCount) { BITMAPINFOHEADER bmiHeader; memset(&bmiHeader, 0, sizeof(BITMAPINFOHEADER)); bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmiHeader.biBitCount = 4 * 8; bmiHeader.biCompression = 0L; bmiHeader.biHeight = height; bmiHeader.biPlanes = 1; bmiHeader.biWidth = width; bmiHeader.biSizeImage = width * height * byteCount; OdStreamBufPtr pFileBuf = OdMemoryStream::createNew(sizeof(BITMAPINFOHEADER) + width * height * byteCount); OdPlatformStreamer::wrInt16(*pFileBuf, 0x4d42); OdUInt32 scanLinesPos = (OdUInt32)sizeof(BITMAPFILEHEADER) + (OdUInt32)sizeof(BITMAPINFOHEADER) + 0; // Below version is correct only on Windows OdUInt32 size = scanLinesPos + OdGiRasterImage::calcBMPScanLineSize(bmiHeader.biWidth, bmiHeader.biBitCount) * bmiHeader.biHeight; OdPlatformStreamer::wrInt32(*pFileBuf, size); OdPlatformStreamer::wrInt32(*pFileBuf, 0); // reserved OdPlatformStreamer::wrInt32(*pFileBuf, scanLinesPos); // offBits OdPlatformStreamer::wrInt32(*pFileBuf, bmiHeader.biSize); // not portable: sizeof(BITMAPINFOHEADER)); // save BITMAPINFOHEADER OdPlatformStreamer::wrInt32(*pFileBuf, bmiHeader.biWidth); OdPlatformStreamer::wrInt32(*pFileBuf, bmiHeader.biHeight); OdPlatformStreamer::wrInt16(*pFileBuf, bmiHeader.biPlanes); OdPlatformStreamer::wrInt16(*pFileBuf, bmiHeader.biBitCount); OdPlatformStreamer::wrInt32(*pFileBuf, bmiHeader.biCompression); OdPlatformStreamer::wrInt32(*pFileBuf, bmiHeader.biSizeImage); OdPlatformStreamer::wrInt32(*pFileBuf, bmiHeader.biXPelsPerMeter); OdPlatformStreamer::wrInt32(*pFileBuf, bmiHeader.biYPelsPerMeter); OdPlatformStreamer::wrInt32(*pFileBuf, bmiHeader.biClrUsed); OdPlatformStreamer::wrInt32(*pFileBuf, bmiHeader.biClrImportant); //OdUInt32 tmp = 0; //pFileBuf->putBytes(&tmp, 4); //tmp = 0xffffff; //pFileBuf->putBytes(&tmp, 4); pFileBuf->putBytes(data, bmiHeader.biSizeImage); pFileBuf->rewind(); return pFileBuf; }