summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2013-03-17 14:55:48 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2013-03-17 14:55:48 +0100
commitd369bbe7164dd35e75a7bad9e7b5497512bb5fe9 (patch)
treee5077f726ffe80016f7609af4a84f548b06b6546
parent0f981dab5d477e82abe4b01f6477193707997f7d (diff)
Added PNG loadin support through a new Image class.
-rw-r--r--configure.in5
-rw-r--r--plugingui/Makefile.am8
-rw-r--r--plugingui/Makefile.am.plugingui1
-rw-r--r--plugingui/Makefile.mingw3214
-rw-r--r--plugingui/image.cc160
-rw-r--r--plugingui/image.h63
-rw-r--r--plugingui/painter.cc13
-rw-r--r--plugingui/painter.h2
-rw-r--r--vst/Makefile.mingw329
9 files changed, 264 insertions, 11 deletions
diff --git a/configure.in b/configure.in
index 1b3445e..8d5700a 100644
--- a/configure.in
+++ b/configure.in
@@ -255,6 +255,11 @@ dnl ======================
PKG_CHECK_MODULES(SNDFILE, sndfile >= 1.0.21)
dnl ======================
+dnl Check for sndfile
+dnl ======================
+PKG_CHECK_MODULES(PNG, libpng >= 1.5)
+
+dnl ======================
dnl Check for the pthread library
dnl ======================
tmp_CXXFLAGS="$CXXFLAGS"
diff --git a/plugingui/Makefile.am b/plugingui/Makefile.am
index 300e594..0953a70 100644
--- a/plugingui/Makefile.am
+++ b/plugingui/Makefile.am
@@ -3,9 +3,12 @@ bin_PROGRAMS = plugingui
include Makefile.am.plugingui
#include $(top_srcdir)/src/Makefile.am.drumgizmo
-plugingui_LDADD = $(SNDFILE_LIBS) $(PTHREAD_LIBS) $(EXPAT_LIBS) -ldl -lX11
+plugingui_LDADD = $(SNDFILE_LIBS) $(PTHREAD_LIBS) $(EXPAT_LIBS) \
+ -ldl -lX11 $(PNG_LIBS)
-plugingui_CXXFLAGS = $(SNDFILE_CXXFLAGS) $(PTHREAD_CFLAGS) $(EXPAT_CFLAGS) -I$(top_srcdir)/include $(PLUGIN_GUI_CFLAGS) -I$(top_srcdir)/src -DSTANDALONE -DX11 -DUSE_THREAD
+plugingui_CXXFLAGS = $(SNDFILE_CXXFLAGS) $(PTHREAD_CFLAGS) $(EXPAT_CFLAGS) \
+ -I$(top_srcdir)/include $(PLUGIN_GUI_CFLAGS) -I$(top_srcdir)/src \
+ -DSTANDALONE -DX11 -DUSE_THREAD $(PNG_CFLAGS)
plugingui_CFLAGS = $(plugingui_CXXFLAGS)
@@ -25,6 +28,7 @@ EXTRA_DIST = \
font.h \
globalcontext.h \
guievent.h \
+ image.h \
img_back.h \
img_font.h \
img_test.h \
diff --git a/plugingui/Makefile.am.plugingui b/plugingui/Makefile.am.plugingui
index 51049c8..b3f7d8d 100644
--- a/plugingui/Makefile.am.plugingui
+++ b/plugingui/Makefile.am.plugingui
@@ -22,6 +22,7 @@ PLUGIN_GUI_SOURCES = \
$(top_srcdir)/plugingui/listbox.cc \
$(top_srcdir)/plugingui/knob.cc \
$(top_srcdir)/plugingui/filebrowser.cc \
+ $(top_srcdir)/plugingui/image.cc \
$(top_srcdir)/plugingui/combobox.cc
PLUGIN_GUI_LIBS = -lX11
diff --git a/plugingui/Makefile.mingw32 b/plugingui/Makefile.mingw32
index 17e232f..6d6c003 100644
--- a/plugingui/Makefile.mingw32
+++ b/plugingui/Makefile.mingw32
@@ -2,9 +2,8 @@ top_srcdir=..
include Makefile.am.plugingui
CFLAGS=-DSTANDALONE -DWIN32 -DUSE_THREAD ${PLUGIN_GUI_CFLAGS} \
- -I$(top_srcdir)/src
-LDFLAGS=-mconsole -lgdi32 -lsetupapi -lws2_32
-#-lgdi32
+ -I$(top_srcdir)/src -I/local/include
+LDFLAGS=-mconsole -lgdi32 -lsetupapi -lws2_32 -L/local/lib -lpng -lz -pthread
C_SOURCES = \
$(top_srcdir)/hugin/hugin.c \
@@ -33,6 +32,7 @@ CXX_SOURCES = \
$(top_srcdir)/plugingui/filebrowser.cc \
$(top_srcdir)/plugingui/knob.cc \
$(top_srcdir)/plugingui/combobox.cc \
+ $(top_srcdir)/plugingui/image.cc \
$(top_srcdir)/src/thread.cc \
$(top_srcdir)/src/semaphore.cc
@@ -44,13 +44,13 @@ OBJECTS=$(CXX_SOURCES:.cc=.o) $(C_SOURCES:.c=.o)
all: $(CXX_SOURCES) $(C_SOURCES) plugingui.exe
plugingui.exe: $(OBJECTS)
- g++ $(OBJECTS) $(LDFLAGS) $(CFLAGS) -o $@
+ g++ -static -static-libgcc $(OBJECTS) $(LDFLAGS) $(CFLAGS) -o $@
%.o: %.cc
- g++ -O2 -c $(CFLAGS) $< -o $@
+ g++ -static -static-libgcc -O2 -c $(CFLAGS) $< -o $@
%.o: %.c
- gcc -O2 -c $(CFLAGS) $< -o $@
+ gcc -static -static-libgcc -O2 -c $(CFLAGS) $< -o $@
clean:
- del -rf *.o plugingui.exe
+ rm -rf $(OBJECTS) plugingui.exe
diff --git a/plugingui/image.cc b/plugingui/image.cc
new file mode 100644
index 0000000..1a0e73c
--- /dev/null
+++ b/plugingui/image.cc
@@ -0,0 +1,160 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * image.cc
+ *
+ * Sat Mar 16 15:05:09 CET 2013
+ * Copyright 2013 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo 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 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo 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 DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "image.h"
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+
+void abort_(const char * s, ...)
+{
+ va_list args;
+ va_start(args, s);
+ vfprintf(stderr, s, args);
+ fprintf(stderr, "\n");
+ va_end(args);
+ abort();
+}
+
+GUI::Image::Image(const char* data, size_t size)
+{
+}
+
+GUI::Image::Image(std::string filename)
+{
+ char header[8]; // 8 is the maximum size that can be checked
+
+ /* open file and test for it being a png */
+ FILE *fp = fopen(filename.c_str(), "rb");
+ if (!fp)
+ abort_("[read_png_file] File %s could not be opened for reading",
+ filename.c_str());
+ size_t r = fread(header, 1, 8, fp);
+ (void)r;
+ if(png_sig_cmp((const png_byte*)header, 0, 8)) {
+ abort_("[read_png_file] File %s is not recognized as a PNG file",
+ filename.c_str());
+ }
+
+ /* initialize stuff */
+ png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+
+ if(!png_ptr) {
+ abort_("[read_png_file] png_create_read_struct failed");
+ }
+
+ info_ptr = png_create_info_struct(png_ptr);
+ if(!info_ptr) {
+ abort_("[read_png_file] png_create_info_struct failed");
+ }
+
+ if(setjmp(png_jmpbuf(png_ptr))) {
+ abort_("[read_png_file] Error during init_io");
+ }
+
+ png_init_io(png_ptr, fp);
+ png_set_sig_bytes(png_ptr, 8);
+
+ png_read_info(png_ptr, info_ptr);
+
+ w = png_get_image_width(png_ptr, info_ptr);
+ h = png_get_image_height(png_ptr, info_ptr);
+ color_type = png_get_color_type(png_ptr, info_ptr);
+ bit_depth = png_get_bit_depth(png_ptr, info_ptr);
+
+ number_of_passes = png_set_interlace_handling(png_ptr);
+ png_read_update_info(png_ptr, info_ptr);
+
+
+ /* read file */
+ if (setjmp(png_jmpbuf(png_ptr))) {
+ abort_("[read_png_file] Error during read_image");
+ }
+
+ row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * h);
+ size_t y;
+ for(y = 0; y < h; y++) {
+ row_pointers[y] = (png_byte*) malloc(png_get_rowbytes(png_ptr,info_ptr));
+ }
+
+ png_read_image(png_ptr, row_pointers);
+
+ fclose(fp);
+}
+#if 0
+void process_file(void)
+{
+ if(png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB) {
+ abort_("[process_file] input file is PNG_COLOR_TYPE_RGB but must be"
+ " PNG_COLOR_TYPE_RGBA (lacks the alpha channel)");
+ }
+
+ if(png_get_color_type(png_ptr, info_ptr) != PNG_COLOR_TYPE_RGBA) {
+ abort_("[process_file] color_type of input file must be "
+ "PNG_COLOR_TYPE_RGBA (%d) (is %d)",
+ PNG_COLOR_TYPE_RGBA, png_get_color_type(png_ptr, info_ptr));
+ }
+
+ size_t x, y;
+ for(y = 0; y < height(); y++) {
+ png_byte* row = row_pointers[y];
+ for(x = 0; x < width; x++) {
+ png_byte* ptr = &(row[x*4]);
+ printf("Pixel at position [%d - %d] has RGBA values: %d - %d - %d - %d\n",
+ x, y, ptr[0], ptr[1], ptr[2], ptr[3]);
+
+ /* set red value to 0 and green value to the blue one */
+ ptr[0] = 0;
+ ptr[1] = ptr[2];
+ }
+ }
+}
+#endif
+
+GUI::Image::~Image()
+{
+}
+
+size_t GUI::Image::width()
+{
+ return w;
+}
+
+size_t GUI::Image::height()
+{
+ return h;
+}
+
+GUI::Colour GUI::Image::getPixel(size_t x, size_t y)
+{
+ png_byte* row = row_pointers[y];
+ png_byte* ptr = &(row[x*4]);
+ GUI::Colour c(ptr[0], ptr[1], ptr[2], ptr[3]);
+ return c;
+}
diff --git a/plugingui/image.h b/plugingui/image.h
new file mode 100644
index 0000000..c509159
--- /dev/null
+++ b/plugingui/image.h
@@ -0,0 +1,63 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * image.h
+ *
+ * Sat Mar 16 15:05:08 CET 2013
+ * Copyright 2013 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo 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 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo 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 DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __DRUMGIZMO_IMAGE_H__
+#define __DRUMGIZMO_IMAGE_H__
+
+#include <png.h>
+#include <string>
+
+#include "colour.h"
+
+namespace GUI {
+
+class Image {
+public:
+ Image(const char* data, size_t size);
+ Image(std::string filename);
+ ~Image();
+
+ size_t width();
+ size_t height();
+
+ Colour getPixel(size_t x, size_t y);
+
+ unsigned int *pixels;
+ unsigned int order;
+
+private:
+ size_t w, h;
+ png_byte color_type;
+ png_byte bit_depth;
+ png_structp png_ptr;
+ png_infop info_ptr;
+ int number_of_passes;
+ png_bytep * row_pointers;
+};
+
+};
+
+#endif/*__DRUMGIZMO_IMAGE_H__*/
diff --git a/plugingui/painter.cc b/plugingui/painter.cc
index ce88333..40d6112 100644
--- a/plugingui/painter.cc
+++ b/plugingui/painter.cc
@@ -383,6 +383,19 @@ void GUI::Painter::drawImage(int x0, int y0, struct __img__ * img)
}
}
+void GUI::Painter::drawImage(int x0, int y0, GUI::Image *image)
+{
+ size_t fw = image->width();
+ size_t fh = image->height();
+
+ for(size_t x = 0; x < fw; x++) {
+ for(size_t y = 0; y < fh; y++) {
+ GUI::Colour c = image->getPixel(x, y);
+ pixbuf->setPixel(x0 + x, y0 + y, c.red, c.green, c.blue, c.alpha);
+ }
+ }
+}
+
void GUI::Painter::flush()
{
#ifdef X11
diff --git a/plugingui/painter.h b/plugingui/painter.h
index f236369..467e612 100644
--- a/plugingui/painter.h
+++ b/plugingui/painter.h
@@ -33,6 +33,7 @@
#include "colour.h"
#include "pixelbuffer.h"
#include "font.h"
+#include "image.h"
namespace GUI {
@@ -67,6 +68,7 @@ public:
void drawCircle(int x, int y, double r);
void drawFilledCircle(int x, int y, int r);
void drawImage(int x, int y, struct __img__ * img);
+ void drawImage(int x, int y, Image *image);
void clear();
diff --git a/vst/Makefile.mingw32 b/vst/Makefile.mingw32
index 4e4866c..a2e06e9 100644
--- a/vst/Makefile.mingw32
+++ b/vst/Makefile.mingw32
@@ -52,7 +52,8 @@ GUI_SRC = \
$(DG_BASE)/plugingui/listbox.cc \
$(DG_BASE)/plugingui/knob.cc \
$(DG_BASE)/plugingui/filebrowser.cc \
- $(DG_BASE)/plugingui/combobox.cc
+ $(DG_BASE)/plugingui/combobox.cc \
+ $(DG_BASE)/plugingui/image.cc
GUI_CFLAGS=-I../plugingui -DUSE_THREAD
GUI_LIBS=-lgdi32 -lsetupapi -lws2_32
@@ -78,6 +79,10 @@ SNDFILE_BASE=${MSYS}
SNDFILE_CFLAGS=-I${SNDFILE_BASE}/include
SNDFILE_LIBS=-L${SNDFILE_BASE}/lib -lsndfile
+PNG_BASE=${MSYS}
+PNG_CFLAGS=-I${SNDFILE_BASE}/include
+PNG_LIBS=-L${SNDFILE_BASE}/lib -lpng -lz
+
SRC = \
drumgizmo_vst.cc \
input_vst.cc \
@@ -117,7 +122,7 @@ SRC = \
all:
gcc $(DBG_CFLAGS) $(top_srcdir)/hugin/hugin.c -c
gcc $(DBG_CFLAGS) $(top_srcdir)/hugin/hugin_syslog.c -c
- g++ -static -static-libgcc -O2 -g -Wall -DWIN32 $(DBG_CFLAGS) $(DG_CFLAGS) $(DG_LIBS) $(VST_CFLAGS) hugin.o hugin_syslog.o $(DG_SRC) $(VST_SRC) ${SRC} ${GUI_SRC} ${GUI_CFLAGS} $(GUI_LIBS) $(EXPAT_CFLAGS) $(EXPAT_LIBS) $(SNDFILE_CFLAGS) $(SNDFILE_LIBS) -shared -o drumgizmo_vst.dll -Wl,--out-implib,libdrumgizmo_vst.a
+ g++ -static -static-libgcc -O2 -g -Wall -DWIN32 $(DBG_CFLAGS) $(PNG_CFLAGS) $(DG_CFLAGS) $(DG_LIBS) $(VST_CFLAGS) hugin.o hugin_syslog.o $(DG_SRC) $(VST_SRC) ${SRC} ${GUI_SRC} ${GUI_CFLAGS} $(GUI_LIBS) $(EXPAT_CFLAGS) $(EXPAT_LIBS) $(SNDFILE_CFLAGS) $(SNDFILE_LIBS) $(PNG_LIBS) -shared -o drumgizmo_vst.dll -Wl,--out-implib,libdrumgizmo_vst.a
clean:
del -f drumgizmo_vst.dll libdrumgizmo_vst.a