summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErkin Bahceci <erkinbah@gmail.com>2009-07-23 19:32:34 -0500
committerErkin Bahceci <erkinbah@gmail.com>2009-07-23 19:32:34 -0500
commit5e69064329054569cf7d56f82d783ad0b565c826 (patch)
treebc53b323e4e6aa726e49d376efbee84262be711c
parent97c86a485365a7f7a318b5d189e1d510922c494b (diff)
downloadjpeg-5e69064329054569cf7d56f82d783ad0b565c826.tar.gz
jpeg-5e69064329054569cf7d56f82d783ad0b565c826.tar.bz2
Initial C++ port.
-rw-r--r--CMakeLists.txt7
-rw-r--r--Makefile533
-rw-r--r--imgjpeg.c463
-rw-r--r--imgjpeg.xml.in32
-rw-r--r--plugin.info2
-rw-r--r--src/imgjpeg.cpp310
-rw-r--r--src/imgjpeg.h75
7 files changed, 405 insertions, 1017 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0f9bcc0..3b6c0c8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,7 @@
+find_package (Compiz REQUIRED)
+include (CompizPlugin)
include (FindJPEG)
-include (CompizFusion)
if (JPEG_FOUND)
- compiz_fusion_plugin (imgjpeg LIBRARIES ${JPEG_LIBRARIES} INCDIRS ${JPEG_INCLUDE_DIR})
-endif (JPEG_FOUND) \ No newline at end of file
+ compiz_plugin (imgjpeg LIBRARIES ${JPEG_LIBRARIES} INCDIRS ${JPEG_INCLUDE_DIR})
+endif (JPEG_FOUND)
diff --git a/Makefile b/Makefile
deleted file mode 100644
index d9a07cf..0000000
--- a/Makefile
+++ /dev/null
@@ -1,533 +0,0 @@
-##
-#
-# Compiz plugin Makefile
-#
-# Copyright : (C) 2007 by Dennis Kasprzyk
-# E-mail : onestone@deltatauchi.de
-#
-#
-# 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
-# of the License, 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.
-#
-##
-
-# plugin.info file contents
-#
-# PLUGIN = foo
-# PKG_DEP = pango
-# LDFLAGS_ADD = -lGLU
-# CFLAGS_ADD = -I/usr/include/foo
-# CHK_HEADERS = compiz-cube.h
-#
-
-#load config file
-
-ECHO = `which echo`
-
-# default color settings
-color := $(shell if [ $$TERM = "dumb" ]; then $(ECHO) "no"; else $(ECHO) "yes"; fi)
-
-ifeq ($(shell if [ -f plugin.info ]; then $(ECHO) -n "found"; fi ),found)
-include plugin.info
-else
-$(error $(shell if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\033[1;31m[ERROR]\033[0m \"plugin.info\" file not found"; \
- else \
- $(ECHO) "[ERROR] \"plugin.info\" file not found"; \
- fi;))
-endif
-
-ifneq ($(shell if pkg-config --exists compiz; then $(ECHO) -n "found"; fi ),found)
-$(error $(shell if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e -n "\033[1;31m[ERROR]\033[0m Compiz not installed"; \
- else \
- $(ECHO) -n "[ERROR] Compiz not installed"; \
- fi))
-endif
-
-
-ifneq ($(shell if [ -n "$(PKG_DEP)" ]; then if pkg-config --exists $(PKG_DEP); then $(ECHO) -n "found"; fi; \
- else $(ECHO) -n "found"; fi ),found)
-$(error $(shell if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e -n "\033[1;31m[ERROR]\033[0m "; \
- else \
- $(ECHO) -n "[ERROR] "; \
- fi; \
- pkg-config --print-errors --short-errors --errors-to-stdout $(PKG_DEP); ))
-endif
-
-
-ifeq ($(BUILD_GLOBAL),true)
- PREFIX = $(shell pkg-config --variable=prefix compiz)
- CLIBDIR = $(shell pkg-config --variable=libdir compiz)
- CINCDIR = $(shell pkg-config --variable=includedir compiz)
- PKGDIR = $(CLIBDIR)/pkgconfig
- DESTDIR = $(shell pkg-config --variable=libdir compiz)/compiz
- XMLDIR = $(shell pkg-config --variable=prefix compiz)/share/compiz
- IMAGEDIR = $(shell pkg-config --variable=prefix compiz)/share/compiz
- DATADIR = $(shell pkg-config --variable=prefix compiz)/share/compiz
-else
- DESTDIR = $(HOME)/.compiz/plugins
- XMLDIR = $(HOME)/.compiz/metadata
- IMAGEDIR = $(HOME)/.compiz/images
- DATADIR = $(HOME)/.compiz/data
-endif
-
-BUILDDIR = build
-
-CC = gcc
-CPP = g++
-LIBTOOL = libtool
-INSTALL = install
-
-BCOP = `pkg-config --variable=bin bcop`
-
-CFLAGS = -g -Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -fno-strict-aliasing `pkg-config --cflags $(PKG_DEP) compiz ` $(CFLAGS_ADD)
-LDFLAGS = `pkg-config --libs $(PKG_DEP) compiz ` $(LDFLAGS_ADD)
-
-DEFINES = -DIMAGEDIR=\"$(IMAGEDIR)\" -DDATADIR=\"$(DATADIR)\"
-
-POFILEDIR = $(shell if [ -n "$(PODIR)" ]; then $(ECHO) $(PODIR); else $(ECHO) ./po;fi )
-
-COMPIZ_HEADERS = compiz.h compiz-core.h
-COMPIZ_INC = $(shell pkg-config --variable=includedir compiz)/compiz/
-
-is-bcop-target := $(shell if [ -e $(PLUGIN).xml.in ]; then cat $(PLUGIN).xml.in | grep "useBcop=\"true\""; \
- else if [ -e $(PLUGIN).xml ]; then cat $(PLUGIN).xml | grep "useBcop=\"true\""; fi; fi)
-
-trans-target := $(shell if [ -e $(PLUGIN).xml.in -o -e $(PLUGIN).xml ]; then $(ECHO) $(BUILDDIR)/$(PLUGIN).xml;fi )
-
-bcop-target := $(shell if [ -n "$(is-bcop-target)" ]; then $(ECHO) $(BUILDDIR)/$(PLUGIN).xml; fi )
-bcop-target-src := $(shell if [ -n "$(is-bcop-target)" ]; then $(ECHO) $(BUILDDIR)/$(PLUGIN)_options.c; fi )
-bcop-target-hdr := $(shell if [ -n "$(is-bcop-target)" ]; then $(ECHO) $(BUILDDIR)/$(PLUGIN)_options.h; fi )
-
-gen-schemas := $(shell if [ \( -e $(PLUGIN).xml.in -o -e $(PLUGIN).xml \) -a -n "`pkg-config --variable=xsltdir compiz-gconf`" ]; then $(ECHO) true; fi )
-schema-target := $(shell if [ -n "$(gen-schemas)" ]; then $(ECHO) $(BUILDDIR)/$(PLUGIN).xml; fi )
-schema-output := $(shell if [ -n "$(gen-schemas)" ]; then $(ECHO) $(BUILDDIR)/compiz-$(PLUGIN).schema; fi )
-
-ifeq ($(BUILD_GLOBAL),true)
- pkg-target := $(shell if [ -e compiz-$(PLUGIN).pc.in -a -n "$(PREFIX)" -a -d "$(PREFIX)" ]; then $(ECHO) "$(BUILDDIR)/compiz-$(PLUGIN).pc"; fi )
- hdr-install-target := $(shell if [ -e compiz-$(PLUGIN).pc.in -a -n "$(PREFIX)" -a -d "$(PREFIX)" -a -e compiz-$(PLUGIN).h ]; then $(ECHO) "compiz-$(PLUGIN).h"; fi )
-endif
-
-# find all the object files
-
-c-objs := $(patsubst %.c,%.lo,$(shell find -name '*.c' 2> /dev/null | grep -v "$(BUILDDIR)/" | sed -e 's/^.\///'))
-c-objs += $(patsubst %.cpp,%.lo,$(shell find -name '*.cpp' 2> /dev/null | grep -v "$(BUILDDIR)/" | sed -e 's/^.\///'))
-c-objs += $(patsubst %.cxx,%.lo,$(shell find -name '*.cxx' 2> /dev/null | grep -v "$(BUILDDIR)/" | sed -e 's/^.\///'))
-c-objs := $(filter-out $(bcop-target-src:.c=.lo),$(c-objs))
-
-h-files := $(shell find -name '*.h' 2> /dev/null | grep -v "$(BUILDDIR)/" | sed -e 's/^.\///')
-h-files += $(bcop-target-hdr)
-h-files += $(foreach file,$(COMPIZ_HEADERS) $(CHK_HEADERS),$(shell $(ECHO) -n "$(COMPIZ_INC)$(file)"))
-
-all-c-objs := $(addprefix $(BUILDDIR)/,$(c-objs))
-all-c-objs += $(bcop-target-src:.c=.lo)
-
-# additional files
-
-data-files := $(shell find data/ -name '*' -type f 2> /dev/null | sed -e 's/data\///')
-image-files := $(shell find images/ -name '*' -type f 2> /dev/null | sed -e 's/images\///')
-
-# system include path parameter, -isystem doesn't work on old gcc's
-inc-path-param = $(shell if [ -z "`gcc --version | head -n 1 | grep ' 3'`" ]; then $(ECHO) "-isystem"; else $(ECHO) "-I"; fi)
-
-# Tests
-ifeq ($(shell if [ -n "$(is-bcop-target)" -a -z "$(BCOP)" ]; then $(ECHO) -n "error"; fi ),error)
-$(error $(shell if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e -n "\033[1;31m[ERROR]\033[0m BCOP not installed but is needed to build plugin"; \
- else \
- $(ECHO) -n "[ERROR] BCOP not installed but is needed to build plugin"; \
- fi))
-endif
-
-ifeq ($(shell if [ "x$(BUILD_GLOBAL)" != "xtrue" -a -e compiz-$(PLUGIN).pc.in ]; then $(ECHO) -n "warn"; fi ),warn)
-$(warning $(shell if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e -n "\033[1;31m[WARNING]\033[0m This plugin might be needed by other plugins. Install it with \"BUILD_GLOBAL=true sudo make install\" "; \
- else \
- $(ECHO) -n "[WARNING] This plugin might be needed by other plugins. Install it with \"BUILD_GLOBAL=true sudo make install\""; \
- fi))
-endif
-
-#
-# Do it.
-#
-
-.PHONY: $(BUILDDIR) build-dir trans-target bcop-build pkg-creation schema-creation c-build-objs c-link-plugin
-
-all: $(BUILDDIR) build-dir trans-target bcop-build pkg-creation schema-creation c-build-objs c-link-plugin
-
-trans-build: $(trans-target)
-
-bcop-build: $(bcop-target-hdr) $(bcop-target-src)
-
-schema-creation: $(schema-output)
-
-c-build-objs: $(all-c-objs)
-
-c-link-plugin: $(BUILDDIR)/lib$(PLUGIN).la
-
-pkg-creation: $(pkg-target)
-
-#
-# Create build directory
-#
-
-$(BUILDDIR) :
- @mkdir -p $(BUILDDIR)
-
-$(DESTDIR) :
- @mkdir -p $(DESTDIR)
-
-#
-# fallback if xml.in doesn't exists
-#
-$(BUILDDIR)/%.xml: %.xml
- @cp $< $@
-
-#
-# Translating
-#
-$(BUILDDIR)/%.xml: %.xml.in
- @if [ -d $(POFILEDIR) ]; then \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e -n "\033[0;1;5mtranslate \033[0m: \033[0;32m$< \033[0m-> \033[0;31m$@\033[0m"; \
- else \
- $(ECHO) "translate $< -> $@"; \
- fi; \
- intltool-merge -x -u $(POFILEDIR) $< $@ > /dev/null; \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0mtranslate : \033[34m$< -> $@\033[0m"; \
- fi; \
- else \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e -n "\033[0;1;5mconvert \033[0m: \033[0;32m$< \033[0m-> \033[0;31m$@\033[0m"; \
- else \
- $(ECHO) "convert $< -> $@"; \
- fi; \
- cat $< | sed -e 's;<_;<;g' -e 's;</_;</;g' > $@; \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0mconvert : \033[34m$< -> $@\033[0m"; \
- fi; \
- fi
-
-#
-# BCOP'ing
-
-$(BUILDDIR)/%_options.h: $(BUILDDIR)/%.xml
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e -n "\033[0;1;5mbcop'ing \033[0m: \033[0;32m$< \033[0m-> \033[0;31m$@\033[0m"; \
- else \
- $(ECHO) "bcop'ing $< -> $@"; \
- fi
- @$(BCOP) --header=$@ $<
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0mbcop'ing : \033[34m$< -> $@\033[0m"; \
- fi
-
-$(BUILDDIR)/%_options.c: $(BUILDDIR)/%.xml
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e -n "\033[0;1;5mbcop'ing \033[0m: \033[0;32m$< \033[0m-> \033[0;31m$@\033[0m"; \
- else \
- $(ECHO) "bcop'ing $< -> $@"; \
- fi
- @$(BCOP) --source=$@ $<
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0mbcop'ing : \033[34m$< -> $@\033[0m"; \
- fi
-
-#
-# Schema generation
-
-$(BUILDDIR)/compiz-%.schema: $(BUILDDIR)/%.xml
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e -n "\033[0;1;5mschema'ing\033[0m: \033[0;32m$< \033[0m-> \033[0;31m$@\033[0m"; \
- else \
- $(ECHO) "schema'ing $< -> $@"; \
- fi
- @xsltproc `pkg-config --variable=xsltdir compiz-gconf`/schemas.xslt $< > $@
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0mschema : \033[34m$< -> $@\033[0m"; \
- fi
-
-#
-# pkg config file generation
-
-$(BUILDDIR)/compiz-%.pc: compiz-%.pc.in
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e -n "\033[0;1;5mpkgconfig \033[0m: \033[0;32m$< \033[0m-> \033[0;31m$@\033[0m"; \
- else \
- $(ECHO) "pkgconfig $< -> $@"; \
- fi
- @COMPIZREQUIRES=`cat $(PKGDIR)/compiz.pc | grep Requires | sed -e 's;Requires: ;;g'`; \
- COMPIZCFLAGS=`cat $(PKGDIR)/compiz.pc | grep Cflags | sed -e 's;Cflags: ;;g'`; \
- sed -e 's;@prefix@;$(PREFIX);g' -e 's;\@libdir@;$(CLIBDIR);g' \
- -e 's;@includedir@;$(CINCDIR);g' -e 's;\@VERSION@;0.0.1;g' \
- -e "s;@COMPIZ_REQUIRES@;$$COMPIZREQUIRES;g" \
- -e "s;@COMPIZ_CFLAGS@;$$COMPIZCFLAGS;g" $< > $@;
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0mpkgconfig : \033[34m$< -> $@\033[0m"; \
- fi
-
-#
-# Compiling
-#
-
-$(BUILDDIR)/%.lo: %.c $(h-files)
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5mcompiling \033[0m: \033[0;32m$< \033[0m-> \033[0;31m$@\033[0m"; \
- else \
- $(ECHO) "compiling $< -> $@"; \
- fi
- @$(LIBTOOL) --quiet --mode=compile $(CC) $(CFLAGS) $(DEFINES) -I$(BUILDDIR) -c -o $@ $<
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0mcompiling : \033[34m$< -> $@\033[0m"; \
- fi
-
-$(BUILDDIR)/%.lo: $(BUILDDIR)/%.c $(h-files)
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5mcompiling \033[0m: \033[0;32m$< \033[0m-> \033[0;31m$@\033[0m"; \
- else \
- $(ECHO) "compiling $< -> $@"; \
- fi
- @$(LIBTOOL) --quiet --mode=compile $(CC) $(CFLAGS) $(DEFINES) -I$(BUILDDIR) -c -o $@ $<
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0mcompiling : \033[34m$< -> $@\033[0m"; \
- fi
-
-$(BUILDDIR)/%.lo: %.cpp $(h-files)
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5mcompiling \033[0m: \033[0;32m$< \033[0m-> \033[0;31m$@\033[0m"; \
- else \
- $(ECHO) "compiling $< -> $@"; \
- fi
- @$(LIBTOOL) --quiet --mode=compile $(CPP) $(CFLAGS) $(DEFINES) -I$(BUILDDIR) -c -o $@ $<
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0mcompiling : \033[34m$< -> $@\033[0m"; \
- fi
-
-$(BUILDDIR)/%.lo: %.cxx $(h-files)
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5mcompiling \033[0m: \033[0;32m$< \033[0m-> \033[0;31m$@\033[0m"; \
- else \
- $(ECHO) "compiling $< -> $@"; \
- fi
- @$(LIBTOOL) --quiet --mode=compile $(CPP) $(CFLAGS) $(DEFINES) -I$(BUILDDIR) -c -o $@ $<
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0mcompiling : \033[34m$< -> $@\033[0m"; \
- fi
-
-#
-# Linking
-#
-
-cxx-rpath-prefix := -Wl,-rpath,
-
-$(BUILDDIR)/lib$(PLUGIN).la: $(all-c-objs)
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e -n "\033[0;1;5mlinking \033[0m: \033[0;31m$@\033[0m"; \
- else \
- $(ECHO) "linking : $@"; \
- fi
- @$(LIBTOOL) --quiet --mode=link $(CC) $(LDFLAGS) -rpath $(DESTDIR) -o $@ $(all-c-objs)
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0mlinking : \033[34m$@\033[0m"; \
- fi
-
-
-clean:
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e -n "\033[0;1;5mremoving \033[0m: \033[0;31m./$(BUILDDIR)\033[0m"; \
- else \
- $(ECHO) "removing : ./$(BUILDDIR)"; \
- fi
- @rm -rf $(BUILDDIR)
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0mremoving : \033[34m./$(BUILDDIR)\033[0m"; \
- fi
-
-
-install: $(DESTDIR) all
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5minstall \033[0m: \033[0;31m$(DESTDIR)/lib$(PLUGIN).so\033[0m"; \
- else \
- $(ECHO) "install : $(DESTDIR)/lib$(PLUGIN).so"; \
- fi
- @mkdir -p $(DESTDIR)
- @$(INSTALL) $(BUILDDIR)/.libs/lib$(PLUGIN).so $(DESTDIR)/lib$(PLUGIN).so
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0minstall : \033[34m$(DESTDIR)/lib$(PLUGIN).so\033[0m"; \
- fi
- @if [ -e $(BUILDDIR)/$(PLUGIN).xml ]; then \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5minstall \033[0m: \033[0;31m$(XMLDIR)/$(PLUGIN).xml\033[0m"; \
- else \
- $(ECHO) "install : $(XMLDIR)/$(PLUGIN).xml"; \
- fi; \
- mkdir -p $(XMLDIR); \
- $(INSTALL) $(BUILDDIR)/$(PLUGIN).xml $(XMLDIR)/$(PLUGIN).xml; \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0minstall : \033[34m$(XMLDIR)/$(PLUGIN).xml\033[0m"; \
- fi; \
- fi
- @if [ -n "$(hdr-install-target)" ]; then \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5minstall \033[0m: \033[0;31m$(CINCDIR)/compiz/$(hdr-install-target)\033[0m"; \
- else \
- $(ECHO) "install : $(CINCDIR)/compiz/$(hdr-install-target)"; \
- fi; \
- $(INSTALL) --mode=u=rw,go=r,a-s $(hdr-install-target) $(CINCDIR)/compiz/$(hdr-install-target); \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0minstall : \033[34m$(CINCDIR)/compiz/$(hdr-install-target)\033[0m"; \
- fi; \
- fi
- @if [ -n "$(pkg-target)" ]; then \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5minstall \033[0m: \033[0;31m$(PKGDIR)/compiz-$(PLUGIN).pc\033[0m"; \
- else \
- $(ECHO) "install : $(PKGDIR)/compiz-$(PLUGIN).pc"; \
- fi; \
- $(INSTALL) --mode=u=rw,go=r,a-s $(pkg-target) $(PKGDIR)/compiz-$(PLUGIN).pc; \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0minstall : \033[34m$(PKGDIR)/compiz-$(PLUGIN).pc\033[0m"; \
- fi; \
- fi
- @if [ -n "$(schema-output)" -a -e "$(schema-output)" ]; then \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5minstall \033[0m: \033[0;31m$(schema-output)\033[0m"; \
- else \
- $(ECHO) "install : $(schema-output)"; \
- fi; \
- if [ "x$(USER)" = "xroot" ]; then \
- GCONF_CONFIG_SOURCE=`gconftool-2 --get-default-source` \
- gconftool-2 --makefile-install-rule $(schema-output) > /dev/null; \
- else \
- gconftool-2 --install-schema-file=$(schema-output) > /dev/null; \
- fi; \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0minstall : \033[34m$(schema-output)\033[0m"; \
- fi; \
- fi
- @if [ -n "$(data-files)" ]; then \
- mkdir -p $(DATADIR); \
- for FILE in $(data-files); do \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5minstall \033[0m: \033[0;31m$(DATADIR)/$$FILE\033[0m"; \
- else \
- $(ECHO) "install : $(DATADIR)/$$FILE"; \
- fi; \
- FILEDIR="$(DATADIR)/`dirname "$$FILE"`"; \
- mkdir -p "$$FILEDIR"; \
- $(INSTALL) --mode=u=rw,go=r,a-s data/$$FILE $(DATADIR)/$$FILE; \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0minstall : \033[34m$(DATADIR)/$$FILE\033[0m"; \
- fi; \
- done \
- fi
- @if [ -n "$(image-files)" ]; then \
- mkdir -p $(IMAGEDIR); \
- for FILE in $(image-files); do \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5minstall \033[0m: \033[0;31m$(IMAGEDIR)/$$FILE\033[0m"; \
- else \
- $(ECHO) "install : $(IMAGEDIR)/$$FILE"; \
- fi; \
- FILEDIR="$(IMAGEDIR)/`dirname "$$FILE"`"; \
- mkdir -p "$$FILEDIR"; \
- $(INSTALL) --mode=u=rw,go=r,a-s images/$$FILE $(IMAGEDIR)/$$FILE; \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0minstall : \033[34m$(IMAGEDIR)/$$FILE\033[0m"; \
- fi; \
- done \
- fi
-
-uninstall:
- @if [ -e $(DESTDIR)/lib$(PLUGIN).so ]; then \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5muninstall \033[0m: \033[0;31m$(DESTDIR)/lib$(PLUGIN).so\033[0m"; \
- else \
- $(ECHO) "uninstall : $(DESTDIR)/lib$(PLUGIN).so"; \
- fi; \
- rm -f $(DESTDIR)/lib$(PLUGIN).so; \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0muninstall : \033[34m$(DESTDIR)/lib$(PLUGIN).so\033[0m"; \
- fi; \
- fi
- @if [ -e $(XMLDIR)/$(PLUGIN).xml ]; then \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5muninstall \033[0m: \033[0;31m$(XMLDIR)/$(PLUGIN).xml\033[0m"; \
- else \
- $(ECHO) "uninstall : $(XMLDIR)/$(PLUGIN).xml"; \
- fi; \
- rm -f $(XMLDIR)/$(PLUGIN).xml; \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0muninstall : \033[34m$(XMLDIR)/$(PLUGIN).xml\033[0m"; \
- fi; \
- fi
- @if [ -n "$(hdr-install-target)" -a -e $(CINCDIR)/compiz/$(hdr-install-target) ]; then \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5muninstall \033[0m: \033[0;31m$(CINCDIR)/compiz/$(hdr-install-target)\033[0m"; \
- else \
- $(ECHO) "uninstall : $(CINCDIR)/compiz/$(hdr-install-target)"; \
- fi; \
- rm -f $(CINCDIR)/compiz/$(hdr-install-target); \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0muninstall : \033[34m$(CINCDIR)/compiz/$(hdr-install-target)\033[0m"; \
- fi; \
- fi
- @if [ -n "$(pkg-target)" -a -e $(PKGDIR)/compiz-$(PLUGIN).pc ]; then \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5muninstall \033[0m: \033[0;31m$(PKGDIR)/compiz-$(PLUGIN).pc\033[0m"; \
- else \
- $(ECHO) "uninstall : $(PKGDIR)/compiz-$(PLUGIN).pc"; \
- fi; \
- rm -f $(PKGDIR)/compiz-$(PLUGIN).pc; \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0muninstall : \033[34m$(PKGDIR)/compiz-$(PLUGIN).pc\033[0m"; \
- fi; \
- fi
- @if [ -n "$(schema-output)" -a -e "$(schema-output)" -a 'x$(USER)' = 'xroot' ]; then \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5muninstall \033[0m: \033[0;31m$(schema-output)\033[0m"; \
- else \
- $(ECHO) "uninstall : $(schema-output)"; \
- fi; \
- GCONF_CONFIG_SOURCE=`gconftool-2 --get-default-source` \
- gconftool-2 --makefile-uninstall-rule $(schema-output) > /dev/null; \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0muninstall : \033[34m$(schema-output)\033[0m"; \
- fi; \
- fi
- @if [ -n "$(data-files)" ]; then \
- for FILE in $(data-files); do \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5muninstall \033[0m: \033[0;31m$(DATADIR)/$$FILE\033[0m"; \
- else \
- $(ECHO) "uninstall : $(DATADIR)/$$FILE"; \
- fi; \
- rm -f $(DATADIR)/$$FILE; \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0muninstall : \033[34m$(DATADIR)/$$FILE\033[0m"; \
- fi; \
- done \
- fi
- @if [ -n "$(image-files)" ]; then \
- for FILE in $(image-files); do \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5muninstall \033[0m: \033[0;31m$(IMAGEDIR)/$$FILE\033[0m"; \
- else \
- $(ECHO) "uninstall : $(IMAGEDIR)/$$FILE"; \
- fi; \
- rm -f $(IMAGEDIR)/$$FILE; \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0muninstall : \033[34m$(IMAGEDIR)/$$FILE\033[0m"; \
- fi; \
- done \
- fi
diff --git a/imgjpeg.c b/imgjpeg.c
deleted file mode 100644
index 69d590e..0000000
--- a/imgjpeg.c
+++ /dev/null
@@ -1,463 +0,0 @@
-/*
- * beryl-plugins::jpeg.c - adds JPEG image support to beryl.
- * Copyright: (C) 2006 Nicholas Thomas
- * Danny Baumann (JPEG writing, option stuff)
- *
- * 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
- * of the License, 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 program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#define _GNU_SOURCE
-#include <string.h>
-#include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <setjmp.h>
-
-#include <compiz-core.h>
-
-#include <X11/Xarch.h>
-#include <jpeglib.h>
-#include "imgjpeg_options.h"
-
-static int displayPrivateIndex;
-
-struct jpegErrorMgr
-{
- struct jpeg_error_mgr pub; /* "public" fields */
- jmp_buf setjmp_buffer; /* for return to caller */
-};
-
-typedef struct _JPEGDisplay
-{
- FileToImageProc fileToImage;
- ImageToFileProc imageToFile;
-} JPEGDisplay;
-
-#define GET_JPEG_DISPLAY(d) \
- ((JPEGDisplay *) (d)->base.privates[displayPrivateIndex].ptr)
-
-#define JPEG_DISPLAY(d) \
- JPEGDisplay *jd = GET_JPEG_DISPLAY (d)
-
-static Bool
-rgbToBGRA (const JSAMPLE *source,
- void **data,
- int height,
- int width,
- int alpha)
-{
- int h, w;
- char *dest;
-
- dest = malloc (height * width * 4);
- if (!dest)
- return FALSE;
-
- *data = dest;
-
- for (h = 0; h < height; h++)
- for (w = 0; w < width; w++)
- {
- int pos = h * width + w;
-#if __BYTE_ORDER == __BIG_ENDIAN
- dest[(pos * 4) + 3] = source[(pos * 3) + 2]; /* blue */
- dest[(pos * 4) + 2] = source[(pos * 3) + 1]; /* green */
- dest[(pos * 4) + 1] = source[(pos * 3) + 0]; /* red */
- dest[(pos * 4) + 0] = alpha;
-#else
- dest[(pos * 4) + 0] = source[(pos * 3) + 2]; /* blue */
- dest[(pos * 4) + 1] = source[(pos * 3) + 1]; /* green */
- dest[(pos * 4) + 2] = source[(pos * 3) + 0]; /* red */
- dest[(pos * 4) + 3] = alpha;
-#endif
- }
-
- return TRUE;
-}
-
-static Bool
-rgbaToRGB (char *source,
- JSAMPLE **dest,
- int height,
- int width,
- int stride)
-{
- int h, w;
- int ps = stride / width; /* pixel size */
- JSAMPLE *d;
-
- d = malloc (height * width * 3 * sizeof (JSAMPLE));
- if (!d)
- return FALSE;
-
- *dest = d;
-
- for (h = 0; h < height; h++)
- for (w = 0; w < width; w++)
- {
- int pos = h * width + w;
-#if __BYTE_ORDER == __BIG_ENDIAN
- d[(pos * 3) + 0] = source[(pos * ps) + 3]; /* red */
- d[(pos * 3) + 1] = source[(pos * ps) + 2]; /* green */
- d[(pos * 3) + 2] = source[(pos * ps) + 1]; /* blue */
-#else
- d[(pos * 3) + 0] = source[(pos * ps) + 0]; /* red */
- d[(pos * 3) + 1] = source[(pos * ps) + 1]; /* green */
- d[(pos * 3) + 2] = source[(pos * ps) + 2]; /* blue */
-#endif
- }
-
- return TRUE;
-}
-
-static void
-jpegErrorExit (j_common_ptr cinfo)
-{
- char buffer[JMSG_LENGTH_MAX];
- struct jpegErrorMgr *err = (struct jpegErrorMgr *) cinfo->err;
-
- /* Format the message */
- (*cinfo->err->format_message) (cinfo, buffer);
-
- printf("%s\n", buffer);
-
- /* Return control to the setjmp point */
- longjmp (err->setjmp_buffer, 1);
-}
-
-static Bool
-readJPEGFileToImage (FILE *file,
- int *width,
- int *height,
- void **data)
-{
- struct jpeg_decompress_struct cinfo;
- struct jpegErrorMgr jerr;
- JSAMPLE *buf;
- JSAMPROW *rows;
- int i;
- Bool result;
-
- if (!file)
- return FALSE;
-
- cinfo.err = jpeg_std_error (&jerr.pub);
- jerr.pub.error_exit = jpegErrorExit;
-
- if (setjmp (jerr.setjmp_buffer))
- {
- /* this is called on decompression errors */
- jpeg_destroy_decompress (&cinfo);
- return FALSE;
- }
-
- jpeg_create_decompress (&cinfo);
-
- jpeg_stdio_src (&cinfo, file);
-
- jpeg_read_header (&cinfo, TRUE);
-
- cinfo.out_color_space = JCS_RGB;
-
- jpeg_start_decompress (&cinfo);
-
- *height = cinfo.output_height;
- *width = cinfo.output_width;
-
- buf = calloc (cinfo.output_height * cinfo.output_width *
- cinfo.output_components, sizeof (JSAMPLE));
- if (!buf)
- {
- jpeg_finish_decompress (&cinfo);
- jpeg_destroy_decompress (&cinfo);
- return FALSE;
- }
-
- rows = malloc (cinfo.output_height * sizeof (JSAMPROW));
- if (!rows)
- {
- free (buf);
- jpeg_finish_decompress (&cinfo);
- jpeg_destroy_decompress (&cinfo);
- return FALSE;
- }
-
- for (i = 0; i < cinfo.output_height; i++)
- rows[i] = &buf[i * cinfo.output_width * cinfo.output_components];
-
- while (cinfo.output_scanline < cinfo.output_height)
- jpeg_read_scanlines (&cinfo, &rows[cinfo.output_scanline],
- cinfo.output_height - cinfo.output_scanline);
-
- jpeg_finish_decompress (&cinfo);
- jpeg_destroy_decompress (&cinfo);
-
- /* convert the rgb data into BGRA format */
- result = rgbToBGRA (buf, data, *height, *width, 255);
-
- free (rows);
- free(buf);
- return result;
-}
-
-static Bool
-writeJPEG (CompDisplay *d,
- void *buffer,
- FILE *file,
- int width,
- int height,
- int stride)
-{
- struct jpeg_compress_struct cinfo;
- struct jpeg_error_mgr jerr;
- JSAMPROW row_pointer[1];
- JSAMPLE *data;
-
- /* convert the rgb data into BGRA format */
- if (!rgbaToRGB (buffer, &data, height, width, stride))
- return FALSE;
-
- cinfo.err = jpeg_std_error (&jerr);
- jpeg_create_compress (&cinfo);
-
- jpeg_stdio_dest (&cinfo, file);
-
- cinfo.image_width = width;
- cinfo.image_height = height;
- cinfo.input_components = 3;
- cinfo.in_color_space = JCS_RGB;
-
- jpeg_set_defaults (&cinfo);
- jpeg_set_quality (&cinfo, imgjpegGetQuality (d), TRUE);
- jpeg_start_compress (&cinfo, TRUE);
-
- while (cinfo.next_scanline < cinfo.image_height)
- {
- row_pointer[0] =
- &data[(cinfo.image_height - cinfo.next_scanline - 1) * width * 3];
- jpeg_write_scanlines (&cinfo, row_pointer, 1);
- }
-
- jpeg_finish_compress (&cinfo);
- jpeg_destroy_compress (&cinfo);
-
- free (data);
-
- return TRUE;
-}
-
-/* Turns the path & name into a real, absolute path
- No extensions jiggery-pokery here, as JPEGs can be
- .jpg or .jpeg - or, indeed, whatever.
- Deals with the path, regardless of what it's passed. */
-static char*
-createFilename (const char *path,
- const char *name)
-{
- char *filename = NULL;
-
- if (path && !name)
- asprintf (&filename, "%s", path);
- else if (!path && name)
- asprintf (&filename, "%s", name);
- else
- asprintf (&filename, "%s/%s", path, name);
-
- return filename;
-}
-
-static Bool
-JPEGImageToFile (CompDisplay *d,
- const char *path,
- const char *name,
- const char *format,
- int width,
- int height,
- int stride,
- void *data)
-{
- Bool status = FALSE;
- char *fileName;
- FILE *file;
-
- /* Not a JPEG */
- if (strcasecmp (format, "jpeg") != 0 && strcasecmp (format, "jpg") != 0)
- {
- JPEG_DISPLAY (d);
- UNWRAP (jd, d, imageToFile);
- status = (*d->imageToFile) (d, path, name, format,
- width, height, stride, data);
- WRAP (jd, d, imageToFile, JPEGImageToFile);
- return status;
- }
-
- /* Is a JPEG */
- fileName = createFilename (path, name);
- if (!fileName)
- return FALSE;
-
- file = fopen (fileName, "wb");
- if (file)
- {
- status = writeJPEG (d, data, file, width, height, stride);
- fclose (file);
- }
-
- free (fileName);
- return status;
-}
-
-static Bool
-JPEGFileToImage (CompDisplay *d,
- const char *path,
- const char *name,
- int *width,
- int *height,
- int *stride,
- void **data)
-{
- Bool status = FALSE;
- char *fileName, *extension;
-
- JPEG_DISPLAY (d);
-
- fileName = createFilename (path, name);
- if (!fileName)
- return FALSE;
-
- /* Do some testing here to see if it's got a .jpg or .jpeg extension */
- extension = strrchr (fileName, '.');
- if (extension)
- {
- if (strcasecmp (extension, ".jpeg") == 0 ||
- strcasecmp (extension, ".jpg") == 0)
- {
- FILE *file;
-
- file = fopen (fileName, "rb");
- if (file)
- {
- status = readJPEGFileToImage (file, width, height, data);
- fclose (file);
-
- if (status) /* Success! */
- {
- free (fileName);
- *stride = *width * 4;
- return TRUE;
- }
- }
- }
- }
- free (fileName);
-
- /* Isn't a JPEG - pass to the next in the chain. */
- UNWRAP (jd, d, fileToImage);
- status = (*d->fileToImage) (d, path, name, width, height, stride, data);
- WRAP (jd, d, fileToImage, JPEGFileToImage);
-
- return status;
-}
-
-static Bool
-JPEGInitDisplay (CompPlugin *p,
- CompDisplay *d)
-{
- JPEGDisplay *jd;
-
- if (!checkPluginABI ("core", CORE_ABIVERSION))
- return FALSE;
-
- jd = malloc (sizeof (JPEGDisplay));
- if (!jd)
- return FALSE;
-
- WRAP (jd, d, fileToImage, JPEGFileToImage);
- WRAP (jd, d, imageToFile, JPEGImageToFile);
-
- d->base.privates[displayPrivateIndex].ptr = jd;
-
- return TRUE;
-}
-
-static void
-JPEGFiniDisplay (CompPlugin *p,
- CompDisplay *d)
-{
- JPEG_DISPLAY (d);
-
- UNWRAP (jd, d, fileToImage);
- UNWRAP (jd, d, imageToFile);
-
- free (jd);
-}
-
-static CompBool
-JPEGInitObject (CompPlugin *p,
- CompObject *o)
-{
- static InitPluginObjectProc dispTab[] = {
- (InitPluginObjectProc) 0, /* InitCore */
- (InitPluginObjectProc) JPEGInitDisplay,
- };
-
- RETURN_DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), TRUE, (p, o));
-}
-
-static void
-JPEGFiniObject (CompPlugin *p,
- CompObject *o)
-{
- static FiniPluginObjectProc dispTab[] = {
- (FiniPluginObjectProc) 0, /* FiniCore */
- (FiniPluginObjectProc) JPEGFiniDisplay,
- };
-
- DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), (p, o));
-}
-
-static Bool
-JPEGInit (CompPlugin *p)
-{
- displayPrivateIndex = allocateDisplayPrivateIndex ();
- if (displayPrivateIndex < 0)
- return FALSE;
-
- return TRUE;
-}
-
-static void
-JPEGFini (CompPlugin *p)
-{
- freeDisplayPrivateIndex (displayPrivateIndex);
-}
-
-CompPluginVTable JPEGVTable = {
- "imgjpeg",
- 0,
- JPEGInit,
- JPEGFini,
- JPEGInitObject,
- JPEGFiniObject,
- 0,
- 0
-};
-
-CompPluginVTable*
-getCompPluginInfo (void)
-{
- return &JPEGVTable;
-}
diff --git a/imgjpeg.xml.in b/imgjpeg.xml.in
index 53cfef9..ebc3086 100644
--- a/imgjpeg.xml.in
+++ b/imgjpeg.xml.in
@@ -1,20 +1,20 @@
<?xml version="1.0"?>
<compiz>
- <plugin name="imgjpeg" useBcop="true">
- <_short>JPEG</_short>
- <_long>JPEG image format plugin</_long>
+ <plugin name="imgjpeg" useBcop="true">
+ <_short>JPEG</_short>
+ <_long>JPEG image format plugin</_long>
<category>Image Loading</category>
- <feature>imageext:jpeg</feature>
- <feature>imageext:jpg</feature>
- <feature>imagemime:image/jpeg</feature>
- <display>
- <option name="quality" type="int">
- <_short>Compression Quality</_short>
- <_long>Quality of compression when saving JPEG images</_long>
- <default>80</default>
- <min>0</min>
- <max>100</max>
- </option>
- </display>
- </plugin>
+ <feature>imageext:jpeg</feature>
+ <feature>imageext:jpg</feature>
+ <feature>imagemime:image/jpeg</feature>
+ <options>
+ <option name="quality" type="int">
+ <_short>Compression Quality</_short>
+ <_long>Quality of compression when saving JPEG images</_long>
+ <default>80</default>
+ <min>0</min>
+ <max>100</max>
+ </option>
+ </options>
+ </plugin>
</compiz>
diff --git a/plugin.info b/plugin.info
deleted file mode 100644
index d81bf19..0000000
--- a/plugin.info
+++ /dev/null
@@ -1,2 +0,0 @@
-PLUGIN = imgjpeg
-LDFLAGS_ADD = -ljpeg \ No newline at end of file
diff --git a/src/imgjpeg.cpp b/src/imgjpeg.cpp
new file mode 100644
index 0000000..4fcbe6f
--- /dev/null
+++ b/src/imgjpeg.cpp
@@ -0,0 +1,310 @@
+/*
+ * beryl-plugins::jpeg.c - adds JPEG image support to beryl.
+ * Copyright: (C) 2006 Nicholas Thomas
+ * Danny Baumann (JPEG writing, option stuff)
+ *
+ * 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
+ * of the License, 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 program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "imgjpeg.h"
+
+COMPIZ_PLUGIN_20090315 (imgjpeg, JpegPluginVTable)
+
+static bool
+rgbToBGRA (const JSAMPLE *source,
+ void *&data,
+ CompSize &size,
+ int alpha)
+{
+ int h, w;
+ char *dest;
+ int height = size.height ();
+ int width = size.width ();
+
+ dest = (char *) malloc (height * width * 4);
+ if (!dest)
+ return false;
+
+ data = dest;
+
+ for (h = 0; h < height; h++)
+ for (w = 0; w < width; w++)
+ {
+ int pos = h * width + w;
+#if __BYTE_ORDER == __BIG_ENDIAN
+ dest[(pos * 4) + 3] = source[(pos * 3) + 2]; /* blue */
+ dest[(pos * 4) + 2] = source[(pos * 3) + 1]; /* green */
+ dest[(pos * 4) + 1] = source[(pos * 3) + 0]; /* red */
+ dest[(pos * 4) + 0] = alpha;
+#else
+ dest[(pos * 4) + 0] = source[(pos * 3) + 2]; /* blue */
+ dest[(pos * 4) + 1] = source[(pos * 3) + 1]; /* green */
+ dest[(pos * 4) + 2] = source[(pos * 3) + 0]; /* red */
+ dest[(pos * 4) + 3] = alpha;
+#endif
+ }
+
+ return true;
+}
+
+static bool
+rgbaToRGB (unsigned char *source,
+ JSAMPLE **dest,
+ CompSize &size,
+ int stride)
+{
+ int h, w;
+ int height = size.height ();
+ int width = size.width ();
+ int ps = stride / width; /* pixel size */
+ JSAMPLE *d;
+
+ d = (JSAMPLE *) malloc (height * width * 3 * sizeof (JSAMPLE));
+ if (!d)
+ return false;
+
+ *dest = d;
+
+ for (h = 0; h < height; h++)
+ for (w = 0; w < width; w++)
+ {
+ int pos = h * width + w;
+#if __BYTE_ORDER == __BIG_ENDIAN
+ d[(pos * 3) + 0] = source[(pos * ps) + 3]; /* red */
+ d[(pos * 3) + 1] = source[(pos * ps) + 2]; /* green */
+ d[(pos * 3) + 2] = source[(pos * ps) + 1]; /* blue */
+#else
+ d[(pos * 3) + 0] = source[(pos * ps) + 0]; /* red */
+ d[(pos * 3) + 1] = source[(pos * ps) + 1]; /* green */
+ d[(pos * 3) + 2] = source[(pos * ps) + 2]; /* blue */
+#endif
+ }
+
+ return true;
+}
+
+static void
+jpegErrorExit (j_common_ptr cinfo)
+{
+ char buffer[JMSG_LENGTH_MAX];
+ struct jpegErrorMgr *err = (struct jpegErrorMgr *) cinfo->err;
+
+ /* Format the message */
+ (*cinfo->err->format_message) (cinfo, buffer);
+
+ printf ("%s\n", buffer);
+
+ /* Return control to the setjmp point */
+ longjmp (err->setjmp_buffer, 1);
+}
+
+bool
+JpegScreen::readJPEG (FILE *file,
+ CompSize &size,
+ void *&data)
+{
+ struct jpeg_decompress_struct cinfo;
+ struct jpegErrorMgr jerr;
+ JSAMPLE *buf;
+ JSAMPROW *rows;
+ bool result;
+
+ if (!file)
+ return false;
+
+ cinfo.err = jpeg_std_error (&jerr.pub);
+ jerr.pub.error_exit = jpegErrorExit;
+
+ if (setjmp (jerr.setjmp_buffer))
+ {
+ /* this is called on decompression errors */
+ jpeg_destroy_decompress (&cinfo);
+ return false;
+ }
+
+ jpeg_create_decompress (&cinfo);
+
+ jpeg_stdio_src (&cinfo, file);
+
+ jpeg_read_header (&cinfo, true);
+
+ cinfo.out_color_space = JCS_RGB;
+
+ jpeg_start_decompress (&cinfo);
+
+ size.setHeight (cinfo.output_height);
+ size.setWidth (cinfo.output_width);
+
+ buf = (JSAMPLE *) calloc (cinfo.output_height * cinfo.output_width *
+ cinfo.output_components, sizeof (JSAMPLE));
+ if (!buf)
+ {
+ jpeg_finish_decompress (&cinfo);
+ jpeg_destroy_decompress (&cinfo);
+ return false;
+ }
+
+ rows = (JSAMPROW *) malloc (cinfo.output_height * sizeof (JSAMPROW));
+ if (!rows)
+ {
+ free (buf);
+ jpeg_finish_decompress (&cinfo);
+ jpeg_destroy_decompress (&cinfo);
+ return false;
+ }
+
+ for (unsigned int i = 0; i < cinfo.output_height; i++)
+ rows[i] = &buf[i * cinfo.output_width * cinfo.output_components];
+
+ while (cinfo.output_scanline < cinfo.output_height)
+ jpeg_read_scanlines (&cinfo, &rows[cinfo.output_scanline],
+ cinfo.output_height - cinfo.output_scanline);
+
+ jpeg_finish_decompress (&cinfo);
+ jpeg_destroy_decompress (&cinfo);
+
+ /* convert the rgb data into BGRA format */
+ result = rgbToBGRA (buf, data, size, 255);
+
+ free (rows);
+ free (buf);
+ return result;
+}
+
+bool
+JpegScreen::writeJPEG (unsigned char *buffer,
+ FILE *file,
+ CompSize &size,
+ int stride)
+{
+ struct jpeg_compress_struct cinfo;
+ struct jpeg_error_mgr jerr;
+ JSAMPROW row_pointer[1];
+ JSAMPLE *data;
+
+ /* convert the rgb data into BGRA format */
+ if (!rgbaToRGB (buffer, &data, size, stride))
+ return false;
+
+ cinfo.err = jpeg_std_error (&jerr);
+ jpeg_create_compress (&cinfo);
+
+ jpeg_stdio_dest (&cinfo, file);
+
+ cinfo.image_width = size.width ();
+ cinfo.image_height = size.height ();
+ cinfo.input_components = 3;
+ cinfo.in_color_space = JCS_RGB;
+
+ jpeg_set_defaults (&cinfo);
+ jpeg_set_quality (&cinfo, optionGetQuality (), true);
+ jpeg_start_compress (&cinfo, true);
+
+ while (cinfo.next_scanline < cinfo.image_height)
+ {
+ row_pointer[0] =
+ &data[(cinfo.image_height - cinfo.next_scanline - 1) *
+ size.width () * 3];
+ jpeg_write_scanlines (&cinfo, row_pointer, 1);
+ }
+
+ jpeg_finish_compress (&cinfo);
+ jpeg_destroy_compress (&cinfo);
+
+ free (data);
+
+ return true;
+}
+
+CompString
+JpegScreen::fileNameWithExtension (CompString &path)
+{
+ unsigned int len = path.length ();
+
+ if ((len > 5 && path.substr (len - 5, 5) == ".jpeg") ||
+ (len > 4 && path.substr (len - 4, 4) == ".jpg"))
+ return path;
+
+ return path + ".jpeg";
+}
+
+bool
+JpegScreen::imageToFile (CompString &path,
+ CompString &format,
+ CompSize &size,
+ int stride,
+ void *data)
+{
+ bool status = false;
+ FILE *file;
+ CompString fileName = fileNameWithExtension (path);
+
+ if (format == "jpeg" || format == "jpg" ||
+ !(status = screen->imageToFile (path, format, size, stride, data)))
+ {
+ file = fopen (fileName.c_str (), "wb");
+ if (file)
+ {
+ status = writeJPEG ((unsigned char *) data, file, size, stride);
+ fclose (file);
+ }
+ }
+
+ return status;
+}
+
+bool
+JpegScreen::fileToImage (CompString &name,
+ CompSize &size,
+ int &stride,
+ void *&data)
+{
+ bool status = false;
+ FILE *file;
+ CompString fileName = fileNameWithExtension (name);
+
+ file = fopen (fileName.c_str (), "rb");
+ if (file)
+ {
+ status = readJPEG (file, size, data);
+ fclose (file);
+ }
+
+ if (status)
+ {
+ stride = size.width () * 4;
+ return true;
+ }
+
+ /* Isn't a JPEG - pass to the next in the chain. */
+ return screen->fileToImage (name, size, stride, data);
+}
+
+JpegScreen::JpegScreen (CompScreen *screen) :
+ PluginClassHandler<JpegScreen, CompScreen> (screen)
+{
+ ScreenInterface::setHandler (screen, true);
+}
+
+bool
+JpegPluginVTable::init ()
+{
+ if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION))
+ return false;
+
+ return true;
+}
+
diff --git a/src/imgjpeg.h b/src/imgjpeg.h
new file mode 100644
index 0000000..65d2cfd
--- /dev/null
+++ b/src/imgjpeg.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright © 2006 Novell, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Novell, Inc. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Novell, Inc. makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: David Reveman <davidr@novell.com>
+ */
+
+#include <string.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <setjmp.h>
+
+#include <core/core.h>
+#include <core/pluginclasshandler.h>
+
+#include <X11/Xarch.h>
+#include <jpeglib.h>
+
+#include "imgjpeg_options.h"
+
+
+
+struct jpegErrorMgr
+{
+ struct jpeg_error_mgr pub; /* "public" fields */
+ jmp_buf setjmp_buffer; /* for return to caller */
+};
+
+class JpegScreen :
+ public ScreenInterface,
+ public PluginClassHandler<JpegScreen, CompScreen>,
+ public ImgjpegOptions
+{
+ public:
+ JpegScreen (CompScreen *screen);
+
+ bool fileToImage (CompString &path, CompSize &size,
+ int &stride, void *&data);
+ bool imageToFile (CompString &path, CompString &format,
+ CompSize &size, int stride, void *data);
+
+ private:
+ CompString fileNameWithExtension (CompString &path);
+
+ bool readJPEG (FILE *file, CompSize &size, void *&data);
+ bool writeJPEG (unsigned char *buffer, FILE *file,
+ CompSize &size, int stride);
+};
+
+class JpegPluginVTable :
+ public CompPlugin::VTableForScreen<JpegScreen>
+{
+ public:
+ bool init ();
+};
+