- fchao-Sinus-Wechselrichter AliExpress         
Ergebnis 1 bis 6 von 6

Thema: JPEG/GIF/BMP->BIN bzw. andersrum

  1. #1
    Erfahrener Benutzer Roboter Experte
    Registriert seit
    25.03.2006
    Ort
    Darmstadt
    Alter
    33
    Beiträge
    522

    JPEG/GIF/BMP->BIN bzw. andersrum

    Anzeige

    Praxistest und DIY Projekte
    Hallo,

    Wie kann man ein JPEG/GIF/BMP(oder ein anderes übliches Bildformat)-Bild nach binär RGB-3-3-2 bzw 5-6-5 umwandeln bzw andersrum? Mit binär meine ich, dass die ersten 2 Bytes die X- und Y-Größe des Bildes darstellen und die restlichen Bytes dann einfach die Pixeldaten von links nach rechts von oben nach unten sind. Sind die Routinen überhaupt freigegeben?

    danke im Voraus

    MfG Mark

  2. #2
    Super-Moderator Robotik Visionär Avatar von PicNick
    Registriert seit
    23.11.2004
    Ort
    Wien
    Beiträge
    6.842
    Schau die doch erstmal die Docu von den ca 847 verschiedenen Graphikspeicherformaten mal an.
    Wenn du dem eine neue, bessere, hinzufügen willst ?
    Ein paar sind frei, ein paar nicht, die nimmt dann aber eh' keiner.

    Laß dir von Windows mit den vorhandenen Funktionen eine "standard" Bitmap machen, die ist genau pixel für pixel das Bild.
    Aus der Map kannst du dann beliebig was neues machen und speichern.
    mfg robert
    Wer glaubt zu wissen, muß wissen, er glaubt.

  3. #3
    Erfahrener Benutzer Roboter Experte
    Registriert seit
    25.03.2006
    Ort
    Darmstadt
    Alter
    33
    Beiträge
    522
    Laß dir von Windows mit den vorhandenen Funktionen eine "standard" Bitmap machen, die ist genau pixel für pixel das Bild.
    Verstehe ich nicht so ganz. Welche Funktion meinst Du?

    Schau die doch erstmal die Docu von den ca 847 verschiedenen Graphikspeicherformaten mal an.
    Wenn du dem eine neue, bessere, hinzufügen willst ?
    Ein paar sind frei, ein paar nicht, die nimmt dann aber eh' keiner.
    Ich möchte kein neues Grafikformat machen, ich habe halt nur eine Kamera, die mir digitale Pixeldaten liefert und ich möchte diese einfach als GIF oder so speichern, damit ich mir diese am PC angucken kann und nicht ständig nur auf dem kleinen Display des Roboters.

    MfG Mark

  4. #4
    Erfahrener Benutzer Robotik Einstein Avatar von SprinterSB
    Registriert seit
    09.06.2005
    Ort
    An der Saar
    Beiträge
    2.802
    Wenn du die Daten nur "roh", also nicht in irgendeinem Standard-Format hast, dann kommst man am besten in die Pötte, indem man das als Windows-Bitmap (bmp, unkomprimiert) abspeichert. Das dann als Palette oder RGB.

    Doc vom Win-BMP:
    Code:
    #ifndef _BMP_BASIC_H_
    #define _BMP_BASIC_H_
    
    #include <inttypes.h>
    
    typedef struct
    {
    	char bfType[2];		// 19778 must always be set to 'BM' to declare that this is a .bmp-file.
    	uint32_t bfSize;		// the size of the file in bytes.
    	uint16_t bfReserved1;	// must always be set to zero.
    	uint16_t bfReserved2;	// must always be set to zero.
    	uint32_t bfOffBits;	// 1078 offset from the beginning of the file to the bitmap data.
    } __attribute__ ((__packed__)) BMPFileHeader;
    
    typedef struct
    {
    	uint32_t biSize;		// 40 size of the BITMAPINFOHEADER structure, in bytes.
    	uint32_t biWidth;		// width of the image, in pixels.
    	uint32_t biHeight;		// height of the image, in pixels.
    	uint16_t biPlanes;		// 1 planes of the target device, must be set to zero.
    	uint16_t biBitCount;	// 8 bits per pixel.
    	uint32_t biCompression; // 0 the type of compression, usually set to zero (no compression).
    	uint32_t biSizeImage;	// 0 the size of the image data, in bytes. If there is no compression, it is valid to set this member to zero.
    	uint32_t biXPelsPerMeter; // 0 usually set to zero.
    	uint32_t biYPelsPerMeter; // 0 usually set to zero.
    	uint32_t biClrUsed;		// 0 number of colors in the bitmap, if zero, the number of colors is calculated using biBitCount
    	uint32_t biClrImportant; // 0 number of color that are 'important' for the bitmap, if zero, all colors are important.
    } __attribute__ ((__packed__)) BMPInfoHeader;
    
    typedef struct
    {
    	uint8_t blue;
    	uint8_t green;
    	uint8_t red;
    	uint8_t Reserved;
    } __attribute__ ((__packed__)) RGBQUAD;
    
    typedef struct
    {
    	BMPFileHeader bmfh;
    	BMPInfoHeader bmih;
    	RGBQUAD		*colors;
    	uint8_t *data;
    	int rowlen;
    } BMP;
    
    
    typedef union
    {
    	struct
    	{
    		uint8_t red;
    		uint8_t green;
    		uint8_t blue;
    	};
    	int index;
    } Color;
    
    #endif /* _BMP_BASIC_H_ */
    
    
    /*
    
    The .bmp file format
    
    Introduction:
    The .bmp file format (sometimes also saved as .dib) is the standard
    for a Windows 3.0 or later DIB(device independent bitmap) file. It may
    use compression (though I never came across a compressed .bmp-file)
    and is (by itself) not capable of storing animation. However, you can
    animate a bitmap using different methods but you have to write the
    code which performs the animation. There are different ways to
    compress a .bmp-file, but I won't explain them here because they are
    so rarely used. The image data itself can either contain pointers to
    entries in a color table or literal RGB values (this is explained
    later).
    
    Basic structure:
    A .bmp file contains of the following data structures:
    
    BITMAPFILEHEADER    bmfh;
    BITMAPINFOHEADER    bmih;
    RGBQUAD             aColors[];
    BYTE                aBitmapBits[];
    
    bmfh contains some information about the bitmap file (about the file,
    not about the bitmap itself). bmih contains information about the
    bitmap such as size, colors,... The aColors array contains a color
    table. The rest is the image data, which format is specified by the
    bmih structure.
    
    Exact structure:
    The following tables give exact information about the data structures
    and also contain the settings for a bitmap with the following
    dimensions: size 100x100, 256 colors, no compression. The start-value
    is the position of the byte in the file at which the explained data
    element of the structure starts, the size-value contains the nuber of
    bytes used by this data element, the name-value is the name assigned
    to this data element by the Microsoft API documentation. Stdvalue
    stands for standard value. There actually is no such a thing as a
    standard value but this is the value Paint assigns to the data element
    if using the bitmap dimensions specified above (100x100x256). The
    meaning-column gives a short explanation of the purpose of this data
    element.
    
    The BITMAPFILEHEADER:
    start 	size 	name 	stdvalue 	purpose
    1 	2 	bfType 	19778 	must always be set to 'BM' to declare that this is a .bmp-file.
    3 	4 	bfSize 	?? 	specifies the size of the file in bytes.
    7 	2 	bfReserved1 	0 	must always be set to zero.
    9 	2 	bfReserved2 	0 	must always be set to zero.
    11 	4 	bfOffBits 	1078 	specifies the offset from the beginning of the file to the bitmap data.
    
    The BITMAPINFOHEADER:
    start 	size 	name 	stdvalue 	purpose
    15 	4 	biSize 	40 	specifies the size of the BITMAPINFOHEADER structure, in bytes.
    19 	4 	biWidth 	100 	specifies the width of the image, in pixels.
    23 	4 	biHeight 	100 	specifies the height of the image, in pixels.
    27 	2 	biPlanes 	1 	specifies the number of planes of the target device, must be set to zero.
    29 	2 	biBitCount 	8 	specifies the number of bits per pixel.
    31 	4 	biCompression 	0 	Specifies the type of compression, usually set to zero (no compression).
    35 	4 	biSizeImage 	0 	specifies the size of the image data, in bytes. If there is no compression, it is valid to set this member to zero.
    39 	4 	biXPelsPerMeter 	0 	specifies the the horizontal pixels per meter on the designated targer device, usually set to zero.
    43 	4 	biYPelsPerMeter 	0 	specifies the the vertical pixels per meter on the designated targer device, usually set to zero.
    47 	4 	biClrUsed 	0 	specifies the number of colors used in the bitmap, if set to zero the number of colors is calculated using the biBitCount member.
    51 	4 	biClrImportant 	0 	specifies the number of color that are 'important' for the bitmap, if set to zero, all colors are important.
    
    Note that biBitCount actually specifies the color resolution of the
    bitmap. The possible values are: 1 (black/white); 4 (16 colors); 8
    (256 colors); 24 (16.7 million colors). The biBitCount data element
    also decides if there is a color table in the file and how it looks
    like. In 1-bit mode the color table has to contain 2 entries (usually
    white and black). If a bit in the image data is clear, it points to
    the first palette entry. If the bit is set, it points to the
    second.
    
    In 4-bit mode the color table must contain 16 colors. Every
    byte in the image data represents two pixels. The byte is split into
    the higher 4 bits and the lower 4 bits and each value of them points
    to a palette entry. There are also standard colors for 16 colors mode
    (16 out of Windows 20 reserved colors (without the entries 8, 9, 246,
    247)). Note that you do not need to use this standard colors if the
    bitmap is to be displayed on a screen which support 256 colors or
    more, however (nearly) every 4-bit image uses this standard colors.
    
    In 8-bit mode every byte represents a pixel. The value points to an entry
    in the color table which contains 256 entries (for details see
    Palettes in Windows.
    
    In 24-bit mode three bytes represent one
    pixel. The first byte represents the red part, the second the green
    and the third the blue part. There is no need for a palette because
    every pixel contains a literal RGB-value, so the palette is omitted.
    
    
    The RGBQUAD array:
    The following table shows a single RGBQUAD structure:
    start 	size 	name 	stdvalue 	purpose
    1 	1 	rgbBlue 	- 	specifies the blue part of the color.
    2 	1 	rgbGreen 	- 	specifies the green part of the color.
    3 	1 	rgbRed 	- 	specifies the red part of the color.
    4 	1 	rgbReserved 	- 	must always be set to zero.
    
    Note that the term palette does not refer to a RGBQUAD array, which is
    called color table instead. Also note that, in a color table
    (RGBQUAD), the specification for a color starts with the blue byte. In
    a palette a color always starts with the red byte. There is no simple
    way to map the whole color table into a LOGPALETTE structure, which
    you will need to display the bitmap. You will have to write a function
    that copies byte after byte.
    
    
    The pixel data:
    It depens on the BITMAPINFOHEADER structure how the pixel data is to
    be interpreted (see above).
    It is important to know that the rows of a DIB are stored upside
    down. That means that the uppest row which appears on the screen
    actually is the lowest row stored in the bitmap, a short example:
    
    
    	
    pixels displayed on the screen 	pixels stored in .bmp-file
    
    You do not need to turn around the rows manually. The API functions
    which also display the bitmap will do that for you automatically.
    
    Another important thing is that the number of bytes in one row must
    always be adjusted to fit into the border of a multiple of four. You
    simply append zero bytes until the number of bytes in a row reaches a
    multiple of four, an example:
    
    
    6 bytes that represent a row in the bitmap: 	A0 37 F2 8B 31 C4
    must be saved as: 	A0 37 F2 8B 31 C4 00 00
    
    to reach the multiple of four which is the next higher after six
    (eight). If you keep these few rules in mind while working with .bmp
    files it should be easy for you, to master it.
    
    */
    Die Implementierung ist dann straight forward :P
    Disclaimer: none. Sue me.

  5. #5
    Erfahrener Benutzer Fleißiges Mitglied
    Registriert seit
    01.03.2006
    Beiträge
    138
    Mich würde da eher Interesieren ob es da ein Application Sheet gibt oder BSPs wie man eine JPEG von z.b. ner SD liest dann auf nem farblcd ausgibt. denn jeder pixel hat ja sein platz.

    MFG

    M.R.

  6. #6
    Erfahrener Benutzer Robotik Einstein Avatar von SprinterSB
    Registriert seit
    09.06.2005
    Ort
    An der Saar
    Beiträge
    2.802
    (i) Man liest das JPEG von der SD
    (ii) Man gibt das JPEG aus

    Teil (i) ist hier wohl nicht interessant, das Datenfprmat ist beim Lesen ja irrelevant. Üblicherweise stellen SDs eine SPI-SChnittstelle zur Verfügung. Wie die Kommandos und electrical Characteristics sind entnimmt man dem Datenblatt.

    (ii) Das JPEG muss erst decodiert werden, also eine DCT (discrete cosine transform) drüberlaufen. Diese Rücktrafo braucht nicht global gemacht zu werden, sondern nur auf einem 8×8 (?) Pixel-Block. Also sich ne Spez besorgen und anfangen zu proggen oder zB in den Linux-, KDE- oder gimp-Quellen schauen, ob da was inspirierendes anbei ist
    Disclaimer: none. Sue me.

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •  

12V Akku bauen