Exploring LSB of Each Byte in a 24-Bit Picture

  • Thread starter hadi amiri 4
  • Start date
  • Tags
    Picture
In summary: Size; //allocating memory for the image data pixel=malloc(raw_data_size); //reading in the image data fread(pixel,raw_data_size,1,fp); //calculating the pointer to the data x=
  • #1
hadi amiri 4
98
1
Hello every body :
i am very new to programming ,i am trying to write a programme that will work on the LSB of each byte in a 24 bit picture.
now my question is how to treat a .bmp file ,i mean can i consider it as an array of integers with leth (for example)800x600.
and start to changing the LSB of bytes after a specific element (0x36 where the image datas strat) or i should define some structure for keeping the different parts of the bmp like header and...

or i should treat it as a binary file or a text file?
 
Technology news on Phys.org
  • #3
A .bmp file is a binary file, not a text file. And you don't want an array of integers, since they won't align with the data in your file, which is 24 bits/pixel, probably with 8 bits each for red, green, and blue. The int data type in C is typically 32 bits, but might be 16 bits for an older compiler.
 
  • #4
I know the internal structure of .bmp and i know that it is made of headers which contains information about the .bmp like width,height ,bitdepth.
but my problem is that how to open it into my program .i have seen lots of codes on the internet that are named for example "bitmaploader" or thing like this which are concerned with complicated structures and use of I/O functions which are far from the contents of what i have learned .my knowledge of programming is very little and i got confused when i go through them can anyone give me some make it more clear for me .
 
  • #5
Sorry, these are not things that can be done without some knowledge. If you don't understand code that you see, you probably need to learn more before trying.

You have to treat the file as binary, open it, read part of the content into header structure, then the rest into allocated memory.
 
  • #6
in page http://en.wikipedia.org/wiki/BMP_file_format" [Broken] at the bottom ther is a table which draws the contents of the a 2x2 bmp pictures
the are in 0x :42 4D 46 00 00 00 00 00 36 00 ...00 FF 00 00 00
so they are separate numbers stored in bytes,and if i (for example) want to modify the LSB of pixels
i start to modifying from the 0x36th byte is it legal?
 
Last edited by a moderator:
  • #7
Borek said:
Sorry, these are not things that can be done without some knowledge. If you don't understand code that you see, you probably need to learn more before trying.

You have to treat the file as binary, open it, read part of the content into header structure, then the rest into allocated memory.

Dear Borek
Can you translate the last sentence into C language i would be very thankful:blushing:
 
  • #8
This is your lucky day, I found something almost ready on my disk. This can be my unlucky day, as I guess posting it I risk of being bombarded with tons of questions about the code. So here goes disclaimer - this is part of an old project, part that I have not tested now. Basically I am posting it 'as is' - I can't guarantee it will work nor I I can't guarantee I will answer any questions you may ask.

Code:
#include "stdafx.h"

int main(int argc, char* argv[])
{
	FILE *f;
	BITMAPINFOHEADER bmphdr;
	BITMAPFILEHEADER bmpfhdr;
	char *pBMP,*pch;
	int iBW;

// open file
	if ((f = fopen("name.bmp","rb")) == NULL) return -1;
// read headers
	fread(&bmpfhdr,sizeof(bmpfhdr),1,f);
	fread(&bmphdr,sizeof(bmphdr),1,f);
// width of the picture as stored in memory - note, it works only for RGB pictures
	iBW = (3*bmphdr.biWidth + 3) & (0xFFFFFFFF ^ 0x3);

// allocate memory for image data
	pBMP = new char[iBW*bmphdr.biHeight];
// read image data
	fread(pBMP,sizeof(char),iBW*bmphdr.biHeight,f);

// calculate pointer to point at coordinates (100,100)
	int x = 100, y = 100; 
	pch = pBMP + 3*x + (bmphdr.biHeight-y-1)*iBW;

	fclose(f);

	delete pBMP;

	return 0;
}

To save file to disk write same data in the same order to file.

Note that you may expect problems with signed/unsigned char when trying to modify picture in memory, I don't remember what were compiler settings at the time.
 
  • #9
Thank you Borek for this piece of code.i will go to implement it to what i want.and don't worry i will not bombard you with questions until i read it (the codes)carefully and check my courses stuff.but be ready !
 
  • #10
Code:
what is wrong with this code?

typedef unsigned long DWORD;
typedef unsigned short WORD;


typedef struct {
    int Signature;
	DWORD Size;
	DWORD Reserved;
	DWORD BitsOffset;
} BITMAP_FILEHEADER;


typedef struct {
	DWORD HeaderSize;
	DWORD Width;
	DWORD Height;
	WORD Planes;
	WORD BitCount;
	DWORD Compression;
	DWORD SizeImage;
	DWORD PelsPerMeterX;
	DWORD PelsPerMeterY;
	DWORD ClrUsed;
	DWORD ClrImportant;

} BITMAP_HEADER;

#include <stdio.h>
main()
{
    FILE * fp;
    BITMAP_FILEHEADER bmpheader;
    BITMAP_HEADER bmpinfheader;
    int raw_data_size;
    char *pixel;

    //openning file
    fp=fopen("c:\\pic.bmp","rb");

    /*if(fp==NULL){
        printf("error in opennig file");
        exit(1);
    }*/



    fread(&bmpheader,sizeof(bmpheader),1,fp);//reads the header
    fread(&bmpinfheader,sizeof(bmpinfheader),1,fp);//reads the info header

    raw_data_size=bmpheader.SizeImage;//stores the size of raw bitmaps

    pixel=new char [raw_data_size];//create an array for holding the pixels

    fread(pixel,sizeof(char),raw_data_size,fp);//reads them from memory to aray

    printf("%x",bmpheader.Signature);//prints 424D

    fclose(fp);
    return 0;
}
 

1. What is the purpose of exploring the LSB of each byte in a 24-bit picture?

The purpose of exploring the LSB (Least Significant Bit) of each byte in a 24-bit picture is to extract hidden information or data that may be embedded within the image. This technique is often used in steganography, which is the practice of concealing a message within another medium.

2. How is the LSB of a byte determined in a 24-bit picture?

In a 24-bit picture, each pixel is represented by three bytes - one for red, green, and blue color values. The LSB of each byte is the least significant bit, or the rightmost bit, which determines the color intensity of that particular color channel. For example, a binary value of 00000001 would represent the lowest possible intensity for that color, while a value of 11111110 would represent the highest intensity.

3. What techniques are used to explore the LSB of each byte in a 24-bit picture?

There are several techniques that can be used to explore the LSB of each byte in a 24-bit picture. One common technique is to compare the values of the LSB across all pixels in the image and look for any patterns or discrepancies. Another technique is to use specialized software or algorithms to analyze the LSB values and extract any hidden information.

4. What type of information can be hidden within the LSB of each byte in a 24-bit picture?

Any type of digital information can be hidden within the LSB of each byte in a 24-bit picture, including text, images, and even executable files. The amount of information that can be hidden depends on the size of the image and the complexity of the encoding algorithm used.

5. Are there any ethical concerns surrounding the exploration of LSB in 24-bit pictures?

There are ethical concerns surrounding the exploration of LSB in 24-bit pictures, particularly in regards to privacy and security. The technique can be used for both legitimate purposes, such as digital watermarking, and malicious purposes, such as hiding malware or illegal content. It is important for researchers and practitioners to consider these concerns and use this technique responsibly.

Similar threads

Replies
1
Views
550
  • Programming and Computer Science
Replies
5
Views
737
  • Engineering and Comp Sci Homework Help
Replies
8
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
892
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
33
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
4K
  • Programming and Computer Science
Replies
1
Views
3K
  • Programming and Computer Science
Replies
7
Views
3K
Back
Top