caedes' Notes

2018-08-06

This Blog has moved to blog.gibson.sh

Filed under: Uncategorized — caedes @ 17:37

I’ll keep this blog up so I don’t break any existing links to my posts etc, but I won’t write new posts here and I won’t add corrections to existing posts here either.

All existing posts have been migrated to the new Blog: https://blog.gibson.sh

Cheers,
- Daniel

Advertisement

2015-07-18

Comparing png compression ratios of stb_image_write, LodePNG, miniz and libpng

Filed under: Programming — caedes @ 04:29
Tags: , , , , , , ,

NOTE: This post has moved to https://blog.gibson.sh/2015/07/18/comparing-png-compression-ratios-of-stb_image_write-lodepng-miniz-and-libpng/
The original article is kept here for now, but is not maintained in any way.

Because of https://github.com/nothings/stb/issues/113 I was wondering how good/bad stb_image_write’s PNG compression really is in comparison to other encoders.

So I did a quick comparison between stb_image_write (v0.98) LodePNG (version 20150418), miniz’s tdefl_write_image_to_png_file_in_memory_ex() (v1.15) and libpng (version 1.2.50 from Ubuntu 14.04), always with the highest possible compression I could configure.
(more…)

2015-04-13

How to integrate your SDL2 window icon (or any image) into your executable

Filed under: Programming,SDL — caedes @ 02:21
Tags: , , , ,

NOTE: This post has moved to https://blog.gibson.sh/2015/04/13/how-to-integrate-your-sdl2-window-icon-or-any-image-into-your-executable/
The original article is kept here for now, but is not maintained in any way.

Let’s assume you have an image that you want to use as a window icon in your cross-platform application that uses libSDL2.
A suitable window icon is 64x64pixels big (other sizes should work as well, though) and has 32bit RGBA colors, which means it contains an alpha-channel.

Now it would be handy if the icon could just be part of the executable and if this could be achieved in a platform-independent way.
Furthermore it’d be great if it didn’t require additional dependencies (e.g. to decode image files).

In this tutorial I’ll show how to translate the image into C source file containing a struct that holds the image data + necessary metadata (width, height, color depth) and how to load that struct into a SDL_Surface* and to set that surface as a window icon.
(more…)

2015-03-23

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

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

NOTE: This post has moved to https://blog.gibson.sh/2015/03/23/comparing-performance-stb_image-vs-libjpeg-turbo-libpng-and-lodepng/
The original article is kept here for now, but is not maintained in any way.

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…)

2014-01-02

How to boot Linux and Windows (7) via UEFI

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

NOTE: This post has moved to https://blog.gibson.sh/2014/01/02/how-to-boot-linux-and-windows-7-via-uefi/
The original article is kept here for now, but is not maintained in any way.

Don’t.
It’s a fucking pain in the ass.
Buy a 2TB for your Windows installation, you have to use GPT partitions (instead of the old MBR style which only supports 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: , , , , ,

NOTE: This post has moved to https://blog.gibson.sh/2013/12/31/reinstalling-grub-to-the-mbr/
The original article is kept here for now, but is not maintained in any way.

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

NOTE: This post has moved to https://blog.gibson.sh/2011/01/05/linux-debian-squeeze-on-thinkpad-t500/
The original article is kept here for now, but is not maintained in any way.

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-06-30

Bug-Hunting: Browsers fail to load research.microsoft.com

Filed under: Bug-Hunting — caedes @ 01:44
Tags: , , , , ,

NOTE: This post has moved to https://blog.gibson.sh/2010/06/30/bug-hunting-browsers-fail-to-load-research.microsoft.com/
The original article is kept here for now, but is not maintained in any way.

This is a follow-up to debian bug #541658 for Iceweasel: “cannot open research.microsoft.com”.
It turned out that this bug applies to all (tested) browsers with cookie-support (Iceweasel, Opera, Chrome, Arora, Kazehakase), but only very few people are experiencing it. If you’re one of them please get in touch via the comments :-)
First I’ll tell how to reproduce the bug, then I’ll sum up the facts I already collected in that bugreport and then I’ll document my further attempts to narrow down the problem.

UPDATE: The reason for that strange behaviour was found and I filed a new bugreport: No. #587789
UPDATE 2: Debians Kernel maintainer considers this expected behavior and told me to file a bugreport upstream and I did: Netfilter bug #622.
UPDATE 3: I think Microsoft has fixed their server. Of course the Linux kernel should be fixed anyway but there doesn’t seem to be much interest in doing so :-/
(more…)

2010-05-11

Shutting down (e)SATA disks under Linux

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

NOTE: This post has moved to https://blog.gibson.sh/2010/05/11/shutting-down-esata-disks-under-linux/
The original article is kept here for now, but is not maintained in any way.

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: , , , , ,

NOTE: This post has moved to https://blog.gibson.sh/2010/05/05/unlock-gnome-keyring-on-login-with-slim-and-pam/
The original article is kept here for now, but is not maintained in any way.

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…)

Next Page »

Create a free website or blog at WordPress.com.