{
file.Seek(Tizen::Io::FILESEEKPOSITION_BEGIN, 0);
- bool isFound = false;\r
+ bool isFound = false;
while (!isFound)
{
switch (blockID[1])
{
- case 0xC0:\r
- case 0xC1:\r
- case 0xC2:\r
- {\r
+ case 0xC0:
+ case 0xC1:
+ case 0xC2:
+ {
unsigned char colorInfo[7];
if (file.Read(colorInfo, sizeof(colorInfo)) != sizeof(colorInfo))
isFound = true;
break;
}
-\r
- outWidth = colorInfo[5] * 256 + colorInfo[6];\r
- outHeight = colorInfo[3] * 256 + colorInfo[4];\r
-\r
- return true;\r
- }\r
- case 0xD8:\r
- // SOI found\r
- break;\r
- case 0xD9:\r
- isFound = true;\r
- break;\r
- default:\r
- {\r
+
+ outWidth = colorInfo[5] * 256 + colorInfo[6];
+ outHeight = colorInfo[3] * 256 + colorInfo[4];
+
+ return true;
+ }
+ case 0xD8:
+ // SOI found
+ break;
+ case 0xD9:
+ isFound = true;
+ break;
+ default:
+ {
unsigned char skipbytes[2];
if (file.Read(skipbytes, sizeof(skipbytes)) != sizeof(skipbytes))
isFound = true;
break;
}
-\r
- int skip = skipbytes[0] * 256 + skipbytes[1];\r
+
+ int skip = skipbytes[0] * 256 + skipbytes[1];
file.Seek(Tizen::Io::FILESEEKPOSITION_CURRENT, skip - 2);
-\r
- break;\r
- }\r
+
+ break;
+ }
}
}
}
}
_OSP_EXPORT_ bool _SaveToBmp(unsigned long* pBuffer, int width, int height, int pixelPerLine, const Tizen::Base::String& fileName)
-{\r
- unsigned char bmpFileHeader[] =\r
- {\r
- 0x42, 0x4D,\r
- 0x00, 0x00, 0x00, 0x00, // size\r
- 0x00, 0x00,\r
- 0x00, 0x00,\r
- 0x36, 0x00, 0x00, 0x00 // offset\r
- };\r
-\r
- unsigned char bmpDibHeader[] =\r
- {\r
- 0x28, 0x00, 0x00, 0x00,\r
- 0x00, 0x00, 0x00, 0x00, // width\r
- 0x00, 0x00, 0x00, 0x00, // height\r
- 0x01, 0x00,\r
- 0x18, 0x00,\r
- 0x00, 0x00, 0x00, 0x00,\r
- 0x00, 0x00, 0x00, 0x00, // image size\r
- 0x00, 0x00, 0x00, 0x00,\r
- 0x00, 0x00, 0x00, 0x00,\r
- 0x00, 0x00, 0x00, 0x00,\r
- 0x00, 0x00, 0x00, 0x00\r
- };\r
-\r
- int dstPitch = width * 3;\r
-\r
- while (dstPitch % 4)\r
- {\r
- ++dstPitch;\r
- }\r
-\r
- int imageSize = dstPitch * height;\r
- int offset = sizeof(bmpFileHeader) + sizeof(bmpDibHeader);\r
-\r
- // fill in the reserved fields \r
- {\r
- struct _LittleEndian\r
- {\r
- static inline void Write(unsigned char* pBuffer, unsigned long data)\r
- {\r
- pBuffer[0] = (data >> 0) & 0xFF;\r
- pBuffer[1] = (data >> 8) & 0xFF;\r
- pBuffer[2] = (data >> 16) & 0xFF;\r
- pBuffer[3] = (data >> 24) & 0xFF;\r
- }\r
- };\r
-\r
- // offset (little endian)\r
- _LittleEndian::Write(&bmpFileHeader[2], imageSize + offset);\r
- // offset (little endian)\r
- _LittleEndian::Write(&bmpFileHeader[10], offset);\r
- // width (little endian)\r
- _LittleEndian::Write(&bmpDibHeader[4], width);\r
- // height (little endian)\r
- _LittleEndian::Write(&bmpDibHeader[8], height);\r
- // image size (little endian)\r
- _LittleEndian::Write(&bmpDibHeader[20], imageSize);\r
- }\r
-\r
- Tizen::Io::File file;\r
-\r
- result r = file.Construct(fileName, "wb");\r
-\r
- if (r != E_SUCCESS)\r
- {\r
- return false;\r
- }\r
-\r
- file.Write(bmpFileHeader, sizeof(bmpFileHeader));\r
- file.Write(bmpDibHeader, sizeof(bmpDibHeader));\r
-\r
- {\r
- typedef unsigned long SourPixel;\r
- typedef unsigned char DestPixel;\r
-\r
- _Util::AutoPtr<DestPixel> lineBuffer(new DestPixel[dstPitch]);\r
-\r
- for (int y = 0; y < height; y++)\r
- {\r
- memset(lineBuffer.Get(), 0, dstPitch);\r
-\r
- SourPixel* pSour32 = pBuffer + pixelPerLine * (height - y - 1);\r
- DestPixel* pDest08 = lineBuffer.Get();\r
-\r
- for (int x = 0; x < width; x++)\r
- {\r
- *pDest08++ = (unsigned char)(*pSour32);\r
- *pDest08++ = (unsigned char)(*pSour32 >> 8);\r
- *pDest08++ = (unsigned char)(*pSour32 >> 16);\r
-\r
- ++pSour32;\r
- }\r
-\r
- file.Write(lineBuffer.Get(), dstPitch);\r
- }\r
-\r
- }\r
-\r
- return true;\r
+{
+ unsigned char bmpFileHeader[] =
+ {
+ 0x42, 0x4D,
+ 0x00, 0x00, 0x00, 0x00, // size
+ 0x00, 0x00,
+ 0x00, 0x00,
+ 0x36, 0x00, 0x00, 0x00 // offset
+ };
+
+ unsigned char bmpDibHeader[] =
+ {
+ 0x28, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, // width
+ 0x00, 0x00, 0x00, 0x00, // height
+ 0x01, 0x00,
+ 0x18, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, // image size
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00
+ };
+
+ int dstPitch = width * 3;
+
+ while (dstPitch % 4)
+ {
+ ++dstPitch;
+ }
+
+ int imageSize = dstPitch * height;
+ int offset = sizeof(bmpFileHeader) + sizeof(bmpDibHeader);
+
+ // fill in the reserved fields
+ {
+ struct _LittleEndian
+ {
+ static inline void Write(unsigned char* pBuffer, unsigned long data)
+ {
+ pBuffer[0] = (data >> 0) & 0xFF;
+ pBuffer[1] = (data >> 8) & 0xFF;
+ pBuffer[2] = (data >> 16) & 0xFF;
+ pBuffer[3] = (data >> 24) & 0xFF;
+ }
+ };
+
+ // offset (little endian)
+ _LittleEndian::Write(&bmpFileHeader[2], imageSize + offset);
+ // offset (little endian)
+ _LittleEndian::Write(&bmpFileHeader[10], offset);
+ // width (little endian)
+ _LittleEndian::Write(&bmpDibHeader[4], width);
+ // height (little endian)
+ _LittleEndian::Write(&bmpDibHeader[8], height);
+ // image size (little endian)
+ _LittleEndian::Write(&bmpDibHeader[20], imageSize);
+ }
+
+ Tizen::Io::File file;
+
+ result r = file.Construct(fileName, "wb");
+
+ if (r != E_SUCCESS)
+ {
+ return false;
+ }
+
+ file.Write(bmpFileHeader, sizeof(bmpFileHeader));
+ file.Write(bmpDibHeader, sizeof(bmpDibHeader));
+
+ {
+ typedef unsigned long SourPixel;
+ typedef unsigned char DestPixel;
+
+ _Util::AutoPtr<DestPixel> lineBuffer(new DestPixel[dstPitch]);
+
+ for (int y = 0; y < height; y++)
+ {
+ memset(lineBuffer.Get(), 0, dstPitch);
+
+ SourPixel* pSour32 = pBuffer + pixelPerLine * (height - y - 1);
+ DestPixel* pDest08 = lineBuffer.Get();
+
+ for (int x = 0; x < width; x++)
+ {
+ *pDest08++ = (unsigned char)(*pSour32);
+ *pDest08++ = (unsigned char)(*pSour32 >> 8);
+ *pDest08++ = (unsigned char)(*pSour32 >> 16);
+
+ ++pSour32;
+ }
+
+ file.Write(lineBuffer.Get(), dstPitch);
+ }
+
+ }
+
+ return true;
}
_OSP_EXPORT_ bool _SaveToBmp(const Canvas& canvas, const Tizen::Base::String& fileName)
{
bool r = false;
- BufferInfo bi;\r
-\r
- const_cast<Canvas*>(&canvas)->Lock(bi);\r
-\r
- if (bi.bitsPerPixel == 32)\r
- {\r
- r = _SaveToBmp((unsigned long*)bi.pPixels, bi.width, bi.height, bi.pitch * 8 / bi.bitsPerPixel, fileName);\r
- }\r
-\r
- const_cast<Canvas*>(&canvas)->Unlock();\r
-\r
- return r;\r
+ BufferInfo bi;
+
+ const_cast<Canvas*>(&canvas)->Lock(bi);
+
+ if (bi.bitsPerPixel == 32)
+ {
+ r = _SaveToBmp((unsigned long*)bi.pPixels, bi.width, bi.height, bi.pitch * 8 / bi.bitsPerPixel, fileName);
+ }
+
+ const_cast<Canvas*>(&canvas)->Unlock();
+
+ return r;
}
_OSP_EXPORT_ bool _SaveToBmp(const Bitmap& bitmap, const Tizen::Base::String& fileName)
{
bool r = false;
- BufferInfo bi;\r
-\r
- const_cast<Bitmap*>(&bitmap)->Lock(bi);\r
-\r
- if (bi.bitsPerPixel == 32)\r
- {\r
- r = _SaveToBmp((unsigned long*)bi.pPixels, bi.width, bi.height, bi.pitch * 8 / bi.bitsPerPixel, fileName);\r
- }\r
-\r
- const_cast<Bitmap*>(&bitmap)->Unlock();\r
-\r
- return r;\r
+ BufferInfo bi;
+
+ const_cast<Bitmap*>(&bitmap)->Lock(bi);
+
+ if (bi.bitsPerPixel == 32)
+ {
+ r = _SaveToBmp((unsigned long*)bi.pPixels, bi.width, bi.height, bi.pitch * 8 / bi.bitsPerPixel, fileName);
+ }
+
+ const_cast<Bitmap*>(&bitmap)->Unlock();
+
+ return r;
}
}} // Tizen::Graphics