1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Nokia 6100 Library

Discussion in 'Microcontrollers' started by AtomSoft, Oct 27, 2009.

  1. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    this is very frustrating heh .. in my mind it should be working but in reality it isnt..

    My screen is setup to write from

    LEFT to Right then top to bottom like:
    [​IMG]

    So in VB im reading from left to right and top to bottom .. placing the data into a listbox and looping through the listbox (visual array)

    I divide each pixel RGB by 17 so 255 == 15 (aka 0x0F) which is the max for each RGB (0xFFF)

    Now i get black pretty good but i get sukish results with the rest... here is my 50x50 image i want to convert: (i had to convert to jpg to place here)
    [​IMG]

    VB Code:
    Code (text):

    Private OnBits(0 To 31) As Long

    Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, _
        ByVal y As Long) As Long


        Dim Red As Byte
       Dim Green As Byte
       Dim Blue As Byte
        Dim Color As Long

    Public Function LShiftLong(ByVal Value As Long, _
        ByVal Shift As Integer) As Long
     
        MakeOnBits
     
        If (Value And (2 ^ (31 - Shift))) Then GoTo OverFlow
     
        LShiftLong = ((Value And OnBits(31 - Shift)) * (2 ^ Shift))
     
        Exit Function

    OverFlow:
     
        LShiftLong = ((Value And OnBits(31 - (Shift + 1))) * _
           (2 ^ (Shift))) Or &H80000000
     
    End Function

    Public Function RShiftLong(ByVal Value As Long, _
       ByVal Shift As Integer) As Long
        Dim hi As Long
        MakeOnBits
        If (Value And &H80000000) Then hi = &H40000000
     
        RShiftLong = (Value And &H7FFFFFFE) \ (2 ^ Shift)
        RShiftLong = (RShiftLong Or (hi \ (2 ^ (Shift - 1))))
    End Function
     


    Private Sub MakeOnBits()
        Dim j As Integer, _
            v As Long
     
        For j = 0 To 30
     
            v = v + (2 ^ j)
            OnBits(j) = v
     
        Next j
     
        OnBits(j) = v + &H80000000

    End Sub

    Private Sub Command1_Click()
    'The following code example counts the number of red pixels on the active form:
    ' assumes that form's ScaleMode
    ' is set to 3 - Pixels
    Text2 = ""
    Text4 = ""
    Text3 = ""
    Dim x As Long, y As Long
    Dim h As Long, count As Long
    Dim q As Long, w As Long
    Dim tmp As Integer
    Dim tmpf As Integer
    ' cache form's hDC property
    h = Picture1.hdc

    'For y = 0 To Picture1.ScaleHeight - 1
    '    For x = 0 To Picture1.ScaleWidth - 1
    Dim hMax As Integer, wMax As Integer
    hMax = Picture1.ScaleHeight - 1
    wMax = Picture1.ScaleWidth - 1

    For y = 0 To hMax
        For x = 0 To wMax
            Color = GetPixel(h, x, y)
            Red = Color And &HFF&                    'mind the ampersand at the end of constant
            Green = (Color And &HFF00&) / 256        'bit masking and "shift"
            Blue = (Color And &HFF0000) / 65535      'bit masking and "shift"

            Red = Red / 17
            Green = Green / 17
            Blue = Blue / 17
                   
            List1.AddItem Red
            List1.AddItem Green
            List1.AddItem Blue
           
            Text2.Text = Text2.Text & Red & "-" & Green & "-" & Blue & ", "
        Next
    Next

    h = List1.ListCount - 1
    If h Mod 2 = 1 Then List1.AddItem 0
    count = List1.ListCount / 2

    h = List1.ListCount - 1


    For y = 0 To List1.ListCount - 1
        tmpf = 0
       
        For x = 0 To 1
            tmpf = tmpf Or Val(List1.List(y + x))
                 
            If tmpf > 9 Then
                Select Case List1.List(y + x)
                    Case 10
                        tmpf = tmpf Or &HA
                    Case 11
                        tmpf = tmpf Or &HB
                    Case 12
                        tmpf = tmpf Or &HC
                    Case 13
                        tmpf = tmpf Or &HD
                    Case 14
                        tmpf = tmpf Or &HE
                    Case 15
                        tmpf = tmpf Or &HF
                End Select
            End If
            If x = 0 Then
                tmpf = LShiftLong(tmpf, 4)
            End If
        Next x
        y = y + 2
        List2.AddItem tmpf
    Next y
    Text3 = Str(List1.ListCount - 1)
    Text4 = Str(List2.ListCount - 1)
    End Sub

    Private Sub List1_Click()
    Dim x As Integer, y As Integer
    Text2.Text = ""
    For x = 0 To List1.ListCount - 1
        Text2.Text = Text2.Text & List1.List(x) & ","
            y = y + 1
            If y = 40 Then
                y = 0
                Text2.Text = Text2.Text & vbNewLine
            End If
    Next x

    Text2.Text = Mid$(Text2.Text, 1, (Len(Text2.Text) - 1))

    End Sub

    Private Sub List2_Click()
    Dim x As Integer, y As Integer
    Text2.Text = ""
    For x = 0 To List2.ListCount - 1
        Text2.Text = Text2.Text & List2.List(x) & ","
        y = y + 1
            If y = 40 Then
                y = 0
                Text2.Text = Text2.Text & vbNewLine
            End If
    Next x

    Text2.Text = Mid$(Text2.Text, 1, (Len(Text2.Text) - 1))

    End Sub

    Private Sub Picture1_Click()
    Picture1.Picture = LoadPicture("d:\colors.bmp")
    End Sub


     
     

    Attached Files:

  2. Mr RB

    Mr RB Well-Known Member

    Joined:
    Jul 22, 2008
    Messages:
    4,716
    Likes:
    194
    Location:
    Out there
    To convert the pixel properly from 0-255 range down to 0-15 range, use this;
    Code (text):

    unsigned char newpixel;   // 8bit var is ok
    unsigned int temp;    // must be 16bit var!

      temp = (pixel + 8);
      newpixel = (temp / 16);
     
    The operation of adding half the divisor then dividing will give you the best colour match (ie least possible error).
     
  3. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    Thanks will try
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US

    Thanks. I also figured out another issue and this is what i get so far:

    [​IMG]
     

    Attached Files:

  6. Mr RB

    Mr RB Well-Known Member

    Joined:
    Jul 22, 2008
    Messages:
    4,716
    Likes:
    194
    Location:
    Out there
    Top line looks ok, then you get a 45 degree angle so you have a 1 pixel error on each line.

    Check your line length values, and for loops etc. Could be a -1 in the wrong spot... ;)
     
  7. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    OMG YES!!!!!!!! i did it:

    [​IMG]
     

    Attached Files:

  8. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    Look a bear lol:

    [​IMG]
     

    Attached Files:

    • bear.jpg
      bear.jpg
      File size:
      306.3 KB
      Views:
      405
  9. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    The main program... can someone test it out for me to see if it works well on other computers. Like does it seem to work well heh

    Tiny Version (NO VB6 RUNTIME FILES INCLUDED) (9kb ZIP)
    http://atomsofttech.info/code/Nokia12Bit_tiny.zip

    Full Version (VB6 RUNTIME FILES INCLUDED) (1,179kb ZIP)
    http://atomsofttech.info/code/Nokia12Bit_full.zip



    EDIT: Just noticed they were making txt files instead of h (headers) so i just fixed it and re-uploaded it

    heh was bored....

    [​IMG]


    Looks way better live
     

    Attached Files:

    • yay.jpg
      yay.jpg
      File size:
      352.8 KB
      Views:
      522
    Last edited: Oct 31, 2009
  10. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    I am currently Cleaning up the code and will post a full source and schematic and VB program all in one. This way people can use it.

    The VB source will not be shared until i fix it up more...

    Also i will be adding the ability to select between 8, 12 and 16 bit color for LCD image conversion and code soon.
     
  11. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    so if i needed to make a RGB pixel to 8 bit LCD which is RRRGGGBB can i simply
    Code (text):


    unsigned char newpixel;   // 8bit var is ok
    unsigned int temp;    // must be 16bit var!

      temp = (RED);
      newRED = (temp / (255/7));

      temp = (GREEN);
      newGREEN = (temp / (255/7));

      temp = (BLUE);
      newBLUE = (temp / (255/3));

    //NewPixel 8 Bit would be shifted like:

    newpixel= (NewRED<<4) | (NewGREEN<<2) | NewBLUE;

     
    Would it be something like that?
     
    Last edited: Nov 1, 2009
  12. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    ok i got 8 bit mode and 12 bit mode working in VB6 now on to 16 bit
     
  13. csaba911

    csaba911 Member

    Joined:
    Jul 2, 2003
    Messages:
    242
    Likes:
    2
    Location:
    Canada
    White made of R=255 + G=255 + B=255 / 8bit+8bit+8bit= 24 bit
    Each color has 256 level, 0=off, 127 on 50%, 255 on 100%
    He use half of it R max 15+ G max 15+ B max 15 / 4bit+4bit+4bit=12 bit
    FF white only if you change all 3 channel "RGB" to FF

    Csaba
     
  14. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    Ok too much work for 16 bit and will waste to much space on pic to be usefull i think heh

    Here is a pic of the new version of the VB6 program.

    [​IMG]

    working on adding the 8 bit stuff to pic code. Should be easy
     

    Attached Files:

    Last edited: Nov 1, 2009
  15. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    for now i will leave this as is 12bit and PIC only. I have no need to make it otherwise...

    I will be working on storage needs now. SD+FAT... New idea and stuff comes to mind.
     
  16. Mr RB

    Mr RB Well-Known Member

    Joined:
    Jul 22, 2008
    Messages:
    4,716
    Likes:
    194
    Location:
    Out there
    That VB program's looking good . :)
     
  17. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    thanks to you it may include all the conversions
     
  18. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    This is version 1 rev 2

    Currently 8bit and 12bit are working 100%

    [​IMG]
     

    Attached Files:

  19. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    Hey guys this is eating up quite a bit of my time so i am omitting the 16bit part but the 8 and 12 bit works 100% and i also made a Color conversion part to this so you can convert colors from RGB to 8, 12 and 16 bit version based on this LCD of course


    [​IMG]
     

    Attached Files:

    • v3.jpg
      v3.jpg
      File size:
      170.8 KB
      Views:
      396
  20. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
  21. Sceadwian

    Sceadwian Banned

    Joined:
    Oct 27, 2006
    Messages:
    14,047
    Likes:
    141
    Location:
    Rochester, US
    You can get around bit depth in some specific applications by using a palleted image format, does the display support pallets? It's the simplest form of compression.
     

Share This Page