diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 3831b73ef1..139e0429f7 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,44 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ +2007-11-16 01:25 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) + + contrib/freeimage + + contrib/freeimage/Makefile + + contrib/freeimage/make_b32.bat + + contrib/freeimage/make_vc.bat + + contrib/freeimage/common.mak + + contrib/freeimage/freeimage.ch + + contrib/freeimage/fi_winfu.c + + contrib/freeimage/fi_wrp.c + + contrib/freeimage/readme.txt + + contrib/freeimage/test + + contrib/freeimage/test/bld_b32.bat + + contrib/freeimage/test/fitest.prg + + contrib/freeimage/test/sample1.jpg + + contrib/freeimage/test/italia.gif + + contrib/freeimage/test/fsg.jpg + + contrib/freeimage/test/images_out + + Added FreeImage OSS library Harbour interface. + ! Some minor fixes and file rearrangements made. + + Added std make files. + ; TOFIX: There is still a potentially dangerous + warning to be fixed in FI_GETBACKGROUNDCOLOR() + ; Borrowed from xhb. + ; NOTE: The lib made some features available through the xhb + specific C struct functionality. Since such functionality + is not implemented in Harbour, the library would need + to be extened with some more wrappers to make C level + vars accessible from Harbour code. But even without + this functionality, the lib seems quite useful. + ; NOTE: The lib also has some Windows specific + + + contrib/xhb/hbfast.h + + Added this file to enhance C interface code compatibility + with xhb. + + * contrib/firebird/* + ! Fixed SVN properties. + 2007-11-15 20:44 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) + contrib/firebird + contrib/firebird/Makefile diff --git a/harbour/contrib/firebird/Makefile b/harbour/contrib/firebird/Makefile index 9ddd1fe990..4b5bb19a56 100644 --- a/harbour/contrib/firebird/Makefile +++ b/harbour/contrib/firebird/Makefile @@ -1,17 +1,17 @@ -# -# $Id: Makefile 4853 2001-12-25 16:51:58Z lculik $ -# - -ROOT = ../../ - -CFLAGS += -I/opt/firebird/include - -C_SOURCES=\ - firebird.c \ - -PRG_SOURCES=\ - tfirebird.prg \ - -LIBNAME=firebird - -include $(TOP)$(ROOT)config/lib.cf +# +# $Id$ +# + +ROOT = ../../ + +CFLAGS += -I/opt/firebird/include + +C_SOURCES=\ + firebird.c \ + +PRG_SOURCES=\ + tfirebird.prg \ + +LIBNAME=firebird + +include $(TOP)$(ROOT)config/lib.cf diff --git a/harbour/contrib/firebird/common.mak b/harbour/contrib/firebird/common.mak index 5b8f4e905c..9beda8a7b2 100644 --- a/harbour/contrib/firebird/common.mak +++ b/harbour/contrib/firebird/common.mak @@ -1,18 +1,18 @@ -# -# $Id: common.mak 7935 2007-11-10 11:31:17Z vszakats $ -# - -LIBNAME = firebird - -LIB_PATH = $(LIB_DIR)\$(LIBNAME)$(LIBEXT) - -# -# LIB rules -# - -LIB_OBJS = \ - $(OBJ_DIR)\firebird$(OBJEXT) \ - $(OBJ_DIR)\tfirebird$(OBJEXT) \ - -all: \ - $(LIB_PATH) \ +# +# $Id$ +# + +LIBNAME = firebird + +LIB_PATH = $(LIB_DIR)\$(LIBNAME)$(LIBEXT) + +# +# LIB rules +# + +LIB_OBJS = \ + $(OBJ_DIR)\firebird$(OBJEXT) \ + $(OBJ_DIR)\tfirebird$(OBJEXT) \ + +all: \ + $(LIB_PATH) \ diff --git a/harbour/contrib/firebird/firebird.c b/harbour/contrib/firebird/firebird.c index fa3ec8a0ee..170f88e871 100644 --- a/harbour/contrib/firebird/firebird.c +++ b/harbour/contrib/firebird/firebird.c @@ -1,737 +1,737 @@ -/* - * $Id: atrepl.c 7583 2007-07-06 21:17:36Z druzus $ - */ - -/* - * xHarbour Project source code: - * Firebird RDBMS low level (client api) interface code. - * - * Copyright 2003 Rodrigo Moreno rodrigo_moreno@yahoo.com - * www - http://www.xharbour.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). - * - * As a special exception, the Harbour Project gives permission for - * additional uses of the text contained in its release of Harbour. - * - * The exception is that, if you link the Harbour libraries with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the Harbour library code into it. - * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by the Harbour - * Project under the name Harbour. If you copy code from other - * Harbour Project or Free Software Foundation releases into a copy of - * Harbour, as the General Public License permits, the exception does - * not apply to the code that you add in this way. To avoid misleading - * anyone as to the status of such modified files, you must delete - * this exception notice from them. - * - * If you write modifications of your own for Harbour, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. - * - * See doc/license.txt for licensing terms. - * - */ - -#define _CLIPDEFS_H -#if defined(HB_OS_WIN_32_USED) - #include -#endif - -#include -#include -#include -#include - -#include "extend.api" -#include "item.api" -#include "hbapiitm.h" -#include "ibase.h" - -#define DIALECT 1 -#define MAX_FIELDS 5 -#define MAX_LEN 256 -#define MAX_BUFFER 1024 - -#define ERREXIT(status) { _retnl(isc_sqlcode(status)); return; } - -#ifndef ISC_INT64_FORMAT - -#if (defined(_MSC_VER) && defined(WIN32)) || (defined(__BORLANDC__) && defined(__WIN32__)) -#define ISC_INT64_FORMAT "I64" -#else -#define ISC_INT64_FORMAT "ll" -#endif -#endif - -HB_FUNC(FBCREATEDB) -{ - isc_db_handle newdb = NULL; - isc_tr_handle trans = NULL; - long status[20]; - char create_db[MAX_BUFFER]; - - char *db_name; - char *user; - char *pass; - char *charset; - int page; - int dialect; - - if (hb_pcount() != 6) - { - _retni(0); - return; - } - - db_name = hb_parcx(1); - user = hb_parcx(2); - pass = hb_parcx(3); - page = hb_parni(4); - charset = hb_parcx(5); - dialect = hb_parni(6); - - sprintf(create_db, - "CREATE DATABASE '%s' USER '%s' PASSWORD '%s' PAGE_SIZE = %i DEFAULT CHARACTER SET %s", - db_name, user, pass, page, charset ); - - if (isc_dsql_execute_immediate(status, &newdb, &trans, 0, create_db, dialect, NULL)) - ERREXIT(status); - - _retni(1); -} - - -HB_FUNC(FBCONNECT) -{ - ISC_STATUS status[MAX_FIELDS]; - isc_db_handle db = NULL; - char *db_connect = NULL; - char *user = NULL; - char *passwd = NULL; - char dpb[128]; - int i = 0, len; - - PHB_ITEM db_handle; - - if (hb_parinfo(1)) - db_connect = hb_parcx(1); - - if (hb_parinfo(2)) - user = hb_parcx(2); - - if (hb_parinfo(3)) - passwd = hb_parcx(3); - - dpb[i++] = isc_dpb_version1; - - dpb[i++] = isc_dpb_user_name; - len = strlen(user); - dpb[i++] = (char) len; - strncpy(&(dpb[i]), user, len); - i += len; - - dpb[i++] = isc_dpb_password; - len = strlen (passwd); - dpb[i++] = len; - strncpy(&(dpb[i]), passwd, len); - i += len; - - if ( isc_attach_database ( status, 0, db_connect, &db, i, dpb ) ) - ERREXIT(status); - - db_handle = hb_itemPutPtr( NULL, ( void * ) db ); - _itemReturn(db_handle); - _itemRelease(db_handle); -} - - -HB_FUNC(FBCLOSE) -{ - isc_db_handle db = NULL; - long status[20]; - - db = ( isc_db_handle ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); - - if ( isc_detach_database ( status, &db ) ) - ERREXIT(status); - - _retnl(1); -} - - -HB_FUNC(FBERROR) -{ - int sqlcode; - char msg[MAX_BUFFER]; - - sqlcode = hb_parni(1); - - isc_sql_interprete(sqlcode, msg, 512); - - _retc(msg); -} - -HB_FUNC(FBSTARTTRANSACTION) -{ - isc_db_handle db = NULL; - isc_tr_handle trans = NULL; - long status[MAX_FIELDS]; - - PHB_ITEM var; - - db = ( isc_db_handle ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); - - if (isc_start_transaction(status, &trans, 1, &db, 0, NULL)) - ERREXIT(status); - - var = hb_itemPutPtr( NULL, ( void * ) trans ); - _itemReturn(var); - _itemRelease(var); -} - - -HB_FUNC(FBCOMMIT) -{ - isc_tr_handle trans = NULL; - long status[MAX_FIELDS]; - - trans = ( isc_db_handle ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); - - if (isc_commit_transaction(status, &trans)) - ERREXIT(status); - - trans = NULL; - _retnl(1); -} - -HB_FUNC(FBROLLBACK) -{ - isc_tr_handle trans = NULL; - long status[MAX_FIELDS]; - - trans = ( isc_db_handle ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); - - if (isc_rollback_transaction(status, &trans)) - ERREXIT(status); - - trans = NULL; - _retnl(1); -} - - -HB_FUNC(FBEXECUTE) -{ - isc_db_handle db = NULL; - isc_tr_handle trans = NULL; - char *exec_str; - long status[20]; - long status_rollback[20]; - int dialect; - - db = ( isc_db_handle ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); - exec_str = hb_parcx(2); - dialect = hb_parni(3); - - if (hb_parinfo(4)) { - trans = (isc_tr_handle) hb_itemGetPtr( hb_param( 4, HB_IT_POINTER ) ); - } else { - if ( isc_start_transaction ( status, &trans, 1, &db, 0, NULL ) ) - ERREXIT(status); - } - - if (isc_dsql_execute_immediate(status, &db, &trans, 0, exec_str, dialect, NULL)) { - if (! hb_parinfo(4)) - isc_rollback_transaction ( status_rollback, &trans ); - - ERREXIT(status); - } - - if (!hb_parinfo(4)) - if ( isc_commit_transaction ( status, &trans ) ) - ERREXIT(status); - - _retnl(1); -} - -HB_FUNC(FBQUERY) -{ - isc_db_handle db = NULL; - isc_tr_handle trans = NULL; - ISC_STATUS status[MAX_FIELDS]; - XSQLDA ISC_FAR * sqlda; - isc_stmt_handle stmt = NULL; - XSQLVAR *var; - - char sel_str[MAX_LEN]; - int dialect; - int n, i, dtype; - int num_cols; - - ITEM qry_handle; - ITEM temp; - ITEM aTemp; - ITEM aNew; - - ITEM itemSqlname; - ITEM itemSqltype; - ITEM itemSqllen ; - ITEM itemSqlscale; - ITEM itemRelname; - - db = ( isc_db_handle ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); - strcpy(sel_str, hb_parcx(2)); - - if (hb_parinfo(3)) { - dialect = hb_parni(3); - } else { - dialect = DIALECT; - } - - if (hb_parinfo(4)) { - trans = (isc_tr_handle) hb_itemGetPtr( hb_param( 4, HB_IT_POINTER ) ); - - } else if ( isc_start_transaction ( status, &trans, 1, &db, 0, NULL ) ) - ERREXIT(status); - - // Allocate an output SQLDA. Just to check number of columns - sqlda = ( XSQLDA * ) hb_xgrab( XSQLDA_LENGTH ( 1 ) ); - sqlda->sqln = 1; - sqlda->version = 1; - - // Allocate a statement - if (isc_dsql_allocate_statement(status, &db, &stmt)) - ERREXIT(status); - - // Prepare the statement. - if (isc_dsql_prepare(status, &trans, &stmt, 0, sel_str, dialect, sqlda)) - ERREXIT(status); - - // Describe sql contents - if (isc_dsql_describe(status, &stmt, dialect, sqlda)) - ERREXIT(status); - - num_cols = sqlda->sqld; - aNew = _itemArrayNew( num_cols ); - - // Relocate necessary number of columns - if ( sqlda->sqld > sqlda->sqln ) { - hb_xfree( sqlda ); - n = sqlda->sqld; - sqlda = ( XSQLDA * ) hb_xgrab( XSQLDA_LENGTH ( n ) ); - sqlda->sqln = n; - sqlda->version = 1; - - if (isc_dsql_describe(status, &stmt, dialect, sqlda)) - ERREXIT(status); - } - - for ( i = 0, var = sqlda->sqlvar; i < sqlda->sqld; i++, var++ ) { - dtype = ( var->sqltype & ~1 ); - switch ( dtype ) { - case SQL_VARYING: - var->sqltype = SQL_TEXT; - var->sqldata = ( char * ) hb_xgrab( sizeof ( char ) * var->sqllen + 2 ); - break; - case SQL_TEXT: - var->sqldata = ( char * ) hb_xgrab( sizeof ( char ) * var->sqllen + 2 ); - break; - case SQL_LONG: - var->sqltype = SQL_LONG; - var->sqldata = ( char * ) hb_xgrab( sizeof ( long ) ); - break; - default: - var->sqldata = ( char * ) hb_xgrab( sizeof ( char ) * var->sqllen ); - break; - } - if ( var->sqltype & 1 ) { - var->sqlind = ( short * ) hb_xgrab( sizeof ( short ) ); - } - - aTemp = _itemArrayNew( 5 ); - - itemSqlname = _itemPutC( NULL, sqlda->sqlvar[i].sqlname ); - _itemArrayPut( aTemp, 1, itemSqlname ); - - itemSqltype = _itemPutNL( NULL, (long)dtype ); - _itemArrayPut( aTemp, 2, itemSqltype ); - - itemSqllen = _itemPutNL( NULL, sqlda->sqlvar[i].sqllen ); - _itemArrayPut( aTemp, 3, itemSqllen ); - - itemSqlscale = _itemPutNL( NULL, sqlda->sqlvar[i].sqlscale ); - _itemArrayPut( aTemp, 4, itemSqlscale ); - - itemRelname = _itemPutC( NULL, sqlda->sqlvar[i].relname ); - _itemArrayPut( aTemp, 5, itemRelname ); - - _itemRelease( itemSqlname ); - _itemRelease( itemSqltype ); - _itemRelease( itemSqllen ); - _itemRelease( itemSqlscale ); - _itemRelease( itemRelname ); - - _itemArrayPut( aNew, i+1, aTemp ); - _itemRelease( aTemp ); - } - - if ( !sqlda->sqld ) { - // Execute and commit non-select querys - if ( isc_dsql_execute ( status, &trans, &stmt, dialect, NULL ) ) - ERREXIT(status); - - } else { - if ( isc_dsql_execute ( status, &trans, &stmt, dialect, sqlda ) ) - ERREXIT(status); - } - - qry_handle = _itemArrayNew(6); - - temp = hb_itemPutPtr( NULL, ( void * ) stmt ); - hb_arraySet(qry_handle, 1, temp); - _itemRelease(temp); - - temp = hb_itemPutPtr( NULL, ( void * ) sqlda ); - hb_arraySet(qry_handle, 2, temp); - _itemRelease(temp); - - if (! hb_parinfo(4)) - { - temp = hb_itemPutPtr( NULL, ( void * ) trans ); - hb_arraySet(qry_handle, 3, temp); - _itemRelease(temp); - } - - temp = _itemPutNL(NULL, (long) num_cols); - hb_arraySet(qry_handle, 4, temp); - _itemRelease(temp); - - temp = _itemPutNL(NULL, (long) dialect); - hb_arraySet(qry_handle, 5, temp); - _itemRelease(temp); - - hb_arraySet(qry_handle, 6, aNew); - - _itemReturn(qry_handle); - _itemRelease(qry_handle); - _itemRelease(aNew); -} - - -HB_FUNC(FBFETCH) -{ - isc_stmt_handle stmt = NULL; - ISC_STATUS status[MAX_FIELDS]; - XSQLDA ISC_FAR * sqlda; - long fetch_stat; - int dialect; - - PHB_ITEM aParam ; - - if (ISARRAY( 1 ) ) - { - aParam = hb_param(1,HB_IT_ARRAY); - - stmt = ( isc_stmt_handle ) hb_itemGetPtr(hb_itemArrayGet( aParam, 1 )); - sqlda = ( XSQLDA ISC_FAR * ) hb_itemGetPtr(hb_itemArrayGet( aParam, 2 )); - dialect = hb_itemGetNI(hb_itemArrayGet( aParam, 5 )); - - fetch_stat = isc_dsql_fetch(status, &stmt, dialect, sqlda); - - if (fetch_stat != 100L) - ERREXIT(status); - - } - _retnl(fetch_stat); -} - - -HB_FUNC(FBFREE) -{ - isc_stmt_handle stmt = NULL; - isc_tr_handle trans = NULL; - ISC_STATUS status[MAX_FIELDS]; - XSQLDA ISC_FAR * sqlda; - - PHB_ITEM aParam ; - - if (ISARRAY( 1 ) ) - { - aParam = hb_param(1,HB_IT_ARRAY); - - stmt = ( isc_stmt_handle ) hb_itemGetPtr(hb_itemArrayGet( aParam, 1 )); - sqlda = ( XSQLDA ISC_FAR * ) hb_itemGetPtr(hb_itemArrayGet( aParam, 2 )); - trans = ( isc_tr_handle ) hb_itemGetPtr( hb_itemArrayGet( aParam, 3 )); - - if (isc_dsql_free_statement(status, &stmt, DSQL_drop)) - ERREXIT(status); - - if (trans) - if (isc_commit_transaction(status, &trans)) - ERREXIT(status); - - if ( sqlda ) - hb_xfree( sqlda ); - - _retnl(1); - } - else - _retnl(0); - -} - - -HB_FUNC(FBGETDATA) -{ - int pos; - short dtype; - char data[MAX_BUFFER], *p; - char date_s[25]; - - struct tm times; - XSQLVAR *var; - XSQLDA ISC_FAR * sqlda; - ISC_STATUS status[MAX_FIELDS]; - ISC_QUAD *blob_id; - - PHB_ITEM aParam ; - PHB_ITEM temp; - - aParam = hb_param(1,HB_IT_ARRAY); - - sqlda = ( XSQLDA ISC_FAR * ) hb_itemGetPtr(hb_itemArrayGet( aParam, 2 )); - pos = (int) hb_parnl(2); - - pos--; - - if ( ( pos + 1 ) > sqlda->sqln ) - ERREXIT(status); - - var = sqlda->sqlvar; - - var += pos; - - dtype = var->sqltype & ~1; - p = data; - - if ( ( var->sqltype & 1 ) && ( *var->sqlind < 0 ) ) { - /* null field */ - _ret(); - - } else { - switch ( dtype ) { - case SQL_TEXT: - case SQL_VARYING: - _retclen( var->sqldata, var->sqllen ); - break; - - case SQL_TIMESTAMP: - isc_decode_timestamp ( ( ISC_TIMESTAMP ISC_FAR * ) var->sqldata, × ); - sprintf ( date_s, "%04d-%02d-%02d %02d:%02d:%02d.%04lu", - times.tm_year + 1900, - times.tm_mon + 1, - times.tm_mday, - times.tm_hour, - times.tm_min, - times.tm_sec, - ( ( ISC_TIMESTAMP * ) var->sqldata )->timestamp_time % 10000 ); - sprintf ( p, "%*s ", 24, date_s ); - - _retc(p); - break; - - case SQL_TYPE_DATE: - isc_decode_sql_date ( ( ISC_DATE ISC_FAR * ) var->sqldata, × ); - sprintf ( date_s, "%04d-%02d-%02d", times.tm_year + 1900, times.tm_mon + 1, times.tm_mday ); - sprintf ( p, "%*s ", 8, date_s ); - - _retc(p); - break; - - case SQL_TYPE_TIME: - isc_decode_sql_time ( ( ISC_TIME ISC_FAR * ) var->sqldata, × ); - sprintf ( date_s, "%02d:%02d:%02d.%04lu", - times.tm_hour, - times.tm_min, - times.tm_sec, ( *( ( ISC_TIME * ) var->sqldata ) ) % 10000 ); - sprintf ( p, "%*s ", 13, date_s ); - - _retc(p); - break; - - case SQL_BLOB: - - blob_id = ( ISC_QUAD * ) var->sqldata; - - temp = hb_itemPutPtr( NULL, ( void * ) blob_id ); - _itemReturn(temp); - _itemRelease(temp); - - break; - - case SQL_SHORT: - case SQL_LONG: - case SQL_INT64: - { - ISC_INT64 value; - short field_width; - short dscale; - switch (dtype) - { - case SQL_SHORT: - value = (ISC_INT64) *(short ISC_FAR *) var->sqldata; - field_width = 6; - break; - - case SQL_LONG: - value = (ISC_INT64) *(long ISC_FAR *) var->sqldata; - field_width = 11; - break; - - case SQL_INT64: - value = (ISC_INT64) *(ISC_INT64 ISC_FAR *) var->sqldata; - field_width = 21; - break; - } - - dscale = var->sqlscale; - - if (dscale < 0) - { - ISC_INT64 tens; - short i; - - tens = 1; - for (i = 0; i > dscale; i--) - tens *= 10; - - if (value >= 0) - sprintf (p, "%*" ISC_INT64_FORMAT "d.%0*" ISC_INT64_FORMAT "d", - field_width - 1 + dscale, - (ISC_INT64) value / tens, - -dscale, - (ISC_INT64) value % tens); - - else if ((value / tens) != 0) - sprintf (p, "%*" ISC_INT64_FORMAT "d.%0*" ISC_INT64_FORMAT "d", - field_width - 1 + dscale, - (ISC_INT64) (value / tens), - -dscale, - (ISC_INT64) -(value % tens)); - - else - sprintf (p, "%*s.%0*" ISC_INT64_FORMAT "d", - field_width - 1 + dscale, - "-0", - -dscale, - (ISC_INT64) -(value % tens)); - } - else if (dscale) - sprintf (p, "%*" ISC_INT64_FORMAT "d%0*d", field_width, (ISC_INT64) value, dscale, 0); - else - sprintf (p, "%*" ISC_INT64_FORMAT "d", field_width, (ISC_INT64) value); - }; - _retc(p); - break; - - case SQL_FLOAT: - sprintf(p, "%15g ", *(float ISC_FAR *) (var->sqldata)); - _retc(p); - break; - - case SQL_DOUBLE: - sprintf(p, "%24f ", *(double ISC_FAR *) (var->sqldata)); - _retc(p); - break; - - default: - _ret(); - break; - } - } -} - - -HB_FUNC(FBGETBLOB) -{ - ISC_STATUS status[MAX_FIELDS]; - isc_db_handle db = NULL; - isc_tr_handle trans = NULL; - isc_blob_handle blob_handle = NULL; - short blob_seg_len; - char *blob_segment; - ISC_QUAD *blob_id; - char p[MAX_BUFFER]; - long blob_stat; - - ITEM temp; - ITEM aNew; - - db = ( isc_db_handle ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); - blob_id = ( ISC_QUAD * ) hb_itemGetPtr( hb_param( 2, HB_IT_POINTER ) ); - - if (_parinfo(3)) { - trans = (isc_tr_handle) hb_itemGetPtr( hb_param( 3, HB_IT_POINTER ) ); - } else { - if ( isc_start_transaction ( status, &trans, 1, &db, 0, NULL ) ) { - ERREXIT(status); - } - } - - if (isc_open_blob2(status, &db, &trans, &blob_handle, blob_id, 0, NULL)) - ERREXIT(status); - - // Get blob segments and their lengths and print each segment. - blob_stat = isc_get_segment(status, &blob_handle, - (unsigned short ISC_FAR *) &blob_seg_len, - sizeof(blob_segment), blob_segment); - - if (blob_stat == 0 || status[1] == isc_segment) - aNew = _itemArrayNew( 0 ); - - while (blob_stat == 0 || status[1] == isc_segment) - { - //p = ( char * ) hb_xgrab( blob_seg_len + 1 ); - sprintf( p, "%*.*s", blob_seg_len, blob_seg_len, blob_segment); - - temp = _itemPutC( NULL, p ); - hb_arrayAdd( aNew, temp ) ; - _itemRelease(temp); - - //hb_xfree(p); - blob_stat = isc_get_segment(status, &blob_handle, - (unsigned short ISC_FAR *)&blob_seg_len, - sizeof(blob_segment), blob_segment); - } - - if (isc_close_blob(status, &blob_handle)) { - _itemRelease(aNew); - ERREXIT(status); - } - - if (!_parinfo(3)) - if ( isc_commit_transaction ( status, &trans ) ) - ERREXIT(status); - - _itemReturn(aNew); - _itemRelease(aNew); -} +/* + * $Id$ + */ + +/* + * xHarbour Project source code: + * Firebird RDBMS low level (client api) interface code. + * + * Copyright 2003 Rodrigo Moreno rodrigo_moreno@yahoo.com + * www - http://www.xharbour.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + * See doc/license.txt for licensing terms. + * + */ + +#define _CLIPDEFS_H +#if defined(HB_OS_WIN_32_USED) + #include +#endif + +#include +#include +#include +#include + +#include "extend.api" +#include "item.api" +#include "hbapiitm.h" +#include "ibase.h" + +#define DIALECT 1 +#define MAX_FIELDS 5 +#define MAX_LEN 256 +#define MAX_BUFFER 1024 + +#define ERREXIT(status) { _retnl(isc_sqlcode(status)); return; } + +#ifndef ISC_INT64_FORMAT + +#if (defined(_MSC_VER) && defined(WIN32)) || (defined(__BORLANDC__) && defined(__WIN32__)) +#define ISC_INT64_FORMAT "I64" +#else +#define ISC_INT64_FORMAT "ll" +#endif +#endif + +HB_FUNC(FBCREATEDB) +{ + isc_db_handle newdb = NULL; + isc_tr_handle trans = NULL; + long status[20]; + char create_db[MAX_BUFFER]; + + char *db_name; + char *user; + char *pass; + char *charset; + int page; + int dialect; + + if (hb_pcount() != 6) + { + _retni(0); + return; + } + + db_name = hb_parcx(1); + user = hb_parcx(2); + pass = hb_parcx(3); + page = hb_parni(4); + charset = hb_parcx(5); + dialect = hb_parni(6); + + sprintf(create_db, + "CREATE DATABASE '%s' USER '%s' PASSWORD '%s' PAGE_SIZE = %i DEFAULT CHARACTER SET %s", + db_name, user, pass, page, charset ); + + if (isc_dsql_execute_immediate(status, &newdb, &trans, 0, create_db, dialect, NULL)) + ERREXIT(status); + + _retni(1); +} + + +HB_FUNC(FBCONNECT) +{ + ISC_STATUS status[MAX_FIELDS]; + isc_db_handle db = NULL; + char *db_connect = NULL; + char *user = NULL; + char *passwd = NULL; + char dpb[128]; + int i = 0, len; + + PHB_ITEM db_handle; + + if (hb_parinfo(1)) + db_connect = hb_parcx(1); + + if (hb_parinfo(2)) + user = hb_parcx(2); + + if (hb_parinfo(3)) + passwd = hb_parcx(3); + + dpb[i++] = isc_dpb_version1; + + dpb[i++] = isc_dpb_user_name; + len = strlen(user); + dpb[i++] = (char) len; + strncpy(&(dpb[i]), user, len); + i += len; + + dpb[i++] = isc_dpb_password; + len = strlen (passwd); + dpb[i++] = len; + strncpy(&(dpb[i]), passwd, len); + i += len; + + if ( isc_attach_database ( status, 0, db_connect, &db, i, dpb ) ) + ERREXIT(status); + + db_handle = hb_itemPutPtr( NULL, ( void * ) db ); + _itemReturn(db_handle); + _itemRelease(db_handle); +} + + +HB_FUNC(FBCLOSE) +{ + isc_db_handle db = NULL; + long status[20]; + + db = ( isc_db_handle ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); + + if ( isc_detach_database ( status, &db ) ) + ERREXIT(status); + + _retnl(1); +} + + +HB_FUNC(FBERROR) +{ + int sqlcode; + char msg[MAX_BUFFER]; + + sqlcode = hb_parni(1); + + isc_sql_interprete(sqlcode, msg, 512); + + _retc(msg); +} + +HB_FUNC(FBSTARTTRANSACTION) +{ + isc_db_handle db = NULL; + isc_tr_handle trans = NULL; + long status[MAX_FIELDS]; + + PHB_ITEM var; + + db = ( isc_db_handle ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); + + if (isc_start_transaction(status, &trans, 1, &db, 0, NULL)) + ERREXIT(status); + + var = hb_itemPutPtr( NULL, ( void * ) trans ); + _itemReturn(var); + _itemRelease(var); +} + + +HB_FUNC(FBCOMMIT) +{ + isc_tr_handle trans = NULL; + long status[MAX_FIELDS]; + + trans = ( isc_db_handle ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); + + if (isc_commit_transaction(status, &trans)) + ERREXIT(status); + + trans = NULL; + _retnl(1); +} + +HB_FUNC(FBROLLBACK) +{ + isc_tr_handle trans = NULL; + long status[MAX_FIELDS]; + + trans = ( isc_db_handle ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); + + if (isc_rollback_transaction(status, &trans)) + ERREXIT(status); + + trans = NULL; + _retnl(1); +} + + +HB_FUNC(FBEXECUTE) +{ + isc_db_handle db = NULL; + isc_tr_handle trans = NULL; + char *exec_str; + long status[20]; + long status_rollback[20]; + int dialect; + + db = ( isc_db_handle ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); + exec_str = hb_parcx(2); + dialect = hb_parni(3); + + if (hb_parinfo(4)) { + trans = (isc_tr_handle) hb_itemGetPtr( hb_param( 4, HB_IT_POINTER ) ); + } else { + if ( isc_start_transaction ( status, &trans, 1, &db, 0, NULL ) ) + ERREXIT(status); + } + + if (isc_dsql_execute_immediate(status, &db, &trans, 0, exec_str, dialect, NULL)) { + if (! hb_parinfo(4)) + isc_rollback_transaction ( status_rollback, &trans ); + + ERREXIT(status); + } + + if (!hb_parinfo(4)) + if ( isc_commit_transaction ( status, &trans ) ) + ERREXIT(status); + + _retnl(1); +} + +HB_FUNC(FBQUERY) +{ + isc_db_handle db = NULL; + isc_tr_handle trans = NULL; + ISC_STATUS status[MAX_FIELDS]; + XSQLDA ISC_FAR * sqlda; + isc_stmt_handle stmt = NULL; + XSQLVAR *var; + + char sel_str[MAX_LEN]; + int dialect; + int n, i, dtype; + int num_cols; + + ITEM qry_handle; + ITEM temp; + ITEM aTemp; + ITEM aNew; + + ITEM itemSqlname; + ITEM itemSqltype; + ITEM itemSqllen ; + ITEM itemSqlscale; + ITEM itemRelname; + + db = ( isc_db_handle ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); + strcpy(sel_str, hb_parcx(2)); + + if (hb_parinfo(3)) { + dialect = hb_parni(3); + } else { + dialect = DIALECT; + } + + if (hb_parinfo(4)) { + trans = (isc_tr_handle) hb_itemGetPtr( hb_param( 4, HB_IT_POINTER ) ); + + } else if ( isc_start_transaction ( status, &trans, 1, &db, 0, NULL ) ) + ERREXIT(status); + + // Allocate an output SQLDA. Just to check number of columns + sqlda = ( XSQLDA * ) hb_xgrab( XSQLDA_LENGTH ( 1 ) ); + sqlda->sqln = 1; + sqlda->version = 1; + + // Allocate a statement + if (isc_dsql_allocate_statement(status, &db, &stmt)) + ERREXIT(status); + + // Prepare the statement. + if (isc_dsql_prepare(status, &trans, &stmt, 0, sel_str, dialect, sqlda)) + ERREXIT(status); + + // Describe sql contents + if (isc_dsql_describe(status, &stmt, dialect, sqlda)) + ERREXIT(status); + + num_cols = sqlda->sqld; + aNew = _itemArrayNew( num_cols ); + + // Relocate necessary number of columns + if ( sqlda->sqld > sqlda->sqln ) { + hb_xfree( sqlda ); + n = sqlda->sqld; + sqlda = ( XSQLDA * ) hb_xgrab( XSQLDA_LENGTH ( n ) ); + sqlda->sqln = n; + sqlda->version = 1; + + if (isc_dsql_describe(status, &stmt, dialect, sqlda)) + ERREXIT(status); + } + + for ( i = 0, var = sqlda->sqlvar; i < sqlda->sqld; i++, var++ ) { + dtype = ( var->sqltype & ~1 ); + switch ( dtype ) { + case SQL_VARYING: + var->sqltype = SQL_TEXT; + var->sqldata = ( char * ) hb_xgrab( sizeof ( char ) * var->sqllen + 2 ); + break; + case SQL_TEXT: + var->sqldata = ( char * ) hb_xgrab( sizeof ( char ) * var->sqllen + 2 ); + break; + case SQL_LONG: + var->sqltype = SQL_LONG; + var->sqldata = ( char * ) hb_xgrab( sizeof ( long ) ); + break; + default: + var->sqldata = ( char * ) hb_xgrab( sizeof ( char ) * var->sqllen ); + break; + } + if ( var->sqltype & 1 ) { + var->sqlind = ( short * ) hb_xgrab( sizeof ( short ) ); + } + + aTemp = _itemArrayNew( 5 ); + + itemSqlname = _itemPutC( NULL, sqlda->sqlvar[i].sqlname ); + _itemArrayPut( aTemp, 1, itemSqlname ); + + itemSqltype = _itemPutNL( NULL, (long)dtype ); + _itemArrayPut( aTemp, 2, itemSqltype ); + + itemSqllen = _itemPutNL( NULL, sqlda->sqlvar[i].sqllen ); + _itemArrayPut( aTemp, 3, itemSqllen ); + + itemSqlscale = _itemPutNL( NULL, sqlda->sqlvar[i].sqlscale ); + _itemArrayPut( aTemp, 4, itemSqlscale ); + + itemRelname = _itemPutC( NULL, sqlda->sqlvar[i].relname ); + _itemArrayPut( aTemp, 5, itemRelname ); + + _itemRelease( itemSqlname ); + _itemRelease( itemSqltype ); + _itemRelease( itemSqllen ); + _itemRelease( itemSqlscale ); + _itemRelease( itemRelname ); + + _itemArrayPut( aNew, i+1, aTemp ); + _itemRelease( aTemp ); + } + + if ( !sqlda->sqld ) { + // Execute and commit non-select querys + if ( isc_dsql_execute ( status, &trans, &stmt, dialect, NULL ) ) + ERREXIT(status); + + } else { + if ( isc_dsql_execute ( status, &trans, &stmt, dialect, sqlda ) ) + ERREXIT(status); + } + + qry_handle = _itemArrayNew(6); + + temp = hb_itemPutPtr( NULL, ( void * ) stmt ); + hb_arraySet(qry_handle, 1, temp); + _itemRelease(temp); + + temp = hb_itemPutPtr( NULL, ( void * ) sqlda ); + hb_arraySet(qry_handle, 2, temp); + _itemRelease(temp); + + if (! hb_parinfo(4)) + { + temp = hb_itemPutPtr( NULL, ( void * ) trans ); + hb_arraySet(qry_handle, 3, temp); + _itemRelease(temp); + } + + temp = _itemPutNL(NULL, (long) num_cols); + hb_arraySet(qry_handle, 4, temp); + _itemRelease(temp); + + temp = _itemPutNL(NULL, (long) dialect); + hb_arraySet(qry_handle, 5, temp); + _itemRelease(temp); + + hb_arraySet(qry_handle, 6, aNew); + + _itemReturn(qry_handle); + _itemRelease(qry_handle); + _itemRelease(aNew); +} + + +HB_FUNC(FBFETCH) +{ + isc_stmt_handle stmt = NULL; + ISC_STATUS status[MAX_FIELDS]; + XSQLDA ISC_FAR * sqlda; + long fetch_stat; + int dialect; + + PHB_ITEM aParam ; + + if (ISARRAY( 1 ) ) + { + aParam = hb_param(1,HB_IT_ARRAY); + + stmt = ( isc_stmt_handle ) hb_itemGetPtr(hb_itemArrayGet( aParam, 1 )); + sqlda = ( XSQLDA ISC_FAR * ) hb_itemGetPtr(hb_itemArrayGet( aParam, 2 )); + dialect = hb_itemGetNI(hb_itemArrayGet( aParam, 5 )); + + fetch_stat = isc_dsql_fetch(status, &stmt, dialect, sqlda); + + if (fetch_stat != 100L) + ERREXIT(status); + + } + _retnl(fetch_stat); +} + + +HB_FUNC(FBFREE) +{ + isc_stmt_handle stmt = NULL; + isc_tr_handle trans = NULL; + ISC_STATUS status[MAX_FIELDS]; + XSQLDA ISC_FAR * sqlda; + + PHB_ITEM aParam ; + + if (ISARRAY( 1 ) ) + { + aParam = hb_param(1,HB_IT_ARRAY); + + stmt = ( isc_stmt_handle ) hb_itemGetPtr(hb_itemArrayGet( aParam, 1 )); + sqlda = ( XSQLDA ISC_FAR * ) hb_itemGetPtr(hb_itemArrayGet( aParam, 2 )); + trans = ( isc_tr_handle ) hb_itemGetPtr( hb_itemArrayGet( aParam, 3 )); + + if (isc_dsql_free_statement(status, &stmt, DSQL_drop)) + ERREXIT(status); + + if (trans) + if (isc_commit_transaction(status, &trans)) + ERREXIT(status); + + if ( sqlda ) + hb_xfree( sqlda ); + + _retnl(1); + } + else + _retnl(0); + +} + + +HB_FUNC(FBGETDATA) +{ + int pos; + short dtype; + char data[MAX_BUFFER], *p; + char date_s[25]; + + struct tm times; + XSQLVAR *var; + XSQLDA ISC_FAR * sqlda; + ISC_STATUS status[MAX_FIELDS]; + ISC_QUAD *blob_id; + + PHB_ITEM aParam ; + PHB_ITEM temp; + + aParam = hb_param(1,HB_IT_ARRAY); + + sqlda = ( XSQLDA ISC_FAR * ) hb_itemGetPtr(hb_itemArrayGet( aParam, 2 )); + pos = (int) hb_parnl(2); + + pos--; + + if ( ( pos + 1 ) > sqlda->sqln ) + ERREXIT(status); + + var = sqlda->sqlvar; + + var += pos; + + dtype = var->sqltype & ~1; + p = data; + + if ( ( var->sqltype & 1 ) && ( *var->sqlind < 0 ) ) { + /* null field */ + _ret(); + + } else { + switch ( dtype ) { + case SQL_TEXT: + case SQL_VARYING: + _retclen( var->sqldata, var->sqllen ); + break; + + case SQL_TIMESTAMP: + isc_decode_timestamp ( ( ISC_TIMESTAMP ISC_FAR * ) var->sqldata, × ); + sprintf ( date_s, "%04d-%02d-%02d %02d:%02d:%02d.%04lu", + times.tm_year + 1900, + times.tm_mon + 1, + times.tm_mday, + times.tm_hour, + times.tm_min, + times.tm_sec, + ( ( ISC_TIMESTAMP * ) var->sqldata )->timestamp_time % 10000 ); + sprintf ( p, "%*s ", 24, date_s ); + + _retc(p); + break; + + case SQL_TYPE_DATE: + isc_decode_sql_date ( ( ISC_DATE ISC_FAR * ) var->sqldata, × ); + sprintf ( date_s, "%04d-%02d-%02d", times.tm_year + 1900, times.tm_mon + 1, times.tm_mday ); + sprintf ( p, "%*s ", 8, date_s ); + + _retc(p); + break; + + case SQL_TYPE_TIME: + isc_decode_sql_time ( ( ISC_TIME ISC_FAR * ) var->sqldata, × ); + sprintf ( date_s, "%02d:%02d:%02d.%04lu", + times.tm_hour, + times.tm_min, + times.tm_sec, ( *( ( ISC_TIME * ) var->sqldata ) ) % 10000 ); + sprintf ( p, "%*s ", 13, date_s ); + + _retc(p); + break; + + case SQL_BLOB: + + blob_id = ( ISC_QUAD * ) var->sqldata; + + temp = hb_itemPutPtr( NULL, ( void * ) blob_id ); + _itemReturn(temp); + _itemRelease(temp); + + break; + + case SQL_SHORT: + case SQL_LONG: + case SQL_INT64: + { + ISC_INT64 value; + short field_width; + short dscale; + switch (dtype) + { + case SQL_SHORT: + value = (ISC_INT64) *(short ISC_FAR *) var->sqldata; + field_width = 6; + break; + + case SQL_LONG: + value = (ISC_INT64) *(long ISC_FAR *) var->sqldata; + field_width = 11; + break; + + case SQL_INT64: + value = (ISC_INT64) *(ISC_INT64 ISC_FAR *) var->sqldata; + field_width = 21; + break; + } + + dscale = var->sqlscale; + + if (dscale < 0) + { + ISC_INT64 tens; + short i; + + tens = 1; + for (i = 0; i > dscale; i--) + tens *= 10; + + if (value >= 0) + sprintf (p, "%*" ISC_INT64_FORMAT "d.%0*" ISC_INT64_FORMAT "d", + field_width - 1 + dscale, + (ISC_INT64) value / tens, + -dscale, + (ISC_INT64) value % tens); + + else if ((value / tens) != 0) + sprintf (p, "%*" ISC_INT64_FORMAT "d.%0*" ISC_INT64_FORMAT "d", + field_width - 1 + dscale, + (ISC_INT64) (value / tens), + -dscale, + (ISC_INT64) -(value % tens)); + + else + sprintf (p, "%*s.%0*" ISC_INT64_FORMAT "d", + field_width - 1 + dscale, + "-0", + -dscale, + (ISC_INT64) -(value % tens)); + } + else if (dscale) + sprintf (p, "%*" ISC_INT64_FORMAT "d%0*d", field_width, (ISC_INT64) value, dscale, 0); + else + sprintf (p, "%*" ISC_INT64_FORMAT "d", field_width, (ISC_INT64) value); + }; + _retc(p); + break; + + case SQL_FLOAT: + sprintf(p, "%15g ", *(float ISC_FAR *) (var->sqldata)); + _retc(p); + break; + + case SQL_DOUBLE: + sprintf(p, "%24f ", *(double ISC_FAR *) (var->sqldata)); + _retc(p); + break; + + default: + _ret(); + break; + } + } +} + + +HB_FUNC(FBGETBLOB) +{ + ISC_STATUS status[MAX_FIELDS]; + isc_db_handle db = NULL; + isc_tr_handle trans = NULL; + isc_blob_handle blob_handle = NULL; + short blob_seg_len; + char *blob_segment; + ISC_QUAD *blob_id; + char p[MAX_BUFFER]; + long blob_stat; + + ITEM temp; + ITEM aNew; + + db = ( isc_db_handle ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); + blob_id = ( ISC_QUAD * ) hb_itemGetPtr( hb_param( 2, HB_IT_POINTER ) ); + + if (_parinfo(3)) { + trans = (isc_tr_handle) hb_itemGetPtr( hb_param( 3, HB_IT_POINTER ) ); + } else { + if ( isc_start_transaction ( status, &trans, 1, &db, 0, NULL ) ) { + ERREXIT(status); + } + } + + if (isc_open_blob2(status, &db, &trans, &blob_handle, blob_id, 0, NULL)) + ERREXIT(status); + + // Get blob segments and their lengths and print each segment. + blob_stat = isc_get_segment(status, &blob_handle, + (unsigned short ISC_FAR *) &blob_seg_len, + sizeof(blob_segment), blob_segment); + + if (blob_stat == 0 || status[1] == isc_segment) + aNew = _itemArrayNew( 0 ); + + while (blob_stat == 0 || status[1] == isc_segment) + { + //p = ( char * ) hb_xgrab( blob_seg_len + 1 ); + sprintf( p, "%*.*s", blob_seg_len, blob_seg_len, blob_segment); + + temp = _itemPutC( NULL, p ); + hb_arrayAdd( aNew, temp ) ; + _itemRelease(temp); + + //hb_xfree(p); + blob_stat = isc_get_segment(status, &blob_handle, + (unsigned short ISC_FAR *)&blob_seg_len, + sizeof(blob_segment), blob_segment); + } + + if (isc_close_blob(status, &blob_handle)) { + _itemRelease(aNew); + ERREXIT(status); + } + + if (!_parinfo(3)) + if ( isc_commit_transaction ( status, &trans ) ) + ERREXIT(status); + + _itemReturn(aNew); + _itemRelease(aNew); +} diff --git a/harbour/contrib/firebird/make_b32.bat b/harbour/contrib/firebird/make_b32.bat index 06fe3c275f..f4fb593135 100644 --- a/harbour/contrib/firebird/make_b32.bat +++ b/harbour/contrib/firebird/make_b32.bat @@ -1,6 +1,6 @@ @echo off rem -rem $Id: make_b32.bat 7974 2007-11-14 23:24:27Z vszakats $ +rem $Id$ rem rem --------------------------------------------------------------- diff --git a/harbour/contrib/firebird/make_vc.bat b/harbour/contrib/firebird/make_vc.bat index fc284ef86e..be50e6fcfe 100644 --- a/harbour/contrib/firebird/make_vc.bat +++ b/harbour/contrib/firebird/make_vc.bat @@ -1,6 +1,6 @@ @echo off rem -rem $Id: make_vc.bat 7974 2007-11-14 23:24:27Z vszakats $ +rem $Id$ rem rem --------------------------------------------------------------- diff --git a/harbour/contrib/firebird/readme.txt b/harbour/contrib/firebird/readme.txt index 2d51f01eae..3bf1dbbeab 100644 --- a/harbour/contrib/firebird/readme.txt +++ b/harbour/contrib/firebird/readme.txt @@ -1,55 +1,55 @@ - -README 23/12/2003 - Harbour Low Level api for Firebird and Interbase RDBMS - -This work is not finished yet. It's to be seem like Harbour TMysql routines. - -To use with bcc, you need import library, ex: implib fbclient.lib fbclient.dll or implib gds32.lib gds32.dll. -On Linux you will need link fbclient.so, this can be found usually at /usr/lib. - -For full firebird documentation look at: - -Firebird home: http://firebird.sourceforge.net/index.php -Api: http://www.ibphoenix.com/downloads/60ApiGuide.zip -Data Definition: http://www.ibphoenix.com/downloads/60DataDef.zip -Language Reference: http://www.ibphoenix.com/downloads/60LangRef.zip -Developers guide: http://www.ibphoenix.com/downloads/60DevGuide.zip - -The Class implementation has no all implementation like TMysql has, because Firebird it's diferent. -For example, you can't navigate in records like Mysql do, ex: Getrow( number of row ), in firebird you can -just go forward. - -You will need ibase.h, it can be found at firebird/include - -FILES: - -firebird.c - Low level api -TFirebird.prg - Class implementation, it's to be seems like TMysql. - -tests\simple.prg - Simple test class -tests\stress.prg - Stress test class -tests\test.prg - Testing using only low level api -tests\test.c - Pure C code to test firebird access. - -TODO: - -Full implementation of blob control. For now, we have only partial control, only for text blobs (sybtype 1). -Improve Insert and Update commands using DSQL. - -Implements to do: -FBOpenBlob( blob_id ) -FBReadBlob(blob_id, string, segment_size) - -FBCreateBlob() -FBPutBlob(blob_id, string, segment_size) - -FBCloseBlob( blob_id ) - - -BUGS: - -Fix a few windows gpf and linux segment fault. I Need some help to find what's going on here. - - -That's all folks and sorry my poor english - + +README 23/12/2003 - Harbour Low Level api for Firebird and Interbase RDBMS + +This work is not finished yet. It's to be seem like Harbour TMysql routines. + +To use with bcc, you need import library, ex: implib fbclient.lib fbclient.dll or implib gds32.lib gds32.dll. +On Linux you will need link fbclient.so, this can be found usually at /usr/lib. + +For full firebird documentation look at: + +Firebird home: http://firebird.sourceforge.net/index.php +Api: http://www.ibphoenix.com/downloads/60ApiGuide.zip +Data Definition: http://www.ibphoenix.com/downloads/60DataDef.zip +Language Reference: http://www.ibphoenix.com/downloads/60LangRef.zip +Developers guide: http://www.ibphoenix.com/downloads/60DevGuide.zip + +The Class implementation has no all implementation like TMysql has, because Firebird it's diferent. +For example, you can't navigate in records like Mysql do, ex: Getrow( number of row ), in firebird you can +just go forward. + +You will need ibase.h, it can be found at firebird/include + +FILES: + +firebird.c - Low level api +TFirebird.prg - Class implementation, it's to be seems like TMysql. + +tests\simple.prg - Simple test class +tests\stress.prg - Stress test class +tests\test.prg - Testing using only low level api +tests\test.c - Pure C code to test firebird access. + +TODO: + +Full implementation of blob control. For now, we have only partial control, only for text blobs (sybtype 1). +Improve Insert and Update commands using DSQL. + +Implements to do: +FBOpenBlob( blob_id ) +FBReadBlob(blob_id, string, segment_size) + +FBCreateBlob() +FBPutBlob(blob_id, string, segment_size) + +FBCloseBlob( blob_id ) + + +BUGS: + +Fix a few windows gpf and linux segment fault. I Need some help to find what's going on here. + + +That's all folks and sorry my poor english + Rodrigo Moreno - rodrigo_moreno@yahoo.com \ No newline at end of file diff --git a/harbour/contrib/firebird/test/Makefile b/harbour/contrib/firebird/test/Makefile index a480da9c1c..5db94ce5cb 100644 --- a/harbour/contrib/firebird/test/Makefile +++ b/harbour/contrib/firebird/test/Makefile @@ -1,32 +1,32 @@ -# -# $Id: Makefile,v 1.1 2003/12/31 00:24:35 lculik Exp $ -# - -ifeq ($(HB_MAIN),) - HB_MAIN = std -endif - -ROOT = ../../../ - -CONTRIBS=\ - firebird \ - -PRG_SOURCES=\ - simple.prg \ - -PRG_MAIN=\ - simple.prg - -LIBS=\ - debug \ - vm \ - rtl \ - lang \ - rdd \ - rtl \ - vm \ - macro \ - common \ - fbclient \ - -include $(TOP)$(ROOT)config/bin.cf +# +# $Id$ +# + +ifeq ($(HB_MAIN),) + HB_MAIN = std +endif + +ROOT = ../../../ + +CONTRIBS=\ + firebird \ + +PRG_SOURCES=\ + simple.prg \ + +PRG_MAIN=\ + simple.prg + +LIBS=\ + debug \ + vm \ + rtl \ + lang \ + rdd \ + rtl \ + vm \ + macro \ + common \ + fbclient \ + +include $(TOP)$(ROOT)config/bin.cf diff --git a/harbour/contrib/firebird/test/bld_b32.bat b/harbour/contrib/firebird/test/bld_b32.bat index 4375049cb3..bcf79eccc4 100644 --- a/harbour/contrib/firebird/test/bld_b32.bat +++ b/harbour/contrib/firebird/test/bld_b32.bat @@ -1,6 +1,6 @@ @echo off rem -rem $Id: bld_b32.bat 7941 2007-11-11 01:42:42Z vszakats $ +rem $Id$ rem if A%1 == A GOTO :SYNTAX diff --git a/harbour/contrib/firebird/test/simple.prg b/harbour/contrib/firebird/test/simple.prg index 1fb60426ee..a208cce1b4 100644 --- a/harbour/contrib/firebird/test/simple.prg +++ b/harbour/contrib/firebird/test/simple.prg @@ -1,188 +1,188 @@ -/* - * $Id: atrepl.c 7583 2007-07-06 21:17:36Z druzus $ - */ - -#include "common.ch" - -Function main() - Local oServer, oQuery, oRow, i, x, aTables, aStruct, aKey - - Local cServer := '192.168.1.33:D:\firebird\test\test.gdb' - Local cUser := 'sysdba' - Local cPass := 'masterkey' - Local nDialect := 1 - Local cQuery - - if File('test.gdb') - FErase('test.gdb') - end - - ? FBCreateDB('test.gdb', cuser, cpass, 1024, 'ASCII', nDialect ) - - ? "Connecting..." - - oServer := TFBServer():New(cServer, cUser, cPass, nDialect) - - if oServer:NetErr() - ? oServer:Error() - quit - end - - ? 'Tables...' - - For x := 1 to 1 - aTables := oServer:ListTables() - - For i := 1 to Len(aTables) - ? aTables[i] - next - Next - - ? 'Using implicit transaction...' - - if oServer:TableExists('TEST') - oServer:Execute('DROP TABLE Test') - oServer:Execute('DROP DOMAIN boolean_field') - end - - ? 'Creating domain for boolean fields...' - oServer:Execute('create domain boolean_field as smallint default 0 not null check (value in (0,1))') - - oServer:StartTransaction() - ? 'Creating test table...' - cQuery := 'CREATE TABLE test(' - cQuery += ' Code SmallInt not null primary key, ' - cQuery += ' dept Integer, ' - cQuery += ' Name Varchar(40), ' - cQuery += ' Sales boolean_field, ' - cQuery += ' Tax Float, ' - cQuery += ' Salary Double Precision, ' - cQuery += ' Budget Numeric(12,2), ' - cQuery += ' Discount Decimal(5,2), ' - cQuery += ' Creation Date, ' - cQuery += ' Description blob sub_type 1 segment size 40 ) ' - - oServer:Execute(cQuery) - - if oServer:neterr() - ? oServer:Error() - end - - oServer:Commit() - - oQuery := oServer:Query('SELECT code, dept, name, sales, salary, creation FROM test') - wait - - - ? 'Structure of test table' - aStruct := oServer:TableStruct('test') - - For i := 1 to Len(aStruct) - ? - For x := 1 to Len(aStruct[i]) - ?? aStruct[i,x] - Next - next - - ? 'Inserting, declared transaction control ' - oServer:StartTransaction() - - For i := 1 to 100 - cQuery := 'INSERT INTO test(code, dept, name, sales, tax, salary, budget, Discount, Creation, Description) ' - cQuery += 'VALUES( ' + str(i) + ', 2, "TEST", 1, 5, 3000, 1500.2, 7.5, "12-22-2003", "Short Description about what ? ")' - - oServer:Execute(cQuery) - - if oServer:neterr() - ? oServer:error() - end - Next - - oServer:Commit() - - oQuery := oServer:Query('SELECT code, name, description, sales FROM test') - - aStruct := oQuery:Struct() - - For i := 1 to Len(aStruct) - ? aStruct[i,1], aStruct[i,2], aStruct[i,3], aStruct[i,4] - Next - - aKey := oQuery:GetKeyField() - - ? "Fields: ", oQuery:Fcount(), "Primary Key: ", aKey[1] - - oRow := oQuery:Blank() - - ? oRow:FCount(), ; - oRow:Fieldpos('code'), ; - oRow:Fieldget(1), ; - oRow:Fieldname(1), ; - oRow:Fieldtype(1), ; - oRow:Fielddec(1), ; - oRow:Fieldlen(1), ; - len(oRow:Getkeyfield()) - - oRow:Fieldput(1, 150) - oRow:Fieldput(2, 'MY TEST') - - ? oRow:Fieldget(1), oRow:Fieldget(2) - - ? oServer:Append(oRow) - - ? oServer:Delete(oQuery:blank(), 'code = 200') - - ? oServer:Execute('error caused intentionaly') - - DO WHILE ! oQuery:Eof() - oQuery:Skip() - ? oQuery:Fieldget(oQuery:Fieldpos('code')), ; - oQuery:Fieldget(4), ; - oQuery:Fieldget(2), ; - oQuery:Fieldname(1),; - oQuery:Fieldtype(1), ; - oQuery:Fielddec(1), ; - oQuery:Fieldlen(1),; - oQuery:Fieldget(3) - - if oQuery:Recno() == 50 - oRow := oQuery:getrow() - - oRow:Fieldput(2, 'My Second test') - ? 'Update: ', oServer:Update(oRow) - end - - if oQuery:Recno() == 60 - oRow := oQuery:getrow() - ? 'Delete: ', oServer:Delete(oRow) - end - END - - ? 'Delete: ', oServer:Delete(oQuery:Blank(), 'code = 70') - - oQuery:Refresh() - - DO WHILE oQuery:Fetch() - oRow := oQuery:getrow() - - ? oRow:Fieldget(oRow:Fieldpos('code')), ; - oRow:Fieldget(4), ; - oRow:Fieldget(2), ; - oRow:Fieldname(1),; - oRow:Fieldtype(1), ; - oRow:Fielddec(1), ; - oRow:Fieldlen(1),; - oRow:Fieldget(3) - END - - oQuery:Destroy() - - oServer:Destroy() - - - ? "Closing..." - - return nil - - - +/* + * $Id$ + */ + +#include "common.ch" + +Function main() + Local oServer, oQuery, oRow, i, x, aTables, aStruct, aKey + + Local cServer := '192.168.1.33:D:\firebird\test\test.gdb' + Local cUser := 'sysdba' + Local cPass := 'masterkey' + Local nDialect := 1 + Local cQuery + + if File('test.gdb') + FErase('test.gdb') + end + + ? FBCreateDB('test.gdb', cuser, cpass, 1024, 'ASCII', nDialect ) + + ? "Connecting..." + + oServer := TFBServer():New(cServer, cUser, cPass, nDialect) + + if oServer:NetErr() + ? oServer:Error() + quit + end + + ? 'Tables...' + + For x := 1 to 1 + aTables := oServer:ListTables() + + For i := 1 to Len(aTables) + ? aTables[i] + next + Next + + ? 'Using implicit transaction...' + + if oServer:TableExists('TEST') + oServer:Execute('DROP TABLE Test') + oServer:Execute('DROP DOMAIN boolean_field') + end + + ? 'Creating domain for boolean fields...' + oServer:Execute('create domain boolean_field as smallint default 0 not null check (value in (0,1))') + + oServer:StartTransaction() + ? 'Creating test table...' + cQuery := 'CREATE TABLE test(' + cQuery += ' Code SmallInt not null primary key, ' + cQuery += ' dept Integer, ' + cQuery += ' Name Varchar(40), ' + cQuery += ' Sales boolean_field, ' + cQuery += ' Tax Float, ' + cQuery += ' Salary Double Precision, ' + cQuery += ' Budget Numeric(12,2), ' + cQuery += ' Discount Decimal(5,2), ' + cQuery += ' Creation Date, ' + cQuery += ' Description blob sub_type 1 segment size 40 ) ' + + oServer:Execute(cQuery) + + if oServer:neterr() + ? oServer:Error() + end + + oServer:Commit() + + oQuery := oServer:Query('SELECT code, dept, name, sales, salary, creation FROM test') + wait + + + ? 'Structure of test table' + aStruct := oServer:TableStruct('test') + + For i := 1 to Len(aStruct) + ? + For x := 1 to Len(aStruct[i]) + ?? aStruct[i,x] + Next + next + + ? 'Inserting, declared transaction control ' + oServer:StartTransaction() + + For i := 1 to 100 + cQuery := 'INSERT INTO test(code, dept, name, sales, tax, salary, budget, Discount, Creation, Description) ' + cQuery += 'VALUES( ' + str(i) + ', 2, "TEST", 1, 5, 3000, 1500.2, 7.5, "12-22-2003", "Short Description about what ? ")' + + oServer:Execute(cQuery) + + if oServer:neterr() + ? oServer:error() + end + Next + + oServer:Commit() + + oQuery := oServer:Query('SELECT code, name, description, sales FROM test') + + aStruct := oQuery:Struct() + + For i := 1 to Len(aStruct) + ? aStruct[i,1], aStruct[i,2], aStruct[i,3], aStruct[i,4] + Next + + aKey := oQuery:GetKeyField() + + ? "Fields: ", oQuery:Fcount(), "Primary Key: ", aKey[1] + + oRow := oQuery:Blank() + + ? oRow:FCount(), ; + oRow:Fieldpos('code'), ; + oRow:Fieldget(1), ; + oRow:Fieldname(1), ; + oRow:Fieldtype(1), ; + oRow:Fielddec(1), ; + oRow:Fieldlen(1), ; + len(oRow:Getkeyfield()) + + oRow:Fieldput(1, 150) + oRow:Fieldput(2, 'MY TEST') + + ? oRow:Fieldget(1), oRow:Fieldget(2) + + ? oServer:Append(oRow) + + ? oServer:Delete(oQuery:blank(), 'code = 200') + + ? oServer:Execute('error caused intentionaly') + + DO WHILE ! oQuery:Eof() + oQuery:Skip() + ? oQuery:Fieldget(oQuery:Fieldpos('code')), ; + oQuery:Fieldget(4), ; + oQuery:Fieldget(2), ; + oQuery:Fieldname(1),; + oQuery:Fieldtype(1), ; + oQuery:Fielddec(1), ; + oQuery:Fieldlen(1),; + oQuery:Fieldget(3) + + if oQuery:Recno() == 50 + oRow := oQuery:getrow() + + oRow:Fieldput(2, 'My Second test') + ? 'Update: ', oServer:Update(oRow) + end + + if oQuery:Recno() == 60 + oRow := oQuery:getrow() + ? 'Delete: ', oServer:Delete(oRow) + end + END + + ? 'Delete: ', oServer:Delete(oQuery:Blank(), 'code = 70') + + oQuery:Refresh() + + DO WHILE oQuery:Fetch() + oRow := oQuery:getrow() + + ? oRow:Fieldget(oRow:Fieldpos('code')), ; + oRow:Fieldget(4), ; + oRow:Fieldget(2), ; + oRow:Fieldname(1),; + oRow:Fieldtype(1), ; + oRow:Fielddec(1), ; + oRow:Fieldlen(1),; + oRow:Fieldget(3) + END + + oQuery:Destroy() + + oServer:Destroy() + + + ? "Closing..." + + return nil + + + diff --git a/harbour/contrib/firebird/test/stress.prg b/harbour/contrib/firebird/test/stress.prg index 2c48342bf0..f732c456ac 100644 --- a/harbour/contrib/firebird/test/stress.prg +++ b/harbour/contrib/firebird/test/stress.prg @@ -1,134 +1,134 @@ -/* - * $Id: atrepl.c 7583 2007-07-06 21:17:36Z druzus $ - */ - -/* VERY IMPORTANT: Don't use this querys as sample, they are used for stress tests !!! */ - -Function Main() - Local oServer, oQuery, oRow, i, x - - Local cServer := '192.168.1.33:D:\firebird\test\test2.gdb' - Local cUser := 'sysdba' - Local cPass := 'masterkey' - Local nDialect := 1 - Local cQuery - - CLEAR SCREEN - - if ! File('test2.gdb') .and. .F. - ? FBCreateDB('test2.gdb', cuser, cpass, 1024, 'WIN1251', nDialect ) - end - - ? "Connecting..." - - oServer := TFBServer():New(cServer, cUser, cPass, nDialect) - - if oServer:NetErr() - ? oServer:Error() - quit - end - - if oServer:TableExists('test') - ? oServer:Execute('DROP TABLE Test') - ? oServer:Execute('DROP DOMAIN boolean_field') - end - - ? 'Creating domain for boolean fields...' - - ? oServer:Execute('create domain boolean_field as smallint default 0 not null check (value in (0,1))') - - ? 'Creating test table...' - cQuery := 'CREATE TABLE test(' - cQuery += ' Code SmallInt not null primary key, ' - cQuery += ' dept Integer, ' - cQuery += ' Name Varchar(40), ' - cQuery += ' Sales boolean_field, ' - cQuery += ' Tax Float, ' - cQuery += ' Salary Double Precision, ' - cQuery += ' Budget Numeric(12,2), ' - cQuery += ' Discount Decimal(5,2), ' - cQuery += ' Creation Date, ' - cQuery += ' Description blob sub_type 1 segment size 40 ) ' - - ? oServer:Execute(cQuery) - -quit - - oQuery := oServer:Query('SELECT code, dept, name, sales, salary, creation FROM test') - - oServer:StartTransaction() - - For i := 1 to 10000 - @ 15,0 say 'Inserting values....' + str(i) - - oRow := oQuery:Blank() - - oRow:Fieldput(1, i) - oRow:Fieldput(2, i+1) - oRow:Fieldput(3, 'DEPARTMENT NAME ' + strzero(i) ) - oRow:Fieldput(4, (mod(i,10) == 0) ) - oRow:Fieldput(5, 3000 + i ) - oRow:fieldput(6, Date() ) - - oServer:Append(oRow) - - if mod(i,100) == 0 - oServer:Commit() - oServer:StartTransaction() - end - Next - - For i := 5000 to 7000 - @ 16,0 say 'Deleting values....' + str(i) - - oRow := oQuery:Blank() - oServer:Delete(oRow, 'code = ' + str(i)) - - if mod(i,100) == 0 - oServer:Commit() - oServer:StartTransaction() - end - Next - - For i := 2000 to 3000 - @ 17,0 say 'Updating values....' + str(i) - - oRow := oQuery:Blank() - oRow:Fieldput(5, 4000+i) - oServer:update(oRow, 'code = ' + str(i)) - - if mod(i,100) == 0 - oServer:Commit() - oServer:StartTransaction() - end - Next - - oQuery := oServer:Query('SELECT sum(salary) sum_salary FROM test WHERE code between 1 and 4000') - - if ! oQuery:Neterr() - oQuery:Fetch() - @ 18,0 say 'Sum values....' + Str(oQuery:Fieldget(1)) - oQuery:Destroy() - end - - - x := 0 - For i := 1 to 4000 - oQuery := oServer:Query('SELECT * FROM test WHERE code = ' + str(i)) - - if ! oQuery:Neterr() - oQuery:Fetch() - oRow := oQuery:getrow() - - oQuery:destroy() - x += oRow:fieldget(oRow:fieldpos('salary')) - - @ 19,0 say 'Sum values....' + str(x) - end - Next - - - oServer:Destroy() - - ? "Closing..." -return nil +/* + * $Id$ + */ + +/* VERY IMPORTANT: Don't use this querys as sample, they are used for stress tests !!! */ + +Function Main() + Local oServer, oQuery, oRow, i, x + + Local cServer := '192.168.1.33:D:\firebird\test\test2.gdb' + Local cUser := 'sysdba' + Local cPass := 'masterkey' + Local nDialect := 1 + Local cQuery + + CLEAR SCREEN + + if ! File('test2.gdb') .and. .F. + ? FBCreateDB('test2.gdb', cuser, cpass, 1024, 'WIN1251', nDialect ) + end + + ? "Connecting..." + + oServer := TFBServer():New(cServer, cUser, cPass, nDialect) + + if oServer:NetErr() + ? oServer:Error() + quit + end + + if oServer:TableExists('test') + ? oServer:Execute('DROP TABLE Test') + ? oServer:Execute('DROP DOMAIN boolean_field') + end + + ? 'Creating domain for boolean fields...' + + ? oServer:Execute('create domain boolean_field as smallint default 0 not null check (value in (0,1))') + + ? 'Creating test table...' + cQuery := 'CREATE TABLE test(' + cQuery += ' Code SmallInt not null primary key, ' + cQuery += ' dept Integer, ' + cQuery += ' Name Varchar(40), ' + cQuery += ' Sales boolean_field, ' + cQuery += ' Tax Float, ' + cQuery += ' Salary Double Precision, ' + cQuery += ' Budget Numeric(12,2), ' + cQuery += ' Discount Decimal(5,2), ' + cQuery += ' Creation Date, ' + cQuery += ' Description blob sub_type 1 segment size 40 ) ' + + ? oServer:Execute(cQuery) + +quit + + oQuery := oServer:Query('SELECT code, dept, name, sales, salary, creation FROM test') + + oServer:StartTransaction() + + For i := 1 to 10000 + @ 15,0 say 'Inserting values....' + str(i) + + oRow := oQuery:Blank() + + oRow:Fieldput(1, i) + oRow:Fieldput(2, i+1) + oRow:Fieldput(3, 'DEPARTMENT NAME ' + strzero(i) ) + oRow:Fieldput(4, (mod(i,10) == 0) ) + oRow:Fieldput(5, 3000 + i ) + oRow:fieldput(6, Date() ) + + oServer:Append(oRow) + + if mod(i,100) == 0 + oServer:Commit() + oServer:StartTransaction() + end + Next + + For i := 5000 to 7000 + @ 16,0 say 'Deleting values....' + str(i) + + oRow := oQuery:Blank() + oServer:Delete(oRow, 'code = ' + str(i)) + + if mod(i,100) == 0 + oServer:Commit() + oServer:StartTransaction() + end + Next + + For i := 2000 to 3000 + @ 17,0 say 'Updating values....' + str(i) + + oRow := oQuery:Blank() + oRow:Fieldput(5, 4000+i) + oServer:update(oRow, 'code = ' + str(i)) + + if mod(i,100) == 0 + oServer:Commit() + oServer:StartTransaction() + end + Next + + oQuery := oServer:Query('SELECT sum(salary) sum_salary FROM test WHERE code between 1 and 4000') + + if ! oQuery:Neterr() + oQuery:Fetch() + @ 18,0 say 'Sum values....' + Str(oQuery:Fieldget(1)) + oQuery:Destroy() + end + + + x := 0 + For i := 1 to 4000 + oQuery := oServer:Query('SELECT * FROM test WHERE code = ' + str(i)) + + if ! oQuery:Neterr() + oQuery:Fetch() + oRow := oQuery:getrow() + + oQuery:destroy() + x += oRow:fieldget(oRow:fieldpos('salary')) + + @ 19,0 say 'Sum values....' + str(x) + end + Next + + + oServer:Destroy() + + ? "Closing..." +return nil diff --git a/harbour/contrib/firebird/test/test.prg b/harbour/contrib/firebird/test/test.prg index df803ac5c8..b520df4702 100644 --- a/harbour/contrib/firebird/test/test.prg +++ b/harbour/contrib/firebird/test/test.prg @@ -1,77 +1,77 @@ -/* - * $Id: atrepl.c 7583 2007-07-06 21:17:36Z druzus $ - */ - -#include "common.ch" - -Function Main() - - nDialect := 1 - - if File('test.gdb') - FErase('test.gdb') - end - - ? FBCreateDB('test.gdb','sysdba', 'masterkey', 1024, 'ASCII', nDialect ) - - - /* Connect rdbms */ - db := FBConnect("127.0.0.1:d:\firebird\test\test.gdb", "sysdba", "masterkey") - - if ISNUMBER(db) - ? 'Error' - quit - end - - ? FBExecute(db, 'sldjfs;ldjs;djf', dialect) - - ? FBClose(db) - - trans := FBStartTransaction(db) - qry := FBQuery(db, 'create table teste (code smallint)', dialect, trans) - FBCommit(trans) - - - ? "Status Execute: ", FBExecute( db, 'insert into customer(customer) values ("test 1")', dialect, trans) - - ? "Status no Rollback: ", FBRollback(trans) - - trans := FBStartTransaction(db) - ? "Status Execute: ", FBExecute( db, 'insert into customer(customer) values ("test 2")', dialect, trans ) - ? "Status commit: ", FBCommit(trans) - - - ? "Status Execute: ", FBExecute( db, 'insert into customer(customer) values ("test 3")', dialect ) - - // FIX WINDOWS GPF BELOW - - qry := FBQuery(db, "SELECT * FROM sales", dialect) - - num_cols := qry[4] - columns := qry[6] - - For x := 1 to num_cols - ? x, "> " - For y := 1 to len(columns[x]) - ?? columns[x,y], ' ' - Next - Next - - ? '---' - - do while (fetch_stat := FBFetch(qry)) == 0 - ? fetch_stat - for x := 1 to num_cols - ?? FBGetData(qry,x), ', ' - next - end - - ? 'Fetch code:', fetch_stat - - ? "Status Free sql: ", FBFree(qry) - - - /* Close connection with rdbms */ - ? "Status Fechar Database: ", FBClose(db) - - Return Nil +/* + * $Id$ + */ + +#include "common.ch" + +Function Main() + + nDialect := 1 + + if File('test.gdb') + FErase('test.gdb') + end + + ? FBCreateDB('test.gdb','sysdba', 'masterkey', 1024, 'ASCII', nDialect ) + + + /* Connect rdbms */ + db := FBConnect("127.0.0.1:d:\firebird\test\test.gdb", "sysdba", "masterkey") + + if ISNUMBER(db) + ? 'Error' + quit + end + + ? FBExecute(db, 'sldjfs;ldjs;djf', dialect) + + ? FBClose(db) + + trans := FBStartTransaction(db) + qry := FBQuery(db, 'create table teste (code smallint)', dialect, trans) + FBCommit(trans) + + + ? "Status Execute: ", FBExecute( db, 'insert into customer(customer) values ("test 1")', dialect, trans) + + ? "Status no Rollback: ", FBRollback(trans) + + trans := FBStartTransaction(db) + ? "Status Execute: ", FBExecute( db, 'insert into customer(customer) values ("test 2")', dialect, trans ) + ? "Status commit: ", FBCommit(trans) + + + ? "Status Execute: ", FBExecute( db, 'insert into customer(customer) values ("test 3")', dialect ) + + // FIX WINDOWS GPF BELOW + + qry := FBQuery(db, "SELECT * FROM sales", dialect) + + num_cols := qry[4] + columns := qry[6] + + For x := 1 to num_cols + ? x, "> " + For y := 1 to len(columns[x]) + ?? columns[x,y], ' ' + Next + Next + + ? '---' + + do while (fetch_stat := FBFetch(qry)) == 0 + ? fetch_stat + for x := 1 to num_cols + ?? FBGetData(qry,x), ', ' + next + end + + ? 'Fetch code:', fetch_stat + + ? "Status Free sql: ", FBFree(qry) + + + /* Close connection with rdbms */ + ? "Status Fechar Database: ", FBClose(db) + + Return Nil diff --git a/harbour/contrib/firebird/test/testapi.c b/harbour/contrib/firebird/test/testapi.c index f6656a2813..2d88e1bdff 100644 --- a/harbour/contrib/firebird/test/testapi.c +++ b/harbour/contrib/firebird/test/testapi.c @@ -1,403 +1,403 @@ -/* - * $Id: atrepl.c 7583 2007-07-06 21:17:36Z druzus $ - */ - -#include -#include -#include -#include -#include -#include - -#ifndef ISC_INT64_FORMAT - -#if (defined(_MSC_VER) && defined(WIN32)) || (defined(__BORLANDC__) && defined(__WIN32__)) -#define ISC_INT64_FORMAT "I64" -#else -#define ISC_INT64_FORMAT "ll" -#endif -#endif - -#define USER "sysdba" -#define PASSWORD "masterkey" -#define DATABASE "192.168.1.33:d:\\fontes\\lixo\\test.gdb" -#define ERREXIT(status, rc) {isc_print_status(status); return rc;} -#define MAX_BUFFER 1024 - -int execute( char *exec_str ); -int query( char *sel_str ); -int fetch( void ); -int qclose( void ); -char *getdata(int pos); - - -isc_db_handle db = NULL; -int dialect = 1; -XSQLDA ISC_FAR * sqlda; -isc_stmt_handle stmt = NULL; -isc_tr_handle trans = NULL; - -int main () -{ - char dpb[48]; - int i = 0, len; - long status[20]; - - dpb[i++] = isc_dpb_version1; - - dpb[i++] = isc_dpb_user_name; - len = strlen(USER); - dpb[i++] = (char) len; - strncpy(&(dpb[i]), USER, len); - i += len; - - dpb[i++] = isc_dpb_password; - len = strlen (PASSWORD); - dpb[i++] = len; - strncpy(&(dpb[i]), PASSWORD, len); - i += len; - - if (isc_attach_database(status, 0, DATABASE, &db, i, dpb)) - ERREXIT(status, 1); - - execute("DROP TABLE TESTE"); - - execute("CREATE TABLE TESTE (code smallint)"); - - execute("INSERT INTO TESTE (code) VALUES (100)"); - - query("SELECT * FROM TESTE"); - while (fetch() == 0) - printf("%s\n", getdata(0)); - qclose(); - - - if (isc_detach_database(status, &db)) - ERREXIT(status, 1); - - return 1; -} - -int execute( char *exec_str ) -{ - isc_tr_handle trans = NULL; - long status[20]; - - if (isc_start_transaction(status, &trans, 1, &db, 0, NULL)) - ERREXIT(status, 1); - - if (isc_dsql_execute_immediate(status, &db, &trans, 0, exec_str, dialect, NULL)) - ERREXIT(status, 1); - - if (isc_commit_transaction(status, &trans)) - ERREXIT(status, 1); - - return 1; -} - -int query( char *sel_str ) -{ - ISC_STATUS status[20]; - XSQLVAR *var; - - int n, i, dtype; - - if ( isc_start_transaction ( status, &trans, 1, &db, 0, NULL ) ) - ERREXIT(status, 1); - - // Allocate an output SQLDA. Just to check number of columns - sqlda = ( XSQLDA * ) malloc( XSQLDA_LENGTH ( 1 ) ); - sqlda->sqln = 1; - sqlda->version = 1; - - // Allocate a statement - if (isc_dsql_allocate_statement(status, &db, &stmt)) - ERREXIT(status, 1); - - // Prepare the statement. - if (isc_dsql_prepare(status, &trans, &stmt, 0, sel_str, dialect, sqlda)) - ERREXIT(status, 1); - - // Describe sql contents - if (isc_dsql_describe(status, &stmt, dialect, sqlda)) - ERREXIT(status, 1); - - // Relocate necessary number of columns - if ( sqlda->sqld > sqlda->sqln ) { - free( sqlda ); - n = sqlda->sqld; - sqlda = ( XSQLDA * ) malloc( XSQLDA_LENGTH ( n ) ); - sqlda->sqln = n; - sqlda->version = 1; - - if (isc_dsql_describe(status, &stmt, dialect, sqlda)) - ERREXIT(status, 1); - } - - for ( i = 0, var = sqlda->sqlvar; i < sqlda->sqld; i++, var++ ) { - dtype = ( var->sqltype & ~1 ); - switch ( dtype ) { - case SQL_VARYING: - var->sqltype = SQL_TEXT; - var->sqldata = ( char * ) malloc( sizeof ( char ) * var->sqllen + 2 ); - break; - case SQL_TEXT: - var->sqldata = ( char * ) malloc( sizeof ( char ) * var->sqllen + 2 ); - break; - case SQL_LONG: - var->sqltype = SQL_LONG; - var->sqldata = ( char * ) malloc( sizeof ( long ) ); - break; - default: - var->sqldata = ( char * ) malloc( sizeof ( char ) * var->sqllen ); - break; - } - if ( var->sqltype & 1 ) { - var->sqlind = ( short * ) malloc( sizeof ( short ) ); - } - } - - if ( !sqlda->sqld ) { - // Execute and commit non-select querys - if ( isc_dsql_execute ( status, &trans, &stmt, dialect, NULL ) ) - ERREXIT(status, 1); - - if (isc_commit_transaction(status, &trans)) - ERREXIT(status, 1); - - trans = NULL; - - } else { - if ( isc_dsql_execute ( status, &trans, &stmt, dialect, sqlda ) ) - ERREXIT(status, 1); - } - - return 1; -} - -int fetch( void ) -{ - long fetch_stat; - long status[20]; - - fetch_stat = isc_dsql_fetch(status, &stmt, dialect, sqlda); - - if (fetch_stat != 100L) - ERREXIT(status, 1); - - return fetch_stat; -} - -int qclose( void ) -{ - long status[20]; - - if (isc_dsql_free_statement(status, &stmt, DSQL_drop)) - ERREXIT(status, 1); - - if (trans) - if (isc_commit_transaction(status, &trans)) - ERREXIT(status, 1); - - if ( sqlda ) - free( sqlda ); - - return 1; -} - -char *getdata(int pos) -{ - short dtype; - char data[MAX_BUFFER], *p; - char blob_s[20], date_s[25]; - short len; - long status[20]; - - struct tm times; - ISC_QUAD bid; - XSQLVAR *var; - - if ( ( pos + 1 ) > sqlda->sqln ) - return "error"; - - var = sqlda->sqlvar; - - var += pos; - - dtype = var->sqltype & ~1; - p = data; - - if ( ( var->sqltype & 1 ) && ( *var->sqlind < 0 ) ) { - switch ( dtype ) { - case SQL_TEXT: - case SQL_VARYING: - len = var->sqllen; - break; - case SQL_SHORT: - len = 6; - if ( var->sqlscale > 0 ) - len += var->sqlscale; - break; - case SQL_LONG: - len = 11; - if ( var->sqlscale > 0 ) - len += var->sqlscale; - break; - case SQL_INT64: - len = 21; - if ( var->sqlscale > 0 ) - len += var->sqlscale; - break; - case SQL_FLOAT: - len = 15; - break; - case SQL_DOUBLE: - len = 24; - break; - case SQL_TIMESTAMP: - len = 24; - break; - case SQL_TYPE_DATE: - len = 10; - break; - case SQL_TYPE_TIME: - len = 13; - break; - case SQL_BLOB: - case SQL_ARRAY: - default: - len = 17; - break; - } - if ( ( dtype == SQL_TEXT ) || ( dtype == SQL_VARYING ) ) - sprintf ( p, "%-*s ", len, "NULL" ); - else - sprintf ( p, "%*s ", len, "NULL" ); - } else { - switch ( dtype ) { - case SQL_TEXT: - sprintf ( p, "%.*s ", var->sqllen, var->sqldata ); - break; - - case SQL_VARYING: - sprintf ( p, "%.*s ", var->sqllen, var->sqldata ); - break; - - case SQL_SHORT: - case SQL_LONG: - case SQL_INT64: - { - ISC_INT64 value = 0; - short field_width = 0; - short dscale; - - switch ( dtype ) { - case SQL_SHORT: - value = ( ISC_INT64 ) * ( short ISC_FAR * ) var->sqldata; - field_width = 6; - break; - case SQL_LONG: - value = ( ISC_INT64 ) * ( long ISC_FAR * ) var->sqldata; - field_width = 11; - break; - case SQL_INT64: - value = ( ISC_INT64 ) * ( ISC_INT64 ISC_FAR * ) var->sqldata; - field_width = 21; - break; - } - dscale = var->sqlscale; - if ( dscale < 0 ) { - ISC_INT64 tens; - short i; - - tens = 1; - for ( i = 0; i > dscale; i-- ) { - tens *= 10; - - if ( value >= 0 ) { - - sprintf ( p, - "%*" ISC_INT64_FORMAT "d.%0*" - ISC_INT64_FORMAT "d", - field_width - 1 + dscale, - ( ISC_INT64 ) ( value / tens ), -dscale, - ( ISC_INT64 ) ( value % tens ) ); - } else if ( ( value / tens ) != 0 ) { - - sprintf ( p, - "%*" ISC_INT64_FORMAT "d.%0*" - ISC_INT64_FORMAT "d", - field_width - 1 + dscale, - ( ISC_INT64 ) ( value / tens ), -dscale, - ( ISC_INT64 ) - ( value % tens ) ); - } else { - - sprintf ( p, "%*s.%0*" ISC_INT64_FORMAT "d", - field_width - 1 + dscale, - "-0", -dscale, - ( ISC_INT64 ) - ( value % tens ) ); - } - } - } else if ( dscale ) { - sprintf ( p, "%*" ISC_INT64_FORMAT "d%0*d", - field_width, ( ISC_INT64 ) value, dscale, 0 ); - } else { - sprintf ( p, "%*" ISC_INT64_FORMAT "d", - field_width, ( ISC_INT64 ) value ); - } - }; - break; - - case SQL_FLOAT: - sprintf ( p, "%15g ", *( float ISC_FAR * ) ( var->sqldata ) ); - break; - - case SQL_DOUBLE: - sprintf ( p, "%24f ", *( double ISC_FAR * ) ( var->sqldata ) ); - break; - - case SQL_TIMESTAMP: - isc_decode_timestamp ( ( ISC_TIMESTAMP ISC_FAR * ) var->sqldata, × ); - sprintf ( date_s, "%04d-%02d-%02d %02d:%02d:%02d.%04lui", - times.tm_year + 1900, - times.tm_mon + 1, - times.tm_mday, - times.tm_hour, - times.tm_min, - times.tm_sec, - ( ( ISC_TIMESTAMP * ) var->sqldata )->timestamp_time % 10000 ); - sprintf ( p, "%*s ", 24, date_s ); - break; - - case SQL_TYPE_DATE: - isc_decode_sql_date ( ( ISC_DATE ISC_FAR * ) var->sqldata, × ); - sprintf ( date_s, "%04d-%02d-%02d", - times.tm_year + 1900, times.tm_mon + 1, times.tm_mday ); - sprintf ( p, "%*s ", 10, date_s ); - break; - - case SQL_TYPE_TIME: - isc_decode_sql_time ( ( ISC_TIME ISC_FAR * ) var->sqldata, × ); - sprintf ( date_s, "%02d:%02d:%02d.%04lui", - times.tm_hour, - times.tm_min, - times.tm_sec, ( *( ( ISC_TIME * ) var->sqldata ) ) % 10000 ); - sprintf ( p, "%*s ", 13, date_s ); - break; - - case SQL_BLOB: - case SQL_ARRAY: - /* Print the blob id on blobs or arrays */ - bid = *( ISC_QUAD ISC_FAR * ) var->sqldata; - sprintf ( blob_s, "%08x:%08x", ( unsigned int ) bid.gds_quad_high, - ( unsigned int ) bid.gds_quad_low ); - sprintf ( p, "%17s ", blob_s ); - break; - - default: - break; - } - } - - return ( p ); -} +/* + * $Id$ + */ + +#include +#include +#include +#include +#include +#include + +#ifndef ISC_INT64_FORMAT + +#if (defined(_MSC_VER) && defined(WIN32)) || (defined(__BORLANDC__) && defined(__WIN32__)) +#define ISC_INT64_FORMAT "I64" +#else +#define ISC_INT64_FORMAT "ll" +#endif +#endif + +#define USER "sysdba" +#define PASSWORD "masterkey" +#define DATABASE "192.168.1.33:d:\\fontes\\lixo\\test.gdb" +#define ERREXIT(status, rc) {isc_print_status(status); return rc;} +#define MAX_BUFFER 1024 + +int execute( char *exec_str ); +int query( char *sel_str ); +int fetch( void ); +int qclose( void ); +char *getdata(int pos); + + +isc_db_handle db = NULL; +int dialect = 1; +XSQLDA ISC_FAR * sqlda; +isc_stmt_handle stmt = NULL; +isc_tr_handle trans = NULL; + +int main () +{ + char dpb[48]; + int i = 0, len; + long status[20]; + + dpb[i++] = isc_dpb_version1; + + dpb[i++] = isc_dpb_user_name; + len = strlen(USER); + dpb[i++] = (char) len; + strncpy(&(dpb[i]), USER, len); + i += len; + + dpb[i++] = isc_dpb_password; + len = strlen (PASSWORD); + dpb[i++] = len; + strncpy(&(dpb[i]), PASSWORD, len); + i += len; + + if (isc_attach_database(status, 0, DATABASE, &db, i, dpb)) + ERREXIT(status, 1); + + execute("DROP TABLE TESTE"); + + execute("CREATE TABLE TESTE (code smallint)"); + + execute("INSERT INTO TESTE (code) VALUES (100)"); + + query("SELECT * FROM TESTE"); + while (fetch() == 0) + printf("%s\n", getdata(0)); + qclose(); + + + if (isc_detach_database(status, &db)) + ERREXIT(status, 1); + + return 1; +} + +int execute( char *exec_str ) +{ + isc_tr_handle trans = NULL; + long status[20]; + + if (isc_start_transaction(status, &trans, 1, &db, 0, NULL)) + ERREXIT(status, 1); + + if (isc_dsql_execute_immediate(status, &db, &trans, 0, exec_str, dialect, NULL)) + ERREXIT(status, 1); + + if (isc_commit_transaction(status, &trans)) + ERREXIT(status, 1); + + return 1; +} + +int query( char *sel_str ) +{ + ISC_STATUS status[20]; + XSQLVAR *var; + + int n, i, dtype; + + if ( isc_start_transaction ( status, &trans, 1, &db, 0, NULL ) ) + ERREXIT(status, 1); + + // Allocate an output SQLDA. Just to check number of columns + sqlda = ( XSQLDA * ) malloc( XSQLDA_LENGTH ( 1 ) ); + sqlda->sqln = 1; + sqlda->version = 1; + + // Allocate a statement + if (isc_dsql_allocate_statement(status, &db, &stmt)) + ERREXIT(status, 1); + + // Prepare the statement. + if (isc_dsql_prepare(status, &trans, &stmt, 0, sel_str, dialect, sqlda)) + ERREXIT(status, 1); + + // Describe sql contents + if (isc_dsql_describe(status, &stmt, dialect, sqlda)) + ERREXIT(status, 1); + + // Relocate necessary number of columns + if ( sqlda->sqld > sqlda->sqln ) { + free( sqlda ); + n = sqlda->sqld; + sqlda = ( XSQLDA * ) malloc( XSQLDA_LENGTH ( n ) ); + sqlda->sqln = n; + sqlda->version = 1; + + if (isc_dsql_describe(status, &stmt, dialect, sqlda)) + ERREXIT(status, 1); + } + + for ( i = 0, var = sqlda->sqlvar; i < sqlda->sqld; i++, var++ ) { + dtype = ( var->sqltype & ~1 ); + switch ( dtype ) { + case SQL_VARYING: + var->sqltype = SQL_TEXT; + var->sqldata = ( char * ) malloc( sizeof ( char ) * var->sqllen + 2 ); + break; + case SQL_TEXT: + var->sqldata = ( char * ) malloc( sizeof ( char ) * var->sqllen + 2 ); + break; + case SQL_LONG: + var->sqltype = SQL_LONG; + var->sqldata = ( char * ) malloc( sizeof ( long ) ); + break; + default: + var->sqldata = ( char * ) malloc( sizeof ( char ) * var->sqllen ); + break; + } + if ( var->sqltype & 1 ) { + var->sqlind = ( short * ) malloc( sizeof ( short ) ); + } + } + + if ( !sqlda->sqld ) { + // Execute and commit non-select querys + if ( isc_dsql_execute ( status, &trans, &stmt, dialect, NULL ) ) + ERREXIT(status, 1); + + if (isc_commit_transaction(status, &trans)) + ERREXIT(status, 1); + + trans = NULL; + + } else { + if ( isc_dsql_execute ( status, &trans, &stmt, dialect, sqlda ) ) + ERREXIT(status, 1); + } + + return 1; +} + +int fetch( void ) +{ + long fetch_stat; + long status[20]; + + fetch_stat = isc_dsql_fetch(status, &stmt, dialect, sqlda); + + if (fetch_stat != 100L) + ERREXIT(status, 1); + + return fetch_stat; +} + +int qclose( void ) +{ + long status[20]; + + if (isc_dsql_free_statement(status, &stmt, DSQL_drop)) + ERREXIT(status, 1); + + if (trans) + if (isc_commit_transaction(status, &trans)) + ERREXIT(status, 1); + + if ( sqlda ) + free( sqlda ); + + return 1; +} + +char *getdata(int pos) +{ + short dtype; + char data[MAX_BUFFER], *p; + char blob_s[20], date_s[25]; + short len; + long status[20]; + + struct tm times; + ISC_QUAD bid; + XSQLVAR *var; + + if ( ( pos + 1 ) > sqlda->sqln ) + return "error"; + + var = sqlda->sqlvar; + + var += pos; + + dtype = var->sqltype & ~1; + p = data; + + if ( ( var->sqltype & 1 ) && ( *var->sqlind < 0 ) ) { + switch ( dtype ) { + case SQL_TEXT: + case SQL_VARYING: + len = var->sqllen; + break; + case SQL_SHORT: + len = 6; + if ( var->sqlscale > 0 ) + len += var->sqlscale; + break; + case SQL_LONG: + len = 11; + if ( var->sqlscale > 0 ) + len += var->sqlscale; + break; + case SQL_INT64: + len = 21; + if ( var->sqlscale > 0 ) + len += var->sqlscale; + break; + case SQL_FLOAT: + len = 15; + break; + case SQL_DOUBLE: + len = 24; + break; + case SQL_TIMESTAMP: + len = 24; + break; + case SQL_TYPE_DATE: + len = 10; + break; + case SQL_TYPE_TIME: + len = 13; + break; + case SQL_BLOB: + case SQL_ARRAY: + default: + len = 17; + break; + } + if ( ( dtype == SQL_TEXT ) || ( dtype == SQL_VARYING ) ) + sprintf ( p, "%-*s ", len, "NULL" ); + else + sprintf ( p, "%*s ", len, "NULL" ); + } else { + switch ( dtype ) { + case SQL_TEXT: + sprintf ( p, "%.*s ", var->sqllen, var->sqldata ); + break; + + case SQL_VARYING: + sprintf ( p, "%.*s ", var->sqllen, var->sqldata ); + break; + + case SQL_SHORT: + case SQL_LONG: + case SQL_INT64: + { + ISC_INT64 value = 0; + short field_width = 0; + short dscale; + + switch ( dtype ) { + case SQL_SHORT: + value = ( ISC_INT64 ) * ( short ISC_FAR * ) var->sqldata; + field_width = 6; + break; + case SQL_LONG: + value = ( ISC_INT64 ) * ( long ISC_FAR * ) var->sqldata; + field_width = 11; + break; + case SQL_INT64: + value = ( ISC_INT64 ) * ( ISC_INT64 ISC_FAR * ) var->sqldata; + field_width = 21; + break; + } + dscale = var->sqlscale; + if ( dscale < 0 ) { + ISC_INT64 tens; + short i; + + tens = 1; + for ( i = 0; i > dscale; i-- ) { + tens *= 10; + + if ( value >= 0 ) { + + sprintf ( p, + "%*" ISC_INT64_FORMAT "d.%0*" + ISC_INT64_FORMAT "d", + field_width - 1 + dscale, + ( ISC_INT64 ) ( value / tens ), -dscale, + ( ISC_INT64 ) ( value % tens ) ); + } else if ( ( value / tens ) != 0 ) { + + sprintf ( p, + "%*" ISC_INT64_FORMAT "d.%0*" + ISC_INT64_FORMAT "d", + field_width - 1 + dscale, + ( ISC_INT64 ) ( value / tens ), -dscale, + ( ISC_INT64 ) - ( value % tens ) ); + } else { + + sprintf ( p, "%*s.%0*" ISC_INT64_FORMAT "d", + field_width - 1 + dscale, + "-0", -dscale, + ( ISC_INT64 ) - ( value % tens ) ); + } + } + } else if ( dscale ) { + sprintf ( p, "%*" ISC_INT64_FORMAT "d%0*d", + field_width, ( ISC_INT64 ) value, dscale, 0 ); + } else { + sprintf ( p, "%*" ISC_INT64_FORMAT "d", + field_width, ( ISC_INT64 ) value ); + } + }; + break; + + case SQL_FLOAT: + sprintf ( p, "%15g ", *( float ISC_FAR * ) ( var->sqldata ) ); + break; + + case SQL_DOUBLE: + sprintf ( p, "%24f ", *( double ISC_FAR * ) ( var->sqldata ) ); + break; + + case SQL_TIMESTAMP: + isc_decode_timestamp ( ( ISC_TIMESTAMP ISC_FAR * ) var->sqldata, × ); + sprintf ( date_s, "%04d-%02d-%02d %02d:%02d:%02d.%04lui", + times.tm_year + 1900, + times.tm_mon + 1, + times.tm_mday, + times.tm_hour, + times.tm_min, + times.tm_sec, + ( ( ISC_TIMESTAMP * ) var->sqldata )->timestamp_time % 10000 ); + sprintf ( p, "%*s ", 24, date_s ); + break; + + case SQL_TYPE_DATE: + isc_decode_sql_date ( ( ISC_DATE ISC_FAR * ) var->sqldata, × ); + sprintf ( date_s, "%04d-%02d-%02d", + times.tm_year + 1900, times.tm_mon + 1, times.tm_mday ); + sprintf ( p, "%*s ", 10, date_s ); + break; + + case SQL_TYPE_TIME: + isc_decode_sql_time ( ( ISC_TIME ISC_FAR * ) var->sqldata, × ); + sprintf ( date_s, "%02d:%02d:%02d.%04lui", + times.tm_hour, + times.tm_min, + times.tm_sec, ( *( ( ISC_TIME * ) var->sqldata ) ) % 10000 ); + sprintf ( p, "%*s ", 13, date_s ); + break; + + case SQL_BLOB: + case SQL_ARRAY: + /* Print the blob id on blobs or arrays */ + bid = *( ISC_QUAD ISC_FAR * ) var->sqldata; + sprintf ( blob_s, "%08x:%08x", ( unsigned int ) bid.gds_quad_high, + ( unsigned int ) bid.gds_quad_low ); + sprintf ( p, "%17s ", blob_s ); + break; + + default: + break; + } + } + + return ( p ); +} diff --git a/harbour/contrib/firebird/tfirebird.prg b/harbour/contrib/firebird/tfirebird.prg index 15ba12f7fa..caaba0547e 100644 --- a/harbour/contrib/firebird/tfirebird.prg +++ b/harbour/contrib/firebird/tfirebird.prg @@ -1,1063 +1,1063 @@ -/* - * $Id: atrepl.c 7583 2007-07-06 21:17:36Z druzus $ - */ - -/* - * xHarbour Project source code: - * Firebird RDBMS low level (client api) interface code. - * - * Copyright 2003 Rodrigo Moreno rodrigo_moreno@yahoo.com - * www - http://www.xharbour.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). - * - * As a special exception, the Harbour Project gives permission for - * additional uses of the text contained in its release of Harbour. - * - * The exception is that, if you link the Harbour libraries with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the Harbour library code into it. - * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by the Harbour - * Project under the name Harbour. If you copy code from other - * Harbour Project or Free Software Foundation releases into a copy of - * Harbour, as the General Public License permits, the exception does - * not apply to the code that you add in this way. To avoid misleading - * anyone as to the status of such modified files, you must delete - * this exception notice from them. - * - * If you write modifications of your own for Harbour, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. - * - * See doc/license.txt for licensing terms. - * - */ - -#include "common.ch" -#include "hbclass.ch" - -#define SQL_TEXT 452 -#define SQL_VARYING 448 -#define SQL_SHORT 500 -#define SQL_LONG 496 -#define SQL_FLOAT 482 -#define SQL_DOUBLE 480 -#define SQL_D_FLOAT 530 -#define SQL_TIMESTAMP 510 -#define SQL_BLOB 520 -#define SQL_ARRAY 540 -#define SQL_QUAD 550 -#define SQL_TYPE_TIME 560 -#define SQL_TYPE_DATE 570 -#define SQL_INT64 580 -#define SQL_DATE SQL_TIMESTAMP - - -CLASS TFbServer - DATA db - DATA trans - DATA StartedTrans - DATA nError - DATA lError - DATA dialect - - METHOD New( cServer, cUser, cPassword, nDialect ) - METHOD Destroy() INLINE FBClose(::db) - METHOD Close() INLINE FBClose(::db) - - METHOD TableExists( cTable ) - METHOD ListTables() - METHOD TableStruct( cTable ) - - METHOD StartTransaction() - METHOD Commit() - METHOD Rollback() - - METHOD Execute( cQuery ) - METHOD Query( cQuery ) - - METHOD Update( oRow, cWhere ) - METHOD Delete( oRow, cWhere ) - METHOD Append( oRow ) - - METHOD NetErr() INLINE ::lError - METHOD Error() INLINE FBError(::nError) - METHOD ErrorNo() INLINE ::nError -ENDCLASS - - -METHOD New( cServer, cUser, cPassword, nDialect ) CLASS TFbServer - - Default nDialect TO 1 - - ::lError := .F. - ::nError := 0 - ::StartedTrans := .F. - ::Dialect := nDialect - - ::db := FBConnect(cServer, cUser, cPassword) - - if ISNUMBER(::db) - ::lError := .T. - ::nError := ::db - end -RETURN self - - -METHOD StartTransaction() CLASS TFbServer - Local result := .F. - - ::trans := FBStartTransaction(::db) - - if ISNUMBER(::trans) - ::lError := .T. - ::nError := ::trans - else - result := .T. - ::lError := .F. - ::lnError := 0 - ::StartedTrans := .T. - end -RETURN result - - -METHOD Rollback() CLASS TFbServer - Local result := .F., n - - if ::StartedTrans - if (n := FBRollback(::trans)) < 0 - ::lError := .T. - ::nError := n - else - ::lError := .F. - ::nError := 0 - result := .T. - ::StartedTrans := .F. - end - end -RETURN result - - -METHOD Commit() CLASS TFbServer - Local result := .F., n - - if ::StartedTrans - if (n := FBCommit(::trans)) < 0 - ::lError := .T. - ::nError := n - else - ::lError := .F. - ::nError := 0 - result := .T. - ::StartedTrans := .F. - end - end -RETURN result - - -METHOD Execute( cQuery ) CLASS TFbServer - Local result, n - - cQuery := RemoveSpaces(cQuery) - - if ::StartedTrans - n := FBExecute( ::db, cQuery, ::dialect, ::trans ) - else - n := FBExecute( ::db, cQuery, ::dialect ) - end - - if n < 0 - ::lError := .T. - ::nError := n - result := .F. - else - ::lError := .F. - ::nError := 0 - result := .T. - end -RETURN result - - -METHOD Query( cQuery ) CLASS TFbServer - Local oQuery - - oQuery := TFbQuery():New(::db, cQuery, ::dialect) -RETURN oQuery - - -METHOD TableExists( cTable ) CLASS TFbServer - Local cQuery, result := .F., qry - - cQuery := 'select rdb$relation_name from rdb$relations where rdb$relation_name = "' + Upper(cTable) + '"' - - qry := FBQuery(::db, cQuery, ::dialect) - - if ISARRAY(qry) - result := (FBFetch(qry) == 0) - - FBFree(qry) - end - -RETURN result - - -METHOD ListTables() CLASS TFbServer - Local result := {}, cQuery, qry, fetch_stmt - - cQuery := 'select rdb$relation_name ' - cQuery += ' from rdb$relations ' - cQuery += ' where rdb$relation_name not like "RDB$%" ' - cQuery += ' and rdb$view_blr is null ' - cQuery += ' order by 1 ' - - qry := FBQuery(::db, RemoveSpaces(cQuery), ::dialect) - - if ISARRAY(qry) - do while (fetch_stmt := FBFetch(qry)) == 0 - aadd( result, FBGetdata(qry, 1) ) - end - - FBFree(qry) - end -RETURN result - - -METHOD TableStruct( cTable ) CLASS TFbServer - Local result := {}, cQuery, cType, nSize, cDomain, cField, nType, nDec, fetch_stmt - Local qry - - - cQuery := 'select ' - cQuery += ' a.rdb$field_name,' - cQuery += ' b.rdb$field_type,' - cQuery += ' b.rdb$field_length,' - cQuery += ' b.rdb$field_scale * -1,' - cQuery += ' a.rdb$field_source ' - cQuery += 'from ' - cQuery += ' rdb$relation_fields a, rdb$fields b ' - cQuery += 'where ' - cQuery += ' a.rdb$field_source = b.rdb$field_name ' - cQuery += ' and a.rdb$relation_name = "' + Upper(ctable) + '" ' - cQuery += 'order by ' - cQuery += ' a.rdb$field_position ' - - qry := FBQuery(::db, RemoveSpaces(cQuery), ::dialect) - - if ISARRAY(qry) - do while (fetch_stmt := FBFetch(qry)) == 0 - cField := FBGetData(qry, 1) - nType := val(FBGetData(qry, 2)) - nSize := val(FBGetData(qry, 3)) - nDec := val(FBGetData(qry, 4)) - cDomain := FBGetData(qry, 5) - - switch nType - case 7 // SMALLINT - if "BOOL" $ cDomain - cType := "L" - nSize := 1 - nDec := 0 - else - cType := 'N' - nSize := 5 - end - - exit - - case 8 // INTEGER - case 9 - cType := 'N' - nSize := 9 - exit - - case 10 // FLOAT - case 11 - cType := 'N' - nSize := 15 - exit - - case 12 // DATE - cType := 'D' - nSize := 8 - exit - - case 13 // TIME - cType := 'C' - nSize := 10 - exit - - case 14 // CHAR - cType := 'C' - exit - - case 16 // INT64 - cType := 'N' - nSize := 9 - exit - - case 27 // DOUBLE - cType := 'N' - nSize := 15 - exit - - case 35 // TIMESTAMP - cType := 'D' - nSize := 8 - exit - - case 37 // VARCHAR - case 40 - cType := 'C' - exit - - case 261 // BLOB - cType := 'M' - nSize := 10 - exit - - otherwise - cType := 'C' - nDec := 0 - end - - aadd( result, { cField, cType, nSize, nDec } ) - - end - - FBFree(qry) - end -RETURN result - - -METHOD Delete( oRow, cWhere ) CLASS TFbServer - Local result := .F., aKeys, i, nField, xField, cQuery, aTables - - aTables := oRow:GetTables() - - if ! ISNUMBER(::db) .and. len(aTables) == 1 - // Cannot delete joined tables - - if ISNIL(cWhere) - aKeys := oRow:GetKeyField() - - cWhere := '' - For i := 1 to len(aKeys) - nField := oRow:Fieldpos(aKeys[i]) - xField := oRow:Fieldget(nField) - - cWhere += aKeys[i] + '=' + DataToSql(xField) - - if i <> len(aKeys) - cWhere += ',' - end - Next - end - - if ! (cWhere == '') - cQuery := 'DELETE FROM ' + aTables[1] + ' WHERE ' + cWhere - - result := ::Execute(cQuery) - end - end -RETURN result - - -METHOD Append( oRow ) CLASS TFbServer - Local result := .F., cQuery, i, aTables - - aTables := oRow:GetTables() - - if ! ISNUMBER(::db) .and. len(aTables) == 1 - // Can insert only one table, not in joined tables - - cQuery := 'INSERT INTO ' + aTables[1] + '(' - For i := 1 to oRow:FCount() - if oRow:Changed(i) - // Send only changed field - cQuery += oRow:Fieldname(i) + ',' - end - Next - - cQuery := Left( cQuery, len(cQuery) - 1 ) + ') VALUES (' - - For i := 1 to oRow:FCount() - if oRow:Changed(i) - cQuery += DataToSql(oRow:FieldGet(i)) + ',' - end - Next - - cQuery := Left( cQuery, len(cQuery) - 1 ) + ')' - - result := ::Execute(cQuery) - end -RETURN result - - -METHOD Update( oRow, cWhere ) CLASS TFbServer - Local result := .F., aKeys, cQuery, i, nField, xField, aTables - - aTables := oRow:GetTables() - - if ! ISNUMBER(::db) .and. len(aTables) == 1 - // Can't insert joined tables - - if ISNIL(cWhere) - aKeys := oRow:GetKeyField() - - cWhere := '' - For i := 1 to len(aKeys) - nField := oRow:Fieldpos(aKeys[i]) - xField := oRow:Fieldget(nField) - - cWhere += aKeys[i] + '=' + DataToSql(xField) - - if i <> len(aKeys) - cWhere += ', ' - end - Next - end - - cQuery := 'UPDATE ' + aTables[1] + ' SET ' - For i := 1 to oRow:FCount() - if oRow:Changed(i) - cQuery += oRow:Fieldname(i) + ' = ' + DataToSql(oRow:FieldGet(i)) + ',' - end - Next - - if ! (cWhere == '') - cQuery := Left( cQuery, len(cQuery) - 1 ) + ' WHERE ' + cWhere - - result := ::Execute(cQuery) - end - end -RETURN result - - -CLASS TFbQuery - DATA ErrorNo - DATA nError - DATA lError - DATA Dialect - DATA lBof - DATA lEof - DATA nRecno - DATA qry - DATA aStruct - DATA numcols - DATA closed - DATA db - DATA query - DATA aKeys - DATA aTables - - METHOD New( db, cQuery, nDialect ) - METHOD Destroy() - METHOD Close() INLINE ::Destroy() - - METHOD Refresh() - METHOD Fetch() - METHOD Skip() INLINE ::Fetch() - - METHOD Bof() INLINE ::lBof - METHOD Eof() INLINE ::lEof - METHOD RecNo() INLINE ::nRecno - - METHOD NetErr() INLINE ::lError - METHOD Error() INLINE FBError(::nError) - METHOD ErrorNo() INLINE ::nError - - METHOD FCount() INLINE ::numcols - METHOD Struct() - METHOD FieldName( nField ) - METHOD FieldPos( cField ) - METHOD FieldLen( nField ) - METHOD FieldDec( nField ) - METHOD FieldType( nField ) - - METHOD FieldGet( nField ) - METHOD GetRow() - METHOD GetBlankRow() - METHOD Blank() INLINE ::GetBlankRow() - METHOD GetKeyField() - -ENDCLASS - - -METHOD New( nDB, cQuery, nDialect ) CLASS TFbQuery - ::db := nDb - ::query := RemoveSpaces(cQuery) - ::dialect := nDialect - ::closed := .T. - ::aKeys := NIL - - ::Refresh() - -RETURN self - - -METHOD Refresh() CLASS TFbQuery - Local qry, result := .F., i, aTable := {} - - if ! ::closed - ::Destroy() - end - - ::lBof := .T. - ::lEof := .F. - ::nRecno := 0 - ::closed := .F. - ::numcols := 0 - ::aStruct := {} - ::nError := 0 - ::lError := .F. - - result := .T. - - qry := FBQuery( ::db, ::query, ::dialect ) - - if ISARRAY(qry) - ::numcols := qry[4] - - ::aStruct := StructConvert(qry[6], ::db, ::dialect) - - ::lError := .F. - ::nError := 0 - ::qry := qry - - /* Tables in query */ - For i := 1 To len(::aStruct) - if (ASCAN(aTable, ::aStruct[i,5]) == 0) - aadd( aTable, ::aStruct[i,5]) - end - Next - - ::aTables := aTable - - else - ::lError := .T. - ::nError := qry - end - -RETURN result - - -METHOD Destroy() CLASS TFbQuery - Local result := .T., n - - if (! ::lError) .and. ((n := FBFree(::qry)) < 0) - ::lError := .T. - ::nError := n - end - - ::closed := .T. - -RETURN result - - -METHOD Fetch() CLASS TFbQuery - Local result := .F., fetch_stat - - if ! ::lError .and. ! ::lEof - - if ! ::Closed - fetch_stat := FBFetch(::qry) - - ::nRecno++ - - if fetch_stat == 0 - ::lBof := .F. - result := .T. - - else - ::lEof := .T. - - end - end - end -RETURN result - - -METHOD Struct() CLASS TFbQuery - Local result := {}, i - - if ! ::lError - for i := 1 to Len(::aStruct) - aadd( result, { ::aStruct[i,1], ::aStruct[i,2], ::aStruct[i,3], ::aStruct[i,4] } ) - next - end - -RETURN result - - -METHOD FieldPos( cField ) CLASS TFbQuery - Local result := 0 - - if ! ::lError - result := AScan( ::aStruct, {|x| x[1] == trim(Upper(cField)) }) - end - -RETURN result - - -METHOD FieldName( nField ) CLASS TFbQuery - Local result - - if ! ::lError .and. nField >= 1 .and. nField <= len(::aStruct) - result := ::aStruct[nField, 1] - end - -RETURN result - - -METHOD FieldType( nField ) CLASS TFbQuery - Local result - - if ! ::lError .and. nField >= 1 .and. nField <= len(::aStruct) - result := ::aStruct[nField, 2] - end - -RETURN result - - -METHOD FieldLen( nField ) CLASS TFbQuery - Local result - - if ! ::lError .and. nField >= 1 .and. nField <= len(::aStruct) - result := ::aStruct[nField, 3] - end -RETURN result - - -METHOD FieldDec( nField ) CLASS TFbQuery - Local result - - if ! ::lError .and. nField >= 1 .and. nField <= len(::aStruct) - result := ::aStruct[nField, 4] - end -RETURN result - - -METHOD FieldGet( nField ) CLASS TFbQuery - Local result, aBlob, i, cType - - if ! ::lError .and. nField >= 1 .and. nField <= len(::aStruct) .and. ! ::closed - - /* TODO: Convert to right data type */ - - result := FBGetData(::qry, nField) - cType := ::aStruct[ nField, 2 ] - - if cType == "M" - /* Blob */ - - if ! ISNIL(result) - aBlob := FBGetBlob( ::db, result) - - result := '' - For i := 1 to Len(aBlob) - result += aBlob[i] - Next - - //result := FBGetBlob( ::db, result) - else - result := '' - end - - elseif cType == "N" - if ! ISNIL(result) - result := val(result) - else - result := 0 - end - - elseif cType == "D" - if ! ISNIL(result) - result := StoD(left(result,4) + substr(result, 5, 2) + substr(result, 7, 2)) - else - result := CtoD('') - end - - elseif cType == "L" - if ! ISNIL(result) - result := (val(result) == 1) - else - result := .F. - end - end - end -RETURN result - - -METHOD Getrow() CLASS TFbQuery - Local result, aRow := {}, i - - if ! ::lError .and. ! ::closed - ASize(aRow, ::numcols) - - For i := 1 to ::numcols - aRow[i] := ::Fieldget(i) - Next - - result := TFbRow():New( aRow, ::aStruct, ::db, ::dialect, ::aTables ) - end -RETURN result - - -METHOD GetBlankRow() CLASS TFbQuery - Local result, aRow := {}, i - - if ! ::lError - ASize(aRow, ::numcols) - - For i := 1 to ::numcols - if ::aStruct[i, 2] == 'C' - aRow[i] := '' - elseif ::aStruct[i, 2] == 'N' - aRow[i] := 0 - elseif ::aStruct[i, 2] == 'L' - aRow[i] := .F. - elseif ::aStruct[i, 2] == 'D' - aRow[i] := CtoD('') - elseif ::aStruct[i, 2] == 'M' - aRow[i] := '' - end - Next - - result := TFbRow():New( aRow, ::aStruct, ::db, ::dialect, ::aTables ) - end -RETURN result - - -METHOD GetKeyField() CLASS TFbQuery - - if ISNIL(::aKeys) - ::aKeys := KeyField( ::aTables, ::db, ::dialect ) - end -RETURN ::aKeys - - -CLASS TFbRow - DATA aRow - DATA aStruct - DATA aChanged - DATA aKeys - DATA db - DATA dialect - DATA aTables - - METHOD New( row, struct, db, dialect ) - METHOD Changed(nField) - METHOD GetTables() INLINE ::aTables - METHOD FCount() INLINE Len(::aRow) - METHOD FieldGet( nField ) - METHOD FieldPut( nField, Value ) - METHOD FieldName( nField ) - METHOD FieldPos( cFieldName ) - METHOD FieldLen( nField ) - METHOD FieldDec( nField ) - METHOD FieldType( nField ) - METHOD GetKeyField() -ENDCLASS - - -METHOD new( row, struct, nDb, nDialect, aTable ) CLASS TFbRow - ::aRow := row - ::aStruct := struct - ::db := nDB - ::dialect := nDialect - ::aTables := aTable - ::aChanged := Array(len(row)) -RETURN self - - -METHOD Changed( nField ) CLASS TFbRow - Local result - - if nField >= 1 .and. nField <= len(::aRow) - result := ! ISNIL(::aChanged[nField]) - end - -RETURN result - - -METHOD FieldGet( nField ) CLASS TFbRow - Local result - - if nField >= 1 .and. nField <= len(::aRow) - result := ::aRow[nField] - end - -RETURN result - - -METHOD FieldPut( nField, Value ) CLASS TFbRow - Local result - - if nField >= 1 .and. nField <= len(::aRow) - ::aChanged[nField] := .T. - result := ::aRow[nField] := Value - end - -RETURN result - - -METHOD FieldName( nField ) CLASS TFbRow - Local result - - if nField >= 1 .and. nField <= len(::aStruct) - result := ::aStruct[nField, 1] - end - -RETURN result - - -METHOD FieldPos( cField ) CLASS TFbRow - Local result := 0 - - result := AScan( ::aStruct, {|x| x[1] == trim(Upper(cField)) }) - -RETURN result - - -METHOD FieldType( nField ) CLASS TFbRow - Local result - - if nField >= 1 .and. nField <= len(::aStruct) - result := ::aStruct[nField, 2] - end - -RETURN result - - -METHOD FieldLen( nField ) CLASS TFbRow - Local result - - if nField >= 1 .and. nField <= len(::aStruct) - result := ::aStruct[nField, 3] - end -RETURN result - - -METHOD FieldDec( nField ) CLASS TFbRow - Local result - - if nField >= 1 .and. nField <= len(::aStruct) - result := ::aStruct[nField, 4] - end -RETURN result - - -METHOD GetKeyField() CLASS TFbRow - - if ISNIL(::aKeys) - ::aKeys := KeyField( ::aTables, ::db, ::dialect ) - end -RETURN ::aKeys - - - -Static Function KeyField( aTables, db, dialect ) - Local cTable, cQuery - Local qry, fetch_stmt - Local aKeys := {} - - /* Check row, many tables exists in current query, so we must have only one table */ - - if Len(aTables) = 1 - cTable := aTables[1] - - cQuery := ' select ' - cQuery += ' a.rdb$field_name ' - cQuery += ' from ' - cQuery += ' rdb$index_segments a, ' - cQuery += ' rdb$relation_constraints b ' - cQuery += ' where ' - cQuery += ' a.rdb$index_name = b.rdb$index_name and ' - cQuery += ' b.rdb$constraint_type = "PRIMARY KEY" and ' - cQuery += ' b.rdb$relation_name = ' + DataToSql(cTable) - cQuery += ' order by ' - cQuery += ' b.rdb$relation_name, ' - cQuery += ' a.rdb$field_position ' - - qry := FBQuery(db, RemoveSpaces(cQuery), dialect) - - if ISARRAY(qry) - do while (fetch_stmt := FBFetch(qry)) == 0 - aadd(aKeys, trim(FBGetdata(qry, 1))) - end - - FBFree(qry) - end - end - -RETURN aKeys - - -Static Function DataToSql(xField) - Local cType, result - - cType := ValType(xField) - - if cType == "C" - result := '"' + strtran(xField, '"', ' ') + '"' - elseif cType == "D" - result := '"' + StrZero(month(xField),2) + '/' + StrZero(day(xField),2) + '/' + StrZero(Year(xField),4) + '"' - elseif cType == "N" - result := str(xField) - elseif cType == "L" - result := iif( xField, '1', '0' ) - end - -return result - - -Static Function StructConvert( aStru, db, dialect) - Local aNew := {} - Local cField - Local nType - Local cType - Local nSize - Local nDec - Local cTable - Local cDomain - Local i - Local qry - Local cQuery - Local aDomains := {} - Local fetch_stmt - Local nVal - - Local xTables := '' - Local xFields := '' - - /* create table list and field list */ - - For i := 1 to Len(aStru) - xtables += DataToSql(aStru[i, 5]) - xfields += DataToSql(aStru[i, 1]) - - if i <> len(aStru) - xtables += ',' - xfields += ',' - end - Next - - /* Look for domains */ - cQuery := 'select rdb$relation_name, rdb$field_name, rdb$field_source ' - cQuery += ' from rdb$relation_fields ' - cQuery += ' where rdb$field_name not like "RDB$%" ' - cQuery += ' and rdb$relation_name in (' + xtables + ')' - cQuery += ' and rdb$field_name in (' + xfields + ')' - - qry := FBQuery(db, RemoveSpaces(cQuery), dialect) - - if ISARRAY(qry) - - do while (fetch_stmt := FBFetch(qry)) == 0 - aadd( aDomains, { FBGetdata(qry, 1), FBGetdata(qry,2), FBGetdata(qry,3) } ) - end - - FBFree(qry) - - For i := 1 to Len(aStru) - cField := trim(aStru[i,1]) - nType := aStru[i,2] - nSize := aStru[i,3] - nDec := aStru[i,4] * -1 - cTable := trim(aStru[i,5]) - - nVal := AScan(aDomains, {|x| trim(x[1]) == cTable .and. trim(x[2]) == cField}) - - if nVal != 0 - cDomain := aDomains[ nVal, 3 ] - else - cDomain := '' - end - - switch nType - case SQL_TEXT - cType := "C" - exit - case SQL_VARYING - cType := "C" - exit - case SQL_SHORT - /* Firebird doesn't have boolean field, so if you define domain with BOOL then i will consider logical, ex: - create domain boolean_field as smallint default 0 not null check (value in (0,1)) */ - - if "BOOL" $ cDomain - cType := "L" - nSize := 1 - nDec := 0 - else - cType := "N" - nSize := 5 - end - exit - case SQL_LONG - cType := "N" - nSize := 9 - exit - case SQL_INT64 - cType := "N" - nSize := 9 - exit - case SQL_FLOAT - cType := "N" - nSize := 15 - exit - case SQL_DOUBLE - cType := "N" - nSize := 15 - exit - case SQL_TIMESTAMP - cType := "D" - nSize := 8 - exit - case SQL_TYPE_DATE - cType := "D" - nSize := 8 - exit - case SQL_TYPE_TIME - cType := "C" - nSize := 8 - exit - case SQL_BLOB - cType := "M" - nSize := 10 - exit - otherwise - cType := "C" - nDec := 0 - end - - aadd( aNew, { cField, cType, nSize, nDec, cTable, cDomain } ) - Next - End - -return aNew - -Static Function RemoveSpaces( cQuery ) - Do While AT(" ", cQuery) != 0 - cQuery := Strtran(cQuery, " ", " ") - end -Return cQuery +/* + * $Id$ + */ + +/* + * xHarbour Project source code: + * Firebird RDBMS low level (client api) interface code. + * + * Copyright 2003 Rodrigo Moreno rodrigo_moreno@yahoo.com + * www - http://www.xharbour.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + * See doc/license.txt for licensing terms. + * + */ + +#include "common.ch" +#include "hbclass.ch" + +#define SQL_TEXT 452 +#define SQL_VARYING 448 +#define SQL_SHORT 500 +#define SQL_LONG 496 +#define SQL_FLOAT 482 +#define SQL_DOUBLE 480 +#define SQL_D_FLOAT 530 +#define SQL_TIMESTAMP 510 +#define SQL_BLOB 520 +#define SQL_ARRAY 540 +#define SQL_QUAD 550 +#define SQL_TYPE_TIME 560 +#define SQL_TYPE_DATE 570 +#define SQL_INT64 580 +#define SQL_DATE SQL_TIMESTAMP + + +CLASS TFbServer + DATA db + DATA trans + DATA StartedTrans + DATA nError + DATA lError + DATA dialect + + METHOD New( cServer, cUser, cPassword, nDialect ) + METHOD Destroy() INLINE FBClose(::db) + METHOD Close() INLINE FBClose(::db) + + METHOD TableExists( cTable ) + METHOD ListTables() + METHOD TableStruct( cTable ) + + METHOD StartTransaction() + METHOD Commit() + METHOD Rollback() + + METHOD Execute( cQuery ) + METHOD Query( cQuery ) + + METHOD Update( oRow, cWhere ) + METHOD Delete( oRow, cWhere ) + METHOD Append( oRow ) + + METHOD NetErr() INLINE ::lError + METHOD Error() INLINE FBError(::nError) + METHOD ErrorNo() INLINE ::nError +ENDCLASS + + +METHOD New( cServer, cUser, cPassword, nDialect ) CLASS TFbServer + + Default nDialect TO 1 + + ::lError := .F. + ::nError := 0 + ::StartedTrans := .F. + ::Dialect := nDialect + + ::db := FBConnect(cServer, cUser, cPassword) + + if ISNUMBER(::db) + ::lError := .T. + ::nError := ::db + end +RETURN self + + +METHOD StartTransaction() CLASS TFbServer + Local result := .F. + + ::trans := FBStartTransaction(::db) + + if ISNUMBER(::trans) + ::lError := .T. + ::nError := ::trans + else + result := .T. + ::lError := .F. + ::lnError := 0 + ::StartedTrans := .T. + end +RETURN result + + +METHOD Rollback() CLASS TFbServer + Local result := .F., n + + if ::StartedTrans + if (n := FBRollback(::trans)) < 0 + ::lError := .T. + ::nError := n + else + ::lError := .F. + ::nError := 0 + result := .T. + ::StartedTrans := .F. + end + end +RETURN result + + +METHOD Commit() CLASS TFbServer + Local result := .F., n + + if ::StartedTrans + if (n := FBCommit(::trans)) < 0 + ::lError := .T. + ::nError := n + else + ::lError := .F. + ::nError := 0 + result := .T. + ::StartedTrans := .F. + end + end +RETURN result + + +METHOD Execute( cQuery ) CLASS TFbServer + Local result, n + + cQuery := RemoveSpaces(cQuery) + + if ::StartedTrans + n := FBExecute( ::db, cQuery, ::dialect, ::trans ) + else + n := FBExecute( ::db, cQuery, ::dialect ) + end + + if n < 0 + ::lError := .T. + ::nError := n + result := .F. + else + ::lError := .F. + ::nError := 0 + result := .T. + end +RETURN result + + +METHOD Query( cQuery ) CLASS TFbServer + Local oQuery + + oQuery := TFbQuery():New(::db, cQuery, ::dialect) +RETURN oQuery + + +METHOD TableExists( cTable ) CLASS TFbServer + Local cQuery, result := .F., qry + + cQuery := 'select rdb$relation_name from rdb$relations where rdb$relation_name = "' + Upper(cTable) + '"' + + qry := FBQuery(::db, cQuery, ::dialect) + + if ISARRAY(qry) + result := (FBFetch(qry) == 0) + + FBFree(qry) + end + +RETURN result + + +METHOD ListTables() CLASS TFbServer + Local result := {}, cQuery, qry, fetch_stmt + + cQuery := 'select rdb$relation_name ' + cQuery += ' from rdb$relations ' + cQuery += ' where rdb$relation_name not like "RDB$%" ' + cQuery += ' and rdb$view_blr is null ' + cQuery += ' order by 1 ' + + qry := FBQuery(::db, RemoveSpaces(cQuery), ::dialect) + + if ISARRAY(qry) + do while (fetch_stmt := FBFetch(qry)) == 0 + aadd( result, FBGetdata(qry, 1) ) + end + + FBFree(qry) + end +RETURN result + + +METHOD TableStruct( cTable ) CLASS TFbServer + Local result := {}, cQuery, cType, nSize, cDomain, cField, nType, nDec, fetch_stmt + Local qry + + + cQuery := 'select ' + cQuery += ' a.rdb$field_name,' + cQuery += ' b.rdb$field_type,' + cQuery += ' b.rdb$field_length,' + cQuery += ' b.rdb$field_scale * -1,' + cQuery += ' a.rdb$field_source ' + cQuery += 'from ' + cQuery += ' rdb$relation_fields a, rdb$fields b ' + cQuery += 'where ' + cQuery += ' a.rdb$field_source = b.rdb$field_name ' + cQuery += ' and a.rdb$relation_name = "' + Upper(ctable) + '" ' + cQuery += 'order by ' + cQuery += ' a.rdb$field_position ' + + qry := FBQuery(::db, RemoveSpaces(cQuery), ::dialect) + + if ISARRAY(qry) + do while (fetch_stmt := FBFetch(qry)) == 0 + cField := FBGetData(qry, 1) + nType := val(FBGetData(qry, 2)) + nSize := val(FBGetData(qry, 3)) + nDec := val(FBGetData(qry, 4)) + cDomain := FBGetData(qry, 5) + + switch nType + case 7 // SMALLINT + if "BOOL" $ cDomain + cType := "L" + nSize := 1 + nDec := 0 + else + cType := 'N' + nSize := 5 + end + + exit + + case 8 // INTEGER + case 9 + cType := 'N' + nSize := 9 + exit + + case 10 // FLOAT + case 11 + cType := 'N' + nSize := 15 + exit + + case 12 // DATE + cType := 'D' + nSize := 8 + exit + + case 13 // TIME + cType := 'C' + nSize := 10 + exit + + case 14 // CHAR + cType := 'C' + exit + + case 16 // INT64 + cType := 'N' + nSize := 9 + exit + + case 27 // DOUBLE + cType := 'N' + nSize := 15 + exit + + case 35 // TIMESTAMP + cType := 'D' + nSize := 8 + exit + + case 37 // VARCHAR + case 40 + cType := 'C' + exit + + case 261 // BLOB + cType := 'M' + nSize := 10 + exit + + otherwise + cType := 'C' + nDec := 0 + end + + aadd( result, { cField, cType, nSize, nDec } ) + + end + + FBFree(qry) + end +RETURN result + + +METHOD Delete( oRow, cWhere ) CLASS TFbServer + Local result := .F., aKeys, i, nField, xField, cQuery, aTables + + aTables := oRow:GetTables() + + if ! ISNUMBER(::db) .and. len(aTables) == 1 + // Cannot delete joined tables + + if ISNIL(cWhere) + aKeys := oRow:GetKeyField() + + cWhere := '' + For i := 1 to len(aKeys) + nField := oRow:Fieldpos(aKeys[i]) + xField := oRow:Fieldget(nField) + + cWhere += aKeys[i] + '=' + DataToSql(xField) + + if i <> len(aKeys) + cWhere += ',' + end + Next + end + + if ! (cWhere == '') + cQuery := 'DELETE FROM ' + aTables[1] + ' WHERE ' + cWhere + + result := ::Execute(cQuery) + end + end +RETURN result + + +METHOD Append( oRow ) CLASS TFbServer + Local result := .F., cQuery, i, aTables + + aTables := oRow:GetTables() + + if ! ISNUMBER(::db) .and. len(aTables) == 1 + // Can insert only one table, not in joined tables + + cQuery := 'INSERT INTO ' + aTables[1] + '(' + For i := 1 to oRow:FCount() + if oRow:Changed(i) + // Send only changed field + cQuery += oRow:Fieldname(i) + ',' + end + Next + + cQuery := Left( cQuery, len(cQuery) - 1 ) + ') VALUES (' + + For i := 1 to oRow:FCount() + if oRow:Changed(i) + cQuery += DataToSql(oRow:FieldGet(i)) + ',' + end + Next + + cQuery := Left( cQuery, len(cQuery) - 1 ) + ')' + + result := ::Execute(cQuery) + end +RETURN result + + +METHOD Update( oRow, cWhere ) CLASS TFbServer + Local result := .F., aKeys, cQuery, i, nField, xField, aTables + + aTables := oRow:GetTables() + + if ! ISNUMBER(::db) .and. len(aTables) == 1 + // Can't insert joined tables + + if ISNIL(cWhere) + aKeys := oRow:GetKeyField() + + cWhere := '' + For i := 1 to len(aKeys) + nField := oRow:Fieldpos(aKeys[i]) + xField := oRow:Fieldget(nField) + + cWhere += aKeys[i] + '=' + DataToSql(xField) + + if i <> len(aKeys) + cWhere += ', ' + end + Next + end + + cQuery := 'UPDATE ' + aTables[1] + ' SET ' + For i := 1 to oRow:FCount() + if oRow:Changed(i) + cQuery += oRow:Fieldname(i) + ' = ' + DataToSql(oRow:FieldGet(i)) + ',' + end + Next + + if ! (cWhere == '') + cQuery := Left( cQuery, len(cQuery) - 1 ) + ' WHERE ' + cWhere + + result := ::Execute(cQuery) + end + end +RETURN result + + +CLASS TFbQuery + DATA ErrorNo + DATA nError + DATA lError + DATA Dialect + DATA lBof + DATA lEof + DATA nRecno + DATA qry + DATA aStruct + DATA numcols + DATA closed + DATA db + DATA query + DATA aKeys + DATA aTables + + METHOD New( db, cQuery, nDialect ) + METHOD Destroy() + METHOD Close() INLINE ::Destroy() + + METHOD Refresh() + METHOD Fetch() + METHOD Skip() INLINE ::Fetch() + + METHOD Bof() INLINE ::lBof + METHOD Eof() INLINE ::lEof + METHOD RecNo() INLINE ::nRecno + + METHOD NetErr() INLINE ::lError + METHOD Error() INLINE FBError(::nError) + METHOD ErrorNo() INLINE ::nError + + METHOD FCount() INLINE ::numcols + METHOD Struct() + METHOD FieldName( nField ) + METHOD FieldPos( cField ) + METHOD FieldLen( nField ) + METHOD FieldDec( nField ) + METHOD FieldType( nField ) + + METHOD FieldGet( nField ) + METHOD GetRow() + METHOD GetBlankRow() + METHOD Blank() INLINE ::GetBlankRow() + METHOD GetKeyField() + +ENDCLASS + + +METHOD New( nDB, cQuery, nDialect ) CLASS TFbQuery + ::db := nDb + ::query := RemoveSpaces(cQuery) + ::dialect := nDialect + ::closed := .T. + ::aKeys := NIL + + ::Refresh() + +RETURN self + + +METHOD Refresh() CLASS TFbQuery + Local qry, result := .F., i, aTable := {} + + if ! ::closed + ::Destroy() + end + + ::lBof := .T. + ::lEof := .F. + ::nRecno := 0 + ::closed := .F. + ::numcols := 0 + ::aStruct := {} + ::nError := 0 + ::lError := .F. + + result := .T. + + qry := FBQuery( ::db, ::query, ::dialect ) + + if ISARRAY(qry) + ::numcols := qry[4] + + ::aStruct := StructConvert(qry[6], ::db, ::dialect) + + ::lError := .F. + ::nError := 0 + ::qry := qry + + /* Tables in query */ + For i := 1 To len(::aStruct) + if (ASCAN(aTable, ::aStruct[i,5]) == 0) + aadd( aTable, ::aStruct[i,5]) + end + Next + + ::aTables := aTable + + else + ::lError := .T. + ::nError := qry + end + +RETURN result + + +METHOD Destroy() CLASS TFbQuery + Local result := .T., n + + if (! ::lError) .and. ((n := FBFree(::qry)) < 0) + ::lError := .T. + ::nError := n + end + + ::closed := .T. + +RETURN result + + +METHOD Fetch() CLASS TFbQuery + Local result := .F., fetch_stat + + if ! ::lError .and. ! ::lEof + + if ! ::Closed + fetch_stat := FBFetch(::qry) + + ::nRecno++ + + if fetch_stat == 0 + ::lBof := .F. + result := .T. + + else + ::lEof := .T. + + end + end + end +RETURN result + + +METHOD Struct() CLASS TFbQuery + Local result := {}, i + + if ! ::lError + for i := 1 to Len(::aStruct) + aadd( result, { ::aStruct[i,1], ::aStruct[i,2], ::aStruct[i,3], ::aStruct[i,4] } ) + next + end + +RETURN result + + +METHOD FieldPos( cField ) CLASS TFbQuery + Local result := 0 + + if ! ::lError + result := AScan( ::aStruct, {|x| x[1] == trim(Upper(cField)) }) + end + +RETURN result + + +METHOD FieldName( nField ) CLASS TFbQuery + Local result + + if ! ::lError .and. nField >= 1 .and. nField <= len(::aStruct) + result := ::aStruct[nField, 1] + end + +RETURN result + + +METHOD FieldType( nField ) CLASS TFbQuery + Local result + + if ! ::lError .and. nField >= 1 .and. nField <= len(::aStruct) + result := ::aStruct[nField, 2] + end + +RETURN result + + +METHOD FieldLen( nField ) CLASS TFbQuery + Local result + + if ! ::lError .and. nField >= 1 .and. nField <= len(::aStruct) + result := ::aStruct[nField, 3] + end +RETURN result + + +METHOD FieldDec( nField ) CLASS TFbQuery + Local result + + if ! ::lError .and. nField >= 1 .and. nField <= len(::aStruct) + result := ::aStruct[nField, 4] + end +RETURN result + + +METHOD FieldGet( nField ) CLASS TFbQuery + Local result, aBlob, i, cType + + if ! ::lError .and. nField >= 1 .and. nField <= len(::aStruct) .and. ! ::closed + + /* TODO: Convert to right data type */ + + result := FBGetData(::qry, nField) + cType := ::aStruct[ nField, 2 ] + + if cType == "M" + /* Blob */ + + if ! ISNIL(result) + aBlob := FBGetBlob( ::db, result) + + result := '' + For i := 1 to Len(aBlob) + result += aBlob[i] + Next + + //result := FBGetBlob( ::db, result) + else + result := '' + end + + elseif cType == "N" + if ! ISNIL(result) + result := val(result) + else + result := 0 + end + + elseif cType == "D" + if ! ISNIL(result) + result := StoD(left(result,4) + substr(result, 5, 2) + substr(result, 7, 2)) + else + result := CtoD('') + end + + elseif cType == "L" + if ! ISNIL(result) + result := (val(result) == 1) + else + result := .F. + end + end + end +RETURN result + + +METHOD Getrow() CLASS TFbQuery + Local result, aRow := {}, i + + if ! ::lError .and. ! ::closed + ASize(aRow, ::numcols) + + For i := 1 to ::numcols + aRow[i] := ::Fieldget(i) + Next + + result := TFbRow():New( aRow, ::aStruct, ::db, ::dialect, ::aTables ) + end +RETURN result + + +METHOD GetBlankRow() CLASS TFbQuery + Local result, aRow := {}, i + + if ! ::lError + ASize(aRow, ::numcols) + + For i := 1 to ::numcols + if ::aStruct[i, 2] == 'C' + aRow[i] := '' + elseif ::aStruct[i, 2] == 'N' + aRow[i] := 0 + elseif ::aStruct[i, 2] == 'L' + aRow[i] := .F. + elseif ::aStruct[i, 2] == 'D' + aRow[i] := CtoD('') + elseif ::aStruct[i, 2] == 'M' + aRow[i] := '' + end + Next + + result := TFbRow():New( aRow, ::aStruct, ::db, ::dialect, ::aTables ) + end +RETURN result + + +METHOD GetKeyField() CLASS TFbQuery + + if ISNIL(::aKeys) + ::aKeys := KeyField( ::aTables, ::db, ::dialect ) + end +RETURN ::aKeys + + +CLASS TFbRow + DATA aRow + DATA aStruct + DATA aChanged + DATA aKeys + DATA db + DATA dialect + DATA aTables + + METHOD New( row, struct, db, dialect ) + METHOD Changed(nField) + METHOD GetTables() INLINE ::aTables + METHOD FCount() INLINE Len(::aRow) + METHOD FieldGet( nField ) + METHOD FieldPut( nField, Value ) + METHOD FieldName( nField ) + METHOD FieldPos( cFieldName ) + METHOD FieldLen( nField ) + METHOD FieldDec( nField ) + METHOD FieldType( nField ) + METHOD GetKeyField() +ENDCLASS + + +METHOD new( row, struct, nDb, nDialect, aTable ) CLASS TFbRow + ::aRow := row + ::aStruct := struct + ::db := nDB + ::dialect := nDialect + ::aTables := aTable + ::aChanged := Array(len(row)) +RETURN self + + +METHOD Changed( nField ) CLASS TFbRow + Local result + + if nField >= 1 .and. nField <= len(::aRow) + result := ! ISNIL(::aChanged[nField]) + end + +RETURN result + + +METHOD FieldGet( nField ) CLASS TFbRow + Local result + + if nField >= 1 .and. nField <= len(::aRow) + result := ::aRow[nField] + end + +RETURN result + + +METHOD FieldPut( nField, Value ) CLASS TFbRow + Local result + + if nField >= 1 .and. nField <= len(::aRow) + ::aChanged[nField] := .T. + result := ::aRow[nField] := Value + end + +RETURN result + + +METHOD FieldName( nField ) CLASS TFbRow + Local result + + if nField >= 1 .and. nField <= len(::aStruct) + result := ::aStruct[nField, 1] + end + +RETURN result + + +METHOD FieldPos( cField ) CLASS TFbRow + Local result := 0 + + result := AScan( ::aStruct, {|x| x[1] == trim(Upper(cField)) }) + +RETURN result + + +METHOD FieldType( nField ) CLASS TFbRow + Local result + + if nField >= 1 .and. nField <= len(::aStruct) + result := ::aStruct[nField, 2] + end + +RETURN result + + +METHOD FieldLen( nField ) CLASS TFbRow + Local result + + if nField >= 1 .and. nField <= len(::aStruct) + result := ::aStruct[nField, 3] + end +RETURN result + + +METHOD FieldDec( nField ) CLASS TFbRow + Local result + + if nField >= 1 .and. nField <= len(::aStruct) + result := ::aStruct[nField, 4] + end +RETURN result + + +METHOD GetKeyField() CLASS TFbRow + + if ISNIL(::aKeys) + ::aKeys := KeyField( ::aTables, ::db, ::dialect ) + end +RETURN ::aKeys + + + +Static Function KeyField( aTables, db, dialect ) + Local cTable, cQuery + Local qry, fetch_stmt + Local aKeys := {} + + /* Check row, many tables exists in current query, so we must have only one table */ + + if Len(aTables) = 1 + cTable := aTables[1] + + cQuery := ' select ' + cQuery += ' a.rdb$field_name ' + cQuery += ' from ' + cQuery += ' rdb$index_segments a, ' + cQuery += ' rdb$relation_constraints b ' + cQuery += ' where ' + cQuery += ' a.rdb$index_name = b.rdb$index_name and ' + cQuery += ' b.rdb$constraint_type = "PRIMARY KEY" and ' + cQuery += ' b.rdb$relation_name = ' + DataToSql(cTable) + cQuery += ' order by ' + cQuery += ' b.rdb$relation_name, ' + cQuery += ' a.rdb$field_position ' + + qry := FBQuery(db, RemoveSpaces(cQuery), dialect) + + if ISARRAY(qry) + do while (fetch_stmt := FBFetch(qry)) == 0 + aadd(aKeys, trim(FBGetdata(qry, 1))) + end + + FBFree(qry) + end + end + +RETURN aKeys + + +Static Function DataToSql(xField) + Local cType, result + + cType := ValType(xField) + + if cType == "C" + result := '"' + strtran(xField, '"', ' ') + '"' + elseif cType == "D" + result := '"' + StrZero(month(xField),2) + '/' + StrZero(day(xField),2) + '/' + StrZero(Year(xField),4) + '"' + elseif cType == "N" + result := str(xField) + elseif cType == "L" + result := iif( xField, '1', '0' ) + end + +return result + + +Static Function StructConvert( aStru, db, dialect) + Local aNew := {} + Local cField + Local nType + Local cType + Local nSize + Local nDec + Local cTable + Local cDomain + Local i + Local qry + Local cQuery + Local aDomains := {} + Local fetch_stmt + Local nVal + + Local xTables := '' + Local xFields := '' + + /* create table list and field list */ + + For i := 1 to Len(aStru) + xtables += DataToSql(aStru[i, 5]) + xfields += DataToSql(aStru[i, 1]) + + if i <> len(aStru) + xtables += ',' + xfields += ',' + end + Next + + /* Look for domains */ + cQuery := 'select rdb$relation_name, rdb$field_name, rdb$field_source ' + cQuery += ' from rdb$relation_fields ' + cQuery += ' where rdb$field_name not like "RDB$%" ' + cQuery += ' and rdb$relation_name in (' + xtables + ')' + cQuery += ' and rdb$field_name in (' + xfields + ')' + + qry := FBQuery(db, RemoveSpaces(cQuery), dialect) + + if ISARRAY(qry) + + do while (fetch_stmt := FBFetch(qry)) == 0 + aadd( aDomains, { FBGetdata(qry, 1), FBGetdata(qry,2), FBGetdata(qry,3) } ) + end + + FBFree(qry) + + For i := 1 to Len(aStru) + cField := trim(aStru[i,1]) + nType := aStru[i,2] + nSize := aStru[i,3] + nDec := aStru[i,4] * -1 + cTable := trim(aStru[i,5]) + + nVal := AScan(aDomains, {|x| trim(x[1]) == cTable .and. trim(x[2]) == cField}) + + if nVal != 0 + cDomain := aDomains[ nVal, 3 ] + else + cDomain := '' + end + + switch nType + case SQL_TEXT + cType := "C" + exit + case SQL_VARYING + cType := "C" + exit + case SQL_SHORT + /* Firebird doesn't have boolean field, so if you define domain with BOOL then i will consider logical, ex: + create domain boolean_field as smallint default 0 not null check (value in (0,1)) */ + + if "BOOL" $ cDomain + cType := "L" + nSize := 1 + nDec := 0 + else + cType := "N" + nSize := 5 + end + exit + case SQL_LONG + cType := "N" + nSize := 9 + exit + case SQL_INT64 + cType := "N" + nSize := 9 + exit + case SQL_FLOAT + cType := "N" + nSize := 15 + exit + case SQL_DOUBLE + cType := "N" + nSize := 15 + exit + case SQL_TIMESTAMP + cType := "D" + nSize := 8 + exit + case SQL_TYPE_DATE + cType := "D" + nSize := 8 + exit + case SQL_TYPE_TIME + cType := "C" + nSize := 8 + exit + case SQL_BLOB + cType := "M" + nSize := 10 + exit + otherwise + cType := "C" + nDec := 0 + end + + aadd( aNew, { cField, cType, nSize, nDec, cTable, cDomain } ) + Next + End + +return aNew + +Static Function RemoveSpaces( cQuery ) + Do While AT(" ", cQuery) != 0 + cQuery := Strtran(cQuery, " ", " ") + end +Return cQuery diff --git a/harbour/contrib/freeimage/Makefile b/harbour/contrib/freeimage/Makefile new file mode 100644 index 0000000000..cd05884018 --- /dev/null +++ b/harbour/contrib/freeimage/Makefile @@ -0,0 +1,15 @@ +# +# $Id$ +# + +ROOT = ../../ + +C_SOURCES = \ + fi_winfu.c \ + fi_wrp.c \ + +PRG_SOURCES= \ + +LIBNAME=fi_lib + +include $(TOP)$(ROOT)config/lib.cf diff --git a/harbour/contrib/freeimage/common.mak b/harbour/contrib/freeimage/common.mak new file mode 100644 index 0000000000..55ce756219 --- /dev/null +++ b/harbour/contrib/freeimage/common.mak @@ -0,0 +1,18 @@ +# +# $Id$ +# + +LIBNAME = fi_lib + +LIB_PATH = $(LIB_DIR)\$(LIBNAME)$(LIBEXT) + +# +# LIB rules +# + +LIB_OBJS = \ + $(OBJ_DIR)\fi_winfu$(OBJEXT) \ + $(OBJ_DIR)\fi_wrp$(OBJEXT) \ + +all: \ + $(LIB_PATH) \ diff --git a/harbour/contrib/freeimage/fi_winfu.c b/harbour/contrib/freeimage/fi_winfu.c new file mode 100644 index 0000000000..cfb2b68d9b --- /dev/null +++ b/harbour/contrib/freeimage/fi_winfu.c @@ -0,0 +1,245 @@ +/* + * $Id$ + */ + +/* + * xHarbour Project source code: + * FreeImage windows specific functions. + * + * Copyright 2005 Francesco Saverio Giudice + * www - http://www.xharbour.org http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +/* + * + * See doc/license files for licensing terms. + * + */ + +/* NOTE: we need this to prevent base types redefinition */ +#define _CLIPDEFS_H +#if defined(HB_OS_WIN_32_USED) + #include +#endif + +#include "hbapi.h" +#include "hbapiitm.h" +#include "hbstack.h" +#include "hbapierr.h" +#include "hbapifs.h" +//#include "hrbdll.h" +#include "hbvm.h" + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include "FreeImage.h" + +// -------------------------------------------------------------------------- +// Convert from FreeImage to HBITMAP ---------------------------------------- +// -------------------------------------------------------------------------- +#if ( defined(HB_OS_WIN_32) || defined(__WIN32__) ) + +// implementation: HBITMAP bitmap = FI_FiToBitmap( FIBITMAP *dib ); +HB_FUNC( FI_FITOBITMAP ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + HBITMAP bitmap; + HDC hDC; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function */ + hDC = GetDC( NULL ); + bitmap = CreateDIBitmap(hDC, FreeImage_GetInfoHeader(dib), + CBM_INIT, FreeImage_GetBits(dib), + FreeImage_GetInfo(dib), DIB_RGB_COLORS); + ReleaseDC( NULL, hDC ); + + /* return value */ + if ( bitmap != NULL ) + { + hb_retnl( (LONG) bitmap ); + } + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_FITOBITMAP", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// -------------------------------------------------------------------------- +// Convert from HBITMAP to FreeImage ---------------------------------------- +// -------------------------------------------------------------------------- + +// implementation: FIBITMAP *dib = FI_BitmapToFi( HBITMAP bitmap ); +HB_FUNC( FI_BITMAPTOFI ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + HBITMAP bitmap; + + /* Retrieve parameters */ + bitmap = (HBITMAP) hb_parnl( 1 ); + + /* run function */ + dib = NULL; + + if( bitmap ) { + BITMAP bm; + HDC hDC; + int Success; + + GetObject( bitmap, sizeof(BITMAP), (LPSTR) &bm ); + dib = FreeImage_Allocate(bm.bmWidth, bm.bmHeight, bm.bmBitsPixel, 0, 0, 0); + hDC = GetDC( NULL ); + Success = GetDIBits( hDC, bitmap, 0, FreeImage_GetHeight(dib), + FreeImage_GetBits(dib), FreeImage_GetInfo(dib), DIB_RGB_COLORS); + ReleaseDC( NULL, hDC ); + + HB_SYMBOL_UNUSED( Success ); + } + + /* return value */ + if ( dib != NULL ) + { + hb_retptr( dib ); + } + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_BITMAPTOFI", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// -------------------------------------------------------------------------- +// Draw an image in a window Box -------------------------------------------- +// -------------------------------------------------------------------------- + +// implementation: int scanlines = FI_WinDraw( FIBITMAP *dib, HDC hDC, nTop, nLeft, nBottom, nRight ); +HB_FUNC( FI_WINDRAW ) +{ + if ( hb_pcount() == 6 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC && + hb_parinfo( 5 ) & HB_IT_NUMERIC && + hb_parinfo( 6 ) & HB_IT_NUMERIC + ) + { + FIBITMAP *dib; + HDC hDC; + RECT rcDest; + int scanlines; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + hDC = (HDC) hb_parnl( 2 ); + rcDest.top = hb_parni( 3 ); + rcDest.left = hb_parni( 4 ); + rcDest.bottom = hb_parni( 5 ); + rcDest.right = hb_parni( 6 ); + + /* run function */ + SetStretchBltMode(hDC, COLORONCOLOR); + + scanlines = StretchDIBits(hDC, rcDest.left, + rcDest.top, + rcDest.right-rcDest.left, + rcDest.bottom-rcDest.top, + 0, 0, FreeImage_GetWidth(dib), FreeImage_GetHeight(dib), + FreeImage_GetBits(dib), FreeImage_GetInfo(dib), + DIB_RGB_COLORS, SRCCOPY); + + /* return value */ + hb_retni( scanlines ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_WINDRAW", 6, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), + hb_paramError( 4 ), hb_paramError( 5 ), hb_paramError( 6 ) + ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +#endif // ( defined(HB_OS_WIN_32) || defined(__WIN32__) ) diff --git a/harbour/contrib/freeimage/fi_wrp.c b/harbour/contrib/freeimage/fi_wrp.c new file mode 100644 index 0000000000..b1bc8f6e14 --- /dev/null +++ b/harbour/contrib/freeimage/fi_wrp.c @@ -0,0 +1,2877 @@ +/* + * $Id$ + */ + +/* + * xHarbour Project source code: + * FreeImage graphic library low level (client api) interface code. + * + * Copyright 2005 Francesco Saverio Giudice + * www - http://www.xharbour.org http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +/* NOTE: we need this to prevent base types redefinition */ +#define _CLIPDEFS_H + +#include "hbapi.h" +#include "hbapiitm.h" +#include "hbstack.h" +#include "hbapierr.h" +#include "hbapifs.h" +//#include "hrbdll.h" +#include "hbvm.h" + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include "FreeImage.h" + +/* ************************* WRAPPED FUNCTIONS ****************************** */ + +// static for error handler (see below FI_SETOUTPUTMESSAGE ) +static void *pErrorHandler = NULL; + +// -------------------------------------------------------------------------- +// Init / Error routines ---------------------------------------------------- +// -------------------------------------------------------------------------- + +// DLL_API void DLL_CALLCONV FreeImage_Initialise(BOOL load_local_plugins_only FI_DEFAULT(FALSE)); +HB_FUNC( FI_INITIALISE ) +{ + BOOL bLoadPluginsOnly; + + /* Retrieve parameters */ + bLoadPluginsOnly = ( hb_parinfo( 1 ) & HB_IT_LOGICAL ? hb_parl( 1 ) : FALSE ); + + /* Run function */ + FreeImage_Initialise( bLoadPluginsOnly ); +} + +// -------------------------------------------------------------------------- + +// DLL_API void DLL_CALLCONV FreeImage_DeInitialise(void); +HB_FUNC( FI_DEINITIALISE ) +{ + /* Run function */ + FreeImage_DeInitialise(); +} + +// -------------------------------------------------------------------------- +// Version routines --------------------------------------------------------- +// -------------------------------------------------------------------------- + +// DLL_API const char *DLL_CALLCONV FreeImage_GetVersion(void); +HB_FUNC( FI_GETVERSION ) +{ + /* Run function & return value */ + hb_retc( FreeImage_GetVersion() ); +} + +// -------------------------------------------------------------------------- + +// DLL_API const char *DLL_CALLCONV FreeImage_GetCopyrightMessage(void); +HB_FUNC( FI_GETCOPYRIGHTMESSAGE ) +{ + /* Run function & return value */ + hb_retc( FreeImage_GetCopyrightMessage() ); +} + +// -------------------------------------------------------------------------- +// Message output functions ------------------------------------------------- +// -------------------------------------------------------------------------- + +// DLL_API void DLL_CALLCONV FreeImage_OutputMessageProc(int fif, const char *fmt, ...); + +// typedef void (*FreeImage_OutputMessageFunction)(FREE_IMAGE_FORMAT fif, const char *msg); +// DLL_API void DLL_CALLCONV FreeImage_SetOutputMessage(FreeImage_OutputMessageFunction omf); + +// implementation: void FreeImage_SetOutputMessage( pFunctionPointer ) + +/** +FreeImage error handler +@param fif Format / Plugin responsible for the error +@param message Error message +*/ +void FreeImageErrorHandler(FREE_IMAGE_FORMAT fif, const char *message) +{ + const char *format; + PHB_SYMB pSymbol; + + if ( pErrorHandler == NULL ) + { + // Do nothing + return; + } + + pSymbol = (PHB_SYMB) pErrorHandler; + + //TraceLog( NULL, "ErrorHandle %p\n\r", pErrorHandler ); + + if( pSymbol == NULL ) + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, "FreeImageErrorHandler", 1, hb_paramError( 1 ) ); + return; + } + + format = FreeImage_GetFormatFromFIF(fif); + + /* launch error function at prg level */ + hb_vmPushSymbol( pSymbol ); + hb_vmPushNil(); + hb_vmPushString( format, strlen( format ) ); + hb_vmPushString( message, strlen( message ) ); + hb_vmDo( 2 ); + +} + +HB_FUNC( FI_SETOUTPUTMESSAGE ) +{ + pErrorHandler = NULL; + FreeImage_SetOutputMessage(FreeImageErrorHandler); + +/* TraceLog( NULL, "PCount = %i\n\r", hb_pcount() ); */ + + if ( hb_pcount() == 1 ) + { + if ( hb_parinfo( 1 ) & HB_IT_POINTER ) + { + // Set the pointer + pErrorHandler = hb_parptr( 1 ); + } + else if ( ISNIL( 1 ) ) + { + // do nothing + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_SETOUTPUTMESSAGE", 1, + hb_paramError( 1 ) + ); + return; + } + } + } +} +// -------------------------------------------------------------------------- +// Allocate / Clone / Unload routines --------------------------------------- +// -------------------------------------------------------------------------- + +// DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Allocate(int width, int height, int bpp, unsigned red_mask FI_DEFAULT(0), unsigned green_mask FI_DEFAULT(0), unsigned blue_mask FI_DEFAULT(0)); +HB_FUNC( FI_ALLOCATE ) +{ + if ( hb_pcount() >= 3 && + hb_parinfo( 1 ) & HB_IT_NUMERIC && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC + ) + { + int width, height, bpp; + UINT red_mask, green_mask, blue_mask; + + /* Retrieve parameters */ + width = hb_parni( 1 ); + height = hb_parni( 2 ); + bpp = hb_parni( 3 ); + red_mask = ( hb_parinfo( 4 ) & HB_IT_NUMERIC ? hb_parni( 4 ) : 0 ); + green_mask = ( hb_parinfo( 5 ) & HB_IT_NUMERIC ? hb_parni( 5 ) : 0 ); + blue_mask = ( hb_parinfo( 6 ) & HB_IT_NUMERIC ? hb_parni( 6 ) : 0 ); + + /* run function & return value */ + hb_retptr( FreeImage_Allocate(width, height, bpp, red_mask, green_mask, blue_mask) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_ALLOCATE", 3, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ) + ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API FIBITMAP *DLL_CALLCONV FreeImage_AllocateT(FREE_IMAGE_TYPE type, int width, int height, int bpp FI_DEFAULT(8), unsigned red_mask FI_DEFAULT(0), unsigned green_mask FI_DEFAULT(0), unsigned blue_mask FI_DEFAULT(0)); +HB_FUNC( FI_ALLOCATET ) +{ + if ( hb_pcount() >= 3 && + hb_parinfo( 1 ) & HB_IT_NUMERIC && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC + ) + { + FREE_IMAGE_TYPE type; + int width, height, bpp; + UINT red_mask, green_mask, blue_mask; + + /* Retrieve parameters */ + type = hb_parni( 1 ); + width = hb_parni( 2 ); + height = hb_parni( 3 ); + bpp = ( hb_parinfo( 3 ) & HB_IT_NUMERIC ? hb_parni( 3 ) : 8 ); + red_mask = ( hb_parinfo( 4 ) & HB_IT_NUMERIC ? hb_parni( 4 ) : 0 ); + green_mask = ( hb_parinfo( 5 ) & HB_IT_NUMERIC ? hb_parni( 5 ) : 0 ); + blue_mask = ( hb_parinfo( 6 ) & HB_IT_NUMERIC ? hb_parni( 6 ) : 0 ); + + /* run function & return value */ + hb_retptr( FreeImage_AllocateT(type, width, height, bpp, red_mask, green_mask, blue_mask) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_ALLOCATET", 3, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ) + ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API FIBITMAP * DLL_CALLCONV FreeImage_Clone(FIBITMAP *dib); +HB_FUNC( FI_CLONE ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + FIBITMAP *fiClonePtr; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function */ + fiClonePtr = FreeImage_Clone( dib ); + + /* return value */ + if ( fiClonePtr != NULL ) + { + hb_retptr( fiClonePtr ); + } + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_CLONE", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API void DLL_CALLCONV FreeImage_Unload(FIBITMAP *dib); +HB_FUNC( FI_UNLOAD ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function */ + FreeImage_Unload( dib ); + + /* return value */ + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_UNLOAD", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- +// Load / Save routines ----------------------------------------------------- +// -------------------------------------------------------------------------- + +// DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Load(FREE_IMAGE_FORMAT fif, const char *filename, int flags FI_DEFAULT(0)); +HB_FUNC( FI_LOAD ) +{ + if ( hb_pcount() == 3 && + hb_parinfo( 1 ) & HB_IT_NUMERIC && + hb_parinfo( 2 ) & HB_IT_STRING && + hb_parinfo( 3 ) & HB_IT_NUMERIC + ) + { + FIBITMAP *dib; + FREE_IMAGE_FORMAT fif; + const char *filename; + int flags; + + /* Retrieve parameters */ + fif = hb_parni( 1 ); + filename = hb_parcx( 2 ); + flags = hb_parni( 3 ); + + /* run function */ + dib = FreeImage_Load(fif, filename, flags); + + /* return value */ + if ( dib != NULL ) + { + hb_retptr( dib ); + } + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_LOAD", 3, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API FIBITMAP *DLL_CALLCONV FreeImage_LoadU(FREE_IMAGE_FORMAT fif, const wchar_t *filename, int flags FI_DEFAULT(0)); +// DLL_API FIBITMAP *DLL_CALLCONV FreeImage_LoadFromHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flags FI_DEFAULT(0)); + +// -------------------------------------------------------------------------- + +// DLL_API BOOL DLL_CALLCONV FreeImage_Save(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, const char *filename, int flags FI_DEFAULT(0)); +HB_FUNC( FI_SAVE ) +{ + if ( hb_pcount() == 4 && + hb_parinfo( 1 ) & HB_IT_NUMERIC && + hb_parinfo( 2 ) & HB_IT_POINTER && + hb_parinfo( 3 ) & HB_IT_STRING && + hb_parinfo( 4 ) & HB_IT_NUMERIC + ) + { + FREE_IMAGE_FORMAT fif; + FIBITMAP *dib; + const char *filename; + int flags; + + /* Retrieve parameters */ + fif = hb_parni( 1 ); + dib = hb_parptr( 2 ); + filename = hb_parcx( 3 ); + flags = hb_parni( 4 ); + + /* run function & return value */ + hb_retl( FreeImage_Save(fif, dib, filename, flags) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_SAVE", 4, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API BOOL DLL_CALLCONV FreeImage_SaveU(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, const wchar_t *filename, int flags FI_DEFAULT(0)); +// DLL_API BOOL DLL_CALLCONV FreeImage_SaveToHandle(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, FreeImageIO *io, fi_handle handle, int flags FI_DEFAULT(0)); + +// -------------------------------------------------------------------------- +// Memory I/O stream routines ----------------------------------------------- +// -------------------------------------------------------------------------- + +// DLL_API FIMEMORY *DLL_CALLCONV FreeImage_OpenMemory(BYTE *data FI_DEFAULT(0), DWORD size_in_bytes FI_DEFAULT(0)); +// DLL_API void DLL_CALLCONV FreeImage_CloseMemory(FIMEMORY *stream); +// DLL_API FIBITMAP *DLL_CALLCONV FreeImage_LoadFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY *stream, int flags FI_DEFAULT(0)); +// DLL_API BOOL DLL_CALLCONV FreeImage_SaveToMemory(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, FIMEMORY *stream, int flags FI_DEFAULT(0)); +// DLL_API long DLL_CALLCONV FreeImage_TellMemory(FIMEMORY *stream); +// DLL_API BOOL DLL_CALLCONV FreeImage_SeekMemory(FIMEMORY *stream, long offset, int origin); +// DLL_API BOOL DLL_CALLCONV FreeImage_AcquireMemory(FIMEMORY *stream, BYTE **data, DWORD *size_in_bytes); + +// -------------------------------------------------------------------------- +// Plugin Interface --------------------------------------------------------- +// -------------------------------------------------------------------------- + +// DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_RegisterLocalPlugin(FI_InitProc proc_address, const char *format FI_DEFAULT(0), const char *description FI_DEFAULT(0), const char *extension FI_DEFAULT(0), const char *regexpr FI_DEFAULT(0)); +// DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_RegisterExternalPlugin(const char *path, const char *format FI_DEFAULT(0), const char *description FI_DEFAULT(0), const char *extension FI_DEFAULT(0), const char *regexpr FI_DEFAULT(0)); +// DLL_API int DLL_CALLCONV FreeImage_GetFIFCount(void); +// DLL_API int DLL_CALLCONV FreeImage_SetPluginEnabled(FREE_IMAGE_FORMAT fif, BOOL enable); +// DLL_API int DLL_CALLCONV FreeImage_IsPluginEnabled(FREE_IMAGE_FORMAT fif); +// DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_GetFIFFromFormat(const char *format); +// DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_GetFIFFromMime(const char *mime); +// DLL_API const char *DLL_CALLCONV FreeImage_GetFormatFromFIF(FREE_IMAGE_FORMAT fif); +// DLL_API const char *DLL_CALLCONV FreeImage_GetFIFExtensionList(FREE_IMAGE_FORMAT fif); +// DLL_API const char *DLL_CALLCONV FreeImage_GetFIFDescription(FREE_IMAGE_FORMAT fif); +// DLL_API const char *DLL_CALLCONV FreeImage_GetFIFRegExpr(FREE_IMAGE_FORMAT fif); +// DLL_API const char *DLL_CALLCONV FreeImage_GetFIFMimeType(FREE_IMAGE_FORMAT fif); +// DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_GetFIFFromFilename(const char *filename); +// DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_GetFIFFromFilenameU(const wchar_t *filename); +// DLL_API BOOL DLL_CALLCONV FreeImage_FIFSupportsReading(FREE_IMAGE_FORMAT fif); +// DLL_API BOOL DLL_CALLCONV FreeImage_FIFSupportsWriting(FREE_IMAGE_FORMAT fif); +// DLL_API BOOL DLL_CALLCONV FreeImage_FIFSupportsExportBPP(FREE_IMAGE_FORMAT fif, int bpp); +// DLL_API BOOL DLL_CALLCONV FreeImage_FIFSupportsExportType(FREE_IMAGE_FORMAT fif, FREE_IMAGE_TYPE type); +// DLL_API BOOL DLL_CALLCONV FreeImage_FIFSupportsICCProfiles(FREE_IMAGE_FORMAT fif); + +// -------------------------------------------------------------------------- +// Multipaging interface ---------------------------------------------------- +// -------------------------------------------------------------------------- + +// DLL_API FIMULTIBITMAP * DLL_CALLCONV FreeImage_OpenMultiBitmap(FREE_IMAGE_FORMAT fif, const char *filename, BOOL create_new, BOOL read_only, BOOL keep_cache_in_memory FI_DEFAULT(FALSE), int flags FI_DEFAULT(0)); +HB_FUNC( FI_OPENMULTIBITMAP ) +{ + if ( hb_pcount() >= 4 && + hb_parinfo( 1 ) & HB_IT_NUMERIC && + hb_parinfo( 2 ) & HB_IT_STRING && + hb_parinfo( 3 ) & HB_IT_LOGICAL && + hb_parinfo( 4 ) & HB_IT_LOGICAL + ) + { + FIMULTIBITMAP *dib; + FREE_IMAGE_FORMAT fif; + const char *filename; + BOOL create_new; + BOOL read_only; + BOOL keep_cache_in_memory; + int flags; + + /* Retrieve parameters */ + fif = hb_parni( 1 ); + filename = hb_parcx( 2 ); + create_new = hb_parl( 3 ); + read_only = hb_parl( 4 ); + keep_cache_in_memory = ( hb_parinfo( 5 ) & HB_IT_LOGICAL ? hb_parl( 5 ) : FALSE ); + flags = ( hb_parinfo( 6 ) & HB_IT_NUMERIC ? hb_parni( 6 ) : 0 ); + + /* run function */ + dib = FreeImage_OpenMultiBitmap(fif, filename, create_new, read_only, keep_cache_in_memory, flags); + + /* return value */ + if ( dib != NULL ) + { + hb_retptr( dib ); + } + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_OPENMULTIBITMAP", 4, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API BOOL DLL_CALLCONV FreeImage_CloseMultiBitmap(FIMULTIBITMAP *bitmap, int flags FI_DEFAULT(0)); +HB_FUNC( FI_CLOSEMULTIBITMAP ) +{ + if ( hb_pcount() >= 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIMULTIBITMAP *bitmap; + int flags; + + /* Retrieve parameters */ + bitmap = hb_parptr( 1 ); + flags = ( hb_parinfo( 2 ) & HB_IT_NUMERIC ? hb_parni( 2 ) : 0 ); + + /* run function & return value */ + hb_retl( FreeImage_CloseMultiBitmap(bitmap, flags) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_CLOSEMULTIBITMAP", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API int DLL_CALLCONV FreeImage_GetPageCount(FIMULTIBITMAP *bitmap); +HB_FUNC( FI_GETPAGECOUNT ) +{ + if ( hb_pcount() >= 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIMULTIBITMAP *bitmap; + + /* Retrieve parameters */ + bitmap = hb_parptr( 1 ); + + /* run function & return value */ + hb_retni( FreeImage_GetPageCount(bitmap) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_GETPAGECOUNT", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API void DLL_CALLCONV FreeImage_AppendPage(FIMULTIBITMAP *bitmap, FIBITMAP *data); +HB_FUNC( FI_APPENDPAGE ) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_POINTER + ) + { + FIMULTIBITMAP *bitmap; + FIBITMAP *data; + + /* Retrieve parameters */ + bitmap = hb_parptr( 1 ); + data = hb_parptr( 2 ); + + /* run function & return value */ + FreeImage_AppendPage(bitmap, data); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_APPENDPAGE", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API void DLL_CALLCONV FreeImage_InsertPage(FIMULTIBITMAP *bitmap, int page, FIBITMAP *data); +HB_FUNC( FI_INSERTPAGE ) +{ + if ( hb_pcount() == 3 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_POINTER + ) + { + FIMULTIBITMAP *bitmap; + int page; + FIBITMAP *data; + + /* Retrieve parameters */ + bitmap = hb_parptr( 1 ); + page = hb_parni( 2 ) - 1; // 0-based index + data = hb_parptr( 3 ); + + /* run function & return value */ + FreeImage_InsertPage(bitmap, page, data); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_INSERTPAGE", 3, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API void DLL_CALLCONV FreeImage_DeletePage(FIMULTIBITMAP *bitmap, int page); +HB_FUNC( FI_DELETEPAGE ) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC + ) + { + FIMULTIBITMAP *bitmap; + int page; + + /* Retrieve parameters */ + bitmap = hb_parptr( 1 ); + page = hb_parni( 2 ) - 1; // 0-based index + + /* run function & return value */ + FreeImage_DeletePage(bitmap, page); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_DELETEPAGE", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API FIBITMAP * DLL_CALLCONV FreeImage_LockPage(FIMULTIBITMAP *bitmap, int page); +HB_FUNC( FI_LOCKPAGE ) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC + ) + { + FIMULTIBITMAP *bitmap; + int page; + + /* Retrieve parameters */ + bitmap = hb_parptr( 1 ); + page = hb_parni( 2 ) - 1; // 0-based index + + /* run function & return value */ + hb_retptr( FreeImage_LockPage(bitmap, page) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_LOCKPAGE", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API void DLL_CALLCONV FreeImage_UnlockPage(FIMULTIBITMAP *bitmap, FIBITMAP *page, BOOL changed); +HB_FUNC( FI_UNLOCKPAGE ) +{ + if ( hb_pcount() == 3 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_LOGICAL + ) + { + FIMULTIBITMAP *bitmap; + FIBITMAP *page; + BOOL changed; + + /* Retrieve parameters */ + bitmap = hb_parptr( 1 ); + page = hb_parptr( 2 ); + changed = hb_parl( 3 ); + + /* run function & return value */ + FreeImage_UnlockPage(bitmap, page, changed); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_UNLOCKPAGE", 3, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API BOOL DLL_CALLCONV FreeImage_MovePage(FIMULTIBITMAP *bitmap, int target, int source); +HB_FUNC( FI_MOVEPAGE ) +{ + if ( hb_pcount() == 3 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC + ) + { + FIMULTIBITMAP *bitmap; + int target, source; + + /* Retrieve parameters */ + bitmap = hb_parptr( 1 ); + target = hb_parni( 2 ); + source = hb_parni( 3 ); + + /* run function & return value */ + hb_retl( FreeImage_MovePage(bitmap, target, source) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_MOVEPAGE", 3, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API BOOL DLL_CALLCONV FreeImage_GetLockedPageNumbers(FIMULTIBITMAP *bitmap, int *pages, int *count); + +// -------------------------------------------------------------------------- +// Filetype request routines ------------------------------------------------ +// -------------------------------------------------------------------------- + +// -------------------------------------------------------------------------- + +// DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_GetFileType(const char *filename, int size FI_DEFAULT(0)); +HB_FUNC( FI_GETFILETYPE ) +{ + if ( hb_pcount() >= 1 && + hb_parinfo( 1 ) & HB_IT_STRING + ) + { + const char *filename; + int size; + + /* Retrieve parameters */ + filename = hb_parcx( 1 ); + size = ( hb_parinfo( 2 ) & HB_IT_NUMERIC ? hb_parni( 1 ) : 0 ); + + /* run function & return value */ + hb_retni( FreeImage_GetFileType(filename, size) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_GETFILETYPE", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_GetFileTypeU(const wchar_t *filename, int size FI_DEFAULT(0)); +// DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_GetFileTypeFromHandle(FreeImageIO *io, fi_handle handle, int size FI_DEFAULT(0)); +// DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_GetFileTypeFromMemory(FIMEMORY *stream, int size FI_DEFAULT(0)); + +// -------------------------------------------------------------------------- +// Image type request routine ----------------------------------------------- +// -------------------------------------------------------------------------- + +// DLL_API FREE_IMAGE_TYPE DLL_CALLCONV FreeImage_GetImageType(FIBITMAP *dib); +HB_FUNC( FI_GETIMAGETYPE ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retni( FreeImage_GetImageType(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_GETIMAGETYPE", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- +// FreeImage helper routines ------------------------------------------------ +// -------------------------------------------------------------------------- + +// DLL_API BOOL DLL_CALLCONV FreeImage_IsLittleEndian(void); +HB_FUNC( FI_ISLITTLEENDIAN ) +{ + /* run function & return value */ + hb_retl( FreeImage_IsLittleEndian() ); +} + +// -------------------------------------------------------------------------- + +// DLL_API BOOL DLL_CALLCONV FreeImage_LookupX11Color(const char *szColor, BYTE *nRed, BYTE *nGreen, BYTE *nBlue); +// DLL_API BOOL DLL_CALLCONV FreeImage_LookupSVGColor(const char *szColor, BYTE *nRed, BYTE *nGreen, BYTE *nBlue); + + +// -------------------------------------------------------------------------- +// Pixel access routines ---------------------------------------------------- +// -------------------------------------------------------------------------- + +// DLL_API BYTE *DLL_CALLCONV FreeImage_GetBits(FIBITMAP *dib); +HB_FUNC( FI_GETBITS ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retptr( FreeImage_GetBits(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_GETBITS", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API BYTE *DLL_CALLCONV FreeImage_GetScanLine(FIBITMAP *dib, int scanline); +HB_FUNC( FI_GETSCANLINE ) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC + ) + { + FIBITMAP *dib; + int scanline; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + scanline = hb_parni( 2 ); + + /* run function & return value */ + hb_retptr( FreeImage_GetScanLine(dib, scanline) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_GETSCANLINE", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// +// DLL_API BOOL DLL_CALLCONV FreeImage_GetPixelIndex(FIBITMAP *dib, unsigned x, unsigned y, BYTE *value); +// DLL_API BOOL DLL_CALLCONV FreeImage_GetPixelColor(FIBITMAP *dib, unsigned x, unsigned y, RGBQUAD *value); +// DLL_API BOOL DLL_CALLCONV FreeImage_SetPixelIndex(FIBITMAP *dib, unsigned x, unsigned y, BYTE *value); +// DLL_API BOOL DLL_CALLCONV FreeImage_SetPixelColor(FIBITMAP *dib, unsigned x, unsigned y, RGBQUAD *value); + +// -------------------------------------------------------------------------- +// DIB info routines -------------------------------------------------------- +// -------------------------------------------------------------------------- + +// DLL_API unsigned DLL_CALLCONV FreeImage_GetColorsUsed(FIBITMAP *dib); +HB_FUNC( FI_GETCOLORSUSED ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retnl( FreeImage_GetColorsUsed(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_GETCOLORSUSED", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API unsigned DLL_CALLCONV FreeImage_GetBPP(FIBITMAP *dib); +HB_FUNC( FI_GETBPP ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value*/ + hb_retnl( FreeImage_GetBPP(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_GETBPP", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API unsigned DLL_CALLCONV FreeImage_GetWidth(FIBITMAP *dib); +HB_FUNC( FI_GETWIDTH ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retnl( FreeImage_GetWidth(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_GETWIDTH", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API unsigned DLL_CALLCONV FreeImage_GetHeight(FIBITMAP *dib); +HB_FUNC( FI_GETHEIGHT ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retnl( FreeImage_GetHeight(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_GETHEIGHT", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API unsigned DLL_CALLCONV FreeImage_GetLine(FIBITMAP *dib); +HB_FUNC( FI_GETLINE ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retnl( FreeImage_GetLine(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_GETLINE", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API unsigned DLL_CALLCONV FreeImage_GetPitch(FIBITMAP *dib); +HB_FUNC( FI_GETPITCH ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retnl( FreeImage_GetPitch(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_GETPITCH", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API unsigned DLL_CALLCONV FreeImage_GetDIBSize(FIBITMAP *dib); +HB_FUNC( FI_GETDIBSIZE ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retnl( FreeImage_GetDIBSize(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_GETDIBSIZE", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API RGBQUAD *DLL_CALLCONV FreeImage_GetPalette(FIBITMAP *dib); +HB_FUNC( FI_GETPALETTE ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retptr( FreeImage_GetPalette(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_GETPALETTE", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API unsigned DLL_CALLCONV FreeImage_GetDotsPerMeterX(FIBITMAP *dib); +HB_FUNC( FI_GETDOTSPERMETERX ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retnl( FreeImage_GetDotsPerMeterX(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_GETDOTSPERMETERX", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API unsigned DLL_CALLCONV FreeImage_GetDotsPerMeterY(FIBITMAP *dib); +HB_FUNC( FI_GETDOTSPERMETERY ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retnl( FreeImage_GetDotsPerMeterY(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_GETDOTSPERMETERY", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API void DLL_CALLCONV FreeImage_SetDotsPerMeterX(FIBITMAP *dib, unsigned res); +HB_FUNC( FI_SETDOTSPERMETERX ) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC + ) + { + FIBITMAP *dib; + UINT res; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + res = hb_parni( 2 ); + + /* run function & return value */ + FreeImage_SetDotsPerMeterX(dib, res); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_SETDOTSPERMETERX", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API void DLL_CALLCONV FreeImage_SetDotsPerMeterY(FIBITMAP *dib, unsigned res); +HB_FUNC( FI_SETDOTSPERMETERY ) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC + ) + { + FIBITMAP *dib; + UINT res; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + res = hb_parni( 2 ); + + /* run function & return value */ + FreeImage_SetDotsPerMeterY(dib, res); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_SETDOTSPERMETERY", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// +// DLL_API BITMAPINFOHEADER *DLL_CALLCONV FreeImage_GetInfoHeader(FIBITMAP *dib); +HB_FUNC( FI_GETINFOHEADER ) +{ + + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + // We need not worry about Memory Management - will be automatically released! + //BITMAPINFOHEADER *bmpinfoheader = (BITMAPINFOHEADER *) hb_xgrab( sizeof( BITMAPINFOHEADER ) ); + BITMAPINFOHEADER *bmpinfoheader; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + bmpinfoheader = FreeImage_GetInfoHeader(dib); + + //hb_retclenAdoptRaw( (char *) bmpinfoheader, sizeof( BITMAPINFOHEADER ) ); + hb_retptr( bmpinfoheader ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_GETINFOHEADER", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API BITMAPINFO *DLL_CALLCONV FreeImage_GetInfo(FIBITMAP *dib); +HB_FUNC( FI_GETINFO ) +{ + + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + BITMAPINFO *bmpinfo; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + bmpinfo = FreeImage_GetInfo(dib); + + hb_retptr( bmpinfo ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_GETINFO", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API FREE_IMAGE_COLOR_TYPE DLL_CALLCONV FreeImage_GetColorType(FIBITMAP *dib); +HB_FUNC( FI_GETCOLORTYPE ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retni( FreeImage_GetColorType(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_GETCOLORTYPE", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// +// DLL_API unsigned DLL_CALLCONV FreeImage_GetRedMask(FIBITMAP *dib); +HB_FUNC( FI_GETREDMASK ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retni( FreeImage_GetRedMask(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_GETREDMASK", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API unsigned DLL_CALLCONV FreeImage_GetGreenMask(FIBITMAP *dib); +HB_FUNC( FI_GETGREENMASK ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retni( FreeImage_GetGreenMask(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_GETGREENMASK", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API unsigned DLL_CALLCONV FreeImage_GetBlueMask(FIBITMAP *dib); +HB_FUNC( FI_GETBLUEMASK ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retni( FreeImage_GetBlueMask(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_GETBLUEMASK", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// +// DLL_API unsigned DLL_CALLCONV FreeImage_GetTransparencyCount(FIBITMAP *dib); +HB_FUNC( FI_GETTRANSPARENCYCOUNT ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retni( FreeImage_GetTransparencyCount(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_GETTRANSPARENCYCOUNT", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API BYTE * DLL_CALLCONV FreeImage_GetTransparencyTable(FIBITMAP *dib); +HB_FUNC( FI_GETTRANSPARENCYTABLE ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retptr( FreeImage_GetTransparencyTable(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_GETTRANSPARENCYTABLE", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API void DLL_CALLCONV FreeImage_SetTransparent(FIBITMAP *dib, BOOL enabled); +HB_FUNC( FI_SETTRANSPARENT ) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_LOGICAL + ) + { + FIBITMAP *dib; + BOOL enabled; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + enabled = hb_parl( 2 ); + + /* run function & return value */ + FreeImage_SetTransparent(dib, enabled); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_SETTRANSPARENT", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API void DLL_CALLCONV FreeImage_SetTransparencyTable(FIBITMAP *dib, BYTE *table, int count); +HB_FUNC( FI_SETTRANSPARENCYTABLE ) +{ + if ( hb_pcount() == 3 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_POINTER && + hb_parinfo( 3 ) & HB_IT_NUMERIC + ) + { + FIBITMAP *dib; + BYTE *table; + int count; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + table = hb_parptr( 2 ); + count = hb_parni( 3 ); + + /* run function & return value */ + FreeImage_SetTransparencyTable(dib, table, count); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_SETTRANSPARENCYTABLE", 3, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API BOOL DLL_CALLCONV FreeImage_IsTransparent(FIBITMAP *dib); +HB_FUNC( FI_ISTRANSPARENT ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retl( FreeImage_IsTransparent(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_ISTRANSPARENT", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// +// DLL_API BOOL DLL_CALLCONV FreeImage_HasBackgroundColor(FIBITMAP *dib); +HB_FUNC( FI_HASBACKGROUNDCOLOR ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retl( FreeImage_HasBackgroundColor(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_HASBACKGROUNDCOLOR", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API BOOL DLL_CALLCONV FreeImage_GetBackgroundColor(FIBITMAP *dib, RGBQUAD *bkcolor); +HB_FUNC( FI_GETBACKGROUNDCOLOR ) +{ + + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER //&& + //hb_parinfo( 2 ) & HB_IT_STRING + ) + { + FIBITMAP *dib; + RGBQUAD *bkcolor; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + //bkcolor = (RGBQUAD * ) hb_param( 2, HB_IT_STRING )->item.asString.value; + //bkcolor = hb_parptr( 2 ); + + /* run function & return value */ + //hb_retl( FreeImage_GetBackgroundColor(dib, bkcolor) ); + FreeImage_GetBackgroundColor(dib, bkcolor); + //hb_storptr( bkcolor, 2 ); + hb_retptr( bkcolor ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_GETBACKGROUNDCOLOR", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API BOOL DLL_CALLCONV FreeImage_SetBackgroundColor(FIBITMAP *dib, RGBQUAD *bkcolor); +HB_FUNC( FI_SETBACKGROUNDCOLOR ) +{ + + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + //hb_parinfo( 2 ) & HB_IT_POINTER + hb_parinfo( 2 ) & HB_IT_STRING + ) + { + FIBITMAP *dib; + RGBQUAD *bkcolor; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + bkcolor = (RGBQUAD * ) hb_itemGetCPtr( hb_param( 2, HB_IT_STRING ) ); + //bkcolor = hb_parptr( 2 ); + + /* run function & return value */ + hb_retl( FreeImage_SetBackgroundColor(dib, bkcolor) ); + //FreeImage_GetBackgroundColor(dib, bkcolor); + //hb_retptr( bkcolor ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_SETBACKGROUNDCOLOR", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + + + +// -------------------------------------------------------------------------- +// ICC profile routines ----------------------------------------------------- +// -------------------------------------------------------------------------- + +// DLL_API FIICCPROFILE *DLL_CALLCONV FreeImage_GetICCProfile(FIBITMAP *dib); +HB_FUNC( FI_GETICCPROFILE ) +{ + + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retptr( FreeImage_GetICCProfile(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_GETICCPROFILE", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API FIICCPROFILE *DLL_CALLCONV FreeImage_CreateICCProfile(FIBITMAP *dib, void *data, long size); +HB_FUNC( FI_CREATEICCPROFILE ) +{ + + if ( hb_pcount() == 3 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_POINTER && + hb_parinfo( 3 ) & HB_IT_NUMERIC + ) + { + FIBITMAP *dib; + void *data; + long size; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + data = hb_parptr( 2 ); + size = hb_parnl( 3 ); + + /* run function & return value */ + hb_retptr( FreeImage_CreateICCProfile(dib, data, size) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_CREATEICCPROFILE", 3, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ) + ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API void DLL_CALLCONV FreeImage_DestroyICCProfile(FIBITMAP *dib); +HB_FUNC( FI_DESTROYICCPROFILE ) +{ + + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + FreeImage_DestroyICCProfile(dib); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_DESTROYICCPROFILE", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- +// Line conversion routines ------------------------------------------------- +// -------------------------------------------------------------------------- + +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine1To4(BYTE *target, BYTE *source, int width_in_pixels); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine8To4(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine16To4_555(BYTE *target, BYTE *source, int width_in_pixels); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine16To4_565(BYTE *target, BYTE *source, int width_in_pixels); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine24To4(BYTE *target, BYTE *source, int width_in_pixels); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine32To4(BYTE *target, BYTE *source, int width_in_pixels); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine1To8(BYTE *target, BYTE *source, int width_in_pixels); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine4To8(BYTE *target, BYTE *source, int width_in_pixels); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine16To8_555(BYTE *target, BYTE *source, int width_in_pixels); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine16To8_565(BYTE *target, BYTE *source, int width_in_pixels); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine24To8(BYTE *target, BYTE *source, int width_in_pixels); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine32To8(BYTE *target, BYTE *source, int width_in_pixels); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine1To16_555(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine4To16_555(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine8To16_555(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine16_565_To16_555(BYTE *target, BYTE *source, int width_in_pixels); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine24To16_555(BYTE *target, BYTE *source, int width_in_pixels); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine32To16_555(BYTE *target, BYTE *source, int width_in_pixels); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine1To16_565(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine4To16_565(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine8To16_565(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine16_555_To16_565(BYTE *target, BYTE *source, int width_in_pixels); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine24To16_565(BYTE *target, BYTE *source, int width_in_pixels); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine32To16_565(BYTE *target, BYTE *source, int width_in_pixels); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine1To24(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine4To24(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine8To24(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine16To24_555(BYTE *target, BYTE *source, int width_in_pixels); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine16To24_565(BYTE *target, BYTE *source, int width_in_pixels); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine32To24(BYTE *target, BYTE *source, int width_in_pixels); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine1To32(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine4To32(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine8To32(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine16To32_555(BYTE *target, BYTE *source, int width_in_pixels); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine16To32_565(BYTE *target, BYTE *source, int width_in_pixels); +// DLL_API void DLL_CALLCONV FreeImage_ConvertLine24To32(BYTE *target, BYTE *source, int width_in_pixels); + +// -------------------------------------------------------------------------- +// Smart conversion routines ------------------------------------------------ +// -------------------------------------------------------------------------- + +// DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo4Bits(FIBITMAP *dib); +HB_FUNC( FI_CONVERTTO4BITS ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retptr( FreeImage_ConvertTo4Bits(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_CONVERTTO4BITS", 1, + hb_paramError( 1 ) + ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo8Bits(FIBITMAP *dib); +HB_FUNC( FI_CONVERTTO8BITS ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retptr( FreeImage_ConvertTo8Bits(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_CONVERTTO8BITS", 1, + hb_paramError( 1 ) + ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertToGreyscale(FIBITMAP *dib); +HB_FUNC( FI_CONVERTTOGREYSCALE ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retptr( FreeImage_ConvertToGreyscale(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_CONVERTTOGREYSCALE", 1, + hb_paramError( 1 ) + ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo16Bits555(FIBITMAP *dib); +HB_FUNC( FI_CONVERTTO16BITS555 ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retptr( FreeImage_ConvertTo16Bits555(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_CONVERTTO16BITS555", 1, + hb_paramError( 1 ) + ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo16Bits565(FIBITMAP *dib); +HB_FUNC( FI_CONVERTTO16BITS565 ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retptr( FreeImage_ConvertTo16Bits565(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_CONVERTTO16BITS565", 1, + hb_paramError( 1 ) + ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo24Bits(FIBITMAP *dib); +HB_FUNC( FI_CONVERTTO24BITS ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retptr( FreeImage_ConvertTo24Bits(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_CONVERTTO24BITS", 1, + hb_paramError( 1 ) + ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo32Bits(FIBITMAP *dib); +HB_FUNC( FI_CONVERTTO32BITS ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retptr( FreeImage_ConvertTo32Bits(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_CONVERTTO32BITS", 1, + hb_paramError( 1 ) + ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ColorQuantize(FIBITMAP *dib, FREE_IMAGE_QUANTIZE quantize); +HB_FUNC( FI_COLORQUANTIZE ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC + ) + { + FIBITMAP *dib; + FREE_IMAGE_QUANTIZE quantize; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + quantize = hb_parni( 2 ); + + /* run function & return value */ + hb_retptr( FreeImage_ColorQuantize(dib, quantize) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_COLORQUANTIZE", 2, + hb_paramError( 1 ), hb_paramError( 2 ) + ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ColorQuantizeEx(FIBITMAP *dib, FREE_IMAGE_QUANTIZE quantize FI_DEFAULT(FIQ_WUQUANT), int PaletteSize FI_DEFAULT(256), int ReserveSize FI_DEFAULT(0), RGBQUAD *ReservePalette FI_DEFAULT(NULL)); +// DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Threshold(FIBITMAP *dib, BYTE T); + +// -------------------------------------------------------------------------- + +// DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Dither(FIBITMAP *dib, FREE_IMAGE_DITHER algorithm); +HB_FUNC( FI_DITHER ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC + ) + { + FIBITMAP *dib; + FREE_IMAGE_DITHER algorithm; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + algorithm = hb_parni( 2 ); + + /* run function & return value */ + hb_retptr( FreeImage_Dither(dib, algorithm) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_DITHER", 2, + hb_paramError( 1 ), hb_paramError( 2 ) + ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// +// DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertFromRawBits(BYTE *bits, int width, int height, int pitch, unsigned bpp, unsigned red_mask, unsigned green_mask, unsigned blue_mask, BOOL topdown FI_DEFAULT(FALSE)); +// DLL_API void DLL_CALLCONV FreeImage_ConvertToRawBits(BYTE *bits, FIBITMAP *dib, int pitch, unsigned bpp, unsigned red_mask, unsigned green_mask, unsigned blue_mask, BOOL topdown FI_DEFAULT(FALSE)); +// +// -------------------------------------------------------------------------- + +// DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertToRGBF(FIBITMAP *dib); +HB_FUNC( FI_CONVERTTORGBF ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retptr( FreeImage_ConvertToRGBF(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_CONVERTTORGBF", 1, + hb_paramError( 1 ) + ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// +// DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertToStandardType(FIBITMAP *src, BOOL scale_linear FI_DEFAULT(TRUE)); +HB_FUNC( FI_CONVERTTOSTANDARDTYPE ) +{ + if ( hb_pcount() >= 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + BOOL scale_linear; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + scale_linear = ( hb_parinfo( 2 ) & HB_IT_LOGICAL ) ? hb_parl( 2 ) : TRUE; + + /* run function & return value */ + hb_retptr( FreeImage_ConvertToStandardType(dib, scale_linear) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_CONVERTTOSTANDARDTYPE", 1, + hb_paramError( 1 ) + ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertToType(FIBITMAP *src, FREE_IMAGE_TYPE dst_type, BOOL scale_linear FI_DEFAULT(TRUE)); +HB_FUNC( FI_CONVERTTOTYPE ) +{ + if ( hb_pcount() >= 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC + ) + { + FIBITMAP *dib; + FREE_IMAGE_TYPE dst_type; + BOOL scale_linear; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + dst_type = hb_parni( 2 ); + scale_linear = ( hb_parinfo( 3 ) & HB_IT_LOGICAL ) ? hb_parl( 3 ) : TRUE; + + /* run function & return value */ + hb_retptr( FreeImage_ConvertToType(dib, dst_type, scale_linear) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_CONVERTTOTYPE", 2, + hb_paramError( 1 ), hb_paramError( 2 ) + ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// +// // tone mapping operators +// DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ToneMapping(FIBITMAP *dib, FREE_IMAGE_TMO tmo, double first_param FI_DEFAULT(0), double second_param FI_DEFAULT(0)); +// DLL_API FIBITMAP* DLL_CALLCONV FreeImage_TmoDrago03(FIBITMAP *src, double gamma FI_DEFAULT(2.2), double exposure FI_DEFAULT(0)); +// DLL_API FIBITMAP* DLL_CALLCONV FreeImage_TmoReinhard05(FIBITMAP *src, double intensity FI_DEFAULT(0), double contrast FI_DEFAULT(0)); + +// -------------------------------------------------------------------------- +// ZLib interface ----------------------------------------------------------- +// -------------------------------------------------------------------------- + +// DLL_API DWORD DLL_CALLCONV FreeImage_ZLibCompress(BYTE *target, DWORD target_size, BYTE *source, DWORD source_size); +// DLL_API DWORD DLL_CALLCONV FreeImage_ZLibUncompress(BYTE *target, DWORD target_size, BYTE *source, DWORD source_size); +// DLL_API DWORD DLL_CALLCONV FreeImage_ZLibGZip(BYTE *target, DWORD target_size, BYTE *source, DWORD source_size); +// DLL_API DWORD DLL_CALLCONV FreeImage_ZLibGUnzip(BYTE *target, DWORD target_size, BYTE *source, DWORD source_size); +// DLL_API DWORD DLL_CALLCONV FreeImage_ZLibCRC32(DWORD crc, BYTE *source, DWORD source_size); + +// -------------------------------------------------------------------------- +// Metadata routines -------------------------------------------------------- +// -------------------------------------------------------------------------- + +// tag creation / destruction +// DLL_API FITAG *DLL_CALLCONV FreeImage_CreateTag(); +// DLL_API void DLL_CALLCONV FreeImage_DeleteTag(FITAG *tag); +// DLL_API FITAG *DLL_CALLCONV FreeImage_CloneTag(FITAG *tag); + +// tag getters and setters +// DLL_API const char *DLL_CALLCONV FreeImage_GetTagKey(FITAG *tag); +// DLL_API const char *DLL_CALLCONV FreeImage_GetTagDescription(FITAG *tag); +// DLL_API WORD DLL_CALLCONV FreeImage_GetTagID(FITAG *tag); +// DLL_API FREE_IMAGE_MDTYPE DLL_CALLCONV FreeImage_GetTagType(FITAG *tag); +// DLL_API DWORD DLL_CALLCONV FreeImage_GetTagCount(FITAG *tag); +// DLL_API DWORD DLL_CALLCONV FreeImage_GetTagLength(FITAG *tag); +// DLL_API const void *DLL_CALLCONV FreeImage_GetTagValue(FITAG *tag); +// +// DLL_API BOOL DLL_CALLCONV FreeImage_SetTagKey(FITAG *tag, const char *key); +// DLL_API BOOL DLL_CALLCONV FreeImage_SetTagDescription(FITAG *tag, const char *description); +// DLL_API BOOL DLL_CALLCONV FreeImage_SetTagID(FITAG *tag, WORD id); +// DLL_API BOOL DLL_CALLCONV FreeImage_SetTagType(FITAG *tag, FREE_IMAGE_MDTYPE type); +// DLL_API BOOL DLL_CALLCONV FreeImage_SetTagCount(FITAG *tag, DWORD count); +// DLL_API BOOL DLL_CALLCONV FreeImage_SetTagLength(FITAG *tag, DWORD length); +// DLL_API BOOL DLL_CALLCONV FreeImage_SetTagValue(FITAG *tag, const void *value); + +// iterator +// DLL_API FIMETADATA *DLL_CALLCONV FreeImage_FindFirstMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP *dib, FITAG **tag); +// DLL_API BOOL DLL_CALLCONV FreeImage_FindNextMetadata(FIMETADATA *mdhandle, FITAG **tag); +// DLL_API void DLL_CALLCONV FreeImage_FindCloseMetadata(FIMETADATA *mdhandle); + +// metadata setter and getter +// DLL_API BOOL DLL_CALLCONV FreeImage_SetMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP *dib, const char *key, FITAG *tag); +// DLL_API BOOL DLL_CALLCONV FreeImage_GetMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP *dib, const char *key, FITAG **tag); + +// helpers +// DLL_API unsigned DLL_CALLCONV FreeImage_GetMetadataCount(FREE_IMAGE_MDMODEL model, FIBITMAP *dib); + +// tag to C string conversion +// DLL_API const char* DLL_CALLCONV FreeImage_TagToString(FREE_IMAGE_MDMODEL model, FITAG *tag, char *Make FI_DEFAULT(NULL)); + +// -------------------------------------------------------------------------- +// Image manipulation toolkit ----------------------------------------------- +// -------------------------------------------------------------------------- + +// rotation and flipping + +// -------------------------------------------------------------------------- + +// DLL_API FIBITMAP *DLL_CALLCONV FreeImage_RotateClassic(FIBITMAP *dib, double angle); +HB_FUNC( FI_ROTATECLASSIC ) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC + ) + { + FIBITMAP *dib; + double angle; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + angle = hb_parnd( 2 ); + + /* run function & return value */ + hb_retptr( FreeImage_RotateClassic(dib, angle) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_ROTATECLASSIC", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API FIBITMAP *DLL_CALLCONV FreeImage_RotateEx(FIBITMAP *dib, double angle, double x_shift, double y_shift, double x_origin, double y_origin, BOOL use_mask); +HB_FUNC( FI_ROTATEEX ) +{ + if ( hb_pcount() == 7 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC && + hb_parinfo( 5 ) & HB_IT_NUMERIC && + hb_parinfo( 6 ) & HB_IT_NUMERIC && + hb_parinfo( 7 ) & HB_IT_LOGICAL + ) + { + FIBITMAP *dib; + double angle, x_shift, y_shift, x_origin, y_origin; + BOOL use_mask; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + angle = hb_parnd( 2 ); + x_shift = hb_parnd( 3 ); + y_shift = hb_parnd( 4 ); + x_origin = hb_parnd( 5 ); + y_origin = hb_parnd( 6 ); + use_mask = hb_parl( 7 ); + + /* run function & return value */ + hb_retptr( FreeImage_RotateEx(dib, angle, x_shift, y_shift, x_origin, y_origin, use_mask) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_ROTATEEX", 7, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ), + hb_paramError( 5 ), hb_paramError( 6 ), hb_paramError( 7 ) + ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API BOOL DLL_CALLCONV FreeImage_FlipHorizontal(FIBITMAP *dib); +HB_FUNC( FI_FLIPHORIZONTAL ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retl( FreeImage_FlipHorizontal(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_FLIPHORIZONTAL", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API BOOL DLL_CALLCONV FreeImage_FlipVertical(FIBITMAP *dib); +HB_FUNC( FI_FLIPVERTICAL ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retl( FreeImage_FlipVertical(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_FLIPVERTICAL", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API BOOL DLL_CALLCONV FreeImage_JPEGTransform(const char *src_file, const char *dst_file, FREE_IMAGE_JPEG_OPERATION operation, BOOL perfect FI_DEFAULT(FALSE)); + +// -------------------------------------------------------------------------- + +// upsampling / downsampling + +// -------------------------------------------------------------------------- + +// DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Rescale(FIBITMAP *dib, int dst_width, int dst_height, FREE_IMAGE_FILTER filter); +HB_FUNC( FI_RESCALE ) +{ + if ( hb_pcount() == 4 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC + ) + { + FIBITMAP *dib; + int dst_width, dst_height; + FREE_IMAGE_FILTER filter; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + dst_width = hb_parni( 2 ); + dst_height = hb_parni( 3 ); + filter = hb_parni( 4 ); + + /* run function & return value */ + hb_retptr( FreeImage_Rescale(dib, dst_width, dst_height, filter) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_RESCALE", 4, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ) + ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// color manipulation routines (point operations) + +// -------------------------------------------------------------------------- + +// DLL_API BOOL DLL_CALLCONV FreeImage_AdjustCurve(FIBITMAP *dib, BYTE *LUT, FREE_IMAGE_COLOR_CHANNEL channel); + +// -------------------------------------------------------------------------- + +// DLL_API BOOL DLL_CALLCONV FreeImage_AdjustGamma(FIBITMAP *dib, double gamma); +HB_FUNC( FI_ADJUSTGAMMA ) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC + ) + { + FIBITMAP *dib; + double gamma; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + gamma = hb_parnd( 2 ); + + /* run function & return value */ + hb_retl( FreeImage_AdjustGamma(dib, gamma) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_ADJUSTGAMMA", 2, + hb_paramError( 1 ), hb_paramError( 2 ) + ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API BOOL DLL_CALLCONV FreeImage_AdjustBrightness(FIBITMAP *dib, double percentage); +HB_FUNC( FI_ADJUSTBRIGHTNESS ) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC + ) + { + FIBITMAP *dib; + double percentage; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + percentage = hb_parnd( 2 ); + + /* run function & return value */ + hb_retl( FreeImage_AdjustBrightness(dib, percentage) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_ADJUSTBRIGHTNESS", 2, + hb_paramError( 1 ), hb_paramError( 2 ) + ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API BOOL DLL_CALLCONV FreeImage_AdjustContrast(FIBITMAP *dib, double percentage); +HB_FUNC( FI_ADJUSTCONTRAST ) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC + ) + { + FIBITMAP *dib; + double percentage; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + percentage = hb_parnd( 2 ); + + /* run function & return value */ + hb_retl( FreeImage_AdjustContrast(dib, percentage) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_ADJUSTCONTRAST", 2, + hb_paramError( 1 ), hb_paramError( 2 ) + ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API BOOL DLL_CALLCONV FreeImage_Invert(FIBITMAP *dib); +HB_FUNC( FI_INVERT ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + FIBITMAP *dib; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + + /* run function & return value */ + hb_retl( FreeImage_Invert(dib) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_INVERT", 1, + hb_paramError( 1 ) + ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API BOOL DLL_CALLCONV FreeImage_GetHistogram(FIBITMAP *dib, DWORD *histo, FREE_IMAGE_COLOR_CHANNEL channel FI_DEFAULT(FICC_BLACK)); + +// -------------------------------------------------------------------------- + +// channel processing routines + +// -------------------------------------------------------------------------- + +// DLL_API FIBITMAP *DLL_CALLCONV FreeImage_GetChannel(FIBITMAP *dib, FREE_IMAGE_COLOR_CHANNEL channel); +HB_FUNC( FI_GETCHANNEL ) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC + ) + { + FIBITMAP *dib; + FREE_IMAGE_COLOR_CHANNEL channel; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + channel = hb_parni( 2 ); + + /* run function & return value */ + hb_retptr( FreeImage_GetChannel(dib, channel) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_GETCHANNEL", 2, + hb_paramError( 1 ), hb_paramError( 2 ) + ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API BOOL DLL_CALLCONV FreeImage_SetChannel(FIBITMAP *dib, FIBITMAP *dib8, FREE_IMAGE_COLOR_CHANNEL channel); +// DLL_API FIBITMAP *DLL_CALLCONV FreeImage_GetComplexChannel(FIBITMAP *src, FREE_IMAGE_COLOR_CHANNEL channel); +// DLL_API BOOL DLL_CALLCONV FreeImage_SetComplexChannel(FIBITMAP *dst, FIBITMAP *src, FREE_IMAGE_COLOR_CHANNEL channel); + +// -------------------------------------------------------------------------- + +// copy / paste / composite routines + +// -------------------------------------------------------------------------- + +// DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Copy(FIBITMAP *dib, int left, int top, int right, int bottom); +HB_FUNC( FI_COPY ) +{ + if ( hb_pcount() == 5 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC && + hb_parinfo( 5 ) & HB_IT_NUMERIC + ) + { + FIBITMAP *dib; + int left, top, right, bottom; + + /* Retrieve parameters */ + dib = hb_parptr( 1 ); + left = hb_parni( 2 ); + top = hb_parni( 3 ); + right = hb_parni( 4 ); + bottom = hb_parni( 5 ); + + /* run function & return value */ + hb_retptr( FreeImage_Copy(dib, left, top, right, bottom) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_COPY", 5, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ), + hb_paramError( 5 ) + ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API BOOL DLL_CALLCONV FreeImage_Paste(FIBITMAP *dst, FIBITMAP *src, int left, int top, int alpha); +HB_FUNC( FI_PASTE ) +{ + if ( hb_pcount() == 5 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_POINTER && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC && + hb_parinfo( 5 ) & HB_IT_NUMERIC + ) + { + FIBITMAP *dst; + FIBITMAP *src; + int left, top, alpha; + + /* Retrieve parameters */ + dst = hb_parptr( 1 ); + src = hb_parptr( 2 ); + left = hb_parni( 3 ); + top = hb_parni( 4 ); + alpha = hb_parni( 5 ); + + /* run function & return value */ + hb_retl( FreeImage_Paste(dst, src, left, top, alpha) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "FI_PASTE", 5, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ), + hb_paramError( 5 ) + ); + return; + } + } +} + +// -------------------------------------------------------------------------- + +// DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Composite(FIBITMAP *fg, BOOL useFileBkg FI_DEFAULT(FALSE), RGBQUAD *appBkColor FI_DEFAULT(NULL), FIBITMAP *bg FI_DEFAULT(NULL)); + +// -------------------------------------------------------------------------- + diff --git a/harbour/contrib/freeimage/freeimage.ch b/harbour/contrib/freeimage/freeimage.ch new file mode 100644 index 0000000000..6da15e3bc0 --- /dev/null +++ b/harbour/contrib/freeimage/freeimage.ch @@ -0,0 +1,337 @@ +/* + * $Id$ + */ + +/* + * xHarbour Project source code: + * FreeImage graphic library header file. + * + * Copyright 2005 Francesco Saverio Giudice + * www - http://www.xharbour.org http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#ifndef FREEIMAGE_CH +#define FREEIMAGE_CH + +/* ----------------------------------------------------------------------- */ + +#ifndef FREEIMAGE_BIGENDIAN +// Little Endian (x86 / MS Windows, Linux) : BGR(A) order +#define FI_RGBA_RED 2 +#define FI_RGBA_GREEN 1 +#define FI_RGBA_BLUE 0 +#define FI_RGBA_ALPHA 3 +#define FI_RGBA_RED_MASK 0x00FF0000 +#define FI_RGBA_GREEN_MASK 0x0000FF00 +#define FI_RGBA_BLUE_MASK 0x000000FF +#define FI_RGBA_ALPHA_MASK 0xFF000000 +#define FI_RGBA_RED_SHIFT 16 +#define FI_RGBA_GREEN_SHIFT 8 +#define FI_RGBA_BLUE_SHIFT 0 +#define FI_RGBA_ALPHA_SHIFT 24 +#else +// Big Endian (PPC / Linux, MaxOSX) : RGB(A) order +#define FI_RGBA_RED 0 +#define FI_RGBA_GREEN 1 +#define FI_RGBA_BLUE 2 +#define FI_RGBA_ALPHA 3 +#define FI_RGBA_RED_MASK 0xFF000000 +#define FI_RGBA_GREEN_MASK 0x00FF0000 +#define FI_RGBA_BLUE_MASK 0x0000FF00 +#define FI_RGBA_ALPHA_MASK 0x000000FF +#define FI_RGBA_RED_SHIFT 24 +#define FI_RGBA_GREEN_SHIFT 16 +#define FI_RGBA_BLUE_SHIFT 8 +#define FI_RGBA_ALPHA_SHIFT 0 +#endif // FREEIMAGE_BIGENDIAN + +#define FI_RGBA_RGB_MASK (FI_RGBA_RED_MASK|FI_RGBA_GREEN_MASK|FI_RGBA_BLUE_MASK) + +// The 16bit macros only include masks and shifts, since each color element is not byte aligned + +#define FI16_555_RED_MASK 0x7C00 +#define FI16_555_GREEN_MASK 0x03E0 +#define FI16_555_BLUE_MASK 0x001F +#define FI16_555_RED_SHIFT 10 +#define FI16_555_GREEN_SHIFT 5 +#define FI16_555_BLUE_SHIFT 0 +#define FI16_565_RED_MASK 0xF800 +#define FI16_565_GREEN_MASK 0x07E0 +#define FI16_565_BLUE_MASK 0x001F +#define FI16_565_RED_SHIFT 11 +#define FI16_565_GREEN_SHIFT 5 +#define FI16_565_BLUE_SHIFT 0 + +// ICC profile support ------------------------------------------------------ + +#define FIICC_DEFAULT 0x00 +#define FIICC_COLOR_IS_CMYK 0x01 + +/** I/O image format identifiers. +*/ +//FREE_IMAGE_FORMAT +#define FIF_UNKNOWN -1 +#define FIF_BMP 0 +#define FIF_ICO 1 +#define FIF_JPEG 2 +#define FIF_JNG 3 +#define FIF_KOALA 4 +#define FIF_LBM 5 +#define FIF_IFF FIF_LBM +#define FIF_MNG 6 +#define FIF_PBM 7 +#define FIF_PBMRAW 8 +#define FIF_PCD 9 +#define FIF_PCX 10 +#define FIF_PGM 11 +#define FIF_PGMRAW 12 +#define FIF_PNG 13 +#define FIF_PPM 14 +#define FIF_PPMRAW 15 +#define FIF_RAS 16 +#define FIF_TARGA 17 +#define FIF_TIFF 18 +#define FIF_WBMP 19 +#define FIF_PSD 20 +#define FIF_CUT 21 +#define FIF_XBM 22 +#define FIF_XPM 23 +#define FIF_DDS 24 +#define FIF_GIF 25 +#define FIF_HDR 26 + + +/** Image type used in FreeImage. +*/ +//FREE_IMAGE_TYPE +#define FIT_UNKNOWN 0 // unknown type +#define FIT_BITMAP 1 // standard image : 1-, 4-, 8-, 16-, 24-, 32-bit +#define FIT_UINT16 2 // array of unsigned short : unsigned 16-bit +#define FIT_INT16 3 // array of short : signed 16-bit +#define FIT_UINT32 4 // array of unsigned long : unsigned 32-bit +#define FIT_INT32 5 // array of long : signed 32-bit +#define FIT_FLOAT 6 // array of float : 32-bit IEEE floating point +#define FIT_DOUBLE 7 // array of double : 64-bit IEEE floating point +#define FIT_COMPLEX 8 // array of FICOMPLEX : 2 x 64-bit IEEE floating point +#define FIT_RGB16 9 // 48-bit RGB image : 3 x 16-bit +#define FIT_RGBA16 10 // 64-bit RGBA image : 4 x 16-bit +#define FIT_RGBF 11 // 96-bit RGB float image : 3 x 32-bit IEEE floating point +#define FIT_RGBAF 12 // 128-bit RGBA float image : 4 x 32-bit IEEE floating point + + +/** Image color type used in FreeImage. +*/ +//FREE_IMAGE_COLOR_TYPE +#define FIC_MINISWHITE 0 // min value is white +#define FIC_MINISBLACK 1 // min value is black +#define FIC_RGB 2 // RGB color model +#define FIC_PALETTE 3 // color map indexed +#define FIC_RGBALPHA 4 // RGB color model with alpha channel +#define FIC_CMYK 5 // CMYK color model + + +/** Color quantization algorithms. +Constants used in FreeImage_ColorQuantize. +*/ +//FREE_IMAGE_QUANTIZE +#define FIQ_WUQUANT 0 // Xiaolin Wu color quantization algorithm +#define FIQ_NNQUANT 1 // NeuQuant neural-net quantization algorithm by Anthony Dekker + + +/** Dithering algorithms. +Constants used in FreeImage_Dither. +*/ +//FREE_IMAGE_DITHER +#define FID_FS 0 // Floyd & Steinberg error diffusion +#define FID_BAYER4x4 1 // Bayer ordered dispersed dot dithering (order 2 dithering matrix) +#define FID_BAYER8x8 2 // Bayer ordered dispersed dot dithering (order 3 dithering matrix) +#define FID_CLUSTER6x6 3 // Ordered clustered dot dithering (order 3 - 6x6 matrix) +#define FID_CLUSTER8x8 4 // Ordered clustered dot dithering (order 4 - 8x8 matrix) +#define FID_CLUSTER16x16 5 // Ordered clustered dot dithering (order 8 - 16x16 matrix) + + +/** Lossless JPEG transformations +Constants used in FreeImage_JPEGTransform +*/ +//FREE_IMAGE_JPEG_OPERATION +#define FIJPEG_OP_NONE 0 // no transformation +#define FIJPEG_OP_FLIP_H 1 // horizontal flip +#define FIJPEG_OP_FLIP_V 2 // vertical flip +#define FIJPEG_OP_TRANSPOSE 3 // transpose across UL-to-LR axis +#define FIJPEG_OP_TRANSVERSE 4 // transpose across UR-to-LL axis +#define FIJPEG_OP_ROTATE_90 5 // 90-degree clockwise rotation +#define FIJPEG_OP_ROTATE_180 6 // 180-degree rotation +#define FIJPEG_OP_ROTATE_270 7 // 270-degree clockwise (or 90 ccw) + + +/** Tone mapping operators. +Constants used in FreeImage_ToneMapping. +*/ +//FREE_IMAGE_TMO +#define FITMO_DRAGO03 0 // Adaptive logarithmic mapping (F. Drago, 2003) +#define FITMO_REINHARD05 1 // Dynamic range reduction inspired by photoreceptor physiology (E. Reinhard, 2005) + + +/** Upsampling / downsampling filters. +Constants used in FreeImage_Rescale. +*/ +//FREE_IMAGE_FILTER +#define FILTER_BOX 0 // Box, pulse, Fourier window, 1st order (constant) b-spline +#define FILTER_BICUBIC 1 // Mitchell & Netravali's two-param cubic filter +#define FILTER_BILINEAR 2 // Bilinear filter +#define FILTER_BSPLINE 3 // 4th order (cubic) b-spline +#define FILTER_CATMULLROM 4 // Catmull-Rom spline, Overhauser spline +#define FILTER_LANCZOS3 5 // Lanczos3 filter + + +/** Color channels. +Constants used in color manipulation routines. +*/ +//FREE_IMAGE_COLOR_CHANNEL +#define FICC_RGB 0 // Use red, green and blue channels +#define FICC_RED 1 // Use red channel +#define FICC_GREEN 2 // Use green channel +#define FICC_BLUE 3 // Use blue channel +#define FICC_ALPHA 4 // Use alpha channel +#define FICC_BLACK 5 // Use black channel +#define FICC_REAL 6 // Complex images: use real part +#define FICC_IMAG 7 // Complex images: use imaginary part +#define FICC_MAG 8 // Complex images: use magnitude +#define FICC_PHASE 9 // Complex images: use phase + +// Metadata support --------------------------------------------------------- + +/** + Tag data type information (based on TIFF specifications) + + Note: RATIONALs are the ratio of two 32-bit integer values. +*/ +//FREE_IMAGE_MDTYPE +#define FIDT_NOTYPE 0 // placeholder +#define FIDT_BYTE 1 // 8-bit unsigned integer +#define FIDT_ASCII 2 // 8-bit bytes w/ last byte null +#define FIDT_SHORT 3 // 16-bit unsigned integer +#define FIDT_LONG 4 // 32-bit unsigned integer +#define FIDT_RATIONAL 5 // 64-bit unsigned fraction +#define FIDT_SBYTE 6 // 8-bit signed integer +#define FIDT_UNDEFINED 7 // 8-bit untyped data +#define FIDT_SSHORT 8 // 16-bit signed integer +#define FIDT_SLONG 9 // 32-bit signed integer +#define FIDT_SRATIONAL 10 // 64-bit signed fraction +#define FIDT_FLOAT 11 // 32-bit IEEE floating point +#define FIDT_DOUBLE 12 // 64-bit IEEE floating point +#define FIDT_IFD 13 // 32-bit unsigned integer (offset) +#define FIDT_PALETTE 14 // 32-bit RGBQUAD + + +/** + Metadata models supported by FreeImage +*/ +//FREE_IMAGE_MDMODEL +#define FIMD_NODATA -1 +#define FIMD_COMMENTS 0 // single comment or keywords +#define FIMD_EXIF_MAIN 1 // Exif-TIFF metadata +#define FIMD_EXIF_EXIF 2 // Exif-specific metadata +#define FIMD_EXIF_GPS 3 // Exif GPS metadata +#define FIMD_EXIF_MAKERNOTE 4 // Exif maker note metadata +#define FIMD_EXIF_INTEROP 5 // Exif interoperability metadata +#define FIMD_IPTC 6 // IPTC/NAA metadata +#define FIMD_XMP 7 // Abobe XMP metadata +#define FIMD_GEOTIFF 8 // GeoTIFF metadata +#define FIMD_ANIMATION 9 // Animation metadata +#define FIMD_CUSTOM 10 // Used to attach other metadata types to a dib + +// Load / Save flag constants ----------------------------------------------- + +#define BMP_DEFAULT 0 +#define BMP_SAVE_RLE 1 +#define CUT_DEFAULT 0 +#define DDS_DEFAULT 0 +#define GIF_DEFAULT 0 +#define GIF_LOAD256 1 // Load the image as a 256 color image with ununsed palette entries, if it's 16 or 2 color +#define GIF_PLAYBACK 2 // 'Play' the GIF to generate each frame (as 32bpp) instead of returning raw frame data when loading +#define HDR_DEFAULT 0 +#define ICO_DEFAULT 0 +#define ICO_MAKEALPHA 1 // convert to 32bpp and create an alpha channel from the AND-mask when loading +#define IFF_DEFAULT 0 +#define JPEG_DEFAULT 0 +#define JPEG_FAST 1 +#define JPEG_ACCURATE 2 +#define JPEG_QUALITYSUPERB 0x80 +#define JPEG_QUALITYGOOD 0x100 +#define JPEG_QUALITYNORMAL 0x200 +#define JPEG_QUALITYAVERAGE 0x400 +#define JPEG_QUALITYBAD 0x800 +#define JPEG_CMYK 0x1000 // load separated CMYK "as is" (use | to combine with other flags) +#define KOALA_DEFAULT 0 +#define LBM_DEFAULT 0 +#define MNG_DEFAULT 0 +#define PCD_DEFAULT 0 +#define PCD_BASE 1 // load the bitmap sized 768 x 512 +#define PCD_BASEDIV4 2 // load the bitmap sized 384 x 256 +#define PCD_BASEDIV16 3 // load the bitmap sized 192 x 128 +#define PCX_DEFAULT 0 +#define PNG_DEFAULT 0 +#define PNG_IGNOREGAMMA 1 // avoid gamma correction +#define PNM_DEFAULT 0 +#define PNM_SAVE_RAW 0 // If set the writer saves in RAW format (i.e. P4, P5 or P6) +#define PNM_SAVE_ASCII 1 // If set the writer saves in ASCII format (i.e. P1, P2 or P3) +#define PSD_DEFAULT 0 +#define RAS_DEFAULT 0 +#define TARGA_DEFAULT 0 +#define TARGA_LOAD_RGB888 1 // If set the loader converts RGB555 and ARGB8888 -> RGB888. +#define TIFF_DEFAULT 0 +#define TIFF_CMYK 0x0001 // reads/stores tags for separated CMYK (use | to combine with compression flags) +#define TIFF_PACKBITS 0x0100 // save using PACKBITS compression +#define TIFF_DEFLATE 0x0200 // save using DEFLATE compression (a.k.a. ZLIB compression) +#define TIFF_ADOBE_DEFLATE 0x0400 // save using ADOBE DEFLATE compression +#define TIFF_NONE 0x0800 // save without any compression +#define TIFF_CCITTFAX3 0x1000 // save using CCITT Group 3 fax encoding +#define TIFF_CCITTFAX4 0x2000 // save using CCITT Group 4 fax encoding +#define TIFF_LZW 0x4000 // save using LZW compression +#define TIFF_JPEG 0x8000 // save using JPEG compression +#define WBMP_DEFAULT 0 +#define XBM_DEFAULT 0 +#define XPM_DEFAULT 0 + +#endif // FREEIMAGE_CH diff --git a/harbour/contrib/freeimage/make_b32.bat b/harbour/contrib/freeimage/make_b32.bat new file mode 100644 index 0000000000..65f41f74b8 --- /dev/null +++ b/harbour/contrib/freeimage/make_b32.bat @@ -0,0 +1,79 @@ +@echo off +rem +rem $Id$ +rem + +rem --------------------------------------------------------------- +rem IMPORTANT: You'll need Freeimage headers and binary from here: +rem http://freeimage.sourceforge.net/download.html +rem and this envvar to be set to successfully build this library: +rem set FREEIMAGE_DIR=C:\FreeImage +rem --------------------------------------------------------------- + +rem --------------------------------------------------------------- +rem This is a generic template file, if it doesn't fit your own needs +rem please DON'T MODIFY IT. +rem +rem Instead, make a local copy and modify that one, or make a call to +rem this batch file from your customized one. [vszakats] +rem +rem Set any of the below settings to customize your build process: +rem set HB_MAKE_PROGRAM= +rem set HB_MAKE_FLAGS= +rem --------------------------------------------------------------- + +if "%HB_DLL_DIR%" == "" set HB_DLL_DIR=%SystemRoot%\system32 +if "%HB_CC_NAME%" == "" set HB_CC_NAME=b32 +if "%HB_MAKE_PROGRAM%" == "" set HB_MAKE_PROGRAM=make.exe +set HB_MAKEFILE=..\mtpl_%HB_CC_NAME%.mak + +set C_USR=%C_USR% -I%FREEIMAGE_DIR%\source -DHB_OS_WIN_32_USED + +rem --------------------------------------------------------------- + +rem Save the user value, force silent file overwrite with COPY +rem (not all Windows versions support the COPY /Y flag) +set HB_ORGENV_COPYCMD=%COPYCMD% +set COPYCMD=/Y + +rem --------------------------------------------------------------- + +if "%1" == "clean" goto CLEAN +if "%1" == "CLEAN" goto CLEAN + +if "%1" == "install" goto INSTALL +if "%1" == "INSTALL" goto INSTALL + +:BUILD + + implib ..\..\lib\%HB_CC_NAME%\FreeImage.lib %FREEIMAGE_DIR%\Dist\FreeImage.dll + + %HB_MAKE_PROGRAM% %HB_MAKE_FLAGS% -f %HB_MAKEFILE% %1 %2 %3 > make_%HB_CC_NAME%.log + if errorlevel 1 notepad make_%HB_CC_NAME%.log + goto EXIT + +:CLEAN + + %HB_MAKE_PROGRAM% %HB_MAKE_FLAGS% -f %HB_MAKEFILE% CLEAN > make_%HB_CC_NAME%.log + if exist make_%HB_CC_NAME%.log del make_%HB_CC_NAME%.log > nul + if exist inst_%HB_CC_NAME%.log del inst_%HB_CC_NAME%.log > nul + goto EXIT + +:INSTALL + + set _HB_INSTALL_PREFIX=%HB_INSTALL_PREFIX% + if "%_HB_INSTALL_PREFIX%" == "" set _HB_INSTALL_PREFIX=..\.. + set _HB_LIB_INSTALL=%HB_LIB_INSTALL% + if "%_HB_LIB_INSTALL%" == "" set _HB_LIB_INSTALL=%_HB_INSTALL_PREFIX%\lib + + copy ..\..\lib\%HB_CC_NAME%\FreeImage.lib %_HB_LIB_INSTALL% + + %HB_MAKE_PROGRAM% %HB_MAKE_FLAGS% -f %HB_MAKEFILE% INSTALL > nul + goto EXIT + +:EXIT + +rem --------------------------------------------------------------- + +rem Restore user value +set COPYCMD=%HB_ORGENV_COPYCMD% diff --git a/harbour/contrib/freeimage/make_vc.bat b/harbour/contrib/freeimage/make_vc.bat new file mode 100644 index 0000000000..52a587b165 --- /dev/null +++ b/harbour/contrib/freeimage/make_vc.bat @@ -0,0 +1,95 @@ +@echo off +rem +rem $Id$ +rem + +rem --------------------------------------------------------------- +rem IMPORTANT: You'll need Freeimage headers and binary from here: +rem http://freeimage.sourceforge.net/download.html +rem and this envvar to be set to successfully build this library: +rem set FREEIMAGE_DIR=C:\FreeImage +rem --------------------------------------------------------------- + +rem --------------------------------------------------------------- +rem This is a generic template file, if it doesn't fit your own needs +rem please DON'T MODIFY IT. +rem +rem Instead, make a local copy and modify that one, or make a call to +rem this batch file from your customized one. [vszakats] +rem +rem Set any of the below settings to customize your build process: +rem set HB_MAKE_PROGRAM= +rem set HB_MAKE_FLAGS= +rem --------------------------------------------------------------- + +if "%HB_DLL_DIR%" == "" set HB_DLL_DIR=%SystemRoot%\system32 +if "%HB_CC_NAME%" == "" set HB_CC_NAME=vc +if "%HB_MAKE_PROGRAM%" == "" set HB_MAKE_PROGRAM=nmake.exe +set HB_MAKEFILE=..\mtpl_%HB_CC_NAME%.mak + +set C_USR=%C_USR% -I%FREEIMAGE_DIR%\source -DHB_OS_WIN_32_USED + +rem --------------------------------------------------------------- + +rem Save the user value, force silent file overwrite with COPY +rem (not all Windows versions support the COPY /Y flag) +set HB_ORGENV_COPYCMD=%COPYCMD% +set COPYCMD=/Y + +rem --------------------------------------------------------------- + +if "%1" == "clean" goto CLEAN +if "%1" == "CLEAN" goto CLEAN + +if "%1" == "install" goto INSTALL +if "%1" == "INSTALL" goto INSTALL + +:BUILD + + rem --------------------------------------------------------------- + rem This .dll to .lib conversion needs GNU sed.exe in the path + rem --------------------------------------------------------------- + echo./[ \t]*ordinal hint/,/^^[ \t]*Summary/{> _temp.sed + echo. /^^[ \t]\+[0-9]\+/{>> _temp.sed + echo. s/^^[ \t]\+[0-9]\+[ \t]\+[0-9A-Fa-f]\+[ \t]\+[0-9A-Fa-f]\+[ \t]\+\(.*\)/\1/p>> _temp.sed + echo. }>> _temp.sed + echo.}>> _temp.sed + DUMPBIN /EXPORTS %FREEIMAGE_DIR%\Dist\FreeImage.dll > _dump.tmp + echo.LIBRARY %FREEIMAGE_DIR%\Dist\FreeImage.dll > _temp.def + echo.EXPORTS >> _temp.def + sed -nf _temp.sed < _dump.tmp >> _temp.def + LIB /MACHINE:X86 /DEF:_temp.def /OUT:..\..\lib\%HB_CC_NAME%\FreeImage.lib + del _dump.tmp + del _temp.def + del _temp.sed + rem --------------------------------------------------------------- + + %HB_MAKE_PROGRAM% %HB_MAKE_FLAGS% -f %HB_MAKEFILE% %1 %2 %3 > make_%HB_CC_NAME%.log + if errorlevel 1 notepad make_%HB_CC_NAME%.log + goto EXIT + +:CLEAN + + %HB_MAKE_PROGRAM% %HB_MAKE_FLAGS% -f %HB_MAKEFILE% CLEAN > make_%HB_CC_NAME%.log + if exist make_%HB_CC_NAME%.log del make_%HB_CC_NAME%.log > nul + if exist inst_%HB_CC_NAME%.log del inst_%HB_CC_NAME%.log > nul + goto EXIT + +:INSTALL + + set _HB_INSTALL_PREFIX=%HB_INSTALL_PREFIX% + if "%_HB_INSTALL_PREFIX%" == "" set _HB_INSTALL_PREFIX=..\.. + set _HB_LIB_INSTALL=%HB_LIB_INSTALL% + if "%_HB_LIB_INSTALL%" == "" set _HB_LIB_INSTALL=%_HB_INSTALL_PREFIX%\lib + + copy ..\..\lib\%HB_CC_NAME%\FreeImage.lib %_HB_LIB_INSTALL% + + %HB_MAKE_PROGRAM% %HB_MAKE_FLAGS% -f %HB_MAKEFILE% INSTALL > nul + goto EXIT + +:EXIT + +rem --------------------------------------------------------------- + +rem Restore user value +set COPYCMD=%HB_ORGENV_COPYCMD% diff --git a/harbour/contrib/freeimage/readme.txt b/harbour/contrib/freeimage/readme.txt new file mode 100644 index 0000000000..01de1a7b96 --- /dev/null +++ b/harbour/contrib/freeimage/readme.txt @@ -0,0 +1,58 @@ +/* + * $Id$ + */ + +/* + * The following parts are Copyright of the individual authors. + * www - http://www.xharbour.org http://www.harbour-project.org + * + * Copyright 2005 Francesco Saverio Giudice + * README file explaining howto compile FreeImage library + * + * See doc/license.txt for licensing terms. + * + */ + +FreeImage Library is a porting to xHarbour of famous FreeImage Project library. + +Actually based on FreeImage version 3.8.0 +FreeImage Project's web site is http://freeimage.sourceforge.net/ + +COMPILING +========= + +Actually platforms supported are: +- Win32 / BCC32 +- GNU systems / GCC + +to build library on Win32 with BCC use: +make_b32.bat + +on GNU system use: +make install +WARNING: not actually tested + + ** requirements: to build FreeImage library: gcc-c++, libstdc++-devel + +DOCUMENTATION +============= + +Look at doc folder for help files. +Last FreeImage pdf manual is downloadable from http://freeimage.sourceforge.net/download.html + +SAMPLES +======= + +For samples look at tests dir. +fitest.prg is an API test application. + +NOTES +===== + +WARNING: if you are using Windows platform, download the + FreeImage.dll in tests before use it. + +At this time (28/10/2005 CET) it builds on Windows with last CVS. +Not tested on GNU system, but it have to run correctly. + + diff --git a/harbour/contrib/freeimage/test/bld_b32.bat b/harbour/contrib/freeimage/test/bld_b32.bat new file mode 100644 index 0000000000..830467e7d1 --- /dev/null +++ b/harbour/contrib/freeimage/test/bld_b32.bat @@ -0,0 +1,80 @@ +@echo off +rem +rem $Id$ +rem + +if A%1 == A GOTO :SYNTAX +if NOT EXIST %1.prg GOTO :NOEXIST + +ECHO Build: Compiling... + +set hdir=..\..\.. + +%hdir%\bin\harbour %1 /w /n /i..\include;%hdir%\include %2 %3 > bld_b32.log +type bld_b32.log +IF ERRORLEVEL 1 PAUSE +IF ERRORLEVEL 1 GOTO EXIT + +echo -O2 -e%1.exe -I%hdir%\include %1.c > bld_b32.mak +bcc32 -M -c @bld_b32.mak +:ENDCOMPILE + +echo c0w32.obj + > bld_b32.mak +echo %1.obj, + >> bld_b32.mak +echo %1.exe, + >> bld_b32.mak +echo %1.map, + >> bld_b32.mak +echo %hdir%\lib\rtl.lib + >> bld_b32.mak +echo %hdir%\lib\vm.lib + >> bld_b32.mak +echo %hdir%\lib\gtwin.lib + >> bld_b32.mak +echo %hdir%\lib\lang.lib + >> bld_b32.mak +echo %hdir%\lib\macro.lib + >> bld_b32.mak +echo %hdir%\lib\rdd.lib + >> bld_b32.mak +echo %hdir%\lib\dbfntx.lib + >> bld_b32.mak +echo %hdir%\lib\dbfcdx.lib + >> bld_b32.mak +echo %hdir%\lib\debug.lib + >> bld_b32.mak +echo %hdir%\lib\common.lib + >> bld_b32.mak +echo %hdir%\lib\pp.lib + >> bld_b32.mak +echo %hdir%\lib\hbsix.lib + >> bld_b32.mak +echo %hdir%\lib\dbffpt.lib + >> bld_b32.mak +echo %hdir%\lib\fi_lib.lib + >> bld_b32.mak +echo %hdir%\lib\freeimage.lib + >> bld_b32.mak + +rem Uncomment these two lines to use Advantage RDD +rem echo %hdir%\lib\rddads.lib + >> bld_b32.mak +rem echo %hdir%\lib\ace32.lib + >> bld_b32.mak + +echo cw32.lib + >> bld_b32.mak +echo import32.lib, >> bld_b32.mak + +ECHO Build: Linking... +rem Use these flags to avoid the console window creation +rem ilink32 -Gn -aa -Tpe -s @bld_b32.mak +ilink32 -Gn -Tpe -s @bld_b32.mak + +rem delete temporary files +del %1.c +del %1.obj +if exist %1.map del %1.map +if exist %1.tds del %1.tds +del bld_b32.mak +del bld_b32.log + +IF ERRORLEVEL 1 GOTO LINKERROR +ECHO Build: Done. +%1 +GOTO EXIT +ECHO + +:LINKERROR +rem if exist meminfo.txt notepad meminfo.txt +rem PAUSE * Linking errors * +GOTO EXIT + +:SYNTAX +ECHO SYNTAX: bld_b32 [Program] {-- Don't specify .prg extension +GOTO EXIT + +:NOEXIST +ECHO Build: The specified %1.prg does not exist + +:EXIT diff --git a/harbour/contrib/freeimage/test/fitest.prg b/harbour/contrib/freeimage/test/fitest.prg new file mode 100644 index 0000000000..97657fe32e --- /dev/null +++ b/harbour/contrib/freeimage/test/fitest.prg @@ -0,0 +1,242 @@ +/* + * $Id$ + */ + +/* + * Copyright 2005 Francesco Saverio Giudice + * + * FreeImage API test file + */ + +#include "FreeImage.ch" +#include "common.ch" + +#define IMAGES_IN "" +#define IMAGES_OUT "images_out/" + +PROCEDURE Main() + + LOCAL im, clone, rotated, rotatedEx, rescale, im2, im3 + LOCAL centerX, centerY, width, height, appo + LOCAL bmpinfoheader + LOCAL bmpinfo + LOCAL bkcolor + LOCAL iccprofile + LOCAL x + + //? "Press Alt-D + Enter to activate debug" + //AltD( .T. ) + //Inkey(0) + altd() + // Check output directory + IF !hb_DirExists( IMAGES_OUT ) +#ifdef HB_COMPAT_C53 + MakeDir( IMAGES_OUT ) +#endif + ENDIF + + ? "Initialise" + fi_Initialise() + //---------------------------// + + ? "Set Error Message:", fi_SetOutPutMessage( fi_Error() ) + //? "Set Error Message:", fi_SetOutPutMessage( NIL ) + + ? "Version :", fi_GetVersion() + ? "Copyright :", fi_GetCopyrightMessage() + ? "File type :", fi_GetFileType( IMAGES_IN + "sample1.jpg" ) + ? "Load JPEG" + im := fi_Load( FIF_JPEG, IMAGES_IN + "sample1.jpg", JPEG_DEFAULT ) + + ? "Clone image" + clone := fi_Clone( im ) + + ? "Pointer :", ValToPrg( im ) + + ? "Image Type :", fi_GetImageType( im ) + ? "Color Used :", fi_GetColorsUsed( im ) + ? "Pixel size :", fi_GetBPP( im ) + ? "Width :", fi_GetWidth( im ) + ? "Height :", fi_GetHeight( im ) + ? "Byte Size :", fi_GetLine( im ) + ? "Pitch :", fi_GetPitch( im ) + ? "DIB Size :", fi_GetDIBSize( im ) + ? "Dots per Meter X :", fi_GetDotsPerMeterX( im ) + ? "Dots per Meter Y :", fi_GetDotsPerMeterY( im ) + ? "Color Type :", fi_GetColorType( im ) + ? "Red Mask :", fi_GetRedMask( im ) + ? "Green Mask :", fi_GetGreenMask( im ) + ? "Blue Mask :", fi_GetBlueMask( im ) + ? "Transp. Count :", fi_GetTransparencyCount( im ) + ? "Is Transparent ? :", fi_IsTransparent( im ) + ? + ? "Save BMP ? :", fi_Save( FIF_BMP , im, IMAGES_OUT + "sample1.bmp", BMP_DEFAULT ) + ? "Save JPG ? :", fi_Save( FIF_JPEG, im, IMAGES_OUT + "sample1.jpg", JPEG_DEFAULT ) + ? "Save PNG ? :", fi_Save( FIF_PNG , im, IMAGES_OUT + "sample1.png", PNG_DEFAULT ) + + ? "Save TIFF ? :", fi_Save( FIF_TIFF, clone, IMAGES_OUT + "sample1.tif", TIFF_DEFAULT ) + ? "Flip Horizontal ?:", fi_FlipHorizontal( clone ) + ? "Save JPG ? :", fi_Save( FIF_JPEG, clone, IMAGES_OUT + "horizontal.jpg", JPEG_DEFAULT ) + ? "Flip Vertical ? :", fi_FlipVertical( clone ) + ? "Save JPG ? :", fi_Save( FIF_JPEG, clone, IMAGES_OUT + "vertical.jpg", JPEG_DEFAULT ) + + ? "Rotate Classic :", ValToPrg( rotated := fi_RotateClassic( clone, 90 ) ) + ? "Save JPG ? :", fi_Save( FIF_JPEG, rotated, IMAGES_OUT + "rotate.jpg", JPEG_DEFAULT ) + fi_Unload( rotated ) + + centerx := fi_GetWidth( clone ) / 2 + centery := fi_GetHeight( clone ) / 2 + ? "Rotate Ex :", ValToPrg( rotatedEx := fi_RotateEx( clone, 15, 0, 0, centerx, centery, TRUE ) ) + ? "Save JPG ? :", fi_Save( FIF_JPEG, rotatedEx, IMAGES_OUT + "rotateEx.jpg", JPEG_DEFAULT ) + fi_Unload( rotatedEx ) + + width := fi_GetWidth( im ) + height := fi_GetHeight( im ) + + ? "Rescale :", ValToPrg( rescale := fi_Rescale( im, width / 2, height / 2, FILTER_BICUBIC ) ) + ? "Save JPG ? :", fi_Save( FIF_JPEG, rescale, IMAGES_OUT + "rescale.jpg", JPEG_DEFAULT ) + fi_Unload( rescale ) + + im2 := fi_Clone( im ) + ? "Adjust Gamma ? :", fi_AdjustGamma( im2, 3.0 ) + ? "Save JPG ? :", fi_Save( FIF_JPEG, im2, IMAGES_OUT + "adjgamma.jpg", JPEG_DEFAULT ) + fi_Unload( im2 ) + + im2 := fi_Clone( im ) + ? "Adjust Brightness:", fi_AdjustBrightness( im2, -30 ) + ? "Save JPG ? :", fi_Save( FIF_JPEG, im2, IMAGES_OUT + "adjbright.jpg", JPEG_DEFAULT ) + fi_Unload( im2 ) + + im2 := fi_Clone( im ) + ? "Adjust Contrast ?:", fi_AdjustContrast( im2, -30 ) + ? "Save JPG ? :", fi_Save( FIF_JPEG, im2, IMAGES_OUT + "adjcontrast.jpg", JPEG_DEFAULT ) + fi_Unload( im2 ) + + im2 := fi_Clone( im ) + ? "Invert ? :", fi_Invert( im2 ) + ? "Save JPG ? :", fi_Save( FIF_JPEG, im2, IMAGES_OUT + "invert.jpg", JPEG_DEFAULT ) + fi_Unload( im2 ) + + ? "Red Channel :", ValToPrg( im2 := fi_GetChannel( im, FICC_RED ) ) + ? "Save JPG ? :", fi_Save( FIF_JPEG, im2, IMAGES_OUT + "red.jpg", JPEG_DEFAULT ) + fi_Unload( im2 ) + + ? "Green Channel :", ValToPrg( im2 := fi_GetChannel( im, FICC_GREEN ) ) + ? "Save JPG ? :", fi_Save( FIF_JPEG, im2, IMAGES_OUT + "green.jpg", JPEG_DEFAULT ) + fi_Unload( im2 ) + + ? "Blue Channel :", ValToPrg( im2 := fi_GetChannel( im, FICC_BLUE ) ) + ? "Save JPG ? :", fi_Save( FIF_JPEG, im2, IMAGES_OUT + "blue.jpg", JPEG_DEFAULT ) + fi_Unload( im2 ) + + ? "Copy :", ValToPrg( im2 := fi_Copy( im, 300, 100, 800, 200 ) ) + ? "Save JPG ? :", fi_Save( FIF_JPEG, im2, IMAGES_OUT + "copy.jpg", JPEG_DEFAULT ) + + im3 := fi_Clone( im ) + ? "Paste ? :", fi_Paste( im3, im2, 10, 10, 70 ) + ? "Save JPG ? :", fi_Save( FIF_JPEG, im3, IMAGES_OUT + "paste.jpg", JPEG_DEFAULT ) + fi_Unload( im2 ) + fi_Unload( im3 ) + + ? "Allocate Bitmap :", ValToPrg( im3 := fi_AllocateT( FIT_BITMAP, 320, 200, 32 ) ) + ? "Save JPG ? :", fi_Save( FIF_JPEG, im3, IMAGES_OUT + "allocate.jpg", JPEG_DEFAULT ) + fi_Unload( im3 ) + + ? "Create ERROR :" + ? "Save GIF ? :", fi_Save( FIF_GIF, im, IMAGES_OUT + "wrong.gif", 0 ) + + //? ValToPrg( fi_GetInfoHeader( im ) ) + //bmpinfoheader:Buffer( fi_GetInfoHeader( im ), TRUE ) + //bmpinfoheader:Pointer( fi_GetInfoHeader( im ) ) + //? "Header :", ValToPrg( bmpinfoheader ) + //? bmpinfoheader:SayMembers(" ", .t., .t.) + + //bmpinfo:Pointer( fi_GetInfo( im ) ) + ? "Info :", ValToPrg( bmpinfo ) + //? bmpinfo:SayMembers(" ", .t., .t.) + ? "-----------------------------------------------------" + //? ValType( bmpinfo:Devalue() ) + //Tracelog( "bmpinfoheader", ValToPrg( bmpinfoheader ), ; + // bmpinfoheader:SayMembers(, .t.), bmpinfoheader:Value(), bmpinfoheader:DeValue(), hb_dumpvar( bmpinfoheader:Array() ), hb_dumpvar( bmpinfoheader:acMembers ) ) + + //appo := bkcolor:Value() + //? bkcolor:Pointer( fi_GetBackgroundColor( im ) ) + //? fi_GetBackgroundColor( im, @bkcolor:Value() ) + //bkcolor:Buffer( appo ) + //? bkcolor:SayMembers(" ", .t., .t.) + + //bkcolor:rgbBlue := 205 + //? fi_SetBackgroundColor( im, hb_String2Pointer( bkcolor:Value() ) ) + Tracelog("linha 168") + //? fi_SetBackgroundColor( im, bkcolor:Value() ) + Tracelog("linha 170") + //? bkcolor:SayMembers(" ", .t., .t.) +Tracelog("linha 162") +// ? bkcolor:Pointer( fi_GetBackgroundColor( im ) ) + //? fi_GetBackgroundColor( im, @bkcolor:Value() ) + //bkcolor:Buffer( appo ) +Tracelog("linha 176") + //? bkcolor:SayMembers(" ", .t., .t.) + +Tracelog("linha 179") + //iccprofile:Pointer( fi_GetICCProfile( im ) ) + Tracelog("linha 181") + //? "Header :", ValToPrg( iccprofile ) + Tracelog("linha 183") + //? iccprofile:SayMembers(" ", .t., .t.) + + //bmpinfoheader:Reset() + //appo := NIL + //bmpinfoheader := NIL + //hb_GCAll( .T. ) + + ? "Unload images from memory" + fi_Unload( im ) + fi_Unload( clone ) + + + //---------------------------// + ? "DeInitialise" + fi_Deinitialise() + + ? + ? "Look at " + IMAGES_OUT + " folder for output images" + ? + +RETURN + +PROCEDURE fi_Error( cFormat, cMessage ) + ? "ERROR!..." + ? "Format : ", cFormat + ? "Message : ", cMessage +RETURN + +PROCEDURE TraceLog( c ) + HB_SYMBOL_UNUSED( c ) + RETURN + +FUNCTION ValToPrg( xValue ) + LOCAL cType := ValType( xValue ) + + DO CASE + CASE cType == "C" + + xValue := StrTran( xValue, Chr(0), '"+Chr(0)+"' ) + xValue := StrTran( xValue, Chr(9), '"+Chr(9)+"' ) + xValue := StrTran( xValue, Chr(10), '"+Chr(10)+"' ) + xValue := StrTran( xValue, Chr(13), '"+Chr(13)+"' ) + xValue := StrTran( xValue, Chr(26), '"+Chr(26)+"' ) + + RETURN '"' + xValue + '"' + + CASE cType == "N" ; RETURN LTrim( Str( xValue ) ) + CASE cType == "D" ; RETURN 'HB_SToD("' + DToS( xValue ) + '")' + CASE cType == "L" ; RETURN iif( xValue, ".T.", ".F." ) + CASE cType == "O" ; RETURN xValue:className() + " Object" + CASE cType == "U" ; RETURN "NIL" + CASE cType == "B" ; RETURN '{||...}' + CASE cType == "A" ; RETURN '{.[' + LTrim( Str( Len( xValue ) ) ) + '].}' + CASE cType == "M" ; RETURN 'M:"' + xValue + '"' + ENDCASE + + RETURN "" diff --git a/harbour/contrib/freeimage/test/fsg.jpg b/harbour/contrib/freeimage/test/fsg.jpg new file mode 100644 index 0000000000..767bf1b331 Binary files /dev/null and b/harbour/contrib/freeimage/test/fsg.jpg differ diff --git a/harbour/contrib/freeimage/test/italia.gif b/harbour/contrib/freeimage/test/italia.gif new file mode 100644 index 0000000000..73eb4bebcb Binary files /dev/null and b/harbour/contrib/freeimage/test/italia.gif differ diff --git a/harbour/contrib/freeimage/test/sample1.jpg b/harbour/contrib/freeimage/test/sample1.jpg new file mode 100644 index 0000000000..d0a274c551 Binary files /dev/null and b/harbour/contrib/freeimage/test/sample1.jpg differ diff --git a/harbour/contrib/xhb/hbfast.h b/harbour/contrib/xhb/hbfast.h new file mode 100644 index 0000000000..de18c04037 --- /dev/null +++ b/harbour/contrib/xhb/hbfast.h @@ -0,0 +1,5 @@ +/* + * $Id$ + */ + +#include "hbapi.h"