Jump to content

FreeImage Library


ProgAndy
 Share

Recommended Posts

Updated to 3.15.0. Download is in the first post.

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

C:\Users\Jack\Desktop\freeimage0\FreeImage.au3(690,41) : ERROR: syntax error
Global Const $JPEG_OPTIMIZE = 0x20000 / /
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Users\Jack\Desktop\freeimage0\FreeImage.au3(691,41) : ERROR: syntax error
Global Const $JPEG_BASELINE = 0x40000 / /
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Users\Jack\Desktop\freeimage0\FreeImage.au3(732,27) : ERROR: syntax error
Global Const $TIFF_LOGLUV 0
~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Users\Jack\Desktop\freeimage0\FreeImage.au3(1755,163) : ERROR: syntax error
    Local $result = DllCall($__g_hFREEIMAGEDLL, "none", "_FreeImage_ConvertLine1To16_555@16", "ptr", $target, "ptr", $source, "int", $width_in_pixels, "ptr", palette)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    
C:\Users\Jack\Desktop\freeimage0\FreeImage.au3(1761,163) : ERROR: syntax error
    Local $result = DllCall($__g_hFREEIMAGEDLL, "none", "_FreeImage_ConvertLine4To16_555@16", "ptr", $target, "ptr", $source, "int", $width_in_pixels, "ptr", palette)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    
C:\Users\Jack\Desktop\freeimage0\FreeImage.au3(1767,163) : ERROR: syntax error
    Local $result = DllCall($__g_hFREEIMAGEDLL, "none", "_FreeImage_ConvertLine8To16_555@16", "ptr", $target, "ptr", $source, "int", $width_in_pixels, "ptr", palette)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    
C:\Users\Jack\Desktop\freeimage0\FreeImage.au3(1791,163) : ERROR: syntax error
    Local $result = DllCall($__g_hFREEIMAGEDLL, "none", "_FreeImage_ConvertLine1To16_565@16", "ptr", $target, "ptr", $source, "int", $width_in_pixels, "ptr", palette)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    
C:\Users\Jack\Desktop\freeimage0\FreeImage.au3(1797,163) : ERROR: syntax error
    Local $result = DllCall($__g_hFREEIMAGEDLL, "none", "_FreeImage_ConvertLine4To16_565@16", "ptr", $target, "ptr", $source, "int", $width_in_pixels, "ptr", palette)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    
C:\Users\Jack\Desktop\freeimage0\FreeImage.au3(1803,163) : ERROR: syntax error
    Local $result = DllCall($__g_hFREEIMAGEDLL, "none", "_FreeImage_ConvertLine8To16_565@16", "ptr", $target, "ptr", $source, "int", $width_in_pixels, "ptr", palette)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    
C:\Users\Jack\Desktop\freeimage0\FreeImage.au3(1827,159) : ERROR: syntax error
    Local $result = DllCall($__g_hFREEIMAGEDLL, "none", "_FreeImage_ConvertLine1To24@16", "ptr", $target, "ptr", $source, "int", $width_in_pixels, "ptr", palette)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    
C:\Users\Jack\Desktop\freeimage0\FreeImage.au3(1833,159) : ERROR: syntax error
    Local $result = DllCall($__g_hFREEIMAGEDLL, "none", "_FreeImage_ConvertLine4To24@16", "ptr", $target, "ptr", $source, "int", $width_in_pixels, "ptr", palette)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    
C:\Users\Jack\Desktop\freeimage0\FreeImage.au3(1839,159) : ERROR: syntax error
    Local $result = DllCall($__g_hFREEIMAGEDLL, "none", "_FreeImage_ConvertLine8To24@16", "ptr", $target, "ptr", $source, "int", $width_in_pixels, "ptr", palette)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    
C:\Users\Jack\Desktop\freeimage0\FreeImage.au3(1863,159) : ERROR: syntax error
    Local $result = DllCall($__g_hFREEIMAGEDLL, "none", "_FreeImage_ConvertLine1To32@16", "ptr", $target, "ptr", $source, "int", $width_in_pixels, "ptr", palette)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    
C:\Users\Jack\Desktop\freeimage0\FreeImage.au3(1869,159) : ERROR: syntax error
    Local $result = DllCall($__g_hFREEIMAGEDLL, "none", "_FreeImage_ConvertLine4To32@16", "ptr", $target, "ptr", $source, "int", $width_in_pixels, "ptr", palette)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    
C:\Users\Jack\Desktop\freeimage0\FreeImage.au3(1875,159) : ERROR: syntax error
    Local $result = DllCall($__g_hFREEIMAGEDLL, "none", "_FreeImage_ConvertLine8To32@16", "ptr", $target, "ptr", $source, "int", $width_in_pixels, "ptr", palette)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

Link to comment
Share on other sites

All work and no play makes Jack a dull boy.

All work and no play makes Jack a dull boy.

All work and no play makes Jack a dull boy.

All work and no play makes Jack a dull boy.

All work and no play makes Jack a dull boy.

All work and no play makes Jack a dull boy.

All work and no play makes Jack a dull boy.

All work and no play makes Jack a dull boy.

All work and no play makes Jack a dull boy.

All work and no play makes Jack a dull boy.

All work and no play makes Jack a dull boy.

All work and no play makes Jack a dull boy.

All work and no play makes Jack a dull boy.

All work and no play makes Jack a dull boy.

All work and no play makes Jack a dull boy.

All work and no play makes Jack a dull boy.

All work and no play makes Jack a dull boy.

All work and no play makes Jack a dull boy.

All work and no play makes Jack a dull boy.

All work and no play makes Jack a dull boy.

All work and no play makes Jack a dull boy.

All work and no play makes Jack a dull boy.

Link to comment
Share on other sites

Hey, I had corrected those errors. Did I forget to save? Reupload in a minute. Done.

@LaCastiglione: Thank you for that meaningful comment.

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

  • 1 month later...

Thank you very much for this :huh2:

I had a question as far as manipulating pixel data. I have everything working perfectly, until I get to the spot where I need to change the value that the "$bits" pointer points to.

#include <FreeImage.au3>
OnAutoItExitRegister("Cleanup")
func Main()
    _FreeImage_LoadDLL(@ScriptDir&"\FreeImage.dll")
    _FreeImage_Initialise()
    ;=============================================================================
    Global $image = _FreeImage_Load($FIF_TIFF, "test.tif")
    $bitdepth = _FreeImage_GetBPP($image)
    $bitsperpixel = _FreeImage_GetLine($image) / _FreeImage_GetWidth($image)
    Msgbox(0, "", $bitsperpixel)
    Local $bits
    ;$temp = _FreeImage_GetChannel($image, $FICC_RED)
    $y = 0
    $x = 0
    for $y = 0 to _FreeImage_GetHeight($image) step 1
        $bits = _FreeImage_GetScanLine($image, $y)
        ;Tooltip($bits)
        for $x = 0 to _FreeImage_GetWidth($image) step 1
            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            ;;;;;;;Manipulate Pixel here;;;;;;;;;
            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            $bits = $bits + $bitsperpixel
        next
    next
    Msgbox(0, "", "Done")
    _FreeImage_Save($FIF_TIFF, $image, "test.tif")

endfunc
Main()
Exit

func Cleanup()
    _FreeImage_Unload($image)
    _FreeImage_DeInitialise()
endfunc

I've been looking everywhere for how to manipulate data from a pointer (Like in C++, the simple *ptr), and all I'm getting is Cheat Engine stuff ;)

Link to comment
Share on other sites

Here is an example for 32bpp-bitmaps (invert the color: 0xAARRGGBB --> 0xAABBGGRR). For other pixel formats you have to change the code in the loop.

#include <FreeImage.au3>


_FreeImage_LoadDLL(@ScriptDir&"\FreeImage.dll")
_FreeImage_Initialise()
OnAutoItExitRegister("Cleanup")

$sFile = @DesktopDir&"\test.tif"

;=============================================================================
Global $image = _FreeImage_Load($FIF_TIFF, $sFile)
If Not $image Then Exit
$bitsperpixel = _FreeImage_GetBPP($image)
$bytespp = $bitsperpixel / 8
$iType = _FreeImage_GetImageType($image)
If $iType = $FIT_BITMAP And ($bitsperpixel = 32) Then
    $y = 0
    $x = 0
    $h = _FreeImage_GetHeight($image)
    $w = _FreeImage_GetWidth($image)
    for $y = 0 to $h-1 step 1
        $bits = _FreeImage_GetScanLine($image, $y)
        $t = DllStructCreate("align 4; dword[" & $w & "]", $bits)
        for $x = 1 to $w step 1
            $pix = DllStructGetData($t, 1, $x)
            $pix = BitOR(BitAND($pix, 0xFF00FF00), BitShift(BitAND($pix, 0x00FF0000), 16), BitShift(BitAND($pix, 0x000000FF), -16))
            DllStructSetData($t, 1, $pix, $x)
        next
    next
    _FreeImage_Save($FIF_TIFF, $image, @DesktopDir&"\test.tif")
    Msgbox(0, "", "Done")
Else
    MsgBox(0, '', "Not supported")
EndIf
_FreeImage_Unload($image)


Exit

func Cleanup()
    _FreeImage_DeInitialise()
endfunc
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

  • 5 months later...

Before saving as a GIF-image, you'll have to convert the image data to use a color pallette. (FreeImage_ColorQuantize)

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

My code:

#include <FreeImage.au3>
_FreeImage_LoadDLL(@ScriptDir&"FreeImage.dll")
_FreeImage_Initialise()
$sFile = "test.tif"
$FIF = _FreeImage_GetFileTypeU($sFile)
If $FIF = $FIF_UNKNOWN Then
    $FIF = _FreeImage_GetFIFFromFilenameU($sFile)
EndIf
$image = _FreeImage_LoadU($FIF, $sFile)
$bitsperpixel = _FreeImage_GetBPP($image)
MsgBox(0, '', "$bitsperpixel="&$bitsperpixel)
_FreeImage_Unload($image)
_FreeImage_DeInitialise()

When i use it on test.tif, result is "$bitsperpixel=24", but color of .tif is CMYK...

Why? How to use FreeImage with CMYK pictures?

Edited by One
Link to comment
Share on other sites

My code:

#include <FreeImage.au3>
_FreeImage_LoadDLL(@ScriptDir&"FreeImage.dll")
_FreeImage_Initialise()
$sFile = "test.tif"
$FIF = _FreeImage_GetFileTypeU($sFile)
If $FIF = $FIF_UNKNOWN Then
    $FIF = _FreeImage_GetFIFFromFilenameU($sFile)
EndIf
$image = _FreeImage_LoadU($FIF, $sFile)
$bitsperpixel = _FreeImage_GetBPP($image)
MsgBox(0, '', "$bitsperpixel="&$bitsperpixel)
_FreeImage_Unload($image)
_FreeImage_DeInitialise()

When i use it on test.tif, result is "$bitsperpixel=24", but color of .tif is CMYK...

Why? How to use FreeImage with CMYK pictures?

found mistake:

must be "$image = _FreeImage_LoadU($FIF, $sFile, $TIFF_CMYK)"

Link to comment
Share on other sites

  • 4 months later...

hi ProgAndy i found bug, or i can wrong

this work fine

#Include <FreeImage.au3>
$sFile = 'Test.png'
_FreeImage_LoadDLL(@ScriptDir & 'FreeImage.dll')
_FreeImage_Initialise()
$FIF = _FreeImage_GetFileTypeU($sFile)
If $FIF = $FIF_UNKNOWN Then
    $FIF = _FreeImage_GetFIFFromFilenameU($sFile)
EndIf
$hImage = _FreeImage_LoadU($FIF, $sFile)
$hGrey = _FreeImage_ConvertToGreyscale($hImage)
_FreeImage_SaveU($FIF_PNG, $hGrey, @ScriptDir & 'Test_Grey.png')
_FreeImage_Invert($hGrey)
_FreeImage_SaveU($FIF_PNG, $hGrey, @ScriptDir & 'Test_Grey_Inverse.png')
_FreeImage_Unload($hImage)
_FreeImage_Unload($hGrey)
_FreeImage_DeInitialise()

but this wrong

#Include <FreeImage.au3>
$PatchTXT = FileOpenDialog ( "Choice text file", @ScriptDir, "Text files (*.txt)", 2+16, "")
$TXT = FileOpen($PatchTXT, 0)
$sFile = 'Test.png'
_FreeImage_LoadDLL(@ScriptDir & 'FreeImage.dll')
_FreeImage_Initialise()
$FIF = _FreeImage_GetFileTypeU($sFile)
If $FIF = $FIF_UNKNOWN Then
    $FIF = _FreeImage_GetFIFFromFilenameU($sFile)
EndIf
$hImage = _FreeImage_LoadU($FIF, $sFile)
$hGrey = _FreeImage_ConvertToGreyscale($hImage)
_FreeImage_SaveU($FIF_PNG, $hGrey, @ScriptDir & 'Test_Grey.png')
_FreeImage_Invert($hGrey)
_FreeImage_SaveU($FIF_PNG, $hGrey, @ScriptDir & 'Test_Grey_Inverse.png')
_FreeImage_Unload($hImage)
_FreeImage_Unload($hGrey)
_FreeImage_DeInitialise()

script looking png file in directory where i choice txt file

but i have png in script dir

sorry for my eng i from ukraine )

Edited by SyavaK
Link to comment
Share on other sites

FileOpenDialog changes @WorkingDIr, so relative paths start from the new location. If you now the path is relative to the scriptfile, use @ScriptDir to create an absolute path.

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Looks like a captcha, which we don't discuss or help with.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • 3 months later...

How would i go about reducing the output file size? I start out with a JPEG roughly 150KB in size and once i run the following code it outputs at around 250KB's. Is there a way to down sample it a bit?I tried changing the filter but it didn't seem to change much.

Also would just like to thank you for making such an awesome script :)

Func _ProcessImage($Input, $Output)

$sFile = $Input
$iTWidth = 600
$iTHeight = 800
_FreeImage_Initialise()
$FIF = _FreeImage_GetFileTypeU($sFile)
If $FIF = $FIF_UNKNOWN Then
$FIF = _FreeImage_GetFIFFromFilenameU($sFile)
EndIf
$hImage = _FreeImage_LoadU($FIF, $sFile)

$oWidth = _FreeImage_GetWidth($hImage)
$oHeight = _FreeImage_GetHeight($hImage)

$Ratio = $oWidth / $oHeight
If $Ratio > 1 Then
$hImage = _FreeImage_RotateClassic($hImage, 90)
EndIf

$hImage = _FreeImage_Rescale($hImage, $iTWidth, $iTHeight, $FILTER_BILINEAR)
$hImage = _FreeImage_ConvertToGreyscale($hImage)

_FreeImage_SaveU($FIF_PNG, $hImage, $Output)

_FreeImage_Unload($hImage)
_FreeImage_DeInitialise()

EndFunc
Click here for the best AutoIt help possible.Currently Working on: Autoit RAT
Link to comment
Share on other sites

  • 4 months later...

Hi ProgAndy, thanks for your work on interfacing this lib; I seem to be having some issues with combining flags when saving using the "_FreeImage_SaveU" function, basically calling it like this:

_FreeImage_SaveU($FIF, $hImageResized, $Name &"_rsz"&$Ext, $JPEG_OPTIMIZE&'|'&$JPEG_SUBSAMPLING_422&'|'&$JPEG_QUALITYSUPERB)

But the results I am seeing does not indicate that the flags are being picked up right, file size way too small compared to simply passing the JPEG_QUALITYSUPERB flags on its own. Any ideas?

Link to comment
Share on other sites

Hi ProgAndy, thanks for your work on interfacing this lib; I seem to be having some issues with combining flags when saving using the "_FreeImage_SaveU" function, basically calling it like this:

_FreeImage_SaveU($FIF, $hImageResized, $Name &amp;amp;amp;"_rsz"&amp;amp;amp;$Ext, $JPEG_OPTIMIZE&amp;amp;amp;'|'&amp;amp;amp;$JPEG_SUBSAMPLING_422&amp;amp;amp;'|'&amp;amp;amp;$JPEG_QUALITYSUPERB)

But the results I am seeing does not indicate that the flags are being picked up right, file size way too small compared to simply passing the JPEG_QUALITYSUPERB flags on its own. Any ideas?

Hi,

did you try the BitOr function instead of the '&' sign?.

_FreeImage_SaveU($FIF, $hImageResized, $Name & "_rsz"&$Ext, BitOR($JPEG_OPTIMIZE,$JPEG_SUBSAMPLING_422,$JPEG_QUALITYSUPERB))
Edited by Sundance
Link to comment
Share on other sites

Andy,

i have also a problem. Hope you can give me a hint or two :-)

I need to make the white color of a quantized picture transparent. There is an example in the pdf

#include "FreeImage.h"
int main(int argc, char* argv[]) {
FIBITMAP *hDIB24bpp = FreeImage_Load(FIF_BMP, "test.bmp", 0);
if (hDIB24bpp) {
// color-quantize 24bpp (results in a 8bpp bitmap to set transparency)
FIBITMAP *hDIB8bpp = FreeImage_ColorQuantize(hDIB24bpp, FIQ_WUQUANT);
// get palette and find bright green
RGBQUAD *Palette = FreeImage_GetPalette(hDIB8bpp);
BYTE Transparency[256];
for (unsigned i = 0; i < 256; i++) {
Transparency[i] = 0xFF;
if (Palette[i].rgbGreen >= 0xFE &amp;&amp;
Palette[i].rgbBlue == 0x00 &amp;&amp;
Palette[i].rgbRed == 0x00) {
Transparency[i] = 0x00;
}
}
// set the tranparency table
FreeImage_SetTransparencyTable(hDIB8bpp, Transparency, 256);
// save 8bpp image as transparent PNG
FreeImage_Save(FIF_PNG, hDIB8bpp, "test.png", 0);
FreeImage_Unload(hDIB24bpp);
FreeImage_Unload(hDIB8bpp);
}
return 0;
}

My problem is; how can i create a proper structure for the palette? I think it should be 256 times a RGBQUAD structure but i have no idea how to set the value of (ex.) Palette.rgbBlue ....

Could be i think to complex but would be nice if you got an idea :-)

Thanks in advance and happy weekend

sundance

EDIT: I GOT IT. :-)

If someone is interested, i will post it after the weekend...

Edited by Sundance
Link to comment
Share on other sites

Hi,

did you try the BitOr function instead of the '&' sign?.

_FreeImage_SaveU($FIF, $hImageResized, $Name & "_rsz"&$Ext, BitOR($JPEG_OPTIMIZE,$JPEG_SUBSAMPLING_422,$JPEG_QUALITYSUPERB))

I could have sworn I did.. but obviously didn't because this works, thanks a lot for taking time to reply, made my day evening! :) Guess I took the advice about following the FreeImage PDF manual a bit too literal..
Link to comment
Share on other sites

Andy,

i have also a problem. Hope you can give me a hint or two :-)

I need to make the white color of a quantized picture transparent. There is an example in the pdf

#include "FreeImage.h"
int main(int argc, char* argv[]) {
FIBITMAP *hDIB24bpp = FreeImage_Load(FIF_BMP, "test.bmp", 0);
if (hDIB24bpp) {
// color-quantize 24bpp (results in a 8bpp bitmap to set transparency)
FIBITMAP *hDIB8bpp = FreeImage_ColorQuantize(hDIB24bpp, FIQ_WUQUANT);
// get palette and find bright green
RGBQUAD *Palette = FreeImage_GetPalette(hDIB8bpp);
BYTE Transparency[256];
for (unsigned i = 0; i < 256; i++) {
Transparency[i] = 0xFF;
if (Palette[i].rgbGreen >= 0xFE &amp;&amp;
Palette[i].rgbBlue == 0x00 &amp;&amp;
Palette[i].rgbRed == 0x00) {
Transparency[i] = 0x00;
}
}
// set the tranparency table
FreeImage_SetTransparencyTable(hDIB8bpp, Transparency, 256);
// save 8bpp image as transparent PNG
FreeImage_Save(FIF_PNG, hDIB8bpp, "test.png", 0);
FreeImage_Unload(hDIB24bpp);
FreeImage_Unload(hDIB8bpp);
}
return 0;
}

My problem is; how can i create a proper structure for the palette? I think it should be 256 times a RGBQUAD structure but i have no idea how to set the value of (ex.) Palette.rgbBlue ....

Could be i think to complex but would be nice if you got an idea :-)

Thanks in advance and happy weekend

sundance

EDIT: I GOT IT. :-)

If someone is interested, i will post it after the weekend...

I certainly am interested, do post away - used to hack a lot about with http://pngquant.org/ so be interested to see what freeimage can (not?) do when compared!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...