Skip to content

Commit

Permalink
convert zbarimg to C (cross compiled C++ cannot run w/native libraries)
Browse files Browse the repository at this point in the history
    - fix DrawDib image width granularity
    - fix window resize dimensions to include decorations
    - images still inverted, otherwise zbarimg now "working" in windows
  • Loading branch information
[email protected] committed Jun 16, 2009
1 parent 4622aae commit 99bbb73
Show file tree
Hide file tree
Showing 9 changed files with 428 additions and 362 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
current:
* convert zbarimg to C (cross compiled C++ cannot run w/native libraries)
- fix DrawDib image width granularity
- fix window resize dimensions to include decorations
- images still inverted, otherwise zbarimg now "working" in windows
* refactor processor implementation to support cross-platform
- first pass windows processor (before debugging)
- make processor locks reentrant (call APIs from callback)
Expand Down
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ AM_CXXFLAGS = $(AM_CFLAGS)
ACLOCAL_AMFLAGS = -I config
bin_PROGRAMS =
check_PROGRAMS =
EXTRA_PROGRAMS =
lib_LTLIBRARIES =
pyexec_LTLIBRARIES =
CLEANFILES =
Expand Down
12 changes: 5 additions & 7 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -242,20 +242,18 @@ AC_ARG_WITH([imagemagick],
[with_imagemagick="yes"])

AS_IF([test "x$with_imagemagick" != "xno"],
[PKG_CHECK_MODULES([MAGICK], [ImageMagick++ >= 6.2.6])
MAGICK_VERSION=`$PKG_CONFIG ImageMagick++ --modversion`
[PKG_CHECK_MODULES([MAGICK], [MagickWand >= 6.2.6])
MAGICK_VERSION=`$PKG_CONFIG MagickWand --modversion`
AC_MSG_NOTICE([using ImageMagick version $MAGICK_VERSION])
dnl double check ImageMagick install (bug #2582232)
AC_LANG_PUSH([C++])
CPPFLAGS_save="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $MAGICK_CFLAGS"
AC_CHECK_HEADER([Magick++.h], [],
[AC_MSG_FAILURE([ImageMagick++ package found but Magick++.h not installed?!
AC_CHECK_HEADER([wand/MagickWand.h], [],
[AC_MSG_FAILURE([ImageMagick package found but wand/MagickWand.h not installed?!
this is a problem with your ImageMagick install,
please resolve the inconsistency and try again...])])
CPPFLAGS="$CPPFLAGS_save"
AC_LANG_POP([C++])])
CPPFLAGS="$CPPFLAGS_save"])

AM_CONDITIONAL([HAVE_MAGICK], [test "x$with_imagemagick" = "xyes"])

Expand Down
2 changes: 1 addition & 1 deletion test/Makefile.am.inc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test_test_jpeg_LDADD = zbar/libzbar.la $(AM_LDADD)
endif

if HAVE_MAGICK
check_PROGRAMS += test/dbg_scan
EXTRA_PROGRAMS += test/dbg_scan
test_dbg_scan_SOURCES = test/dbg_scan.cpp
test_dbg_scan_CPPFLAGS = $(MAGICK_CFLAGS) $(AM_CPPFLAGS)
test_dbg_scan_LDADD = $(MAGICK_LIBS) zbar/libzbar.la $(AM_LDADD)
Expand Down
32 changes: 22 additions & 10 deletions zbar/processor/win.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
#include "win.h"
#include <assert.h>

#define WIN_STYLE (WS_CAPTION | \
WS_SYSMENU | \
WS_THICKFRAME | \
WS_MINIMIZEBOX | \
WS_MAXIMIZEBOX)
#define EXT_STYLE (WS_EX_APPWINDOW | WS_EX_OVERLAPPEDWINDOW)

static inline int proc_lock (processor_state_t *state,
DWORD self)
{
Expand Down Expand Up @@ -359,7 +366,7 @@ static LRESULT CALLBACK proc_handle_event (HWND hwnd,
case WM_SIZE: {
RECT r;
GetClientRect(hwnd, &r);
zprintf(3, "WM_SIZE %dx%d\n", r.right, r.bottom);
zprintf(3, "WM_SIZE %ldx%ld\n", r.right, r.bottom);
assert(proc);
zbar_window_resize(proc->window, r.right, r.bottom);
InvalidateRect(hwnd, NULL, 0);
Expand Down Expand Up @@ -481,13 +488,12 @@ static inline int proc_open (zbar_processor_t *proc,
"failed to register window class"));
}

DWORD style = WS_OVERLAPPEDWINDOW;
DWORD exstyle = (WS_EX_APPWINDOW |
WS_EX_OVERLAPPEDWINDOW /*|
WS_EX_ACCEPTFILES*/);

state->hwnd = CreateWindowEx(exstyle, (LPCTSTR)(long)wca, "ZBar", style,
CW_USEDEFAULT, CW_USEDEFAULT, width, height,
RECT r = { 0, 0, width, height };
AdjustWindowRectEx(&r, WIN_STYLE, 0, EXT_STYLE);
state->hwnd = CreateWindowEx(EXT_STYLE, (LPCTSTR)(long)wca,
"ZBar", WIN_STYLE,
CW_USEDEFAULT, CW_USEDEFAULT,
r.right - r.left, r.bottom - r.top,
NULL, NULL, hmod, proc);

if(!state->hwnd) {
Expand Down Expand Up @@ -583,9 +589,15 @@ int _zbar_processor_set_size (zbar_processor_t *proc,
unsigned width,
unsigned height)
{
RECT r = { 0, 0, width, height };
processor_state_t *state = proc->state;
if(!SetWindowPos(state->hwnd, NULL, 0, 0, width, height,
SWP_ASYNCWINDOWPOS | SWP_NOACTIVATE | SWP_NOMOVE |
int rc = AdjustWindowRectEx(&r, GetWindowLong(state->hwnd, GWL_STYLE),
0, GetWindowLong(state->hwnd, GWL_EXSTYLE));
zprintf(5, "%dx%d %ld,%ld-%ld,%ld (%d)\n", width, height,
r.left, r.top, r.right, r.bottom, rc);
if(!SetWindowPos(state->hwnd, NULL,
0, 0, r.right - r.left, r.bottom - r.top,
SWP_NOACTIVATE | SWP_NOMOVE |
SWP_NOZORDER | SWP_NOREPOSITION))
return(-1/*FIXME*/);

Expand Down
21 changes: 16 additions & 5 deletions zbar/window/vfw.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,23 @@ vfw_init (zbar_window_t *w,
/* FIXME PNG? */
}
w->bih.biSizeImage = img->datalen;
zprintf(20, "%.4s(%08x)%dx%d->%.4s(%08x) ppm=%ldx%ld comp=%d bpp=%d\n",
(char*)&img->format, img->format, img->width, img->height,
(char*)&w->format, w->format,
w->bih.biXPelsPerMeter, w->bih.biYPelsPerMeter,
(int)w->bih.biCompression, w->bih.biBitCount);
}

w->bih.biSize = sizeof(w->bih);
w->bih.biWidth = img->width;
w->bih.biWidth = (img->width + 3) & ~3;
w->bih.biHeight = img->height;
w->dst_width = w->width;
w->dst_height = w->height;

if(!DrawDibBegin(w->hdd, hdc, w->width, w->height,
&w->bih, img->width, img->height, 0))
&w->bih, w->bih.biWidth, w->bih.biHeight, 0))
return(-1/*FIXME*/);
zprintf(24, "out=%ldx%ld\n", w->bih.biWidth, w->bih.biHeight);
return(0);
}

Expand All @@ -99,23 +105,28 @@ vfw_draw (zbar_window_t *w,
if(!hdc)
return(-1/*FIXME*/);

int width = (img->width + 3) & ~3;

if(((img->format != w->src_format &&
img->format != w->format) ||
img->width != w->bih.biWidth ||
width != w->bih.biWidth ||
img->height != w->bih.biHeight ||
w->width != w->dst_width ||
w->height != w->dst_height) &&
vfw_init(w, img, hdc))
return(-1);

if(img->format != w->format) {
w->image = zbar_image_convert(img, w->format);
if(img->format != w->format ||
img->width != width) {
w->image = zbar_image_convert_resize(img, w->format,
width, img->height);
zbar_image_destroy(img);
img = w->image;
}

zprintf(24, "DrawDibDraw(%dx%d -> %dx%d)\n",
img->width, img->height, w->width, w->height);

DrawDibDraw(w->hdd, hdc,
0, 0, w->width, w->height,
&w->bih, (void*)img->data,
Expand Down
2 changes: 1 addition & 1 deletion zbarimg/Makefile.am.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
bin_PROGRAMS += zbarimg/zbarimg
zbarimg_zbarimg_SOURCES = zbarimg/zbarimg.cpp
zbarimg_zbarimg_SOURCES = zbarimg/zbarimg.c
zbarimg_zbarimg_CPPFLAGS = $(MAGICK_CFLAGS) $(AM_CPPFLAGS)
zbarimg_zbarimg_LDADD = $(MAGICK_LIBS) zbar/libzbar.la
# automake bug in "monolithic mode"?
Expand Down
Loading

0 comments on commit 99bbb73

Please sign in to comment.