Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
wbmp.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "gwlib/gwlib.h"
#include "wbmp.h"

Go to the source code of this file.

Functions

WBMPwbmp_create_empty (void)
 
void wbmp_delete (WBMP *pic)
 
WBMPwbmp_create (int type, int width, int height, Octet *data, int flags)
 
int wbmp_create_stream (WBMP *pic, Octet **stream)
 

Function Documentation

WBMP* wbmp_create ( int  type,
int  width,
int  height,
Octet data,
int  flags 
)

Definition at line 94 of file wbmp.c.

References error(), NEGATIVE, REVERSE, reverse_octet(), type, and wbmp_create_empty().

95 {
96  WBMP *new;
97  int i, siz;
98  Octet val;
99 
100  new = wbmp_create_empty();
101 
102  new->type_field = type;
103  if (type == 0) {
104  new->fix_header_field = 0x00;
105  } else {
106  error(0, "WBMP type %d not supported", type);
107  return NULL;
108  }
109  new->width = width;
110  new->height = height;
111  siz = (width+7)/8 * height;
112 
113  new->main_image = gw_malloc(siz);
114  for(i=0; i < siz; i++) {
115  if (flags & REVERSE) val = reverse_octet(data[i]);
116  else val = data[i];
117  if (flags & NEGATIVE) val = ~val;
118  new->main_image[i] = val;
119  }
120  return new;
121 }
void error(int err, const char *fmt,...)
Definition: log.c:612
#define NEGATIVE
Definition: OTAbitmap.h:94
#define REVERSE
Definition: OTAbitmap.h:95
int type
Definition: smsc_cimd2.c:215
Octet reverse_octet(Octet source)
Definition: utils.c:511
Definition: wbmp.h:85
WBMP * wbmp_create_empty(void)
Definition: wbmp.c:69
unsigned char Octet
Definition: utils.h:75
WBMP* wbmp_create_empty ( void  )

Definition at line 69 of file wbmp.c.

Referenced by wbmp_create().

70 {
71  WBMP *new;
72 
73  new = gw_malloc(sizeof(WBMP));
74  memset(new, 0, sizeof(WBMP));
75  return new;
76 }
Definition: wbmp.h:85
int wbmp_create_stream ( WBMP pic,
Octet **  stream 
)

Definition at line 127 of file wbmp.c.

References debug(), error(), wbmp::height, wbmp::main_image, wbmp::type_field, wbmp::width, and write_variable_value().

128 {
129  Octet tmp_w[30], tmp_h[30];
130  int wl, hl, pic_size;
131 
132  wl = write_variable_value(pic->width, tmp_w);
133  hl = write_variable_value(pic->height, tmp_h);
134 
135  pic_size = ((pic->width+7)/8) * pic->height;
136 
137  if (pic->type_field != 0) {
138  error(0, "Unknown WBMP type %d, cannot convert", pic->type_field);
139  return -1;
140  }
141  *stream = gw_malloc(2+wl+hl+pic_size);
142  sprintf(*stream, "%c%c", 0x00, 0x00);
143  memcpy(*stream+2, tmp_w, wl);
144  memcpy(*stream+2+wl, tmp_h, hl);
145  memcpy(*stream+2+wl+hl, pic->main_image, pic_size);
146 
147  debug("util", 0, "picture %d x %d, stream length %d",
148  pic->width, pic->height, 2+wl+hl+pic_size);
149 
150  return (2+wl+hl+pic_size);
151 }
void error(int err, const char *fmt,...)
Definition: log.c:612
MultibyteInt height
Definition: wbmp.h:95
Octet * main_image
Definition: wbmp.h:96
MultibyteInt width
Definition: wbmp.h:94
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
int write_variable_value(MultibyteInt value, Octet *dest)
Definition: utils.c:490
MultibyteInt type_field
Definition: wbmp.h:86
unsigned char Octet
Definition: utils.h:75
void wbmp_delete ( WBMP pic)

Definition at line 80 of file wbmp.c.

References wbmp::animated_image, wbmp::animimg_count, wbmp::ext_header_field, and wbmp::main_image.

81 {
82  gw_free(pic->ext_header_field);
83  gw_free(pic->main_image);
84  if (pic->animated_image) {
85  int i;
86  for(i=0; i < pic->animimg_count; i++)
87  gw_free(pic->animated_image[i]);
88  gw_free(pic->animated_image);
89  }
90  gw_free(pic);
91 }
Octet * main_image
Definition: wbmp.h:96
ExtParam * ext_header_field
Definition: wbmp.h:92
int animimg_count
Definition: wbmp.h:98
Octet ** animated_image
Definition: wbmp.h:97
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.