ASCII/BIN Art aus JPEG Thema ist als GELÖST markiert

Alles Rund um SAP®.
10 Beiträge • Seite 1 von 1
10 Beiträge Seite 1 von 1

ASCII/BIN Art aus JPEG

Beitrag von Ichse2 (ForumUser / 12 / 3 / 0 ) » 17.01.2020 13:17
Guten Tag,
Ich beschäftige mich aktuell mit ASCII Art, also ein Bild einzugeben und dieses in ASCII-Zeichen nachzuzeichnen. Für diese Problemstellung hatte ich den Ansatz, die JPEG-Datei mit Hilfe des GUI_UPLOAD in SAP zu lesen und diesen mir als Hex-Wert anzeigen zu lassen. Die Problematik auf die ich dabei sties ist, dass es nirgends Informationen zum Aufbau einer JPEG-Datei in Hexadezimal gibt. Falls jemand eine Idee hat wie ich in dieser Ausgangssituation nun auf die jeweiligen Pixel des Bildes zugreifen kann um deren Farbwert auszulesen, einen komplett anderen einfacheren Ansatz oder evtl auch nur Informationen zum Aufbau der JPEG in Hexadezimal Struktur besitzt wäre ich über Hilfe sehr dankbar.
Vielen Dank im Voraus,
mfg Ichse2


Re: ASCII/BIN Art aus JPEG

Beitrag von jocoder (Specialist / 203 / 3 / 55 ) » 20.01.2020 10:54
Dafür ist ABAP nicht unbedingt die beste Wahl.
In anderen Programmiersprachen gibt es dafür bestimmt vorgefertigte Bibliotheken. Aber in ABAP wird das vermutlich ein Großprojekt.

Re: ASCII/BIN Art aus JPEG

Beitrag von fr-g (ForumUser / 57 / 6 / 19 ) » 20.01.2020 12:34
Zwei Zeilen weit in den Wikipedia-Artikel gelesen, beantworten schon einiges:
Ichse2 hat geschrieben:
17.01.2020 13:17
Die Problematik auf die ich dabei sties ist, dass es nirgends Informationen zum Aufbau einer JPEG-Datei in Hexadezimal gibt.
https://jpeg.org/jpeg/workplan.html

Ichse2 hat geschrieben:
17.01.2020 13:17
Falls jemand eine Idee hat wie ich in dieser Ausgangssituation nun auf die jeweiligen Pixel des Bildes zugreifen kann um deren Farbwert auszulesen, einen komplett anderen einfacheren Ansatz oder evtl auch nur Informationen zum Aufbau der JPEG in Hexadezimal Struktur besitzt wäre ich über Hilfe sehr dankbar.
JPEG ist ein Set von Kompressionsmethoden ;) Du möchtest aber bestenfalls eine unkomprimierte Rastergrafik. Da ist JPEG nicht das ideale Format, vielleicht eher BMP o.ä. .... ansonsten was jocoder sagt.

Re: ASCII/BIN Art aus JPEG

Beitrag von edwin (Specialist / 295 / 7 / 63 ) » 20.01.2020 14:28
Hi,
schau dir mal das an :
ABAP Bitmap Image Processing Class




edit :
Link entfernt - funktioniert leider nicht mehr :-((


/Edwin

Folgende Benutzer bedankten sich beim Autor edwin für den Beitrag:
fr-g


Re: ASCII/BIN Art aus JPEG

Beitrag von fr-g (ForumUser / 57 / 6 / 19 ) » 20.01.2020 16:14
edwin hat geschrieben:
20.01.2020 14:28
Hi,
schau dir mal das an :
ABAP Bitmap Image Processing Class




edit :
Link entfernt - funktioniert leider nicht mehr :-((


/Edwin
Die Links funktionieren leider nicht mehr, aber die benutzten Klassen CL_IGS_* (und überhaupt das Paket SPIG) sind durchaus einen Blick wert. Die kannte ich noch so gar nicht ^^

Re: ASCII/BIN Art aus JPEG

Beitrag von edwin (Specialist / 295 / 7 / 63 ) » 20.01.2020 21:40
schau mal auch mal die CL_FXS_IMAGE* Klassen an, als Bsp. noch diesen Beitrag :
https://codezentrale.de/abap-mit-hilfe- ... n-convert/
/Edwin

Re: ASCII/BIN Art aus JPEG

Beitrag von edwin (Specialist / 295 / 7 / 63 ) » 21.01.2020 23:33
Hallo zusammen,
es hat mich doch gepackt - und das ist das Ergebnis (der Code ist nicht schön - ist mir aber egal).
zuerst wird ein Bild(jpg/png..) in BMP umgewandelt, damit man auf die einzelne Pixel zugreifen kann, dann wird das ganze in Graustufen umgewandelt und die Graustufen einzelnen Zeichen zugeordnet.
Problem : je nach Zeichensatz (Höhe/Breite der Zeichen) muss bei der Skalierung des Bildes mit den Einstellungen etwas gespielt werden, sonst sieht das Ergebnis unförmig aus, und das geht nur mit einer monospaces Schrift.

Viel Spass

Code: Alles auswählen.

REPORT zzasciitpic LINE-SIZE 512.
* Dateiname der Bilddatei zum hochladen
PARAMETERS: p_fname TYPE string lower case OBLIGATORY.
PARAMETERS: p_width TYPE i DEFAULT 255.
PARAMETERS: p_height TYPE i DEFAULT 200.

DEFINE read2.     "#EC NEEDED read two bytes as integer and move offset
  w2     = &1.
  CONCATENATE w2+1(1) w2+0(1) INTO xstr IN BYTE MODE.
  &2     = xstr.
END-OF-DEFINITION.
DEFINE write2.    "#EC NEEDED read two bytes as integer and move offset
  w2     = &1.
  CONCATENATE w2+1(1) w2+0(1) INTO xstr IN BYTE MODE.
  &2     = xstr.
END-OF-DEFINITION.
DEFINE read3.     "#EC NEEDED read two bytes as integer and move offset
  w3     = &1.
  CONCATENATE w3+2(1) w3+1(1) w3+0(1) INTO xstr IN BYTE MODE.
  &2     = xstr.
END-OF-DEFINITION.
DEFINE read4.    "#EC NEEDED read four bytes as integer and move offset
  w4     = &1.
  CONCATENATE w4+3(1) w4+2(1) w4+1(1) w4+0(1) INTO xstr IN BYTE MODE.
  &2     = xstr.
END-OF-DEFINITION.
DEFINE write4.   "#EC NEEDED read four bytes as integer and move offset
  w4     = &1.
  CONCATENATE w4+3(1) w4+2(1) w4+1(1) w4+0(1) INTO xstr IN BYTE MODE.
  &2     = xstr.
END-OF-DEFINITION.

DATA it_bb TYPE TABLE OF string.
DATA bb    TYPE string.
DATA pix   TYPE c LENGTH 1.

TYPES:    gt_2byte_value(2) TYPE x .
*TYPES:    gt_3byte_value(3) TYPE x .
TYPES:    gt_4byte_value(4) TYPE x .

constants co_blue  type p decimals 4 value '0.1140'.
constants co_red   type p decimals 4 value '0.2989'.
constants co_green type p decimals 4 value '0.5870'.

DATA magic_number TYPE gt_2byte_value.
data lv_img_conv_data  type xstring.

DATA w2 TYPE gt_2byte_value.
*DATA w3 TYPE gt_3byte_value.
DATA w4 TYPE gt_4byte_value.
DATA xstr   TYPE xstring.
DATA size   TYPE i.
DATA header_size TYPE i.
DATA width TYPE i.
DATA height TYPE i.
DATA bpp         TYPE i.
DATA data_offset TYPE i.
DATA colors_used TYPE i.
DATA color_planes TYPE i.
DATA retc         type sy-subrc.

*--------------------------------------------------------------------*
* wenn die F4-Hilfe für den Dateinamen aufgerufen wird
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.

  DATA: lv_rc TYPE i.
  DATA: it_files TYPE filetable.
  DATA: lv_action TYPE i.

* File-Tabelle leeren, da hier noch alte Einträge von vorherigen Aufrufen drin stehen können
  CLEAR it_files.

* FileOpen-Dialog aufrufen
  TRY.
      cl_gui_frontend_services=>file_open_dialog( EXPORTING
                                                    file_filter = |jpg (*.jpg)\|*.jpg\|{ cl_gui_frontend_services=>filetype_all }|
                                                  CHANGING
                                                    file_table  = it_files
                                                    rc          = lv_rc
                                                    user_action = lv_action ).

      IF lv_action = cl_gui_frontend_services=>action_ok.
* wenn Datei ausgewählt wurde
        IF lines( it_files ) > 0.
* ersten Tabelleneintrag lesen
          p_fname = it_files[ 1 ]-filename.
        ENDIF.
      ENDIF.

    CATCH cx_root INTO DATA(e_text).
      MESSAGE e_text->get_text( ) TYPE 'S' DISPLAY LIKE 'E'.
  ENDTRY.



START-OF-SELECTION.
  PERFORM read_picture_convert_to_bmp changing retc.
  if retc eq 0.
     PERFORM create_ascii_pic.
  endif.

*--------------------------------------------------------------------*
FORM set_pic USING x_pix TYPE i
             CHANGING c_pix TYPE c.
  c_pix = ' '.

  IF x_pix   < 240.    c_pix = '.'. ENDIF.
  IF x_pix   < 210.    c_pix = '-'. ENDIF.
  IF x_pix   < 180.    c_pix = ':'. ENDIF.
  IF x_pix   < 160.    c_pix = ';'. ENDIF.
*  IF x_pix   < 160.    c_pix = '!'. ENDIF.
*  IF x_pix   < 140.    c_pix = '³'. ENDIF.
  IF x_pix   < 120.    c_pix = '+'. ENDIF.
  IF x_pix   < 100.    c_pix = '*'. ENDIF.
  IF x_pix   < 080.    c_pix = 'C'. ENDIF.
  IF x_pix   < 060.    c_pix = 'Y'. ENDIF.
*  IF x_pix   < 010.    c_pix = 'X'. ENDIF.
  IF x_pix   < 040.    c_pix = '§'. ENDIF.


*  IF x_pix   < 240.    c_pix = '.'. ENDIF.
*  IF x_pix   < 220.    c_pix = '-'. ENDIF.
*  IF x_pix   < 200.    c_pix = ':'. ENDIF.
*  IF x_pix   < 180.    c_pix = ';'. ENDIF.
*  IF x_pix   < 160.    c_pix = '!'. ENDIF.
*  IF x_pix   < 140.    c_pix = '³'. ENDIF.
*  IF x_pix   < 120.    c_pix = '+'. ENDIF.
*  IF x_pix   < 100.    c_pix = '*'. ENDIF.
*  IF x_pix   < 080.    c_pix = 'C'. ENDIF.
*  IF x_pix   < 060.    c_pix = 'Y'. ENDIF.
*  IF x_pix   < 040.    c_pix = 'X'. ENDIF.
*  IF x_pix   < 020.    c_pix = '§'. ENDIF.


***  IF x_pix   < 240.    c_pix = '.'. ENDIF.
***  IF x_pix   < 220.    c_pix = '-'. ENDIF.
***  IF x_pix   < 200.    c_pix = ':'. ENDIF.
****  IF x_pix   < 180.    c_pix = ','. ENDIF.
***  IF x_pix   < 160.    c_pix = ';'. ENDIF.
****  IF x_pix   < 140.    c_pix = '!'. ENDIF.
***  IF x_pix   < 120.    c_pix = '³'. ENDIF.
***  IF x_pix   < 100.    c_pix = '+'. ENDIF.
***  IF x_pix   < 080.    c_pix = '*'. ENDIF.
***  IF x_pix   < 060.    c_pix = 'X'. ENDIF.
****  IF x_pix   < 040.    c_pix = '8'. ENDIF.
***  IF x_pix   < 020.    c_pix = '§'. ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  READ_PICTURE_CONVERT_TO_BMP
*&---------------------------------------------------------------------*
FORM read_picture_convert_to_bmp changing rc type sy-subrc.
  TRY.
      DATA: lv_filesize TYPE w3param-cont_len.
*      DATA: lv_filetype TYPE w3param-cont_type.
      DATA: it_bin_data TYPE w3mimetabtype.
      DATA: lv_mimetype TYPE string.
      DATA: lv_xres     TYPE i.
      DATA: lv_yres     TYPE i.
      DATA: lv_xdpi     TYPE i.
      DATA: lv_ydpi     TYPE i.
      DATA: lv_bitdepth TYPE i.
      rc = 0.

* Bild auf Appl. Server hochladen (binary)
      cl_gui_frontend_services=>gui_upload( EXPORTING filename   = |{ p_fname }|
                                                      filetype   = 'BIN'
                                            IMPORTING filelength = lv_filesize
                                            CHANGING  data_tab   = it_bin_data ).

* solix -> xstring
      DATA(lv_img_data) = cl_bcs_convert=>solix_to_xstring( it_solix = it_bin_data ).

* FXS-Objekt holen
      DATA(o_ip) = NEW cl_fxs_image_processor( ).

* Bild zum Konverter hinzufügen
      DATA(lv_hndl) = o_ip->add_image( iv_data = lv_img_data ).

* Infos holen
      o_ip->get_info( EXPORTING iv_handle   = lv_hndl
                      IMPORTING ev_mimetype = lv_mimetype
                                ev_xres     = lv_xres
                                ev_yres     = lv_yres
                                ev_xdpi     = lv_xdpi
                                ev_ydpi     = lv_ydpi
                                ev_bitdepth = lv_bitdepth ).

* Infos ausgeben
      WRITE: / 'MIME-Type:', lv_mimetype.
      WRITE: / '        X:', lv_xres.
      WRITE: / '        Y:', lv_yres.
      WRITE: / '    X-DPI:', lv_xdpi.
      WRITE: / '    Y-DPI:', lv_ydpi.
      WRITE: / '      Bit:', lv_bitdepth.

* Größe ändern (Resize)
      o_ip->resize( EXPORTING iv_handle = lv_hndl
                              iv_xres   = p_width
                              iv_yres   = p_height ).

* Konvertierung (Convert) nach JPG
* Zielformate können nur sein (andernfalls gibt es eine Exception vom Typ cx_sy_range_out_of_bounds):
*   cl_fxs_mime_types=>co_image_bitmap
*   cl_fxs_mime_types=>co_image_png
*   cl_fxs_mime_types=>co_image_jpeg
      o_ip->convert( EXPORTING iv_handle = lv_hndl
                               iv_format = cl_fxs_mime_types=>co_image_bitmap ).

* Infos holen
      o_ip->get_info( EXPORTING iv_handle   = lv_hndl
                      IMPORTING ev_mimetype = lv_mimetype
                                ev_xres     = lv_xres
                                ev_yres     = lv_yres
                                ev_xdpi     = lv_xdpi
                                ev_ydpi     = lv_ydpi
                                ev_bitdepth = lv_bitdepth ).

* Infos ausgeben
      WRITE: / 'MIME-Type:', lv_mimetype.
      WRITE: / '        X:', lv_xres.
      WRITE: / '        Y:', lv_yres.
      WRITE: / '    X-DPI:', lv_xdpi.
      WRITE: / '    Y-DPI:', lv_ydpi.
      WRITE: / '      Bit:', lv_bitdepth.

* Binärdaten (xstring) des Bildes holen
      lv_img_conv_data = o_ip->get_image( EXPORTING iv_handle = lv_hndl ).

*** xstring -> solix
**      DATA(it_img_conv_data) = cl_bcs_convert=>xstring_to_solix( iv_xstring = lv_img_conv_data ).
**
**      WRITE: / |{ p_fname }.bmp|.
**
*** Image lokal speichern
**      cl_gui_frontend_services=>gui_download( EXPORTING
**                                                filename     = |{ p_fname }.bmp|
**                                                filetype     = 'BIN'
**                                                bin_filesize = xstrlen( lv_img_conv_data )
**                                              CHANGING
**                                                data_tab     = it_img_conv_data ).
**
    CATCH cx_root INTO DATA(e_txt).
      WRITE: / e_txt->get_text( ).
      rc = 8.
  ENDTRY.
ENDFORM.
*--------------------------------------------------------------------*
* FORM Create_ascii_pic.
*--------------------------------------------------------------------*
FORM Create_ascii_pic.

  DATA x_width(4)        TYPE x.
  DATA x_height(4)       TYPE x.
  DATA x_bpp(2)          TYPE x.
  DATA x_compression(4)  TYPE x.
  DATA i_compression     TYPE i.
  DATA x_color_planes(2) TYPE x.
  DATA x_colors_used(4)  TYPE x.
  DATA x_header_size(4)  TYPE x.
  DATA x_data_offset(4)  TYPE x.
  DATA x_size(4)         TYPE x.

  magic_number     = lv_img_conv_data+0(2).
  x_size           = lv_img_conv_data+2(4).
  x_data_offset    = lv_img_conv_data+10(4).
  x_header_size    = lv_img_conv_data+14(4).
  read4 x_size size.
  read4 x_data_offset data_offset.
  read4 x_header_size header_size.

* Bitmap Header
  IF header_size = 40. "Windows V3 Format
    x_width        = lv_img_conv_data+18(4).
    x_height       = lv_img_conv_data+22(4).
    x_bpp          = lv_img_conv_data+28(2).
    x_compression  = lv_img_conv_data+30(4).
    x_color_planes = lv_img_conv_data+26(2).
    x_colors_used  = lv_img_conv_data+46(4).
    read4 x_width  width.
    read4 x_height height.
    read2 x_bpp    bpp.
    read4 x_compression i_compression.
    read2 x_color_planes color_planes.
    read4 x_colors_used colors_used.
  ELSE.
    RETURN.
  ENDIF.

  DATA x_data          TYPE xstring.
  DATA x_row           TYPE xstring.
  DATA i_num_pixels    TYPE i.
  DATA i_counter       TYPE i.
  DATA i_counter2      TYPE i.
  DATA l_width         TYPE i.
  DATA bytes_per_pixel TYPE i.
  DATA l_len           TYPE i.
  DATA pad             TYPE i.
  DATA l_mod           TYPE i.
  DATA l_size          TYPE i.
  DATA l_blue          TYPE i.
  DATA l_red           TYPE i.
  DATA l_green         TYPE i.
  DATA x_pixel         TYPE xstring.
  DATA l_scale         TYPE i.

  x_data          = lv_img_conv_data+data_offset.
  bytes_per_pixel = bpp / 8.

  l_width         = width * bytes_per_pixel.
  i_num_pixels    = width.

  l_mod  = l_width MOD 4.
  pad    = 4 - l_mod.
  IF pad = 4. pad = 0.  ENDIF.

  l_width = l_width + pad.
  l_len = xstrlen( x_data ).
*  new_width = width + pad.
  l_size = bytes_per_pixel.


  DO height TIMES.
    x_row = x_data+i_counter(l_width).
    CLEAR i_counter2.
    CLEAR bb.
    DO i_num_pixels TIMES.
      x_pixel =  x_row+i_counter2(bytes_per_pixel).

      l_blue = x_pixel+0(1).
      l_red = x_pixel+1(1).
      l_green = x_pixel+2(1).

* in Graustufen umrechnen
      l_scale = l_blue * co_blue + l_red * co_red + l_green  * co_green.

*     255  - weiss
* Graustufen in Buchstaben umsetzen
      PERFORM set_pic USING l_scale
                      CHANGING pix.

      CONCATENATE bb pix INTO bb RESPECTING BLANKS.

      i_counter2 = i_counter2 + bytes_per_pixel.
    ENDDO.

    INSERT bb INTO it_bb INDEX 1.
    i_counter = i_counter + l_width.
  ENDDO.

  LOOP AT it_bb INTO bb.
    WRITE : / bb.
  ENDLOOP.

ENDFORM.
und so sieht das Ergebnis aus:
Quelle : JPG, X: 630 Y : 472
Skaliert auf X:190 Y:70
Eregbnis in Notepad kopiert und Schriftart mononoki 7

Hier das Bild
/Edwin

Folgende Benutzer bedankten sich beim Autor edwin für den Beitrag (Insgesamt 5):
tm987456ewxHaubia-dead-trousersIHe


Re: ASCII/BIN Art aus JPEG

Beitrag von ewx (Top Expert / 4244 / 200 / 444 ) » 22.01.2020 11:22
Geil! 🤩

Re: ASCII/BIN Art aus JPEG

Beitrag von edwin (Specialist / 295 / 7 / 63 ) » 22.01.2020 11:53
Hi,

habe vor noch Kontrast / Helligkeitsänderung einzubauen 😊

/Edwin

Re: ASCII/BIN Art aus JPEG

Beitrag von edwin (Specialist / 295 / 7 / 63 ) » 22.01.2020 21:18
Hi,
neue Version

- Änderung des Kontrastes ( 0 bis 254 höher, -254 bis 0 weniger Kontrast)
- Änderung der Helligkeit (von 0,01 - 0,99- dunkler, > 1,00 heller )
- "Undo" - Änderungen verwerfen und auf Original zurücksetzten
- Neue Skalierung ohne Programm zu verlassen

die Funktionen sind direkt auf der Ausgabeliste erreichbar (Icons mit Hotspot)

Viel Spass
Grüße Edwin

Code: Alles auswählen.

REPORT zzasciitpic LINE-SIZE 512 NO STANDARD PAGE HEADING.
* Dateiname der Bilddatei zum hochladen
PARAMETERS: p_fname TYPE string LOWER CASE OBLIGATORY.
PARAMETERS: p_width TYPE i DEFAULT 255.
PARAMETERS: p_height TYPE i DEFAULT 200.

SELECTION-SCREEN BEGIN OF SCREEN 0200 AS WINDOW.
* Kontrast   -255 bis +255, bei 0 keine Änderung
PARAMETERS: p_con    TYPE i DEFAULT 0.
SELECTION-SCREEN END   OF SCREEN 0200.


SELECTION-SCREEN BEGIN OF SCREEN 0201 AS WINDOW.
*Helligkeit 0,00 bis ca 3,00 bei 0 keine Änderung  0,1 dunkel 3,00 sehr hell
PARAMETERS: p_bri    TYPE p DECIMALS 2 DEFAULT 0.
SELECTION-SCREEN END   OF SCREEN 0201.

SELECTION-SCREEN BEGIN OF SCREEN 0202 AS WINDOW.
PARAMETER : p_mime     TYPE string.
PARAMETER : p_xres     TYPE i.
PARAMETER : p_yres     TYPE i.
PARAMETER : p_xdpi     TYPE i.
PARAMETER : p_ydpi     TYPE i.
PARAMETER : p_bitdep   TYPE i.
SELECTION-SCREEN END   OF SCREEN 0202.

SELECTION-SCREEN BEGIN OF SCREEN 0203 AS WINDOW.
PARAMETERS: p_w      TYPE i.
PARAMETERS: p_h      TYPE i.
SELECTION-SCREEN END   OF SCREEN 0203.

TYPES : ty_contr_array TYPE x LENGTH 256.
*TYPES : ty_factor      TYPE p DECIMALS 2.

DEFINE read2.     "#EC NEEDED read two bytes as integer and move offset
  w2     = &1.
  CONCATENATE w2+1(1) w2+0(1) INTO xstr IN BYTE MODE.
  &2     = xstr.
END-OF-DEFINITION.
DEFINE write2.    "#EC NEEDED read two bytes as integer and move offset
  w2     = &1.
  CONCATENATE w2+1(1) w2+0(1) INTO xstr IN BYTE MODE.
  &2     = xstr.
END-OF-DEFINITION.
DEFINE read3.     "#EC NEEDED read two bytes as integer and move offset
  w3     = &1.
  CONCATENATE w3+2(1) w3+1(1) w3+0(1) INTO xstr IN BYTE MODE.
  &2     = xstr.
END-OF-DEFINITION.
DEFINE read4.    "#EC NEEDED read four bytes as integer and move offset
  w4     = &1.
  CONCATENATE w4+3(1) w4+2(1) w4+1(1) w4+0(1) INTO xstr IN BYTE MODE.
  &2     = xstr.
END-OF-DEFINITION.
DEFINE write4.   "#EC NEEDED read four bytes as integer and move offset
  w4     = &1.
  CONCATENATE w4+3(1) w4+2(1) w4+1(1) w4+0(1) INTO xstr IN BYTE MODE.
  &2     = xstr.
END-OF-DEFINITION.

DATA it_bb TYPE TABLE OF string.
DATA bb    TYPE string.
DATA pix   TYPE c LENGTH 1.

TYPES:    gt_2byte_value(2) TYPE x .
TYPES:    gt_4byte_value(4) TYPE x .

CONSTANTS co_blue  TYPE p DECIMALS 4 VALUE '0.1140'.
CONSTANTS co_red   TYPE p DECIMALS 4 VALUE '0.2989'.
CONSTANTS co_green TYPE p DECIMALS 4 VALUE '0.5870'.

DATA magic_number      TYPE gt_2byte_value.
DATA lv_img_conv_data  TYPE xstring.

DATA w2           TYPE gt_2byte_value.
DATA w4           TYPE gt_4byte_value.
DATA xstr         TYPE xstring.
*DATA size         TYPE i.
DATA header_size  TYPE i.
DATA width        TYPE i.
DATA height       TYPE i.
DATA bpp          TYPE i.
DATA data_offset  TYPE i.
*DATA colors_used  TYPE i.
*DATA color_planes TYPE i.
DATA retc         TYPE sy-subrc.
DATA cont_array   TYPE ty_contr_array.
*Save grayscale image
DATA xbmp_gray    TYPE xstring.
DATA xbmp_work    TYPE xstring.
DATA xbmp_first   TYPE flag VALUE 'X'.
DATA xpix         TYPE x.
DATA but_down          TYPE c LENGTH 1.

FIELD-SYMBOLS <scr_in>  TYPE any.
FIELD-SYMBOLS <scr_out> TYPE any.

DATA va_p_con     TYPE string VALUE 'Änderung Kontrast'.
DATA va_p_bri     TYPE string VALUE 'Änderung Helligkeit'.
DATA va_p_fname   TYPE string VALUE 'Wähle Bild'.
DATA va_p_width   TYPE string VALUE 'X(Bildbreite)'.
DATA va_p_height  TYPE string VALUE 'Y(Bildhöhe)'.

DATA va_p_mime    TYPE string VALUE 'MimeType'.
DATA va_p_xres    TYPE string VALUE 'X-Auflösung'.
DATA va_p_yres    TYPE string VALUE 'Y-Auflösung'.
DATA va_p_xdpi    TYPE string VALUE 'X-DPI'.
DATA va_p_ydpi    TYPE string VALUE 'Y-DPI'.
DATA va_p_bitdep  TYPE string VALUE 'Farbiefe(bit)'.

* Texte setzen
INITIALIZATION.
  UNASSIGN <scr_in>.
  ASSIGN ('%_P_FNAME_%_APP_%-TEXT') TO <scr_in> .
  IF <scr_in> IS ASSIGNED. <scr_in> = va_p_fname.   ENDIF.
  UNASSIGN <scr_in>.
  ASSIGN ('%_P_WIDTH_%_APP_%-TEXT') TO <scr_in> .
  IF <scr_in> IS ASSIGNED. <scr_in> = va_p_width.   ENDIF.
  UNASSIGN <scr_in>.
  ASSIGN ('%_P_HEIGHT_%_APP_%-TEXT') TO <scr_in> .
  IF <scr_in> IS ASSIGNED. <scr_in> = va_p_height.   ENDIF.

AT SELECTION-SCREEN OUTPUT.
  CASE sy-dynnr.
    WHEN '0203'.
      UNASSIGN <scr_in>.
      ASSIGN ('%_P_W_%_APP_%-TEXT') TO <scr_in> .
      IF <scr_in> IS ASSIGNED. <scr_in> = va_p_width.   ENDIF.
      UNASSIGN <scr_in>.
      ASSIGN ('%_P_H_%_APP_%-TEXT') TO <scr_in> .
      IF <scr_in> IS ASSIGNED. <scr_in> = va_p_height.   ENDIF.
    WHEN '0202'.
      UNASSIGN <scr_in>.
      ASSIGN ('%_P_BITDEP_%_APP_%-TEXT') TO <scr_in> .
      IF <scr_in> IS ASSIGNED. <scr_in> = va_p_bitdep.   ENDIF.
      UNASSIGN <scr_in>.
      ASSIGN ('%_P_MIME_%_APP_%-TEXT') TO <scr_in> .
      IF <scr_in> IS ASSIGNED. <scr_in> = va_p_mime.   ENDIF.
      UNASSIGN <scr_in>.
      ASSIGN ('%_P_XRES_%_APP_%-TEXT') TO <scr_in> .
      IF <scr_in> IS ASSIGNED. <scr_in> = va_p_xres.   ENDIF.
      UNASSIGN <scr_in>.
      ASSIGN ('%_P_YRES_%_APP_%-TEXT') TO <scr_in> .
      IF <scr_in> IS ASSIGNED. <scr_in> = va_p_yres.   ENDIF.
      UNASSIGN <scr_in>.
      ASSIGN ('%_P_XDPI_%_APP_%-TEXT') TO <scr_in> .
      IF <scr_in> IS ASSIGNED. <scr_in> = va_p_xdpi.   ENDIF.
      UNASSIGN <scr_in>.
      ASSIGN ('%_P_YDPI_%_APP_%-TEXT') TO <scr_in> .
      IF <scr_in> IS ASSIGNED. <scr_in> = va_p_ydpi.   ENDIF.
      LOOP AT SCREEN.
        screen-input = '0'.
        MODIFY SCREEN.
      ENDLOOP.
    WHEN '0201'.
      UNASSIGN <scr_in>.
      ASSIGN ('%_P_BRI_%_APP_%-TEXT') TO <scr_in> .
      IF <scr_in> IS ASSIGNED. <scr_in> = va_p_bri.   ENDIF.
    WHEN '0200'.
      UNASSIGN <scr_in>.
      ASSIGN ('%_P_CON_%_APP_%-TEXT') TO <scr_in> .
      IF <scr_in> IS ASSIGNED. <scr_in> = va_p_con.   ENDIF.
  ENDCASE.

AT LINE-SELECTION.
  PERFORM at_line_selection.

AT USER-COMMAND.
  IF sy-ucomm = 'DOWN'.
    PERFORM get_check_ucomm.
  ENDIF.

*--------------------------------------------------------------------*
* wenn die F4-Hilfe für den Dateinamen aufgerufen wird
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.

  DATA: lv_rc TYPE i.
  DATA: it_files TYPE filetable.
  DATA: lv_action TYPE i.

* File-Tabelle leeren, da hier noch alte Einträge von vorherigen Aufrufen drin stehen können
  CLEAR it_files.

* FileOpen-Dialog aufrufen
  TRY.
      cl_gui_frontend_services=>file_open_dialog( EXPORTING
                                                    file_filter = |jpg (*.jpg)\|*.jpg\|{ cl_gui_frontend_services=>filetype_all }|
                                                  CHANGING
                                                    file_table  = it_files
                                                    rc          = lv_rc
                                                    user_action = lv_action ).

      IF lv_action = cl_gui_frontend_services=>action_ok.
* wenn Datei ausgewählt wurde
        IF lines( it_files ) > 0.
* ersten Tabelleneintrag lesen
          p_fname = it_files[ 1 ]-filename.
        ENDIF.
      ENDIF.

    CATCH cx_root INTO DATA(e_text).
      MESSAGE e_text->get_text( ) TYPE 'S' DISPLAY LIKE 'E'.
  ENDTRY.


*--------------------------------------------------------------------*
START-OF-SELECTION.
  IF p_con >  255. p_con = 255.  ENDIF.
  IF p_con < -255. p_con = -255. ENDIF.
  PERFORM read_picture_convert_to_bmp CHANGING retc.

  IF  p_con NE 0.
    PERFORM create_contr_array USING    p_con
                               CHANGING cont_array.
  ENDIF.

  IF retc EQ 0.
    PERFORM create_ascii_pic.
    PERFORM show_pic.
  ENDIF.

*--------------------------------------------------------------------*
FORM set_pic USING x_pix TYPE i
             CHANGING c_pix TYPE c.
  c_pix = ' '.

  IF x_pix   < 240.    c_pix = '.'. ENDIF.
  IF x_pix   < 210.    c_pix = '-'. ENDIF.
  IF x_pix   < 180.    c_pix = ':'. ENDIF.
  IF x_pix   < 160.    c_pix = ';'. ENDIF.
*  IF x_pix   < 160.    c_pix = '!'. ENDIF.
*  IF x_pix   < 140.    c_pix = '³'. ENDIF.
  IF x_pix   < 120.    c_pix = '+'. ENDIF.
  IF x_pix   < 100.    c_pix = '*'. ENDIF.
  IF x_pix   < 080.    c_pix = 'C'. ENDIF.
  IF x_pix   < 060.    c_pix = 'Y'. ENDIF.
*  IF x_pix   < 010.    c_pix = 'X'. ENDIF.
  IF x_pix   < 040.    c_pix = '§'. ENDIF.


*  IF x_pix   < 240.    c_pix = '.'. ENDIF.
*  IF x_pix   < 220.    c_pix = '-'. ENDIF.
*  IF x_pix   < 200.    c_pix = ':'. ENDIF.
*  IF x_pix   < 180.    c_pix = ';'. ENDIF.
*  IF x_pix   < 160.    c_pix = '!'. ENDIF.
*  IF x_pix   < 140.    c_pix = '³'. ENDIF.
*  IF x_pix   < 120.    c_pix = '+'. ENDIF.
*  IF x_pix   < 100.    c_pix = '*'. ENDIF.
*  IF x_pix   < 080.    c_pix = 'C'. ENDIF.
*  IF x_pix   < 060.    c_pix = 'Y'. ENDIF.
*  IF x_pix   < 040.    c_pix = 'X'. ENDIF.
*  IF x_pix   < 020.    c_pix = '§'. ENDIF.


***  IF x_pix   < 240.    c_pix = '.'. ENDIF.
***  IF x_pix   < 220.    c_pix = '-'. ENDIF.
***  IF x_pix   < 200.    c_pix = ':'. ENDIF.
****  IF x_pix   < 180.    c_pix = ','. ENDIF.
***  IF x_pix   < 160.    c_pix = ';'. ENDIF.
****  IF x_pix   < 140.    c_pix = '!'. ENDIF.
***  IF x_pix   < 120.    c_pix = '³'. ENDIF.
***  IF x_pix   < 100.    c_pix = '+'. ENDIF.
***  IF x_pix   < 080.    c_pix = '*'. ENDIF.
***  IF x_pix   < 060.    c_pix = 'X'. ENDIF.
****  IF x_pix   < 040.    c_pix = '8'. ENDIF.
***  IF x_pix   < 020.    c_pix = '§'. ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  READ_PICTURE_CONVERT_TO_BMP
*&---------------------------------------------------------------------*
FORM read_picture_convert_to_bmp CHANGING rc TYPE sy-subrc.
  TRY.
      DATA: lv_filesize TYPE w3param-cont_len.
      DATA: it_bin_data TYPE w3mimetabtype.
      DATA: lv_mimetype TYPE string.
      DATA: lv_xres     TYPE i.
      DATA: lv_yres     TYPE i.
      DATA: lv_xdpi     TYPE i.
      DATA: lv_ydpi     TYPE i.
      DATA: lv_bitdepth TYPE i.

      rc = 0.

* Bild auf Appl. Server hochladen (binary)
      cl_gui_frontend_services=>gui_upload( EXPORTING filename   = |{ p_fname }|
                                                      filetype   = 'BIN'
                                            IMPORTING filelength = lv_filesize
                                            CHANGING  data_tab   = it_bin_data ).

* solix -> xstring
      DATA(lv_img_data) = cl_bcs_convert=>solix_to_xstring( it_solix = it_bin_data ).

* FXS-Objekt holen
      DATA(o_ip) = NEW cl_fxs_image_processor( ).

* Bild zum Konverter hinzufügen
      DATA(lv_hndl) = o_ip->add_image( iv_data = lv_img_data ).

* Infos holen
      o_ip->get_info( EXPORTING iv_handle   = lv_hndl
                      IMPORTING ev_mimetype = lv_mimetype
                                ev_xres     = lv_xres
                                ev_yres     = lv_yres
                                ev_xdpi     = lv_xdpi
                                ev_ydpi     = lv_ydpi
                                ev_bitdepth = lv_bitdepth ).

* Infos ausgeben
*      WRITE: / 'MIME-Type:', lv_mimetype.
*      WRITE: / '        X:', lv_xres.
*      WRITE: / '        Y:', lv_yres.
*      WRITE: / '    X-DPI:', lv_xdpi.
*      WRITE: / '    Y-DPI:', lv_ydpi.
*      WRITE: / '      Bit:', lv_bitdepth.

      p_mime     = lv_mimetype.
      p_xres     = lv_xres.
      p_yres     = lv_yres.
      p_xdpi     = lv_xdpi.
      p_ydpi     = lv_ydpi.
      p_bitdep   = lv_bitdepth.

* Größe ändern (Resize)
      o_ip->resize( EXPORTING iv_handle = lv_hndl
                              iv_xres   = p_width
                              iv_yres   = p_height ).

* Konvertierung (Convert) nach JPG
* Zielformate können nur sein (andernfalls gibt es eine Exception vom Typ cx_sy_range_out_of_bounds):
*   cl_fxs_mime_types=>co_image_bitmap
*   cl_fxs_mime_types=>co_image_png
*   cl_fxs_mime_types=>co_image_jpeg
      o_ip->convert( EXPORTING iv_handle = lv_hndl
                               iv_format = cl_fxs_mime_types=>co_image_bitmap ).

* Infos holen
      o_ip->get_info( EXPORTING iv_handle   = lv_hndl
                      IMPORTING ev_mimetype = lv_mimetype
                                ev_xres     = lv_xres
                                ev_yres     = lv_yres
                                ev_xdpi     = lv_xdpi
                                ev_ydpi     = lv_ydpi
                                ev_bitdepth = lv_bitdepth ).

* Infos ausgeben
**      WRITE: / 'MIME-Type:', lv_mimetype.
**      WRITE: / '        X:', lv_xres.
**      WRITE: / '        Y:', lv_yres.
**      WRITE: / '    X-DPI:', lv_xdpi.
**      WRITE: / '    Y-DPI:', lv_ydpi.
**      WRITE: / '      Bit:', lv_bitdepth.
      CLEAR lv_img_conv_data.
* Binärdaten (xstring) des Bildes holen
      lv_img_conv_data = o_ip->get_image( EXPORTING iv_handle = lv_hndl ).

    CATCH cx_root INTO DATA(e_txt).
      WRITE: / e_txt->get_text( ).
      rc = 8.
  ENDTRY.
ENDFORM.
*--------------------------------------------------------------------*
FORM create_contr_array USING    val        TYPE i
                        CHANGING cont_array TYPE ty_contr_array.
  DATA factor TYPE p DECIMALS 4.
  DATA k      TYPE i.
  DATA inx    TYPE i.

  CLEAR cont_array.

  factor = 1 + val / 100.
  DO 255 TIMES.
    inx = sy-index.
    k = round( val = ( inx - 128 ) * factor  dec = 0 )  + 128.
    IF k > 255.
      cont_array+inx(1) = 255.
    ELSEIF k < 0.
      cont_array+inx(1) = 0.
    ELSE.
      cont_array+inx(1) = k.
    ENDIF.
  ENDDO.
ENDFORM.
*--------------------------------------------------------------------*
* FORM Create_ascii_pic.
*--------------------------------------------------------------------*
FORM create_ascii_pic.

  DATA x_width(4)        TYPE x.
  DATA x_height(4)       TYPE x.
  DATA x_bpp(2)          TYPE x.
*  DATA x_compression(4)  TYPE x.
*  DATA i_compression     TYPE i.
*  DATA x_color_planes(2) TYPE x.
*  DATA x_colors_used(4)  TYPE x.
  DATA x_header_size(4)  TYPE x.
  DATA x_data_offset(4)  TYPE x.
*  DATA x_size(4)         TYPE x.

  magic_number     = lv_img_conv_data+0(2).
*  x_size           = lv_img_conv_data+2(4).
  x_data_offset    = lv_img_conv_data+10(4).
  x_header_size    = lv_img_conv_data+14(4).
*  read4 x_size size.
  read4 x_data_offset data_offset.
  read4 x_header_size header_size.

* Bitmap Header
  IF header_size = 40. "Windows V3 Format
    x_width        = lv_img_conv_data+18(4).
    x_height       = lv_img_conv_data+22(4).
    x_bpp          = lv_img_conv_data+28(2).
*    x_compression  = lv_img_conv_data+30(4).
*    x_color_planes = lv_img_conv_data+26(2).
*    x_colors_used  = lv_img_conv_data+46(4).
    read4 x_width  width.
    read4 x_height height.
    read2 x_bpp    bpp.
*    read4 x_compression i_compression.
*    read2 x_color_planes color_planes.
*    read4 x_colors_used colors_used.
  ELSE.
    RETURN.
  ENDIF.

  DATA x_data          TYPE xstring.
  DATA x_row           TYPE xstring.
  DATA i_num_pixels    TYPE i.
  DATA i_counter       TYPE i.
  DATA i_counter2      TYPE i.
  DATA l_width         TYPE i.
  DATA bytes_per_pixel TYPE i.
*  DATA l_len           TYPE i.
  DATA pad             TYPE i.
  DATA l_mod           TYPE i.
*  DATA l_size          TYPE i.
*  DATA l_blue          TYPE i.
*  DATA l_red           TYPE i.
*  DATA l_green         TYPE i.
  DATA x_pixel         TYPE xstring.
  DATA l_scale         TYPE i.

  x_data          = lv_img_conv_data+data_offset.
  bytes_per_pixel = bpp / 8.

  l_width         = width * bytes_per_pixel.
  i_num_pixels    = width.
  CLEAR    xbmp_gray.

  xbmp_first = 'X'.

  l_mod  = l_width MOD 4.
  pad    = 4 - l_mod.
  IF pad = 4. pad = 0.  ENDIF.

  l_width = l_width + pad.
*  l_len = xstrlen( x_data ).
*  l_size = bytes_per_pixel.

  CLEAR it_bb.

  DO height TIMES.
    x_row = x_data+i_counter(l_width).
    CLEAR i_counter2.
    CLEAR bb.
    DO i_num_pixels TIMES.
      x_pixel =  x_row+i_counter2(bytes_per_pixel).

* in Graustufen umrechnen
      l_scale = x_pixel+0(1) * co_blue +
                x_pixel+1(1) * co_red  +
                x_pixel+2(1) * co_green.

      IF l_scale > 255. l_scale = 255. ENDIF.

      IF xbmp_first = 'X'.
        xpix = l_scale.
        xbmp_gray = xbmp_gray && xpix.
      ENDIF.

*     255  - weiss
* Graustufen in Buchstaben umsetzen
      PERFORM set_pic USING l_scale
                      CHANGING pix.

      CONCATENATE bb pix INTO bb RESPECTING BLANKS.

      i_counter2 = i_counter2 + bytes_per_pixel.
    ENDDO.

    INSERT bb INTO it_bb INDEX 1.
    i_counter = i_counter + l_width.
  ENDDO.
  CLEAR xbmp_first.
  FREE lv_img_conv_data.
  xbmp_work = xbmp_gray.
ENDFORM.


*--------------------------------------------------------------------*
FORM show_pic.
  sy-lsind = 0.

  but_down = 'O'.
  WRITE : / icon_information AS ICON HOTSPOT,   'Bild Info          ', but_down.

  but_down = 'S'.
  WRITE : / icon_other_object AS ICON HOTSPOT,  'Bild neu scalieren ', but_down.

  but_down = 'C'.
  WRITE : / icon_execute_object AS ICON HOTSPOT,'Kontrast ändern    ', but_down.

  but_down = 'B'.
  WRITE : / icon_execute_object AS ICON HOTSPOT,'Helligkeit ändern  ', but_down.

  but_down = 'R'.
  WRITE : / icon_system_undo AS ICON HOTSPOT,   'Auf Original zurück', but_down.

  SET BLANK LINES ON.
  LOOP AT it_bb INTO bb.
    WRITE : / bb.
  ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  GET_CHECK_UCOMM
*&---------------------------------------------------------------------*
FORM get_check_ucomm .

  CASE but_down.
    WHEN 'C'.
      CALL SELECTION-SCREEN 0200 STARTING AT 1 1.
      PERFORM create_contr_array USING    p_con
                             CHANGING cont_array.
      IF sy-fdpos > 30. RETURN. ENDIF.
    WHEN 'B'.
      CALL SELECTION-SCREEN 0201 STARTING AT 1 1.
      IF sy-fdpos > 30. RETURN. ENDIF.
    WHEN 'O'.
      CALL SELECTION-SCREEN 0202 STARTING AT 1 1.
      RETURN.
    WHEN 'S'.
      p_w = p_width.
      p_h = p_height.
      CALL SELECTION-SCREEN 0203 STARTING AT 1 1.
      IF sy-fdpos > 30. RETURN. ENDIF.
      p_width  = p_w.
      p_height = p_h.
      PERFORM read_picture_convert_to_bmp CHANGING retc.
      IF retc NE 0. RETURN. ENDIF.

      IF  p_con NE 0.
        PERFORM create_contr_array USING    p_con
                                   CHANGING cont_array.
      ENDIF.

      IF retc EQ 0.
        PERFORM create_ascii_pic.
      ENDIF.

  ENDCASE.

  PERFORM change_pic USING but_down.

ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  at_line_selection
*&---------------------------------------------------------------------*
FORM at_line_selection.
  CLEAR but_down.
  READ CURRENT LINE FIELD VALUE but_down.
  IF sy-subrc NE 0. EXIT. ENDIF.
  PERFORM get_check_ucomm.
ENDFORM.                    " at_line_selection
*&---------------------------------------------------------------------*
*&      Form  CHANGE_CONTR
*&---------------------------------------------------------------------*
FORM change_pic USING mode TYPE c .
  DATA x_data          TYPE xstring.
  DATA x_row           TYPE xstring.
  DATA i_counter       TYPE i.
  DATA i_counter2      TYPE i.
  DATA l_scale         TYPE i.
  DATA pixc            TYPE c LENGTH 1.

  IF mode = 'R'. xbmp_work = xbmp_gray.  ENDIF.

  x_data = xbmp_work.

  CLEAR it_bb.

  i_counter = 0.

  CLEAR xbmp_work.

  DO p_height TIMES.
    x_row = x_data+i_counter(p_width).
    CLEAR i_counter2.
    CLEAR bb.
    DO p_width TIMES.
      l_scale = x_row+i_counter2(1).

* Falls Kontrast
      IF mode = 'C'.
        IF p_con NE 0.
          l_scale = cont_array+l_scale(1).
        ENDIF.
      ENDIF.
* Helligkeit.
      IF mode = 'B'.
        IF p_bri  NE 0.
          l_scale = round( val = l_scale * p_bri dec = 0 ).
          IF l_scale < 0.
            l_scale = 0.
          ELSEIF l_scale > 255.
            l_scale = 255.
          ENDIF.
        ENDIF.
      ENDIF.

      xpix = l_scale.
      xbmp_work = xbmp_work && xpix.

*     255  - weiss
* Graustufen in Buchstaben umsetzen
      PERFORM set_pic USING l_scale
                      CHANGING pixc.

      CONCATENATE bb pixc INTO bb RESPECTING BLANKS.

      i_counter2 = i_counter2 + 1.
    ENDDO.

    INSERT bb INTO it_bb INDEX 1.
    i_counter = i_counter + p_width.
  ENDDO.

  PERFORM show_pic.

ENDFORM.

Folgende Benutzer bedankten sich beim Autor edwin für den Beitrag (Insgesamt 2):
ewxIHe


Seite 1 von 1

Über diesen Beitrag


Unterstütze die Community und teile den Beitrag für mehr Leser und besseren Inhalt:

Vergleichbare Themen

ASCII Zeichen
von gabrielgn » 12.06.2008 07:47
ASCII to Char-Table
von holderda » 27.06.2017 16:25
Tabelle als Ascii ausgeben
von BMWi801 » 05.03.2018 13:26
Convertierung von CHAR nach ASCII
von niermaj » 06.09.2005 13:48
ASCII - Zeichen konvertieren (FuBa)
von Andreas G » 19.09.2006 14:06