19 #include <thumbcache.h>
21 #pragma comment(lib, "shlwapi.lib")
26 class CBlendThumb :
public IInitializeWithStream,
public IThumbnailProvider {
42 static const QITAB qit[] = {
47 return QISearch(
this, qit, riid, ppv);
52 return InterlockedIncrement(&_cRef);
57 ULONG cRef = InterlockedDecrement(&_cRef);
65 IFACEMETHODIMP
Initialize(IStream *pStream, DWORD grfMode);
68 IFACEMETHODIMP
GetThumbnail(
UINT cx, HBITMAP *phbmp, WTS_ALPHATYPE *pdwAlpha);
78 HRESULT hr = pNew ? S_OK : E_OUTOFMEMORY;
89 HRESULT hr = E_UNEXPECTED;
90 if (_pStream ==
NULL) {
92 hr = pStream->QueryInterface(&_pStream);
106 HRESULT hr = S_FALSE;
107 LARGE_INTEGER SeekPos;
110 unsigned char in_magic[3];
111 _pStream->Read(&in_magic, 3, &BytesRead);
113 for (
int i = 0; i < 3; i++)
122 stream.zalloc = Z_NULL;
123 stream.zfree = Z_NULL;
124 stream.opaque = Z_NULL;
127 SeekPos.QuadPart = 0;
128 _pStream->Seek(SeekPos, STREAM_SEEK_END,
NULL);
138 dest_size = 1024 * 70;
140 source_size = (uLong)
max(SeekPos.QuadPart, dest_size);
143 Bytef *src =
new Bytef[source_size];
144 stream.next_in = (Bytef *)src;
145 stream.avail_in = (uInt)source_size;
148 Bytef *dest =
new Bytef[dest_size];
149 stream.next_out = (Bytef *)dest;
150 stream.avail_out = dest_size;
153 SeekPos.QuadPart = 0;
154 _pStream->Seek(SeekPos, STREAM_SEEK_SET,
NULL);
155 _pStream->Read(src, source_size, &BytesRead);
159 err = inflateInit2(&stream, 16);
160 err = inflate(&stream, Z_FINISH);
161 err = inflateEnd(&stream);
165 _pStream = SHCreateMemStream(dest, dest_size);
172 SeekPos.QuadPart = 9;
173 _pStream->Seek(SeekPos, STREAM_SEEK_SET,
NULL);
176 _pStream->Read(&version, 3, &BytesRead);
177 if (BytesRead != 3) {
180 int iVersion = atoi(version);
181 if (iVersion < 250) {
186 SeekPos.QuadPart = 7;
187 _pStream->Seek(SeekPos, STREAM_SEEK_SET,
NULL);
190 _pStream->Read(&_PointerSize, 1, &BytesRead);
192 int PointerSize = _PointerSize ==
'_' ? 4 : 8;
193 int HeaderSize = 16 + PointerSize;
196 SeekPos.QuadPart = 12;
197 _pStream->Seek(SeekPos, STREAM_SEEK_SET,
NULL);
198 int BlockOffset = 12;
205 if (_pStream->Read(BlockName, 4, &BytesRead) == S_OK &&
206 _pStream->Read((
void *)&BlockSize, 4, &BytesRead) == S_OK) {
207 if (strcmp(BlockName,
"TEST") != 0) {
208 SeekPos.QuadPart = BlockOffset += HeaderSize + BlockSize;
209 _pStream->Seek(SeekPos, STREAM_SEEK_SET,
NULL);
218 SeekPos.QuadPart = BlockOffset + HeaderSize;
219 _pStream->Seek(SeekPos, STREAM_SEEK_SET,
NULL);
222 _pStream->Read((
char *)&
width, 4, &BytesRead);
223 _pStream->Read((
char *)&
height, 4, &BytesRead);
227 char *pRGBA =
new char[BlockSize];
228 _pStream->Read(pRGBA, BlockSize, &BytesRead);
230 if (BytesRead != (ULONG)BlockSize) {
235 for (
int i = 0; i < BlockSize; i += 4) {
236 #define RED_BYTE pRGBA[i]
237 #define BLUE_BYTE pRGBA[i + 2]
245 unsigned int LineSize =
width * 4;
246 char *FlippedImage =
new char[BlockSize];
247 for (
int i = 0; i <
height; i++) {
248 if (0 != memcpy_s(&FlippedImage[(
height - i - 1) * LineSize],
250 &pRGBA[i * LineSize],
256 pRGBA = FlippedImage;
259 *phbmp = CreateBitmap(
width,
height, 1, 32, pRGBA);
263 *pdwAlpha = WTSAT_ARGB;
266 if ((
unsigned)
width > cx || (
unsigned)
height > cx) {
268 LONG NewWidth = (LONG)(
width * scale);
269 LONG NewHeight = (LONG)(
height * scale);
273 MessageBox(0,
"Attach now",
"Debugging", MB_OK);
276 IWICImagingFactory *pImgFac;
277 hr = CoCreateInstance(
278 CLSID_WICImagingFactory,
NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pImgFac));
281 hr = pImgFac->CreateBitmapFromHBITMAP(*phbmp, 0, WICBitmapUseAlpha, &WICBmp);
284 bmi.bmiHeader.biSize =
sizeof(bmi.bmiHeader);
285 bmi.bmiHeader.biWidth = NewWidth;
286 bmi.bmiHeader.biHeight = -NewHeight;
287 bmi.bmiHeader.biPlanes = 1;
288 bmi.bmiHeader.biBitCount = 32;
289 bmi.bmiHeader.biCompression = BI_RGB;
292 HBITMAP ResizedHBmp = CreateDIBSection(
NULL, &bmi, DIB_RGB_COLORS, (
void **)&pBits,
NULL, 0);
293 hr = ResizedHBmp ? S_OK : E_OUTOFMEMORY;
295 IWICBitmapScaler *pIScaler;
296 hr = pImgFac->CreateBitmapScaler(&pIScaler);
297 hr = pIScaler->Initialize(WICBmp, NewWidth, NewHeight, WICBitmapInterpolationModeFant);
299 WICRect rect = {0, 0, NewWidth, NewHeight};
300 hr = pIScaler->CopyPixels(&rect, NewWidth * 4, NewWidth * NewHeight * 4, pBits);
303 DeleteObject(*phbmp);
304 *phbmp = ResizedHBmp;
307 DeleteObject(ResizedHBmp);
typedef float(TangentPoint)[2]
HRESULT CBlendThumb_CreateInstance(REFIID riid, void **ppv)
const unsigned char gzip_magic[3]
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
IFACEMETHODIMP Initialize(IStream *pStream, DWORD grfMode)
IFACEMETHODIMP_(ULONG) AddRef()
IFACEMETHODIMP QueryInterface(REFIID riid, void **ppv)
IFACEMETHODIMP GetThumbnail(UINT cx, HBITMAP *phbmp, WTS_ALPHATYPE *pdwAlpha)
IFACEMETHODIMP_(ULONG) Release()