caedes' Notes

2015-03-23

Comparing Performance: stb_image vs libjpeg(-turbo), libpng and lodepng

Filed under: Linux,Programming — caedes @ 02:06
Tags: , , , , , , , , ,

I recently tried out Sean Barrett’s stb_image and was blown away by how fucking easy it is to use.
Integrating it into your project is trivial: Just add the header and somewhere do:

#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"

That’s all. (If you wanna use it in multiple files you just #include "stb_image.h" there without the #define.)

And the API is trivial too:

int width, height, bytesPerPixel;
unsigned char* pixeldata = stbi_load("bla.jpg", &width, &height, &bytesPerPixel, 0);
// if you have already read the image file data into a buffer:
unsigned char* pixeldata2 = stbi_load_from_memory(bufferWithImageData, bufferLength, &width, &height, &bytesPerPixel, 0);
if(pixeldata2 == NULL)
printf("Some error happened: %sn", stbi_failure_reason());

There’s also a simple callback-API which allows you to define some callbacks that stb_image will call to get the data, handy if you’re using some kind of virtual filesystem or want to load the data from .zip files or something.
And it supports lots of common image file types including JPEG, PNG, TGA, BMP, GIF and PSD.

So I wondered if there are any downsides regarding speed.
In short: (On my machine) it’s faster than libjpeg, a bit slower than libjpeg-turbo, twice as fast as lodepng (another one-file-png decoder which also has a nice API) and a bit slower than libpng. For smaller images stb_image’s performance is even closer to libpng/libjpeg-turbo. GCC produces faster code than Clang. All in all I find the performance acceptable and will use stb_image more in the future (my first “victim” was Yamagi Quake II).

The average times decoding a 4000x3000pixel image in milliseconds for GCC and clang with different optimization levels:
(more…)

Advertisements

2014-01-02

How to boot Linux and Windows (7) via UEFI

Filed under: Linux — caedes @ 03:55
Tags: , , , , , , , , , , ,

Don’t.
It’s a fucking pain in the ass.
Buy a <=2TB hard disk for Windows installations (additional Windows partitions can be on larger HDDs using GPT, it’s only painful for the system partitions).
However, if you want to use a hard drive with >2TB for your Windows installation, you have to use GPT partitions (instead of the old MBR style which only supports <= 2TB disks – there you can only use the space >2TB with ugly hacks and can’t have a continuous partition from 2TB) – and Windows can only boot from GPT partitions in UEFI mode.
To make things more challenging, Windows doesn’t offer creating a GPT partition table and partitions in the graphical installer (at least for Win7), so one has to use cmd.exe.
But don’t worry, the Linux part also sucks :-)
I’ll describe how I got Windows to install using GPT partitions on a 3TB harddisk, how to make an existing Linux (Debian Wheezy) installation boot via EFI (using grub-efi) and how I got my Mainboard (ASUS Z87-A) to boot this and GRUB to chainload (UEFI) Windows.
(more…)

2013-12-31

(Re)installing GRUB to the MBR

Filed under: Linux — caedes @ 04:13
Tags: , , , , ,

This is just a very short roundup of the relevant commands needed to reinstall grub, e.g. when migrating a Linux installation to a new hard drive.

  • boot live Linux system (from CD/DVD or USB key, I use grml, any other live Linux should do)
  • mount root-fs of your installation (e.g. /dev/sda2) to /mnt/
  • if they’re in separate partitions, mount the /boot/, /usr/, … partitions of your installation to /mnt/boot, /mnt/usr/, …
  • mount --bind /dev/ and /sys/ to /mnt/dev and /mnt/sys (maybe also /proc for older versions of grub?), grub will need those
  • chroot /mnt
  • execute grub-install $device (e.g. /dev/sda) to install grub to the MBR of $device
  • update-grub to upgrade the grub menu entries
  • If names of partitions changed, don’t forget to adjust /etc/fstab
  • configure your BIOS to boot from that harddisk
  • reboot, remove live linux you should be greeted by a fresh grub that lets you boot your Linux, BSD, Windows, .. installations

2011-01-05

Linux (Debian Squeeze) on Thinkpad T500

I recently got myself a Lenovo Thinkpad T500 (2055V1X) . I chose this older model over the T510 and such, because I prefer a screen resolution of 1680×1050 over a crippled 1600×900 or worse. I write and read a lot of code so I need vertical space on the display and I’d definitely miss the 150pixels additional vertical space my old Laptop (Samsung X20 with a resolution of 1400×1050) has.

However, I shrunk the Windows 7 partition (I didn’t want to dump Windows entirely) and installed Debian Squeeze (AMD64) in the resulting free space. I’m very pleased how painless everything was, almost all hardware ran out of the box, but I’ll document some interesting stuff (how to shrink windows partition without breaking it, how to make special keys work and display information on Linux, how to make the touchpad and trackpoint behave the way I want, …) anyway.
(more…)

2010-05-11

Shutting down (e)SATA disks under Linux

Filed under: Linux — caedes @ 22:55
Tags: , , , , , , ,

I’m using a eSATA external harddrive and want to be able to safely unplug it without shutting down my PC. While just removing the drive after unmounting worked so far, I’m not sure if it’s really safe – I’d really prefer to cleanly disconnect it and spinning it down before pulling the plug.
I googled that and stumbled upon http://www.sakana.fr/blog/2009/05/04/linux-sata-hot-plug-unplug/ which seems to be a clean and safe way to do it, so I just wrote a script to do that.
(more…)

2010-05-05

Unlock gnome-keyring on Login with SLiM and PAM

Filed under: Linux — caedes @ 02:41
Tags: , , , , ,

My favorite desktop environment is XFCE, because it’s fast, doesn’t need much memory┬╣ and still is convenient (automounting of CDs and memory sticks, easy unmounting by clicking, a real desktop, etc).
I also use SLiM as a display manager because it is slim and looks much better than xdm.

On my Laptop I also use GNOME’s NetworkManager because I haven’t yet found a better and less bloat alternative for handling wireless networks and VPNs.
NetworkManager is able to store your passwords (WPA-keys etc) in the GNOME Keyring so you don’t need to enter them each time your laptop connects to a wireless network. But you still have to enter the password to unlock the keyring.. unless you let PAM handle that on login.
(more…)

2010-01-08

Remote administration/tech-support with (reverse) VNC

Filed under: Linux — caedes @ 02:55
Tags: , , , , ,

Like most computer-savvy people I am frequently asked to give tech support to my family etc. Because telling them on the telephone what to do is a major pain in the ass, VNC is my weapon of choice, if SSH isn’t sufficiant (got to show how something is done, SSH impossible/hard because the other side uses Windows or is behind a NAT, …).

I’ll describe how to set up a normal and reverse VNC-connections using x11vnc and TightVNC.

(more…)

2009-10-02

MCabber – Settings and rebinding of PageUp/PageDown

Filed under: Linux — caedes @ 00:34
Tags: , ,

After years of using centericq for ICQ and Jabber I switched to gajim (ICQ via transport), because centericq didn’t have any useable UTF8 support. I was never really satisfied with gajim though, because I happen to switch between my PC and my Notebook multiple times a day, resulting in inconsistent chat-histories etc – a console based solution in a screen is so much nicer.

So I tried MCabber, that turned out to be really great once you’ve configured it to your needs. After installing MCabber (most Linux/BSD distributions should have a package or port) you’ll want to configure it to your needs.
(more…)

Create a free website or blog at WordPress.com.