The default remote tiff file is www.catenary.com/howto/ibit.tif, a 1-bit tiff with group 4 compression.
Requires Victor Image Processing Library for 32-bit Windows static link library, vic32ss.lib.
These are the important functions extracted from the t2j.cpp file. For the complete ActiveX project source files download t2jsrc.zip
' ............................... Includes, Globals, and the Class methods .............................
#include "wininet.h"
#include <vicdefs.h>
int bringinthe_tif(imgdes *image);
int load_tif_local(void);
//................................. Globals
char *Srcname;
char *Desname;
//................................. Methods
STDMETHODIMP t2j::setremotetifname(BSTR remotetifname)
{
char *localstring;
int length;
if(Srcname != 0)
free(Srcname);
localstring = (char *)(((BYTE *)remotetifname) + 0x00);
length = (int)SysStringLen(remotetifname);
if(length > 0) {
Srcname = (char *)calloc(length+1, 1);
WideCharToMultiByte(
0,
0,
(LPCWSTR)localstring,
length,
(LPSTR) Srcname,
length + 1,
0,
0
);
}
return S_OK;
}
STDMETHODIMP t2j::setlocaljpgname(BSTR localjpgname)
{
char *localstring;
int length;
if(Desname != 0)
free(Desname);
localstring = (char *)(((BYTE *)localjpgname) + 0x00);
length = (int)SysStringLen(localjpgname);
if(length > 0) {
Desname = (char *)calloc(length+1, 1);
WideCharToMultiByte(
0,
0,
(LPCWSTR)localstring,
length,
(LPSTR) Desname,
length + 1,
0,
0
);
}
return S_OK;
}
STDMETHODIMP t2j::remotetif2localjpg()
{
int rcode;
imgdes timage;
rcode = allocimage(&timage, 256, 256, 8); // a default image
if(rcode == NO_ERROR) {
rcode = bringinthe_tif(&timage);
freeimage(&timage);
}
return S_OK;
}
// ............................... Helper functions .............................
int bringinthe_tif(imgdes *image)
{
LPTSTR fname;
HINTERNET hOpen;
HINTERNET hOpenUrl = 0;
int rcode = -1;
LPVOID filebuff = 0;
DWORD filesize, bytesread;
TiffData tdat;
BOOL nRc, imageAllocd = FALSE;
fname = Srcname;
hOpen = InternetOpen("Victor Library Sample", INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0);
hOpenUrl = InternetOpenUrl(hOpen, fname, 0, 0, INTERNET_FLAG_RELOAD, 0);
if(hOpenUrl) {
// Get size of file with handle hOpenUrl
filesize = getInetFileSize(hOpenUrl);
if(filesize != 0) {
// Allocate space to hold the tiff file
filebuff = (LPVOID)calloc(filesize, sizeof(BYTE));
if(filebuff) {
// Read file into filebuff
nRc = InternetReadFile(hOpenUrl, filebuff, filesize, &bytesread);
if(nRc == TRUE) {
rcode = tiffinfofrombuffer((UCHAR *)filebuff, &tdat);
if(rcode == NO_ERROR) {
rcode = allocimage(image, tdat.width, tdat.length, tdat.vbitcount);
if(rcode == NO_ERROR) {
imageAllocd = TRUE; // Set flag that image was allocated
rcode = loadtiffrombuffer((UCHAR *)filebuff, image);
if(rcode == NO_ERROR) {
if(tdat.vbitcount == 1) { // If 1-bit image, create 8-bit version of it
imgdes timage;
rcode = allocimage(&timage, tdat.width, tdat.length, 8);
if(rcode == NO_ERROR) {
rcode = convert1bitto8bit(image, &timage); // could also use:convert1bitto8bitsmooth for scale-to-gray effect
if(rcode == NO_ERROR) {
freeimage(image); // free original image
// Replace original image data with that describing the smoothed 8-bit image
copyimgdes(&timage, image); // copy data structure info
}
else
freeimage(&timage);
}
}
rcode = savejpg(Desname, image, 75);
}
}
}
}
}
}
}
// Free all!
if(imageAllocd == TRUE)
freeimage(image);
if(filebuff)
free(filebuff);
if(hOpenUrl)
InternetCloseHandle(hOpenUrl);
if(hOpen)
InternetCloseHandle(hOpen);
return(rcode);
}
// Get size of file with handle hOpenUrl
static DWORD getInetFileSize(HINTERNET hOpenUrl)
{
#define FILEDATA_SIZE 32
DWORD lenbufsiz = FILEDATA_SIZE;
TCHAR filedata[FILEDATA_SIZE];
BOOL nRc;
DWORD filesize = 0;
nRc = HttpQueryInfo(hOpenUrl, HTTP_QUERY_CONTENT_LENGTH, (LPVOID)filedata, &lenbufsiz, (LPDWORD)0);
if(nRc == TRUE) // Get size of file
filesize = atol(filedata);
return(filesize);
}
<object
id = "t2j"
codebase = "http://www.catenary.com/howto/tif2jpg.dll"
classid = "CLSID:6875EE0C-CCB1-47DB-AEDF-A65F2B266F5E"
>
<span style="color:red"<ActiveX control tif2jpg.dll failed to load!
-- Please check browser security settings.</span>
</object>
<form name="testsendsrc">
Remote TIFF file name url:
<input type = "text" name = "srcfilename" value = "http://www.catenary.com/howto/1bit.tif" size = "50" maxlength = "100" >
<br>
Local JPEG file name, complete path:
<input type = "text" name = "desfilename" value = "c:\test.jpg" size = "50" maxlength = "100" >
<br>
<input type = "button" name = "rcd" value = "Load, convert, display" onclick = "convert();check_for_ready()" >
</form>
<script language="javascript">
var rc;
var timerid;
function convert(){
t2j.setremotetifname(document.testsendsrc.srcfilename.value);
t2j.setlocaljpgname(document.testsendsrc.desfilename.value);
t2j.remotetif2localjpg();
rc = 1;
}
function check_for_ready(){
if (rc == 0)
timerid = setTimeout("check_for_ready()", 100);
if (rc == 1) {
td.src = document.testsendsrc.desfilename.value;
rc = 0;
}
}
</script>
Victor Image Processing Library homepage | Victor Product Summary | more source code
Copyright © 2002 Catenary Systems Inc. All rights reserved. Victor Image Processing Library is a trademark of Catenary Systems.