Kobald – Victor Laskin's Blog https://vitiy.info Programming, architecture and design (С++, QT, .Net/WPF, Android, iOS, NoSQL, distributed systems, mobile development, image processing, etc...) Thu, 22 Jan 2015 11:31:39 +0000 en-US hourly 1 https://wordpress.org/?v=5.4.2 Small presentation of my cross-platform engine for mobile and desktop applications https://vitiy.info/small-presentation-of-my-cross-platform-engine-for-mobile-and-desktop-applications/ https://vitiy.info/small-presentation-of-my-cross-platform-engine-for-mobile-and-desktop-applications/#comments Wed, 21 Jan 2015 14:50:39 +0000 http://vitiy.info/?p=444 I made small presentation about my cross-platform engine for mobile and desktop applications. Codename Kobald. Click on image to play it in new window (use arrows and space to move through):

Screenshot 2015-01-21 21.53.14

This is not-so-technical presentation and main info about engine will come later as separate post.

]]>
https://vitiy.info/small-presentation-of-my-cross-platform-engine-for-mobile-and-desktop-applications/feed/ 10
[Mobile] native applications as future internet format https://vitiy.info/mobile-native-applications-as-future-internet-format/ https://vitiy.info/mobile-native-applications-as-future-internet-format/#respond Tue, 03 Jun 2014 10:21:38 +0000 http://vitiy.info/?p=270 Web sites go to native apps

Here are some thoughts on future shift from old html web sites to new native application format, which we are experiencing at mobile segment right now. 

Old approach to global web was simple – the bunch of static pages with links between them. It seemed at that ancient times that everything can be filled in that concept. But when site owners started to give users a lot of functionality that foundation began to shake. HTML was designed to write the books but users now want complex services. Nowadays we see dynamic pages everywhere with lots of AJAX, JQuery, etc. Single-page web interfaces is now wide spread common practice. In truth it is an effort to create the application inside the web page using outdated methods and instruments.

And here comes mobile age! Mobile devices exposed new problems of html web-format – complex pages are too heavy for mobile, interfaces are not fast enough, interaction is limited. Facebook tried to create their first mobile client as HTML5 – but later Zuckerberg said it was a mistake. So they switched to native applications for iOS and Android. And it happened not because HTML5 was not ready at that time, imho. I think it will never be ready as true cross-platform development solution for complex apps.

At mobile field we experience the switch from web-sites to native applications more clearly. What the consumer wants now is not just mobile version of site, but true mobile application (people don’t really surf on smartphones).

Mobile apps dominate

In 2014 only 14% of user time on mobile devices is spent in the web browser (source) and this percentage is reduced every year

At desktop segment the switch is not so obvious but there are some movements here too. For example, i have Evernote as MacOs application, where i could use it as a site instead. And i imagine almost every serious site would benefit from conversion to native app form.

So what the problem? There are several main factors which postpone the shift:

The main problem is high development cost. There are no true cross-platfrom development solutions for the most platforms and you must code for every platform separately. And good desktop/mobile developers are not cheap. I work in that direction attempting to create some framework that has ability to create apps for mobile and desktop systems in one shot. I will write separately about it when at least one solid product will be available on market with support of wide range of systems. Im sure there is some work in that direction not only on my part.

The second missing link which separates now web-pages from the apps is the lack of content-based search inside the applications. Index robots now can’t scan mobile apps and you can’t see the results in Google search. But that will change soon! Google made first move in right direction and some parts of Android apps can be indexed by their search machine if app developer provided certain list of links inside the app. Here is more information about it – App Indexing. I did not test it yet – but it looks promising and i will definitely try it in action.

The last step is the instant installation of new apps. At the moment we used to see the apps as second step: we have the couples – the site and the mobile client app for that site. Common use case is that user is already aware of what he want to install and so he can endure some installation waiting. But if we consider the app as full replacement of site, the installation process should be reduced to almost nothing. I think its not so serious problem as a production cost. As bandwidth goes up installation time will be reduced and I’m sure platforms will come up with some fast installation solution. Application managers should handle it on modern mobile platforms like iOS, Android, etc. As for desktops – Apple has App Store and there were some Click-to-install tries from Microsoft for their .Net apps.

The last concern is the quality of apps. We have a lot of crappy sites all over the web and user don’t want to install such ‘crappy’ apps into the system. Or at least we want to have strong sandboxing and easy way to clean up the mess. Apple has complicated approval policy to prevent such bad quality apps from their market. Its good for clients in some way but its nightmare for devs. In any case this is some problem to solve on the way to new ‘app-sites’ world.

In any way you can expect to see more and more apps in near future. The apps which will take the place of web sites.

]]>
https://vitiy.info/mobile-native-applications-as-future-internet-format/feed/ 0
TripBudget – stylish budget calculator/logger for trips – BETA Android release https://vitiy.info/tripbudget-fast-budget-calculator-logger-for-trips-android/ https://vitiy.info/tripbudget-fast-budget-calculator-logger-for-trips-android/#comments Fri, 31 Jan 2014 19:07:48 +0000 http://vitiy.info/?p=213 TripBudget

My new tool at android play market – you can find it here. This is stylish planner/tracker for your trip’s budgets – planning and logging as one fast and fancy instrument.

More information and screens can be found below…

 

As this is beta version – the following details were modified from version 1.0 and will be changed in future to reflect recent updates.  

TripBudget

Typical workflow is the following – you create new trip and add planned expenses (which are divided by simple categories and are very easy to add). You can create several versions of the same trip and compare final estimated values. After that you switch from plan mode into ‘spending’ mode and log actual expenses. These modes are highlighted by different colors (orange for plans and blue for real expenses) to make it easy to distinguish from each other.

TripBudget - expense entry

When you enter price you can also provide text comment, multiplicator, tax/discount and specify that expense is shared between several people. This data can be modified later in the list of expenses.

In main settings you can add the list of money sources and track their balance. Such sources also can have values of another currency. When you enter tracked expense the value will be automatically subtracted from selected source.

The app uses gps sensor to log expenses locations. This gives you ability to plot tracked points on the map and find the places you liked later. Also you have ability to make photos and attach them to expenses (such as receipts and so on).

You have a lot of view modes for the lists of expenses. Two differed styles for the lists, several types of plots and special map view. The list can be filtered by main category sections, users, money sources. Also there are grouping options – you can group data by days or categories. See more screens below at updates section.

TripBudget expenses listTripbudget bar plot

The app automatically converts expense values into base currency using public rates from open sources (like European Central Bank, etc) which are updated every day (internet connection is required). You can also set your fixed currency rates for each trip budget.

TripBudget 1.010 Theme selection

As for design – i tried to make it as modern looking as possible (while maintaining the best usability). There is support for the tablets – special horizontal layout when upper panel shifts to left side to get better scrolling area. Note that design is targeted for retina-like devices as it has thin fonts.

But also i added a bit of customization. At the moment you can select one of high res backgrounds (travel related). The image has slight movement as well as minor parallax effect.

Incoming updates will also provide cloud synchronisation of trips and expenses.

You can switch between interface languages at real time. At the moment supported languages are: English, Russian, Español, French, Dutch, Italian. If you found some mistakes in translation or want to help with translation to your language – go to the end of this document – there is information about crowd translation there.

Application is powered by my cross-platform engine – so iOS release is coming soon enough (as soon as beta ends).

 

THE UPDATES:

v1.007

The count of supported currencies was greatly increased (and there are several sources now). You can now enter custom currency exchange rates for each trip.

TripBudget currency list

The currency selectors were considerably changed – now its alphabetic list and the most used currencies will go up to the top of the list for easy usage.

App now uses standard android keyboard (the ‘custom’ keyboard was there as part of engine – now it should support standard android keyboard).

Also you can delete old trips now (long press on trip list to see delete dialog).

TripBudget delete trip dialog

v1.010

For better usability at horizontal layout the design has been refactored. When your device is landscape oriented the upper bar moves to left side to make the scrollable area fit all height of the screen. So the expense entry keyboard is supposed to fit without any scrolling.

TripBudget 1.010 horizontal price entry

The settings now have new ‘suggestions’ section from which you can go to the forums and write your ideas. Big thanks for all who will do it.

v1.012

This version introduces two major improvements – multiple trip participants and money sources.

Money sources contain such types as debit cards, credit cards and cash. When you log expense in ‘real’ spending mode the amount will be converted into currency of source automatically and will be subtracted from selected source balance. This will help to track your estimate sources during your journey.

TripBudget money sources

Each trip now has additional section in options where you can add the participants to the list.

TripBudget participants select

When you entering expense you can select who was participating in each spending action. Its also possible to set for who you have to pay if you have to pay not only for yourself. For example, if you are travelling as couple with pair of your friends, you still have to pay for your companion only – which makes 50% of 4 ppl expense and this is possible to track easily now. You also can select money source as DEBT from another participant (the list to track your debts will be added as well).

TripBudget - expenses grouped by users

The list of expenses was improved to support new expense parameters – you can see expenses grouped by participants (to see overall spent amount and total debts) and also check impact on your money source in corresponding section. Clicking on each source or participant will provide the list of connected expenses.

v1.013

New version adds ability to add custom expense categories. You can find new configurable list inside application settings. There are large set of possible icons, but if you think there is something missing – feel free to write below in comments.

There is also new ability to hide selected categories from front panel.

v1.014

+ Ability to attach photos to expenses
+ Grouping by days and categories in expense lists
+ Two types of time-based graphs for expenses
+ Ability to change date of expense

1.015

tripbudgetimmmode

+ support of immersive mode under Android 4.4 with translucent menus
+ new functions for money sources (add balance, delete)

1.016

+ New languages: español, french and dutch
+ Ability to enter fraction of expense value
+ Fix for crash while setting currency rates
+ Application now has default cache for currency rates
+ Clicking on currency at main tabs opens currency options
+ Additional exit button under Immersive mode
+ Modification of tabs for better usability

1.018

+ Italian language

1.019

+ New design and functions of expense view
+ Ability to view expense on the map
+ Ability to delete trip participants
+ Main sections are automatically reordered by usage frequency
+ Fixes for italian localization
+ Minor stability fixes

1.020

TripBudget map view2014-09-04 12.18.04

+ New view mode for expenses list – view expenses on map. We are using Nokia maps here.
+ Ability to modify category of expense.
+ Click on maps will open system map or navigator. So now you can build routes to tracked locations using your favourite gps-navigator in just couple of clicks.
+ Optimizations for large lists of expenses should really improve UI speed on not-so-fast devices.

INCOMING FEATURES

Here is small preview of what coming inside next updates.

– Cloud synchronisation

– Export of trip plan / log

– Additional trip options

– Additional statistics

– New tools for sharing with friends

INSTALL

Get it on google play

ADDITION

TripBudget was featured by XDA – http://www.xda-developers.com/android/keep-your-travel-expenses-under-control-with-tripbudget/  You can join the discussion here: http://forum.xda-developers.com/showthread.php?t=2644669

TRANSLATION

If you want to help with crowd translation of TripBudget to your language – you can help using translation page. THANKS A LOT. Current state – RU, ES, NL, FR, IT langs are already at market.

NOTE:  Any reports and suggestions are highly welcome in comments.

 

 

]]>
https://vitiy.info/tripbudget-fast-budget-calculator-logger-for-trips-android/feed/ 1
Stackblur – C++ multi-threaded version of fast blur algorithm https://vitiy.info/stackblur-algorithm-multi-threaded-blur-for-cpp/ https://vitiy.info/stackblur-algorithm-multi-threaded-blur-for-cpp/#comments Thu, 26 Sep 2013 12:10:42 +0000 http://vitiy.info/?p=130 I found nice algorithm for blurring images – Stackblur by Mario Klingemann. It could do the job relatively fast and gives decent quality. You can check it here – web demonstration. As you can see it can be usable even in web projects.

stackblursample

As i wanted to include it to my cross-platform engine i found two c++ implementations: 

First is SSE friendly, second contains some division optimization via static tables. However, both are not using all cpu cores. I took second one as foundation for my implementation, as i expected my code to work on mobile devices with no SSE support. Single-core processing of 1920×1200 rgba image with 100 px radius took only 219 ms (Intel Q9550, Windows 7).

I improved stackblur code to multi-threaded version – on my quad-core cpu speed results as expected showed 4x improvement – 63ms for the same task. You can download the part my lib below and use it as a foundation to your needs.

Download multi-threaded 32bit-color (RGBA) version of StackBlur:  stackblur.cpp

I believe algorithm can be optimized even further – any suggestions are welcome.

]]>
https://vitiy.info/stackblur-algorithm-multi-threaded-blur-for-cpp/feed/ 7
Alive Numbers 2 – android release of my minimalistic live wallpaper with embedded widgets https://vitiy.info/alive-numbers-2-my-new-live-wallpaper-with-embedded-widgets/ https://vitiy.info/alive-numbers-2-my-new-live-wallpaper-with-embedded-widgets/#comments Sat, 24 Aug 2013 09:22:32 +0000 http://vitiy.info/?p=81 Brand new version of live wallpaper –  Alive Numbers 2 for Android devices. Enjoy smooth OpenGl ES 2.0 animation of minimalistic animated background in couple with customisable embedded widgets. New version has adjustable color schemes and ability to hand-tune widget layout. You can choose from set of base animations and play with a lot of options for every widget.

Alive Numbers 2

It can be found by name ‘Alive numbers 2’ or here: https://play.google.com/store/apps/details?id=com.calibvr.minimal

This topic contains screens and details…

Live wallpaper contains several animations. Default background animation is particle system of flying numbers with tricky blur algorithm. All particles are rendered in single pass. This gives only 3% cpu load under Samsung Galaxy Note 2. Wallpaper do not consume battery resources when is not visible – so power loss is not an issue. Count of particles, speed, color, fade options, desaturation can be adjusted in options.

Alive Numbers 2

Particle system is also coupled with Parallax effect based on accelerometer sensor. Intensity of this effect can be adjusted at animation options (or be completely disabled). You can watch the following video to see how the effect looks like:

Application is powered by my cross-platform engine based on OpenGl ES 2.0. Advantages that comes with it are theme of big separate topic but here are several the most handy:

You can switch interface language at any time from options and this does not correlate with device locale settings.

If details or text are too small you can set global screen scale as you like it (at engine options). Everything will become bigger or smaller as you like it.

You can enjoy rich custom controls which make options easy to handle:

Alive Numbers 2 - animation options

You can change the values and see the results immediately through the transparent layer.

Live wallpaper has the list of widgets you can customize – and more are planned in future. Custom clock, battery indicator, current date indicator, current day of week, weather data based on current gps position with hourly/daily forecast, currency exchange rates based on ECB data, etc…

Alive Numbers 2 - widgets

Each widget has several styles and options. Screen layout can be adjusted very fast. Widgets can be positioned on the screen using drag-drop method – so you can customize your layout as you like:

Alive Numbers 2

Clicking on widgets launches default applications from system – like calendar, clock, battery consumption info, etc. This behaviour can be disabled in options ( for every widget separately ).

From options you can switch base background animation.

Alive Numbers 2 Animation list

Example of settings with sweet hearts animation:

Hearts animation Alive numbers 2

Animation which is very similar to iOS7 alive wallpaper:

Alive Numbers 2 Circles animation

Video of customization process:

Some five-stars-responses from market:

Great app I absolutely love it. Made my home screen a lot less cluttered and uniform.

Incredibly neat and beautiful!!! I love this live wallpaper, love the fact that it comes with in built widget, 5 stars straight!!

Excellent New parralax effect is great.

My Kind Of Wallpaper Alive numbers was my default wallpaper for the last 6 mos. This one, the newer version is so much better. Configuration is a breeze. Keep up the good work!

INSTALL

Alive numbers 2 Icon

The wallpaper can be found by name ‘Alive numbers 2‘ or here: https://play.google.com/store/apps/details?id=com.calibvr.minimal

 

 

LOCALIZATION

I created special tool for online localization available here: http://vitiy.info/localization/alivenumbers2/

There you can make Alive Numbers 2 to support your native language. The list of languages – Bulgarian, Danish, German, Spanish, Finnish, Franch, Croatian, Hungarian, Indonesian, Italian, Lithuanian, Latvian, Norwegian, Dutch, Polish, Portuguese, Romanian, Russian, Slovak, Slovenian, Serbian, Swedish, Turkish, Ukrainian, Vietnamese.

Please note – localization tool is in beta state – please contact me in case of any errors, bugs, etc.

Alive numbers 2 Promo 2

Alive numbers 2 Promo 2

UPDATES

Next section contains information about updates and should be updated when new versions will come at market. Main upper text will be fixed to reflect changes, but lower part can contain additional images and details.

UPDATE (v.2.005):

Clicking on widgets launches default applications from system – like calendar, clock, battery consumption info, etc. Weather widget now has weekly/hourly forecast.

Alive Numbers 2: forecast

UPDATE (v.2.007)

Brand new Parallax effect using accelerometer for inner particle system.

UPDATE (v.2.008)

New widget: Currency Rates. Exchange reference rates from official European Central Bank feed (daily updated). You can select your local currency as the base and monitor the list of rates (up to 28 items).

Currency rates gadget

UPDATE (v.2.009)

Two new animations for background – snowflakes and sweet hearts. New global widget settings section was added. You can set default font for widgets. Clock has separate option for font.

UPDATE (v2.010)

Some urgent fix for weather provider

UPDATE (v2.011)

New animation background was added – circles. Its very similar to iOS7 live wallpaper.

New clock styles for clock widget were added and old styles were improved a bit. PM/AM label was added for 12h format clock.

Alive Numbers 2 Clock style 1

Tower style (one on one) :

Alive Numbers 2 Clock style 2

Clock style as minimal text:

Alive Numbers 2 Clock style 3

Weather widget now has manual refresh button located on forecast panel. Also location now is displayed as city name – not local area of city (there is new option for that).

UPDATE (v2.013)

– spanish localization

– new background animation called “Lasers”

– clock widget now shows current alarm (can be disabled in properties)

– new hi-res xxhdpi icon

– when you switch animation particles are filled instantly

Alive numbers 2 lasers animation

UPDATE (v2.014)

– new stripes animation
– support for ART runtime (Android 4.4)
– fix for clock widget dragging
– minor fixes for parallax effect
– fix of widget dragging bug on high dpi devices
– fps limit was increased for more smooth animation

Screenshot of new STRIPES animation:

Alive numbers 2 Stripes animation

UPDATE (v2.015)

New animation for St.Valentine day – FLOWERS:

Alive numbers 2 - flowers animation

– New localization – Swedish (thanks to Marcus Sundman)

– New more high-res fonts and 2 new fonts for widgets

– New performance settings

UPDATE (v2.016)

– Support for german and polish languages

UPDATE (v2.017)

Alive numbers 2 Coffee animation

+ New animation – COFFEE
+ Currency widget now supports a lot more currencies
+ GPS sensor fixes and new location provider for weather widget
+ Support for timely as custom app for clock widget

UPDATE (v2.018)

+ New option for weather widget – disable GPS data sensor for location (to preserve battery)

+ Minor fixes for GPS implementation

UPDATE (v2.019)

NEW ANIMATION: Contains new long-awaited animation – custom user image (which you can pick from device gallery) combined with parallax and blur effects

UPDATE (v2.020-2.021)

+ fixes for weather widget

+ FR language support

Any suggestions are welcome at comments. 

 

]]>
https://vitiy.info/alive-numbers-2-my-new-live-wallpaper-with-embedded-widgets/feed/ 13
Perfomance of complex GL ES 2.0 shaders on mobile devices https://vitiy.info/perfomance-of-complex-gl-es-2-0-shaders-on-mobile-devices/ https://vitiy.info/perfomance-of-complex-gl-es-2-0-shaders-on-mobile-devices/#respond Sun, 18 Aug 2013 12:29:40 +0000 http://vitiy.info/?p=75 There is very nice site http://glsl.heroku.com/, where you can find the gallery of complex GLSL shaders (from very simple gradients to very complex rendering systems). You can modify their code at real-time using provided editor:

heroku

Current implementation of WebGL is using GL ES 2.0 – the same as all mordern android / iOS phones/tablets. So i decided to test if i can use these shaders at mobile applications – and tested their performance on Sumsung Galaxy Note II. Of course i tested only relatively simple shaders expecting them to run slow…

The results were quite disappointing to me. Only very very simple shaders were working fine. More complex shaders (which were the point of interest) were running at 1 fps or less. Looks like even such modern phone as Note II has no driver optimization for such shaders and even more – some shaders became corrupted – see next picture:

Corrupted shader in Galaxy Note ||

So today unfortunately we cant use such shaders at mobile production. But i hope situation will change in future.

UPD (28.12.20013): I performed some tests on Google Nexus 5 phone and got slightly more positive results. Not trivial (but not so complex) shaders began to work – not so smooth as it should be but fps is above 20. I even added 2 example experimental effects to Alive numbers 2 alive wallpaper on Android (they are visible in elite mode as bonus experimental content). Under Samsung Note 2 these animations do not work at all, but under Nexus 5 they run more or less.

shader1   shader2

 

Later i will perform some test on new IPad mini with retina screen. May be it will show even better results. I expect tablets to show better results.

 

 

]]>
https://vitiy.info/perfomance-of-complex-gl-es-2-0-shaders-on-mobile-devices/feed/ 0
Live Wallpaper under Android can be powered by my cross-platform engine now https://vitiy.info/live-wallpaper-under-android-can-be-powered-by-my-cross-platform-engine-now/ https://vitiy.info/live-wallpaper-under-android-can-be-powered-by-my-cross-platform-engine-now/#respond Tue, 06 Aug 2013 18:30:12 +0000 http://vitiy.info/?p=70 After my recent modifications of android part of my cross-platform engine, it is possible to make application also run as android live background. I plan to implement the same feature as well for iOS 7, but a bit later. Here is working example (https://play.google.com/store/apps/details?id=com.calibvr.synctimer):

Synctimer as live background

Android live wallpaper is not a general Activity application – it is special WallpaperService. And you cant implement it in pure C++ using NativeActivity. All my core is cross-platform C++ so i implemented two-way communication between C++ and JAVA. From C++ NativeActivity you can call JAVA classes through JNI and from java service you can call native (c++) methods of engine core.

The tricky part that all this communication involves a lot of different threads. Wallpaper service has its own thread, but rendering should be performed in another one. My native C++ core is launched as third thread and spawns other async threads which could call some java methods. But i got through all this nightmare using mutexed queues of events. As result i got full functionality of my engine at the background of android launcher.

When i only started working with android i wrote small live wallpaper in pure java (with no OpenGL). Wasted only couple of evenings and even lost the source code. But recently i was surprised when discovered that it has more than 100.000 downloads (https://play.google.com/store/apps/details?id=back.livenumbers). It does not even work properly on my Note 2 now.

But the point is that now i have smooth OpenGl ES 2.0 animations/effects in couple with engine functionality. Probably, i will create couple of stylish backs fused with some in-code widgets (like battery indicator, weather forecast, clock, calendar date or something else) as implementation will be relatively easy now using my engine. Any suggestions on this matter are welcome.

]]>
https://vitiy.info/live-wallpaper-under-android-can-be-powered-by-my-cross-platform-engine-now/feed/ 0
Manual decoding of ICO file format – small c++ cross-platform decoder lib https://vitiy.info/manual-decoding-of-ico-file-format-small-c-cross-platform-decoder-lib/ https://vitiy.info/manual-decoding-of-ico-file-format-small-c-cross-platform-decoder-lib/#comments Wed, 24 Jul 2013 15:44:14 +0000 http://vitiy.info/?p=56 This post is related to one simple task – decode ICO file format from C++ manually (I needed this for one of my projects where i wanted to display fav icons related to web sites and decoder has to be part of my cross-platform framework). As a result you can download small c++ code below (ico.cpp). The description of ICO format you can find here – http://www.daubnet.com/en/file-format-ico. Image data is stored uncompressed so we don’t need to implement some smart decompression algorithms – just read some headers, get data and apply bit mask to fill alpha channel.

icons

As solution i wanted a function like this:  

bool IcoDecoder::decode(unsigned charbuffer,///< input buffer data

    int size,///< size of buffer

    unsigned intwidth,///< output – width

    unsigned intheight,///< output – height

    std::vector<unsigned char>&image///< output – image data

) 

and this function should extract the largest possible image from multiresolution icon.

We need some header structs (i found them somewhere over internet). I skip them – you can find everything in source code below. As first step we check is it really ICO header and get number of images inside:

LPICONDIR icoDir (LPICONDIR)buffer;

int iconsCount icoDir->idCount;

if (icoDir->idReserved!=0return false;

if (icoDir->idType!=1return false;

if (iconsCount==0return false;

if (iconsCount>20return false;

 

Get offset of the largest icon within file:

unsigned charcursor buffer;

cursor += 6;

ICONDIRENTRYdirEntry=(ICONDIRENTRY*)(cursor);

int maxSize=0;

int offset=0;

for(int i=0i<iconsCounti++)

{

    int w=dirEntry->bWidth;

    int h=dirEntry->bHeight;

    int colorCount=dirEntry->bColorCount;

    int bitCount=dirEntry->wBitCount;

    if(w*h>maxSize)// we choose icon with max resolution

    {

         width=w;

         height=h;

         offset=dirEntry->dwImageOffset;

         maxSize = w * h;

    }

    dirEntry++;

}

if (offset==0return false;

 

Get image bit count and bit mask existance flag

cursor=buffer;

cursor+=offset;

ICONIMAGEicon (ICONIMAGE*)(cursor);

int realBitsCount=(int)icon->icHeader.biBitCount;

bool hasAndMask=(height!=icon->icHeader.biHeight);

cursor+=40;

int numBytes=width*height*4;

 

In case of 32 bit data (realBitsCount == 32) we just copy data to output with optional vertical flip:

int shift;

int shift2;

for (int x=0x<widthx++)

for (int y=0y<heighty++)

{

    shift=4*(x+y*width);

    shift2=4*(x+(heighty1)*width);

    image[shift]=cursor[shift2+2];

    image[shift+1]=cursor[shift2+1];

    image[shift+2]=cursor[shift2];

    image[shift+3]=cursor[shift2+3];

}

 

If color count is limited to 256 or 16 we take colors from color table. Here is the part for 256 color:

unsigned charcolors=(unsigned char*)cursor;

cursor+=256*4;

int shift;

int shift2;

int index;

for (int x=0x<widthx++)

    for (int y=0y<heighty++)

    {

         shift=4*(x+y*width);

         shift2=(x+(heighty1)*width);

         index=4*cursor[shift2];

         image[shift]=colors[index+2];

         image[shift+1]=colors[index+1];

         image[shift+2]=colors[index];

         image[shift+3]=255;

    }

 

And final step is optional bit mask (this is not applicable only to icons with 32bit color).

int shift;
int shift2;
unsigned char bit;
int mask;
		
int boundary = width * realBitsCount; //!!! 32 bit boundary (http://www.daubnet.com/en/file-format-ico)
while (boundary % 32 != 0) boundary++;
cursor += boundary * height / 8;
        
boundary = width;
while (boundary % 32 != 0) boundary++;

for (int y = 0; y < height; y++)
	for (int x = 0; x < width; x++)
	{
		shift = 4 * (x + y * width) + 3;
		bit = 7 - (x % 8);
		shift2 = (x + (height - y - 1) * boundary) / 8;
		mask = (0x01 & ((unsigned char)cursor[shift2] >> bit));
		image[shift] *= 1 - mask;
	}

And that all. See complete file to enjoy how compact the decoding is. Feel free to use it. I have tested this on a lot of icons but i cannot guarantee anything. Also i skipped some range checks and stuff to make module more robust – but you are free to modify it as you like.

UPDATE 14.08.2014: Code was updated to rev2  to support 1-bit encoding. Also contains fix for bit mask application.

SOURCE CODE: download ico.cpp (last version – rev2 15.08.2014)

PS. Please post in comments info about any icons which fail to decode using code above.

]]>
https://vitiy.info/manual-decoding-of-ico-file-format-small-c-cross-platform-decoder-lib/feed/ 2
SyncTimer – stylish multiplatform timer with synchronization between devices https://vitiy.info/synctimer/ https://vitiy.info/synctimer/#respond Wed, 08 May 2013 13:15:13 +0000 http://vitiy.info/?p=53 My newly developped cross-platform engine finally goes to markets. Current platfroms are iOS, Android and Windows desktop.

SyncTimer icon

Download stylish multiplatform timer with synchronization between devices. 
You can control your timer from your PC, your iPhone or iPad, your android tablet and more. 
And even get more fun sharing timer with your friends.

http://synctimer.calibvr.com/

]]>
https://vitiy.info/synctimer/feed/ 0