Lego Mindstorms Reference    
This website and I have no affiliation whatsoever with the Lego group. Lego, Lego Systems and Lego MindStorms are trademarks of the Lego group. Jpeg is a trademark of the Independent Joint Picture Experts Group.
By entering this site, you agree to not hold me responsible for any damage that may occur from use of this website.
Use this information at your own risk.


cJpeg Library
This library I wrote as an ActiveX wrapper DLL for the Intel Jpeg Lib (IJL) library. The main purpose of this is to allow Active Server Pages to create Jpeg thumbnails on the fly (for example, see brickbots.com for my first user). This download is a massive 90K! It contains three parts: It also contains the Readme file (4K) which explains how to use the library, where to get updates (here, of course), and exactly what the functions return.

Download (Primary Mirror) Download (Tripod Mirror) The Function Ref is towards the end of the Readme file:
README.TXT
Object written by Tim Hatch (vbq at myrealbox dot com)
(c)2001 Tim Hatch
Freeware for noncommercial and Lego site use (email me for commercial license info).
The soruce code for software is available upon request.


THIS LIBRARY REQUIRES VB6 RUNTIMES.  You may download the RT installer from
	(http://download.microsoft.com/download/vb60pro/install/6/Win98Me/EN-US/VBRun60.exe).
	If this does not work for your platform (assuming it's Windows) contact me and I'll
	search the knowledgebase for you.

INSTALL:
Unzip ijl10.zip
Read the license (you need to "agree" also) and unzip ijl10.dll to /winnt/system32.
Copy the Jpeglib.dll (which is an ActiveX component) to /winnt/system32 also
Run Regsvr32 on jpeglib.dll file to get the RegKeys installed.
	NOTE: regsvr32 is located in system/system32.  If you have no regsvr32,
	please try regsvr.exe.  The command line (in a command prompt in /winnt/system32 is
	C:\winnt\system32\>REGSVR32 JPEGLIB.DLL
	You should then get a "register successful" type of message (or at least no error
	messages)


USAGE:
That's it for the install.  Then, in your script, use this syntax:
    Set J = CreateObject("JpegLib.cJpeg")
    J.Load("c:\temp\0001.jpg")
    if J.Width > 0 then
        'File loaded correctly
        J.SaveModified(120,0,"c:\temp\0001new.jpg",60)
    end if
    Set J = Nothing
    
    All Errors are suppressed, please use Width or Height, in addition to return values,
        to determine if the operation completed correctly.
    Please report any bugs to the email address at the top.  Also email that address to
        be added to the bugfix list (please include  [JpegLib] in the subject line).

    This library cannot be used with PHP.  Please use GD (freely available under the GPL)
        for this purpose.

To verify the install worked correctly, please run testlib.exe and follow its instructions.

UNINSTALL:
    Run regsvr32.exe /u dllname.dll
    Delete jpeglib.dll
    Delete ijl10.dll

REFERENCE:
    Public Function Load(ByVal Fname As Variant) As Variant
    Checks to see if the rightmost character of Fname is "g", if so, opens as a jpeg file.
        Otherwise, tries to use GIF, BMP, WMF library.  When loading GIFs, returns width.
        Returns nonzero (width) on success for GIFs, zero on success for Jpegs (feature.
        Not a bug).  If Jpeg load returns a negative number, it is an error-code.  Possible
        codes are:
          
          -1: Failed to load JPEG.  File not found or bad permissions.  Or something else.
              This is the "generic cannot load image" error.
          -2: Cannot read JPEG data from file.  Invalid or unkonwn format.  File opened
              successfully, but no useful data was retrived from it.
          -4: Failed to init IJL lib.  The ijl10.dll was not loaded (for example, did not exist in 
              winnt/system32; system out of memory/stack; wrong version; or corrupt DLL)
          
          NOTE TO DEVELOPERS:  Error codes returned are nonstandard with the ones mentioned
          in the IJL enum.  The original error-codes were returned only by the ijl_load DLL
          call.  Uncomment the msgbox lines to return to non-quiet operation.

    Public Function SaveModified(ByVal Width As Variant, ByVal Height As Variant, ByVal _
        filename As Variant, ByVal qual As Variant) As Variant
    This forces a save as a jpeg file, compression and dimensions set at runtime.  If
        height is 0, autocompute.  If you want to vary the width, keeping height constant,
        query parameters below, and give this function the dimensions.  To get the img
        height and width tags, compute at runtime by querying params, below.
    If you wish to enlarge the image, you may do so, but it won't look pretty.  Please do
        not use 0 for the Width parameter, as this may cause the computer to hang (or at
        least not do anything useful).  This is a guarranted runtime-error-or-corrupt-file.
    When saving files, do ensure that the destination file does not exist!  If it does,
        the binary write will overlap, causing strange things to happen if the new file
        is smaller (in byte size).

    Public Property Get Height() As Variant
    Height, in pixels, of image.  If no image loaded, returns 0.

    Public Property Get Width() As Variant
    Width, in pixels, of image.  If no image loaded, returns 0.

    Public Property Get ByteSize() As Variant
    Image size, in bytes.  Useful for determining savings in size old/new.  For example,
        create thumb using lib, querying "before" size.  Then, set object=nothing and
        recreate.  Open the new thumbnail and query size.  If the new one is larger than
        the old one, just use the old one as the image, but keep the size tags from the
        thumbnail (in proportion).

---------------------

    This class uses a dibsection when loading image.  At least one GDI handle will be in use when an
        image is loaded.  Loading GIFs will require use of approximately three extra temp
        handles, and will be considerably slower.  They will save at the same speed,
        however, because the slowness is in loading using VB-native objects.



Any troubles, just email me.
Tim Hatch
updates on http://vbq1.tripod.com/

This library probably wouldn't have been available (for free certainly!) without the advanced programming examples of vbAccelerator. Some help also provided by vbweb.
-Tim
BTW: If you've got feedback on the library or the site, feel free to email me or fill out the Feedback Form.


I try for correctness in the Ldraw files and text, but of you see any errors, omissions or other problems, please email me at vbq at myrealbox dot com. (The only purpose of the odd notation is to foil spambots)