Tuesday, February 24, 2015

Sample code for using Image Stride value

Image Stride

When a video image is stored in memory, the memory buffer might contain extra padding bytes after each row of pixels. The padding bytes affect how the image is stored in memory, but do not affect how the image is displayed.
The stride is the number of bytes from one row of pixels in memory to the next row of pixels in memory. Stride is also called pitch.

void ProcessVideoImage(
    BYTE*       pDestScanLine0,    
    LONG        lDestStride,       
    const BYTE* pSrcScanLine0,     
    LONG        lSrcStride,        
    DWORD       dwWidthInPixels,    
    DWORD       dwHeightInPixels
    )
{
    for (DWORD y = 0; y < dwHeightInPixels; y++)
    {
        SOURCE_PIXEL_TYPE *pSrcPixel = (SOURCE_PIXEL_TYPE*)pDestScanLine0;
        DEST_PIXEL_TYPE *pDestPixel = (DEST_PIXEL_TYPE*)pSrcScanLine0;

        for (DWORD x = 0; x < dwWidthInPixels; x +=2)
        {
            pDestPixel[x] = TransformPixelValue(pSrcPixel[x]);
        }
        pDestScanLine0 += lDestStride;
        pSrcScanLine0 += lSrcStride;
    }
}




https://msdn.microsoft.com/en-us/library/windows/desktop/aa473780(v=vs.85).aspx



Using StrTrim function

Courtesy msdn.microsoft.com

Removes specified leading and trailing characters from a string.

https://msdn.microsoft.com/en-us/library/windows/desktop/bb773454(v=vs.85).aspx

BOOL StrTrim(
  _Inout_  PTSTR psz,
  _In_     PCTSTR pszTrimChars
);



Parameters

psz [in, out]

    Type: PTSTR

    A pointer to the null-terminated string to be trimmed. When this function returns successfully, pszreceives the trimmed string.
pszTrimChars [in]

    Type: PCTSTR

    A pointer to a null-terminated string that contains the characters to trim from psz.

Return value

Type: BOOL

TRUE if any characters were removed; otherwise, FALSE.

 #include <windows.h>
#include <iostream.h>
#include "Shlwapi.h"

void main(void)
{
    //String one
    TCHAR buffer[ ] = TEXT("_!ABCDEFG#");
    TCHAR trim[ ] = TEXT("#A!_\0");

    cout  <<  "The string before calling StrTrim: ";
    cout  <<  buffer;
    cout  <<  "\n";

    StrTrim(buffer, trim);

    cout  <<  "The string after calling StrTrim: ";
    cout  <<  buffer;
    cout  <<  "\n";
}

OUTPUT:
- - - - - -
The string before calling StrTrim: _!ABCDEFG#
The string after calling StrTrim: BCDEFG

Control EWF using windows API


 EWF provides a means for protecting a volume from writes. This allows the operating system (OS) to boot from read-only media such as CD-ROMs, write-protected hard disks, or flash media. All writes to an EWF-protected volume are redirected to an overlay. These writes are cached in the overlay and made available as part of the volume. This gives the appearance that the volume is writeable. The overlay may exist either on disk or in random access memory (RAM). If desired, the data stored in the overlay may be committed to the protected volume. Figure 1 is an overview of EWF.


control EWF using windows API:

https://msdn.microsoft.com/en-US/library/ms838476(v=winembedded.5).aspx


Useful EWFMGR commands to use
To use any of the following commands then you will need to firstly navigate to the command prompt window with the following steps:

Click on the Start button on your player.
Please now select the Run option and at the command prompt type cmd
You will now be presented with a black command prompt window and begin typing the following commands:


ewfmgr.exe c: -Enable

Enables the EWF from the DOS prompt.


ewfmgr.exe c: -Disable

Disables the EWF from the DOS prompt.


ewfmgr.exe c: -NoCmd

Clears the state of the Boot Command.



ewfmgr.exe c: -Commit

Commits any changes made to the EWF.


    4. Please note that in the case of LG devices the command should be
ewfmgr C: -commitanddisable

 

The syntax of Windows Registry Editor command-line parameters:


I found a very useful link for this :

http://www.eolsoft.com/freeware/registry_jumper/regedit_switches.htm

  • c:\all.reg, use the /e switch as follows:
    regedit /E c:\all.reg
  • To export a specific registry key to file file.reg, use the /e switch as follows:
    regedit /E file.reg <registry_key>, for example
    regedit /E c:\hklm_run.reg "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run" will export list of Startup programs from Run section.
  • Merge or import file.reg to Registry:
    regedit file.reg
  • Create and replace an existing registry from a file file.reg:
    regedit /C file.reg
  • For silent execution of Regedit command, use the /s parameter. If /S specified, Regedit will be operate quietly, without asking for confirmation.
  • To delete specific registry key from the registry: Win 95,98,ME Regedit has switch /d, use it as follows:
    regedit /D <registry_key>, for example
    regedit /D "HKEY_CLASSES_ROOT\CLSID\{834261E1-DD97-4177-853B-C907E5D5BD6E}" will delete entry of Trojan CWS

    Win 2000, XP You can create .reg file and specify in it minus sign before the key name to delete (example - contents of sample file c:\del.reg):
    REGEDIT4
    [-HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System]
    Now if Regedit will be launched by command regedit c:\del.reg, the key HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System will be removed from the system registry.
  • Win 95,98,ME There are several command line switches for specifying location of User.dat (/L) and user name (/R):
    regedit /L:c:\windows\user.dat /e c:\test.reg

How to take an enum data type index from MYSQL

mysql> SELECT id,enum_col+0 FROM tbl_name where rowid=2;

where enum_col is a coloumn of Enum type in MYSQL
tbl_name is name of your table


This query will return the current index value of enum_col enum {'One','Two','Three'} instead of string 'One' , 'Two' or 'Three' for which rowid= 2

rowid   enum_col
1          One
2          Two
3           Three

Result for SELECT id,enum_col FROM tbl_name where rowid=2;


rowid   enum_col
2          Two


Result for SELECT id,enum_col+0 As enum_index FROM tbl_name where rowid=2;


rowid  enum_index
2         2

Copy Constructor for a String class

String.h


#ifndef STRING_H
#define STRING_H
#include "List.h"

class String{
public:
    String();
    ~String();
    String(const String&);
    String(const char*);
    String(List<char> &copy);
    String& operator=(const String &copy);
    const char* c_str() const;
protected:
    char * entry;
    int length;
};
    static bool operator==(const String &first, const String &second);
    static bool operator>(const String &first, const String &second);
    static bool operator<(const String &first, const String &second);
    static bool operator>=(const String &first, const String &second);
    static bool operator<=(const String &first, const String &second);
#endif


String.CPP


#ifndef STRING_CPP
#define STRING_CPP
#include "String.h"
#include <string>
using std::string;

String::String(){
//  entry = NULL;
    length = 0;
}

String::~String(){
    delete entry;
}

String::String(const String &string1 ){
    length = strlen(string1.c_str());
    entry = new char[length+1];
    for (int i=0;i<length;i++)
        entry[i] = string1.c_str()[i];
    entry[length] = '\0';
}

String& String::operator=(const String &copy){
    length = strlen(copy.c_str());
    entry = new char[length+1];
    for (int i=0;i<length;i++)
        entry[i] = copy.c_str()[i];
    entry[length] = '\0';
    return (*this);
}

String::String(const char * CharToString){
    length = strlen(CharToString);
    entry = new char[length+1];
    strcpy_s(entry,length, CharToString);
}

String::String(List<char> &ListChar){
    length = ListChar.Size();
    entry = new char[length+1];
    for (int i=i;i<length;i++)
        ListChar.Retrieve(entry[i],i);
    entry[length] = '\0';
}

const char * String ::c_str() const{
    return (const char*) entry;
}

 static bool operator==(const String &first, const String &second){
    return strcmp(first.c_str(),second.c_str()) == 0;
}

 static bool operator <(const String &first, const String &second){
    return (strcmp(first.c_str(),second.c_str()) < 0);
}

 static bool operator >(const String &first, const String &second){
    return (strcmp(first.c_str(),second.c_str()) > 0);
}

static bool operator <=(const String &first, const String &second){
    return (strcmp(first.c_str(),second.c_str()) <= 0);
}

static bool operator >=(const String &first, const String &second){
    return (strcmp(first.c_str(),second.c_str()) >= 0);
}


#endif

How to Uppercase a character array in One line code

#include<iostream>
#include<algorithm>
#include<conio.h>

using namespace std;

void main( )
{
    char myarray[30]={0};

   sprintf(myarray , "%s","this is my lower case string??");
   cout<<"\nBefore conversion : "<< myarray;
   transform(myarray ,myarray + std::strlen(myarray ), myarray , static_cast<int(*)(int)>(toupper));
  cout<<"\nAfter conversion : "<< myarray;

_getch( );

}


OutPut :

Before conversion : this is my lower case string??
After conversion :  THIS IS MY LOWER CASE STRING??